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