|
25 | 25 | from aesara.graph.basic import Apply
|
26 | 26 | from aesara.graph.op import Op
|
27 | 27 | from aesara.tensor.nlinalg import det, eigh, matrix_inverse, trace
|
28 |
| -from aesara.tensor.random.basic import MultinomialRV, dirichlet, multivariate_normal, RandomVariable |
| 28 | +from aesara.tensor.random.basic import ( |
| 29 | + MultinomialRV, |
| 30 | + RandomVariable, |
| 31 | + dirichlet, |
| 32 | + multivariate_normal, |
| 33 | +) |
29 | 34 | from aesara.tensor.random.op import default_shape_from_params
|
30 | 35 | from aesara.tensor.random.utils import broadcast_params
|
31 | 36 | from aesara.tensor.slinalg import (
|
|
45 | 50 | from pymc3.distributions.dist_math import bound, factln, logpow
|
46 | 51 | from pymc3.distributions.distribution import Continuous, Discrete
|
47 | 52 | from pymc3.distributions.special import gammaln, multigammaln
|
48 |
| -from pymc3.math import kron_diag, kron_dot, kron_solve_lower, kronecker, sigmoid |
| 53 | +from pymc3.math import kron_diag, kron_dot, kron_solve_lower, kronecker |
49 | 54 |
|
50 | 55 | __all__ = [
|
51 | 56 | "MvNormal",
|
@@ -155,7 +160,7 @@ def quaddist_tau(delta, chol_mat):
|
155 | 160 |
|
156 | 161 |
|
157 | 162 | class MvNormal(Continuous):
|
158 |
| - R""" |
| 163 | + r""" |
159 | 164 | Multivariate normal log-likelihood.
|
160 | 165 |
|
161 | 166 | .. math::
|
@@ -250,7 +255,7 @@ def _distr_parameters_for_repr(self):
|
250 | 255 |
|
251 | 256 |
|
252 | 257 | class MvStudentT(Continuous):
|
253 |
| - R""" |
| 258 | + r""" |
254 | 259 | Multivariate Student-T log-likelihood.
|
255 | 260 |
|
256 | 261 | .. math::
|
@@ -363,7 +368,7 @@ def _distr_parameters_for_repr(self):
|
363 | 368 |
|
364 | 369 |
|
365 | 370 | class Dirichlet(Continuous):
|
366 |
| - R""" |
| 371 | + r""" |
367 | 372 | Dirichlet log-likelihood.
|
368 | 373 |
|
369 | 374 | .. math::
|
@@ -452,7 +457,7 @@ def rng_fn(cls, rng, n, p, size):
|
452 | 457 |
|
453 | 458 |
|
454 | 459 | class Multinomial(Discrete):
|
455 |
| - R""" |
| 460 | + r""" |
456 | 461 | Multinomial log-likelihood.
|
457 | 462 |
|
458 | 463 | Generalizes binomial distribution, but instead of each trial resulting
|
@@ -527,9 +532,7 @@ class DirichletMultinomialRV(RandomVariable):
|
527 | 532 | _print_name = ("DirichletMN", "\\operatorname{DirichletMN}")
|
528 | 533 |
|
529 | 534 | def _shape_from_params(self, dist_params, rep_param_idx=1, param_shapes=None):
|
530 |
| - return default_shape_from_params( |
531 |
| - self.ndim_supp, dist_params, rep_param_idx, param_shapes |
532 |
| - ) |
| 535 | + return default_shape_from_params(self.ndim_supp, dist_params, rep_param_idx, param_shapes) |
533 | 536 |
|
534 | 537 | @classmethod
|
535 | 538 | def rng_fn(cls, rng, n, a, size):
|
@@ -561,7 +564,7 @@ def rng_fn(cls, rng, n, a, size):
|
561 | 564 |
|
562 | 565 |
|
563 | 566 | class DirichletMultinomial(Discrete):
|
564 |
| - R"""Dirichlet Multinomial log-likelihood. |
| 567 | + r"""Dirichlet Multinomial log-likelihood. |
565 | 568 |
|
566 | 569 | Dirichlet mixture of Multinomials distribution, with a marginalized PMF.
|
567 | 570 |
|
@@ -616,10 +619,18 @@ def logp(value, n, a):
|
616 | 619 | -------
|
617 | 620 | TensorVariable
|
618 | 621 | """
|
| 622 | + n = intX(n) |
| 623 | + a = floatX(a) |
| 624 | + if value.ndim >= 1: |
| 625 | + n = at.shape_padright(n) |
| 626 | + if a.ndim > 1: |
| 627 | + a = at.shape_padleft(a) |
| 628 | + |
619 | 629 | sum_a = a.sum(axis=-1, keepdims=True)
|
620 | 630 | const = (gammaln(n + 1) + gammaln(sum_a)) - gammaln(n + sum_a)
|
621 | 631 | series = gammaln(value + a) - (gammaln(value + 1) + gammaln(a))
|
622 | 632 | result = const + series.sum(axis=-1, keepdims=True)
|
| 633 | + |
623 | 634 | # Bounds checking to confirm parameters and data meet all constraints
|
624 | 635 | # and that each observation value_i sums to n_i.
|
625 | 636 | return bound(
|
@@ -686,7 +697,7 @@ def __str__(self):
|
686 | 697 |
|
687 | 698 |
|
688 | 699 | class Wishart(Continuous):
|
689 |
| - R""" |
| 700 | + r""" |
690 | 701 | Wishart log-likelihood.
|
691 | 702 |
|
692 | 703 | The Wishart distribution is the probability distribution of the
|
@@ -798,7 +809,7 @@ def logp(self, X):
|
798 | 809 |
|
799 | 810 |
|
800 | 811 | def WishartBartlett(name, S, nu, is_cholesky=False, return_cholesky=False, initval=None):
|
801 |
| - R""" |
| 812 | + r""" |
802 | 813 | Bartlett decomposition of the Wishart distribution. As the Wishart
|
803 | 814 | distribution requires the matrix to be symmetric positive semi-definite
|
804 | 815 | it is impossible for MCMC to ever propose acceptable matrices.
|
@@ -903,7 +914,7 @@ def _lkj_normalizing_constant(eta, n):
|
903 | 914 |
|
904 | 915 |
|
905 | 916 | class _LKJCholeskyCov(Continuous):
|
906 |
| - R"""Underlying class for covariance matrix with LKJ distributed correlations. |
| 917 | + r"""Underlying class for covariance matrix with LKJ distributed correlations. |
907 | 918 | See docs for LKJCholeskyCov function for more details on how to use it in models.
|
908 | 919 | """
|
909 | 920 |
|
@@ -1083,7 +1094,7 @@ def _distr_parameters_for_repr(self):
|
1083 | 1094 |
|
1084 | 1095 |
|
1085 | 1096 | def LKJCholeskyCov(name, eta, n, sd_dist, compute_corr=False, store_in_trace=True, *args, **kwargs):
|
1086 |
| - R"""Wrapper function for covariance matrix with LKJ distributed correlations. |
| 1097 | + r"""Wrapper function for covariance matrix with LKJ distributed correlations. |
1087 | 1098 |
|
1088 | 1099 | This defines a distribution over Cholesky decomposed covariance
|
1089 | 1100 | matrices, such that the underlying correlation matrices follow an
|
@@ -1236,7 +1247,7 @@ def LKJCholeskyCov(name, eta, n, sd_dist, compute_corr=False, store_in_trace=Tru
|
1236 | 1247 |
|
1237 | 1248 |
|
1238 | 1249 | class LKJCorr(Continuous):
|
1239 |
| - R""" |
| 1250 | + r""" |
1240 | 1251 | The LKJ (Lewandowski, Kurowicka and Joe) log-likelihood.
|
1241 | 1252 |
|
1242 | 1253 | The LKJ distribution is a prior distribution for correlation matrices.
|
@@ -1379,20 +1390,15 @@ def logp(self, x):
|
1379 | 1390 | result = _lkj_normalizing_constant(eta, n)
|
1380 | 1391 | result += (eta - 1.0) * at.log(det(X))
|
1381 | 1392 | return bound(
|
1382 |
| - result, |
1383 |
| - X >= -1, |
1384 |
| - X <= 1, |
1385 |
| - matrix_pos_def(X), |
1386 |
| - eta > 0, |
1387 |
| - broadcast_conditions=False, |
| 1393 | + result, X >= -1, X <= 1, matrix_pos_def(X), eta > 0, broadcast_conditions=False |
1388 | 1394 | )
|
1389 | 1395 |
|
1390 | 1396 | def _distr_parameters_for_repr(self):
|
1391 | 1397 | return ["eta", "n"]
|
1392 | 1398 |
|
1393 | 1399 |
|
1394 | 1400 | class MatrixNormal(Continuous):
|
1395 |
| - R""" |
| 1401 | + r""" |
1396 | 1402 | Matrix-valued normal log-likelihood.
|
1397 | 1403 |
|
1398 | 1404 | .. math::
|
@@ -1651,7 +1657,7 @@ def _distr_parameters_for_repr(self):
|
1651 | 1657 |
|
1652 | 1658 |
|
1653 | 1659 | class KroneckerNormal(Continuous):
|
1654 |
| - R""" |
| 1660 | + r""" |
1655 | 1661 | Multivariate normal log-likelihood with Kronecker-structured covariance.
|
1656 | 1662 |
|
1657 | 1663 | .. math::
|
@@ -1898,7 +1904,7 @@ def _distr_parameters_for_repr(self):
|
1898 | 1904 |
|
1899 | 1905 |
|
1900 | 1906 | class CAR(Continuous):
|
1901 |
| - R""" |
| 1907 | + r""" |
1902 | 1908 | Likelihood for a conditional autoregression. This is a special case of the
|
1903 | 1909 | multivariate normal with an adjacency-structured covariance matrix.
|
1904 | 1910 |
|
|
0 commit comments