34
34
halfcauchy ,
35
35
halfnormal ,
36
36
invgamma ,
37
+ laplace ,
37
38
logistic ,
38
39
lognormal ,
39
40
normal ,
@@ -152,10 +153,16 @@ def default_transform(cls):
152
153
153
154
def transform_params (rv_var ):
154
155
_ , _ , _ , * args = rv_var .owner .inputs
155
- lower = args [cls .bound_args_indices [0 ]]
156
- upper = args [cls .bound_args_indices [1 ]]
156
+
157
+ lower , upper = None , None
158
+ if cls .bound_args_indices [0 ] is not None :
159
+ lower = args [cls .bound_args_indices [0 ]]
160
+ if cls .bound_args_indices [1 ] is not None :
161
+ upper = args [cls .bound_args_indices [1 ]]
162
+
157
163
lower = at .as_tensor_variable (lower ) if lower is not None else None
158
164
upper = at .as_tensor_variable (upper ) if upper is not None else None
165
+
159
166
return lower , upper
160
167
161
168
return transforms .interval (transform_params )
@@ -1505,37 +1512,17 @@ class Laplace(Continuous):
1505
1512
b: float
1506
1513
Scale parameter (b > 0).
1507
1514
"""
1515
+ rv_op = laplace
1508
1516
1509
- def __init__ (self , mu , b , * args , ** kwargs ):
1510
- super ().__init__ (* args , ** kwargs )
1511
- self .b = b = at .as_tensor_variable (floatX (b ))
1512
- self .mean = self .median = self .mode = self .mu = mu = at .as_tensor_variable (floatX (mu ))
1513
-
1514
- self .variance = 2 * self .b ** 2
1517
+ @classmethod
1518
+ def dist (cls , mu , b , * args , ** kwargs ):
1519
+ b = at .as_tensor_variable (floatX (b ))
1520
+ mu = at .as_tensor_variable (floatX (mu ))
1515
1521
1516
1522
assert_negative_support (b , "b" , "Laplace" )
1523
+ return super ().dist ([mu , b ], * args , ** kwargs )
1517
1524
1518
- def random (self , point = None , size = None ):
1519
- """
1520
- Draw random values from Laplace distribution.
1521
-
1522
- Parameters
1523
- ----------
1524
- point: dict, optional
1525
- Dict of variable values on which random values are to be
1526
- conditioned (uses default point if not specified).
1527
- size: int, optional
1528
- Desired size of random sample (returns one sample if not
1529
- specified).
1530
-
1531
- Returns
1532
- -------
1533
- array
1534
- """
1535
- # mu, b = draw_values([self.mu, self.b], point=point, size=size)
1536
- # return generate_samples(np.random.laplace, mu, b, dist_shape=self.shape, size=size)
1537
-
1538
- def logp (self , value ):
1525
+ def logp (value , mu , b ):
1539
1526
"""
1540
1527
Calculate log-probability of Laplace distribution at specified value.
1541
1528
@@ -1549,12 +1536,9 @@ def logp(self, value):
1549
1536
-------
1550
1537
TensorVariable
1551
1538
"""
1552
- mu = self .mu
1553
- b = self .b
1554
-
1555
1539
return - at .log (2 * b ) - abs (value - mu ) / b
1556
1540
1557
- def logcdf (self , value ):
1541
+ def logcdf (value , mu , b ):
1558
1542
"""
1559
1543
Compute the log of the cumulative distribution function for Laplace distribution
1560
1544
at the specified value.
@@ -1569,12 +1553,10 @@ def logcdf(self, value):
1569
1553
-------
1570
1554
TensorVariable
1571
1555
"""
1572
- a = self .mu
1573
- b = self .b
1574
- y = (value - a ) / b
1556
+ y = (value - mu ) / b
1575
1557
return bound (
1576
1558
at .switch (
1577
- at .le (value , a ),
1559
+ at .le (value , mu ),
1578
1560
at .log (0.5 ) + y ,
1579
1561
at .switch (
1580
1562
at .gt (y , 1 ),
@@ -1980,7 +1962,7 @@ def logcdf(self, value):
1980
1962
)
1981
1963
1982
1964
1983
- class Pareto (Continuous ):
1965
+ class Pareto (BoundedContinuous ):
1984
1966
r"""
1985
1967
Pareto log-likelihood.
1986
1968
@@ -2026,6 +2008,7 @@ class Pareto(Continuous):
2026
2008
Scale parameter (m > 0).
2027
2009
"""
2028
2010
rv_op = pareto
2011
+ bound_args_indices = (1 , None ) # lower-bounded by `m`
2029
2012
2030
2013
@classmethod
2031
2014
def dist (
@@ -2039,30 +2022,6 @@ def dist(
2039
2022
2040
2023
return super ().dist ([alpha , m ], ** kwargs )
2041
2024
2042
- def _random (self , alpha , m , size = None ):
2043
- u = np .random .uniform (size = size )
2044
- return m * (1.0 - u ) ** (- 1.0 / alpha )
2045
-
2046
- def random (self , point = None , size = None ):
2047
- """
2048
- Draw random values from Pareto distribution.
2049
-
2050
- Parameters
2051
- ----------
2052
- point: dict, optional
2053
- Dict of variable values on which random values are to be
2054
- conditioned (uses default point if not specified).
2055
- size: int, optional
2056
- Desired size of random sample (returns one sample if not
2057
- specified).
2058
-
2059
- Returns
2060
- -------
2061
- array
2062
- """
2063
- # alpha, m = draw_values([self.alpha, self.m], point=point, size=size)
2064
- # return generate_samples(self._random, alpha, m, dist_shape=self.shape, size=size)
2065
-
2066
2025
def logp (
2067
2026
value : Union [float , np .ndarray , TensorVariable ],
2068
2027
alpha : Union [float , np .ndarray , TensorVariable ],
0 commit comments