@@ -1377,49 +1377,53 @@ class Exponential(PositiveContinuous):
1377
1377
@classmethod
1378
1378
def dist (cls , lam , * args , ** kwargs ):
1379
1379
lam = at .as_tensor_variable (floatX (lam ))
1380
- # mean = 1.0 / lam
1381
- # median = mean * at.log(2)
1382
- # mode = at.zeros_like(lam)
1383
-
1384
- # variance = lam ** -2
1385
1380
1386
1381
assert_negative_support (lam , "lam" , "Exponential" )
1387
- return super ().dist ([lam ], ** kwargs )
1388
1382
1389
- def logp (value , lam ):
1383
+ # Aesara exponential op is parametrized in terms of mu (1/lam)
1384
+ return super ().dist ([at .inv (lam )], ** kwargs )
1385
+
1386
+ def logp (value , mu ):
1390
1387
"""
1391
1388
Calculate log-probability of Exponential distribution at specified value.
1392
1389
1393
1390
Parameters
1394
1391
----------
1395
1392
value: numeric
1396
- Value(s) for which log-probability is calculated. If the log probabilities for multiple
1397
- values are desired the values must be provided in a numpy array or aesara tensor
1393
+ Value(s) for which log-probability is calculated. If the log
1394
+ probabilities for multiple values are desired the values must be
1395
+ provided in a numpy array or aesara tensor
1398
1396
1399
1397
Returns
1400
1398
-------
1401
1399
TensorVariable
1402
1400
"""
1403
- return bound (at .log (lam ) - lam * value , value >= 0 , lam > 0 )
1401
+ lam = at .inv (mu )
1402
+ return bound (
1403
+ at .log (lam ) - lam * value ,
1404
+ value >= 0 ,
1405
+ lam > 0 ,
1406
+ )
1404
1407
1405
- def logcdf (value , lam ):
1408
+ def logcdf (value , mu ):
1406
1409
r"""
1407
1410
Compute the log of cumulative distribution function for the Exponential distribution
1408
1411
at the specified value.
1409
1412
1410
1413
Parameters
1411
1414
----------
1412
1415
value: numeric or np.ndarray or aesara.tensor
1413
- Value(s) for which log CDF is calculated. If the log CDF for multiple
1414
- values are desired the values must be provided in a numpy array or aesara tensor.
1416
+ Value(s) for which log CDF is calculated. If the log CDF for
1417
+ multiple values are desired the values must be provided in a numpy
1418
+ array or aesara tensor.
1415
1419
1416
1420
Returns
1417
1421
-------
1418
1422
TensorVariable
1419
1423
"""
1420
- a = lam * value
1424
+ lam = at . inv ( mu )
1421
1425
return bound (
1422
- log1mexp (a ),
1426
+ log1mexp (lam * value ),
1423
1427
0 <= value ,
1424
1428
0 <= lam ,
1425
1429
)
@@ -2371,15 +2375,13 @@ def dist(cls, alpha=None, beta=None, mu=None, sigma=None, sd=None, no_assert=Fal
2371
2375
alpha , beta = cls .get_alpha_beta (alpha , beta , mu , sigma )
2372
2376
alpha = at .as_tensor_variable (floatX (alpha ))
2373
2377
beta = at .as_tensor_variable (floatX (beta ))
2374
- # mean = alpha / beta
2375
- # mode = at.maximum((alpha - 1) / beta, 0)
2376
- # variance = alpha / beta ** 2
2377
2378
2378
2379
if not no_assert :
2379
2380
assert_negative_support (alpha , "alpha" , "Gamma" )
2380
2381
assert_negative_support (beta , "beta" , "Gamma" )
2381
2382
2382
- return super ().dist ([alpha , at .inv (beta )], ** kwargs )
2383
+ # The Aesara `GammaRV` `Op` will invert the `beta` parameter itself
2384
+ return super ().dist ([alpha , beta ], ** kwargs )
2383
2385
2384
2386
@classmethod
2385
2387
def get_alpha_beta (cls , alpha = None , beta = None , mu = None , sigma = None ):
@@ -2397,45 +2399,47 @@ def get_alpha_beta(cls, alpha=None, beta=None, mu=None, sigma=None):
2397
2399
2398
2400
return alpha , beta
2399
2401
2400
- def _distr_parameters_for_repr (self ):
2401
- return ["alpha" , "beta" ]
2402
-
2403
- def logp (value , alpha , beta ):
2402
+ def logp (value , alpha , inv_beta ):
2404
2403
"""
2405
2404
Calculate log-probability of Gamma distribution at specified value.
2406
2405
2407
2406
Parameters
2408
2407
----------
2409
2408
value: numeric
2410
- Value(s) for which log-probability is calculated. If the log probabilities for multiple
2411
- values are desired the values must be provided in a numpy array or `TensorVariable`.
2409
+ Value(s) for which log-probability is calculated. If the log
2410
+ probabilities for multiple values are desired the values must be
2411
+ provided in a numpy array or `TensorVariable`.
2412
2412
2413
2413
Returns
2414
2414
-------
2415
2415
TensorVariable
2416
2416
"""
2417
+ beta = at .inv (inv_beta )
2417
2418
return bound (
2418
2419
- gammaln (alpha ) + logpow (beta , alpha ) - beta * value + logpow (value , alpha - 1 ),
2419
2420
value >= 0 ,
2420
2421
alpha > 0 ,
2421
2422
beta > 0 ,
2422
2423
)
2423
2424
2424
- def logcdf (value , alpha , beta ):
2425
+ def logcdf (value , alpha , inv_beta ):
2425
2426
"""
2426
2427
Compute the log of the cumulative distribution function for Gamma distribution
2427
2428
at the specified value.
2428
2429
2429
2430
Parameters
2430
2431
----------
2431
2432
value: numeric or np.ndarray or `TensorVariable`
2432
- Value(s) for which log CDF is calculated. If the log CDF for multiple
2433
- values are desired the values must be provided in a numpy array or `TensorVariable`.
2433
+ Value(s) for which log CDF is calculated. If the log CDF for
2434
+ multiple values are desired the values must be provided in a numpy
2435
+ array or `TensorVariable`.
2434
2436
2435
2437
Returns
2436
2438
-------
2437
2439
TensorVariable
2438
2440
"""
2441
+ beta = at .inv (inv_beta )
2442
+
2439
2443
# Avoid C-assertion when the gammainc function is called with invalid values (#4340)
2440
2444
safe_alpha = at .switch (at .lt (alpha , 0 ), 0 , alpha )
2441
2445
safe_beta = at .switch (at .lt (beta , 0 ), 0 , beta )
0 commit comments