/usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__/multinomial.cpython-36.pyc (5020B)
3
Eg @ sX d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z G dd deZ
dS ) N)inf)Distribution)Categorical)constraints)
broadcast_allc s e Zd ZU dZejejdZe e
dd Ze
dd Zd fd d
Z
d fdd Zd
d Zejddddd Ze
dd Ze
dd Ze
dd Zej fddZdd Z ZS )Multinomiala#
Creates a Multinomial distribution parameterized by :attr:`total_count` and
either :attr:`probs` or :attr:`logits` (but not both). The innermost dimension of
:attr:`probs` indexes over categories. All other dimensions index over batches.
Note that :attr:`total_count` need not be specified if only :meth:`log_prob` is
called (see example below)
.. note:: The `probs` argument must be non-negative, finite and have a non-zero sum,
and it will be normalized to sum to 1 along the last dimension. :attr:`probs`
will return this normalized value.
The `logits` argument will be interpreted as unnormalized log probabilities
and can therefore be any real number. It will likewise be normalized so that
the resulting probabilities sum to 1 along the last dimension. :attr:`logits`
will return this normalized value.
- :meth:`sample` requires a single shared `total_count` for all
parameters and samples.
- :meth:`log_prob` allows different `total_count` for each parameter and
sample.
Example::
>>> m = Multinomial(100, torch.tensor([ 1., 1., 1., 1.]))
>>> x = m.sample() # equal probability of 0, 1, 2, 3
tensor([ 21., 24., 30., 25.])
>>> Multinomial(probs=torch.tensor([1., 1., 1., 1.])).log_prob(x)
tensor([-4.1338])
Args:
total_count (int): number of trials
probs (Tensor): event probabilities
logits (Tensor): event log probabilities (unnormalized)
)probslogitsc C s | j | j S )N)r total_count)self r K/usr/local/lib64/python3.6/site-packages/torch/distributions/multinomial.pymean1 s zMultinomial.meanc C s | j | j d| j S )N )r
r )r r r r
variance5 s zMultinomial.variancer Nc sX t |tstd|| _t||d| _| jj}| jjdd }tt | j
|||d d S )Nz*inhomogeneous total_count is not supported)r r r )
validate_args)
isinstanceintNotImplementedErrorr
r _categoricalbatch_shapeparam_shapesuperr __init__)r r
r r r r event_shape) __class__r r
r 9 s
zMultinomial.__init__c sP | j t|}tj|}| j|_| jj||_tt|j|| j dd | j
|_
|S )NF)r )Z_get_checked_instancer torchSizer
r expandr r r _validate_args)r r Z _instancenew)r r r
r B s
zMultinomial.expandc O s | j j||S )N)r _new)r argskwargsr r r
r" K s zMultinomial._newT)Zis_discreteZ event_dimc C s t j| jS )N)r Zmultinomialr
)r r r r
supportN s zMultinomial.supportc C s | j jS )N)r r )r r r r
r R s zMultinomial.logitsc C s | j jS )N)r r )r r r r
r V s zMultinomial.probsc C s | j jS )N)r r )r r r r
r Z s zMultinomial.param_shapec C s t j|}| jjt j| jf| }tt|j }|j|j d |j
| }|j| j|j
}|jd|t j| |j| jS )Nr r r )r r r sampler
listrangeZdimappendpopZpermuter! Z_extended_shapeZzero_Zscatter_add_Z ones_likeZtype_asr )r Zsample_shapeZsamplesZshifted_idxcountsr r r
r&