/usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__/dirichlet.cpython-36.pyc (4085B)
3
Eg @ sd d dl Z d dlmZ d dlmZ d dlmZ d dlmZ dd Z G dd d eZ
G d
d deZdS ) N)Function)once_differentiable)constraints)ExponentialFamilyc C s8 |j ddj|}tj| ||}||| | j dd S )N Tr )sumZ expand_astorchZ_dirichlet_grad)x
concentrationgrad_outputtotalZgrad r I/usr/local/lib64/python3.6/site-packages/torch/distributions/dirichlet.py_Dirichlet_backward s r c @ s( e Zd Zedd Zeedd ZdS )
_Dirichletc C s t j|}| j|| |S )N)r Z_sample_dirichletZsave_for_backward)ctxr r
r r r forward s
z_Dirichlet.forwardc C s | j \}}t|||S )N)Z
saved_tensorsr )r r r
r r r r backward s
z_Dirichlet.backwardN)__name__
__module____qualname__staticmethodr r r r r r r r s r c s e Zd ZdZdejejdiZejZ dZ
d fdd Zd fdd Zf fd
dZ
dd
Zedd Zedd Zdd Zedd Zdd Z ZS ) Dirichleta
Creates a Dirichlet distribution parameterized by concentration :attr:`concentration`.
Example::
>>> m = Dirichlet(torch.tensor([0.5, 0.5]))
>>> m.sample() # Dirichlet distributed with concentrarion concentration
tensor([ 0.1046, 0.8954])
Args:
concentration (Tensor): concentration parameter of the distribution
(often referred to as alpha)
r r TNc sR |j dk rtd|| _|jd d |jdd }}tt| j|||d d S )Nr z;`concentration` parameter must be at least one-dimensional.)
validate_argsr r )Zdim
ValueErrorr shapesuperr __init__)selfr r batch_shapeevent_shape) __class__r r r / s
zDirichlet.__init__c sN | j t|}tj|}| jj|| j |_tt|j|| jdd | j |_ |S )NF)r )
Z_get_checked_instancer r Sizer expandr! r r _validate_args)r r Z _instancenew)r" r r r$ 6 s
zDirichlet.expandc C s | j |}| jj|}tj|S )N)Z_extended_shaper r$ r apply)r Zsample_shaper r r r r rsample> s
zDirichlet.rsamplec C sN | j r| j| tj|| jd jdtj| jjd tj| jjd S )Ng ?r r r r )r% Z_validate_sampler logr r lgamma)r valuer r r log_probC s
*zDirichlet.log_probc C s | j | j jdd S )Nr Tr )r r )r r r r meanJ s zDirichlet.meanc C s0 | j jdd}| j || j |jd|d S )Nr T r )r r pow)r Zcon0r r r varianceN s zDirichlet.variancec C sb | j jd}| j jd}tj| j jdtj| || tj| | j d tj| j jd S )Nr g ?r r r r )r sizer r r* Zdigamma)r kZa0r r r entropyS s ,zDirichlet.entropyc C s | j fS )N)r )r r r r _natural_paramsZ s zDirichlet._natural_paramsc C s |j jdtj |jd S )Nr r r )r* r r )r r
r r r _log_normalizer^ s zDirichlet._log_normalizer)N)N)r r r __doc__r ZindependentZpositiveZarg_constraintsZsimplexZsupportZhas_rsampler r$ r( r, propertyr- r0 r3 r4 r5
__classcell__r r )r" r r s
r )r Ztorch.autogradr Ztorch.autograd.functionr Ztorch.distributionsr Ztorch.distributions.exp_familyr r r r r r r r
s