/usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__/independent.cpython-36.pyc (4506B)
3
Eg @ sL d dl Z d dlmZ d dlmZ d dlmZ d dlmZ G dd deZ dS ) N)constraints)Distribution)_sum_rightmost)Dictc s e Zd ZU dZi Zeeejf d fdd Z d fdd Z
edd Zed d
Z
ejdd Zed
d Zedd Zej fddZej fddZdd Zdd Zd ddZdd Z ZS )!Independenta
Reinterprets some of the batch dims of a distribution as event dims.
This is mainly useful for changing the shape of the result of
:meth:`log_prob`. For example to create a diagonal Normal distribution with
the same shape as a Multivariate Normal distribution (so they are
interchangeable), you can::
>>> loc = torch.zeros(3)
>>> scale = torch.ones(3)
>>> mvn = MultivariateNormal(loc, scale_tril=torch.diag(scale))
>>> [mvn.batch_shape, mvn.event_shape]
[torch.Size(()), torch.Size((3,))]
>>> normal = Normal(loc, scale)
>>> [normal.batch_shape, normal.event_shape]
[torch.Size((3,)), torch.Size(())]
>>> diagn = Independent(normal, 1)
>>> [diagn.batch_shape, diagn.event_shape]
[torch.Size(()), torch.Size((3,))]
Args:
base_distribution (torch.distributions.distribution.Distribution): a
base distribution
reinterpreted_batch_ndims (int): the number of batch dims to
reinterpret as event dims
Nc s |t |jkr$tdj|t |j|j|j }|t |j }|d t || }|t || d }|| _|| _tt| j |||d d S )NzYExpected reinterpreted_batch_ndims <= len(base_distribution.batch_shape), actual {} vs {})
validate_args)
lenbatch_shape
ValueErrorformatevent_shape base_distreinterpreted_batch_ndimssuperr __init__)selfZbase_distributionr r shapeZ event_dimr r ) __class__ K/usr/local/lib64/python3.6/site-packages/torch/distributions/independent.pyr $ s zIndependent.__init__c s` | j t|}tj|}| jj|| jd | j |_| j|_tt|j || jdd | j
|_
|S )NF)r )Z_get_checked_instancer torchSizer
expandr r r r Z_validate_args)r r Z _instancenew)r r r r 1 s
zIndependent.expandc C s | j jS )N)r
has_rsample)r r r r r ; s zIndependent.has_rsamplec C s | j dkrdS | jjS )Nr F)r r
has_enumerate_support)r r r r r ? s
z!Independent.has_enumerate_supportc C s | j j}| jrtj|| j}|S )N)r
supportr r Zindependent)r resultr r r r E s zIndependent.supportc C s | j jS )N)r
mean)r r r r r L s zIndependent.meanc C s | j jS )N)r
variance)r r r r r P s zIndependent.variancec C s | j j|S )N)r
sample)r sample_shaper r r r T s zIndependent.samplec C s | j j|S )N)r
rsample)r r! r r r r" W s zIndependent.rsamplec C s | j j|}t|| jS )N)r
log_probr r )r valuer# r r r r# Z s zIndependent.log_probc C s | j j }t|| jS )N)r
entropyr r )r r% r r r r% ^ s
zIndependent.entropyTc C s | j dkrtd| jj|dS )Nr z5Enumeration over cartesian product is not implemented)r )r NotImplementedErrorr
enumerate_support)r r r r r r' b s
zIndependent.enumerate_supportc C s | j jdj| j| j S )Nz({}, {}))r __name__r r
r )r r r r __repr__g s zIndependent.__repr__)N)N)T)r(
__module____qualname____doc__Zarg_constraintsr strr
Constraintr r propertyr r Zdependent_propertyr r r r r r r" r# r% r' r)
__classcell__r r )r r r s
r )
r Ztorch.distributionsr Z torch.distributions.distributionr Ztorch.distributions.utilsr typingr r r r r r
s