/usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__
NameSizeModeActions
bernoulli.cpython-36.pyc44450644editdlrm
beta.cpython-36.pyc36820644editdlrm
binomial.cpython-36.pyc47610644editdlrm
categorical.cpython-36.pyc58130644editdlrm
cauchy.cpython-36.pyc33100644editdlrm
chi2.cpython-36.pyc14190644editdlrm
constraints.cpython-36.pyc222170644editdlrm
constraint_registry.cpython-36.pyc98950644editdlrm
continuous_bernoulli.cpython-36.pyc80770644editdlrm
dirichlet.cpython-36.pyc40850644editdlrm
distribution.cpython-36.pyc118220644editdlrm
exponential.cpython-36.pyc33630644editdlrm
exp_family.cpython-36.pyc28760644editdlrm
fishersnedecor.cpython-36.pyc32120644editdlrm
gamma.cpython-36.pyc34550644editdlrm
geometric.cpython-36.pyc41830644editdlrm
gumbel.cpython-36.pyc28640644editdlrm
half_cauchy.cpython-36.pyc29300644editdlrm
half_normal.cpython-36.pyc28210644editdlrm
independent.cpython-36.pyc45060644editdlrm
kl.cpython-36.pyc258440644editdlrm
kumaraswamy.cpython-36.pyc30400644editdlrm
laplace.cpython-36.pyc34420644editdlrm
lkj_cholesky.cpython-36.pyc45750644editdlrm
logistic_normal.cpython-36.pyc23200644editdlrm
log_normal.cpython-36.pyc24380644editdlrm
lowrank_multivariate_normal.cpython-36.pyc80740644editdlrm
mixture_same_family.cpython-36.pyc70730644editdlrm
multinomial.cpython-36.pyc50200644editdlrm
multivariate_normal.cpython-36.pyc85340644editdlrm
negative_binomial.cpython-36.pyc41490644editdlrm
normal.cpython-36.pyc41380644editdlrm
one_hot_categorical.cpython-36.pyc51730644editdlrm
pareto.cpython-36.pyc25160644editdlrm
poisson.cpython-36.pyc26820644editdlrm
relaxed_bernoulli.cpython-36.pyc55950644editdlrm
relaxed_categorical.cpython-36.pyc55630644editdlrm
studentT.cpython-36.pyc34830644editdlrm
transformed_distribution.cpython-36.pyc73350644editdlrm
transforms.cpython-36.pyc429810644editdlrm
uniform.cpython-36.pyc35800644editdlrm
utils.cpython-36.pyc68020644editdlrm
von_mises.cpython-36.pyc50790644editdlrm
weibull.cpython-36.pyc27370644editdlrm
__init__.cpython-36.pyc59810644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__/kl.cpython-36.pyc (25844B)
3 Eg.u@s6UddlZddlZddlmZddlmZmZmZmZddl Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ>ddl?m@Z@mAZBiZCiZDeeeefefDdd ZEeGd!d"d"eFZGd#d$ZHd%d&ZId'd(ZJd)d*ZKd+d,ZLeEe e d-d.ZMeEeed/d0ZNeEeed1d2ZOeEeed3d4ZPeEeed5d6ZQeEeed7d8ZReEeed9d:ZSeEeed;d<ZTeEe!e!d=d>ZUeEe%e%d?d@ZVeEe#e#dAdBZWeEe'e'dCdDZXeEe+e+dEdFZYeEe-e-dGdHZZeEe1e-dIdJZ[eEe-e1dKdLZ\eEe1e1dMdNZ]eEe4e4dOdPZ^eEe6e6dQdRZ_eEe8e8dSdTZ`eEe:e:dUdVZaeEee>dYdZZceEe e:d[d\ZdeEeed]d^ZeeEee8d_d`ZfeEeedadbZgeEee!dcddZheEee4dedfZieEee>dgdhZjeEee8didjZkeEeedkdlZleEee4dmdnZmeEee>dodpZneEeeeEeeeEee8eEee>dqdrZoeEee!dsdtZpeEee%dudvZqeEee4dwdxZreEe!eeEe!eeEe!e8eEe!e>dydzZseEe!ed{d|ZteEe!e%d}d~ZueEe!e4ddZveEe%eeEe%eeEe%eeEe%e!eEe%e8eEe%e>ddZweEe%e4ddZxeEe+eeEe+eeEe+eeEe+e!eEe+e8eEe+e>ddZyeEe+e4ddZzeEe4eeEe4eeEe4eeEe4e!eEe4e8eEe4e>ddZ{eEe4e%ddZ|eEe8eeEe8eeEe8e>ddZ}eEe8eddZ~eEe8e!ddZeEe8e4ddZeEe:e eEe:eddZeEe>eddZeEe>eddZeEe>eddZeEe>e!ddZeEe>e%ddZeEe>e4ddZeEe>e8ddZeEe)e)ddZeEeeddZdS)N)total_ordering)TypeDictCallableTuple)inf) Bernoulli)Beta)Binomial) Categorical)Cauchy)ContinuousBernoulli) Dirichlet) Distribution) Exponential)ExponentialFamily)Gamma) Geometric)Gumbel) HalfNormal) Independent)Laplace)LowRankMultivariateNormal_batch_lowrank_logdet_batch_lowrank_mahalanobis)MultivariateNormal_batch_mahalanobis)Normal)OneHotCategorical)Pareto)Poisson)TransformedDistribution)Uniform)_sum_rightmosteuler_constantcsZtt r$ttr$tdjtt rHttrHtdjfdd}|S)a[ Decorator to register a pairwise function with :meth:`kl_divergence`. Usage:: @register_kl(Normal, Normal) def kl_normal_normal(p, q): # insert implementation here Lookup returns the most specific (type,type) match ordered by subclass. If the match is ambiguous, a `RuntimeWarning` is raised. For example to resolve the ambiguous situation:: @register_kl(BaseP, DerivedQ) def kl_version1(p, q): ... @register_kl(DerivedP, BaseQ) def kl_version2(p, q): ... you should register a third most-specific implementation, e.g.:: register_kl(DerivedP, DerivedQ)(kl_version1) # Break the tie. Args: type_p (type): A subclass of :class:`~torch.distributions.Distribution`. type_q (type): A subclass of :class:`~torch.distributions.Distribution`. z8Expected type_p to be a Distribution subclass but got {}z8Expected type_q to be a Distribution subclass but got {}cs|tf<tj|S)N) _KL_REGISTRY _KL_MEMOIZEclear)fun)type_ptype_qB/usr/local/lib64/python3.6/site-packages/torch/distributions/kl.py decoratorGs zregister_kl..decorator) isinstancetype issubclassr TypeErrorformat)r*r+r.r,)r*r+r- register_kl(s r4c@s*eZdZdgZddZddZddZdS) _MatchtypescGs ||_dS)N)r6)selfr6r,r,r-__init__Ssz_Match.__init__cCs |j|jkS)N)r6)r7otherr,r,r-__eq__Vsz _Match.__eq__cCs8x2t|j|jD] \}}t||s&dS||k rPqWdS)NFT)zipr6r1)r7r9xyr,r,r-__le__Ys  z _Match.__le__N)__name__ __module__ __qualname__ __slots__r8r:r>r,r,r,r-r5Osr5c sfddtD}|stStdd|Dj\}}tdd|Dj\}}t||f}t||f}||k rtjdjjj|j|jt|S)zP Find the most specific approximate match, assuming single inheritance. cs,g|]$\}}t|rt|r||fqSr,)r1).0Zsuper_pZsuper_q)r*r+r,r- fsz _dispatch_kl..css|]}t|VqdS)N)r5)rCmr,r,r- msz_dispatch_kl..css|]}tt|VqdS)N)r5reversed)rCrEr,r,r-rFnsz;Ambiguous kl_divergence({}, {}). Please register_kl({}, {})) r&NotImplementedminr6warningswarnr3r?RuntimeWarning) r*r+matchesZleft_pZleft_qZright_qZright_pZleft_funZ right_funr,)r*r+r- _dispatch_klbs  rNcCs tj|tS)zI Helper function for obtaining infinite KL Divergence throughout )torchZ full_liker)tensorr,r,r-_infinite_likexsrQcCs ||jS)z2 Utility function for calculating x log x )log)rPr,r,r-_x_log_xsrScCsD|jd}|jd}|jd||jdjd}|j|jddS) zp Utility function for calculating the trace of XX^{T} with X having arbitrary trailing batch dimensions rNrUrUrV)sizeZreshapepowsumshape)ZbmatnrEZ flat_tracer,r,r-_batch_trace_XXTs  r\c Csjytt|t|f}Wn:tk rRtt|t|}|tt|t|f<YnX|tkr`t|||S)a" Compute Kullback-Leibler divergence :math:`KL(p \| q)` between two distributions. .. math:: KL(p \| q) = \int p(x) \log\frac {p(x)} {q(x)} \,dx Args: p (Distribution): A :class:`~torch.distributions.Distribution` object. q (Distribution): A :class:`~torch.distributions.Distribution` object. Returns: Tensor: A batch of KL divergences of shape `batch_shape`. Raises: NotImplementedError: If the distribution types have not been registered via :meth:`register_kl`. )r'r0KeyErrorrNrHNotImplementedError)pqr)r,r,r- kl_divergencesracCsx|j|j|jj}t||jdk<d||jdk<d|jd|jd|jj}t||jdk<d||jdk<||S)Nrr)probsrRr)r_r`t1t2r,r,r-_kl_bernoulli_bernoullis"rec Cs|j|j}|j|j}|jj|jj|j}|jj|jj|j}|j|jtj|j}|j|jtj|j}||tj|}|||||S)N)concentration1concentration0lgammarOdigamma) r_r`Z sum_params_pZ sum_params_qrcrdt3t4t5r,r,r- _kl_beta_betas  rmcCsh|j|jkjrtd|j|j|j|j|j j|j j}|j|jk}t||||<|S)NzKKL between Binomials where q.total_count > p.total_count is not implemented)Z total_countanyr^rblogitslog1prQ)r_r`klZinf_idxsr,r,r-_kl_binomial_binomials 0 rrcCsD|j|j|j}t||jdkj|<d||jdkj|<|jdS)NrrrU)rbrorZ expand_asrY)r_r`tr,r,r-_kl_categorical_categoricalsrtcCsL|j|j|j}|jtj|j }|j tj|j }|||S)N)meanro_cont_bern_log_normrOrprb)r_r`rcrdrjr,r,r--_kl_continuous_bernoulli_continuous_bernoullisrwcCs||jjd}|jjd}|j|j}|jj|jjjd}|j|j}|jj|jjd}||||jdS)NrrUrUrUrUrU) concentrationrYrhri unsqueeze)r_r`Zsum_p_concentrationZsum_q_concentrationrcrdrjrkr,r,r-_kl_dirichlet_dirichlets   rzcCs"|j|j}|j }||dS)Nr)raterR)r_r`Z rate_ratiorcr,r,r-_kl_exponential_exponentials  r|c Cst|t|kstddd|jD}|j}|j|}tjj|j|dd}|j||}x:t|||D]*\}}} ||| } |t | t |j 8}qjW|S)NzThe cross KL-divergence between different exponential families cannot be computed using Bregman divergencescSsg|]}|jjqSr,)detachZrequires_grad_)rCnpr,r,r-rDsz+_kl_expfamily_expfamily..T)Z create_graph) r0r^Z_natural_paramsZ_log_normalizerrOZautogradZgradrYr;r$len event_shape) r_r`Z p_nparamsZ q_nparamsZ lg_normalZ gradientsresultZpnpZqnpgZtermr,r,r-_kl_expfamily_expfamilys  rcCsn|j|j|jj}tj|jtj|j}|j|jtj|j}|j|j|j|j}||||S)N)rxr{rRrOrhri)r_r`rcrdrjrkr,r,r-_kl_gamma_gamma s rcCsl|j|j}|j|j}|j|j}|j ||}|t}tj|d|j|}|||dtS)Nr)scalelocrR _euler_gammarOexprh)r_r`Zct1Zct2Zct3rcrdrjr,r,r-_kl_gumbel_gumbels   rcCs$|j tj|j |j|jS)N)entropyrOrprbro)r_r`r,r,r-_kl_geometric_geometricsrcCst|j|jS)N)_kl_normal_normal base_dist)r_r`r,r,r-_kl_halfnormal_halfnormal#srcCsV|j|j}|j|jj}|j }||j}|tj| |j}|||dS)Nr)rrabsrRrOr)r_r` scale_ratioZ loc_abs_diffrcrdrjr,r,r-_kl_laplace_laplace(s    rc Cs|j|jkrtdt|j|j|jt|j|j|j}t|j|j|j|j|j}|jjdd |jj d }t j ||jddd}|j|jj d }t |j|jjj d }t ||jjj d }t |j|j} |||| } d|| ||jdS)NzKL-divergence between two Low Rank Multivariate Normals with different event shapes cannot be computedrrTF)upperrg?rUrVrVrUrUrV)r ValueErrorr_unbroadcasted_cov_factor_unbroadcasted_cov_diag_capacitance_trilrr transposeryrOtriangular_solverYr\rsqrtsqrtmatmul) r_r`term1term3 qWt_qDinvAterm21term22Zterm23Zterm24term2r,r,r-7_kl_lowrankmultivariatenormal_lowrankmultivariatenormal3s(       rc Cs|j|jkrtdt|j|j|jd|jjd d djj d }t |j|j|j |j |j}|jj d d |jj d}tj||jddd}t|j|jjj d}t|j|j}||}d||||jdS)NzKL-divergence between two (Low Rank) Multivariate Normals with different event shapes cannot be computedrTr)dim1dim2F)rrg?rVrUrUrUrVrVrU)rrrrrr_unbroadcasted_scale_trildiagonalrRrYrrrryrOrr\rr) r_r`rrrrrrrr,r,r-0_kl_multivariatenormal_lowrankmultivariatenormalOs"      rc Cs(|j|jkrtdd|jjd d djjd t|j|j|j }t |j|j |j }t j j|jjdd |jjdd }|jd}|jj|||f}|jj|||jjdf}t j|jjj|||f}tt j||ddd} tt j||ddd} | | } d|| ||jdS)NzKL-divergence between two (Low Rank) Multivariate Normals with different event shapes cannot be computedrTr)rrrF)rg?rVrUrUrVrVrU)rrrrrRrYrrrrrrrO_C _infer_sizerZexpandZ cov_factorrWZ diag_embedrr\r) r_r`rrcombined_batch_shaper[ q_scale_trilZ p_cov_factorZ p_cov_diagrrrr,r,r-0_kl_lowrankmultivariatenormal_multivariatenormalhs&    rc Cs|j|jkrtd|jjd d djjd |jjd d djjd}tjj|jj dd|jj dd}|jd}|jj |||f}|jj |||f}t tj ||ddd}t |j|j|j}|d|||S)NzvKL-divergence between two Multivariate Normals with different event shapes cannot be computedrTr)rrrF)rg?rVrUrUrVrUrUrVrV)rrrrrRrYrOrrrZrr\rrr) r_r`Z half_term1rr[rZ p_scale_trilrrr,r,r-)_kl_multivariatenormal_multivariatenormals  rcCsB|j|jjd}|j|j|jjd}d||d|jS)NrTg?r)rrXrrR)r_r`Z var_ratiorcr,r,r-rsrcCst|j|jS)N)rtZ _categorical)r_r`r,r,r-'_kl_onehotcategorical_onehotcategoricalsrcCsX|j|j}|j|j}|j|j}|j }|||d}t||jj|jjk<|S)Nr)ralpharRrsupport lower_bound)r_r`rZ alpha_ratiorcrdrr,r,r-_kl_pareto_paretos   rcCs&|j|jj|jj|j|jS)N)r{rR)r_r`r,r,r-_kl_poisson_poissonsrcCs.|j|jkrt|j|jkr tt|j|jS)N)Z transformsr^rrar)r_r`r,r,r-_kl_transformed_transformeds   rcCs<|j|j|j|jj}t||j|jk|j|jkB<|S)N)highlowrRr)r_r`rr,r,r-_kl_uniform_uniformsrcCs |j |j|jj|jS)N)rrbr{rR)r_r`r,r,r-_kl_bernoulli_poissonsrcCs,|j |j|jtj|j |jS)N)rrurorOrprbrv)r_r`r,r,r-_kl_beta_continuous_bernoullisrcCs t|jS)N)rQrf)r_r`r,r,r-_kl_beta_infinitysrcCs,|j |jj|j|j|j|jS)N)rr{rRrfrg)r_r`r,r,r-_kl_beta_exponentialsrcCsp|j }|jj|j|jj}|jd|jj|j|jj}|j|j|j|j}||||S)Nr)rrxrhr{rRrfrirg)r_r`rcrdrjrkr,r,r-_kl_beta_gammas  $rc Cs|j|j|j}|jjd}|j }d|dtjj}|d||j|jd|jdd}|j|}|jjdd}||||||S)NrTg?r) rfrgrrXrmathpirRr) r_r`ZE_beta var_normalrcrdrjrkrlr,r,r-_kl_beta_normals  * rcCs>|j |j|jj}t||j|jjk|j|jjkB<|S)N)rrrrRrrr upper_bound)r_r`rr,r,r-_kl_beta_uniforms rcCs t|jS)N)rQrb)r_r`r,r,r-!_kl_continuous_bernoulli_infinitysrcCs"|j tj|j|j|jS)N)rrOrRr{ru)r_r`r,r,r-$_kl_continuous_bernoulli_exponentialsrcCsz|j }dtjdtjtj|j|jtj|j}|jtj|j d|j|j dtj|j}|||S)Ng?g@) rrrRrrOZsquarerrZvarianceru)r_r`rcrdrjr,r,r-_kl_continuous_bernoulli_normals 22rcCsV|j |j|jj}tjtjtj|j|jj tj |j|jj tj |t |S)N)rrrrRrOwheremaxgerrler ones_liker)r_r`rr,r,r- _kl_continuous_bernoulli_uniform srcCs t|jS)N)rQr{)r_r`r,r,r-_kl_exponential_infinitysrcCsB|j|j}|j tj|}|||jj|jtdtS)Nr)r{rxrOrRrhr)r_r`Zratiorcr,r,r-_kl_exponential_gammas rcCsR|j|j}|j|j}|jd}tj|||d}|j}||||S)Nr)r{rrrRrOr reciprocal)r_r`scale_rate_prodloc_scale_ratiorcrdrjr,r,r-_kl_exponential_gumbel#s    rcCsp|jjd}|jjd}dtj||dtj}|j}|j|j}|jjdd}|d||||S)NrTg?r) rrXr{rOrRrrrr)r_r`rZrate_sqrrcrdrjrkr,r,r-_kl_exponential_normal/s   rcCs t|jS)N)rQrx)r_r`r,r,r-_kl_gamma_infinity:srcCs&|j |jj|j|j|jS)N)rr{rRrx)r_r`r,r,r-_kl_gamma_exponentialBsrcCs~|j|j}|j|j}|jd|jj|jj|j}|j|j|}tj|d|j j |j |}|||S)Nr) r{rrrxrirhrRrOrrrX)r_r`Zbeta_scale_prodrrcrdrjr,r,r-_kl_gamma_gumbelGs   $$rcCs|jjd}|jjd}dtj||dtj|j|jj}d|jjd|j|}|j |j|j}d|j jd}||jd|jj ||||S)NrTg?r) rrXr{rOrRrrrxrhrri)r_r`rZbeta_sqrrcrdrjrkr,r,r-_kl_gamma_normalSs  ,rcCs t|jS)N)rQr)r_r`r,r,r-_kl_gumbel_infinity^srcCsx|j|j}|tjdtjj}tj|djdd}|j|jt|j|jjdd}| ||tdS)NrTg?r)rrrrrRrXrr)r_r`Z param_ratiorcrdrjr,r,r-_kl_gumbel_normaljs  &rcCs t|jS)N)rQr)r_r`r,r,r-_kl_laplace_infinityssrcCs~|jjd}|jjd|}dtjd|tj}d|jjd}|j|j}d|jjd}| |||||dS)NrTg?r)rrXrOrRrrr)r_r`rZscale_sqr_var_ratiorcrdrjrkr,r,r-_kl_laplace_normal}s  rcCs t|jS)N)rQr)r_r`r,r,r-_kl_normal_infinitysrcCs||j|j}|j|jjd}|j|j}|jd}||}tj| d||}| ||ddtjdtjS)NrTg?r)rrrXrRrOrrr)r_r`Zmean_scale_ratioZvar_scale_sqr_ratiorrcrdrjr,r,r-_kl_normal_gumbels   rcCs t|jS)N)rQr)r_r`r,r,r-_kl_pareto_infinitysrcCsZ|j|j}|j|j}|jj}|j||jd}|||d}t||jdk<|S)Nr)rr{rrRrr)r_r`rrcrdrjrr,r,r-_kl_pareto_exponentials  rcCs|jj|jj}|jj|}|jj|j|jj}d|j|}|j|j|j|jd}||||d}t||jdk<|S)Nr)rrRrrrxrhr{r)r_r` common_termrcrdrjrkrr,r,r-_kl_pareto_gammasrc Csd|jjd}|j|jd}tjdtj|j|j|jj}|jj}|j|jd|jd}|j||jjd}|||||d}t ||jdk<|S)NrTr) rrXrrrrrRrrr) r_r`rrrcrdrjrkrr,r,r-_kl_pareto_normals& rcCs t|jS)N)rQr{)r_r`r,r,r-_kl_poisson_infinitysrcCs|j|j}tj|}|jdt|jt|j||}|jdtd|jtd|j||}|jj|jj|j|jj}||||}t||j|j j k|j|j j kB<|S)Nr) rrrOrRrfrSrgrhrrrr)r_r`rrcrdrjrkrr,r,r-_kl_uniform_betas  &.$ rcCsh|j |j|jtj|j |j}tjtjtj |j |j j tj |j|j jtj|t|S)N)rrurorOrprbrvrrrrrrrrrrr)r_r`rr,r,r- _kl_uniform_continuous_bernoullis,rcCsB|j|j|jd|j|j|jj}t||j|jjk<|S)NrT)r{rrrRrrr)r_r`rr,r,r-_kl_uniform_exponetials,rcCs|j|j}|j}|jj|j|jj}d|jt|jt|j||}|j|j|jd}| |||}t||j|jj k<|S)NrrT) rrrRrxrhr{rSrrr)r_r`rrcrdrjrkrr,r,r-_kl_uniform_gammas &rcCsn|j|j|j}|j|j|j}|j|j|j}|jd||}|tj| tj| }||S)Ng?)rrrrrRrOr)r_r`rZ high_loc_diffZ low_loc_diffrcrdr,r,r-_kl_uniform_gumbels rcCst|j|j}tjtjd|j|j}|jdd}|j|jd|jdjd}|d|||jjdS)NrT g?) rrrrrrrRrXr)r_r`rrcrdrjr,r,r-_kl_uniform_normals   rcCsl|j|j}|j|jj|j|j}t|jt|j||}||jd|}t||j|jj k<|S)Nr) rrrrrXrRrSrrr)r_r`Zsupport_uniformrcrdrr,r,r-_kl_uniform_paretos  rcCs*|j|jkrtt|j|j}t||jS)N)Zreinterpreted_batch_ndimsr^rarr$)r_r`rr,r,r-_kl_independent_independents rcCsD|j|jjd|j|jjdj}d|j|jj}||S)NrT)rrXrrR)r_r`rcrdr,r,r-_kl_cauchy_cauchy s(r)rrJ functoolsrtypingrrrrrOZ torch._sixrZ bernoullir betar Zbinomialr Z categoricalr Zcauchyr Zcontinuous_bernoullirZ dirichletr distributionrZ exponentialrZ exp_familyrgammarZ geometricrZgumbelrZ half_normalrZ independentrZlaplacerZlowrank_multivariate_normalrrrZmultivariate_normalrrnormalrZone_hot_categoricalrZparetor Zpoissonr!Ztransformed_distributionr"uniformr#utilsr$r%rr&r'r4objectr5rNrQrSr\rarermrrrtrwrzr|rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr,r,r,r-s                        '  $