@@ -1271,6 +1271,22 @@ def logcdf(value, alpha, beta):
1271
1271
)
1272
1272
1273
1273
1274
+ class KumaraswamyRV (RandomVariable ):
1275
+ name = "kumaraswamy"
1276
+ ndim_supp = 0
1277
+ ndims_params = [0 , 0 ]
1278
+ dtype = "floatX"
1279
+ _print_name = ("Kumaraswamy" , "\\ operatorname{Kumaraswamy}" )
1280
+
1281
+ @classmethod
1282
+ def rng_fn (cls , rng , a , b , size ):
1283
+ u = rng .uniform (size = size )
1284
+ return (1 - (1 - u ) ** (1 / b )) ** (1 / a )
1285
+
1286
+
1287
+ kumaraswamy = KumaraswamyRV ()
1288
+
1289
+
1274
1290
class Kumaraswamy (UnitContinuous ):
1275
1291
r"""
1276
1292
Kumaraswamy log-likelihood.
@@ -1313,67 +1329,54 @@ class Kumaraswamy(UnitContinuous):
1313
1329
b: float
1314
1330
b > 0.
1315
1331
"""
1332
+ rv_op = kumaraswamy
1316
1333
1317
- def __init__ (self , a , b , * args , ** kwargs ):
1318
- super ().__init__ (* args , ** kwargs )
1319
-
1320
- self .a = a = at .as_tensor_variable (floatX (a ))
1321
- self .b = b = at .as_tensor_variable (floatX (b ))
1322
-
1323
- ln_mean = at .log (b ) + at .gammaln (1 + 1 / a ) + at .gammaln (b ) - at .gammaln (1 + 1 / a + b )
1324
- self .mean = at .exp (ln_mean )
1325
- ln_2nd_raw_moment = (
1326
- at .log (b ) + at .gammaln (1 + 2 / a ) + at .gammaln (b ) - at .gammaln (1 + 2 / a + b )
1327
- )
1328
- self .variance = at .exp (ln_2nd_raw_moment ) - self .mean ** 2
1334
+ @classmethod
1335
+ def dist (cls , a , b , * args , ** kwargs ):
1336
+ a = at .as_tensor_variable (floatX (a ))
1337
+ b = at .as_tensor_variable (floatX (b ))
1329
1338
1330
1339
assert_negative_support (a , "a" , "Kumaraswamy" )
1331
1340
assert_negative_support (b , "b" , "Kumaraswamy" )
1332
1341
1333
- def _random (self , a , b , size = None ):
1334
- u = np .random .uniform (size = size )
1335
- return (1 - (1 - u ) ** (1 / b )) ** (1 / a )
1342
+ return super ().dist ([a , b ], * args , ** kwargs )
1336
1343
1337
- def random ( self , point = None , size = None ):
1344
+ def logp ( value , a , b ):
1338
1345
"""
1339
- Draw random values from Kumaraswamy distribution.
1346
+ Calculate log-probability of Kumaraswamy distribution at specified value .
1340
1347
1341
1348
Parameters
1342
1349
----------
1343
- point: dict, optional
1344
- Dict of variable values on which random values are to be
1345
- conditioned (uses default point if not specified).
1346
- size: int, optional
1347
- Desired size of random sample (returns one sample if not
1348
- specified).
1350
+ value: numeric
1351
+ Value(s) for which log-probability is calculated. If the log probabilities for multiple
1352
+ values are desired the values must be provided in a numpy array or Aesara tensor
1349
1353
1350
1354
Returns
1351
1355
-------
1352
- array
1356
+ TensorVariable
1353
1357
"""
1354
- # a, b = draw_values([self.a, self.b], point=point, size=size)
1355
- # return generate_samples(self._random, a, b, dist_shape=self.shape, size=size)
1358
+ logp = at .log (a ) + at .log (b ) + (a - 1 ) * at .log (value ) + (b - 1 ) * at .log (1 - value ** a )
1356
1359
1357
- def logp (self , value ):
1358
- """
1359
- Calculate log-probability of Kumaraswamy distribution at specified value.
1360
+ return bound (logp , value >= 0 , value <= 1 , a > 0 , b > 0 )
1361
+
1362
+ def logcdf (value , a , b ):
1363
+ r"""
1364
+ Compute the log of cumulative distribution function for the Kumaraswamy distribution
1365
+ at the specified value.
1360
1366
1361
1367
Parameters
1362
1368
----------
1363
- value: numeric
1364
- Value(s) for which log-probability is calculated. If the log probabilities for multiple
1365
- values are desired the values must be provided in a numpy array or Aesara tensor
1369
+ value: numeric or np.ndarray or aesara.tensor
1370
+ Value(s) for which log CDF is calculated. If the log CDF for
1371
+ multiple values are desired the values must be provided in a numpy
1372
+ array or Aesara tensor.
1366
1373
1367
1374
Returns
1368
1375
-------
1369
1376
TensorVariable
1370
1377
"""
1371
- a = self .a
1372
- b = self .b
1373
-
1374
- logp = at .log (a ) + at .log (b ) + (a - 1 ) * at .log (value ) + (b - 1 ) * at .log (1 - value ** a )
1375
-
1376
- return bound (logp , value >= 0 , value <= 1 , a > 0 , b > 0 )
1378
+ logcdf = log1mexp (- (b * at .log1p (- (value ** a ))))
1379
+ return bound (at .switch (value < 1 , logcdf , 0 ), value >= 0 , a > 0 , b > 0 )
1377
1380
1378
1381
1379
1382
class Exponential (PositiveContinuous ):
0 commit comments