@@ -770,9 +770,9 @@ def check_selfconsistency_discrete_logcdf(
770
770
err_msg = str (pt ),
771
771
)
772
772
773
- def check_int_to_1 (self , model , value , domain , paramdomains ):
773
+ def check_int_to_1 (self , model , value , domain , paramdomains , n_samples = 10 ):
774
774
pdf = model .fastfn (exp (model .logpt ))
775
- for pt in product (paramdomains , n_samples = 10 ):
775
+ for pt in product (paramdomains , n_samples = n_samples ):
776
776
pt = Point (pt , value = value .tag .test_value , model = model )
777
777
bij = DictToVarBijection (value , (), pt )
778
778
pdfx = bij .mapf (pdf )
@@ -902,6 +902,7 @@ def test_normal(self):
902
902
R ,
903
903
{"mu" : R , "sigma" : Rplus },
904
904
lambda value , mu , sigma : sp .norm .logcdf (value , mu , sigma ),
905
+ decimal = select_by_precision (float64 = 6 , float32 = 2 ),
905
906
)
906
907
907
908
def test_truncated_normal (self ):
@@ -941,25 +942,6 @@ def test_chi_squared(self):
941
942
lambda value , nu : sp .chi2 .logpdf (value , df = nu ),
942
943
)
943
944
944
- @pytest .mark .xfail (
945
- condition = (aesara .config .floatX == "float32" ),
946
- reason = "Poor CDF in SciPy. See scipy/scipy#869 for details." ,
947
- )
948
- def test_wald_scipy (self ):
949
- self .check_logp (
950
- Wald ,
951
- Rplus ,
952
- {"mu" : Rplus , "alpha" : Rplus },
953
- lambda value , mu , alpha : sp .invgauss .logpdf (value , mu = mu , loc = alpha ),
954
- decimal = select_by_precision (float64 = 6 , float32 = 1 ),
955
- )
956
- self .check_logcdf (
957
- Wald ,
958
- Rplus ,
959
- {"mu" : Rplus , "alpha" : Rplus },
960
- lambda value , mu , alpha : sp .invgauss .logcdf (value , mu = mu , loc = alpha ),
961
- )
962
-
963
945
@pytest .mark .parametrize (
964
946
"value,mu,lam,phi,alpha,logp" ,
965
947
[
@@ -979,7 +961,7 @@ def test_wald_scipy(self):
979
961
(50.0 , 15.0 , None , 0.666666 , 10.0 , - 5.6481874 ),
980
962
],
981
963
)
982
- def test_wald (self , value , mu , lam , phi , alpha , logp ):
964
+ def test_wald_logp_custom_points (self , value , mu , lam , phi , alpha , logp ):
983
965
# Log probabilities calculated using the dIG function from the R package gamlss.
984
966
# See e.g., doi: 10.1111/j.1467-9876.2005.00510.x, or
985
967
# http://www.gamlss.org/.
@@ -989,6 +971,27 @@ def test_wald(self, value, mu, lam, phi, alpha, logp):
989
971
decimals = select_by_precision (float64 = 6 , float32 = 1 )
990
972
assert_almost_equal (model .fastlogp (pt ), logp , decimal = decimals , err_msg = str (pt ))
991
973
974
+ def test_wald_logp (self ):
975
+ self .check_logp (
976
+ Wald ,
977
+ Rplus ,
978
+ {"mu" : Rplus , "alpha" : Rplus },
979
+ lambda value , mu , alpha : sp .invgauss .logpdf (value , mu = mu , loc = alpha ),
980
+ decimal = select_by_precision (float64 = 6 , float32 = 1 ),
981
+ )
982
+
983
+ @pytest .mark .xfail (
984
+ condition = (aesara .config .floatX == "float32" ),
985
+ reason = "Poor CDF in SciPy. See scipy/scipy#869 for details." ,
986
+ )
987
+ def test_wald_logcdf (self ):
988
+ self .check_logcdf (
989
+ Wald ,
990
+ Rplus ,
991
+ {"mu" : Rplus , "alpha" : Rplus },
992
+ lambda value , mu , alpha : sp .invgauss .logcdf (value , mu = mu , loc = alpha ),
993
+ )
994
+
992
995
def test_beta (self ):
993
996
self .check_logp (
994
997
Beta ,
@@ -1256,11 +1259,7 @@ def test_gamma_logcdf(self):
1256
1259
skip_paramdomain_outside_edge_test = True ,
1257
1260
)
1258
1261
1259
- @pytest .mark .xfail (
1260
- condition = (aesara .config .floatX == "float32" ),
1261
- reason = "Fails on float32 due to numerical issues" ,
1262
- )
1263
- def test_inverse_gamma (self ):
1262
+ def test_inverse_gamma_logp (self ):
1264
1263
self .check_logp (
1265
1264
InverseGamma ,
1266
1265
Rplus ,
@@ -1269,6 +1268,14 @@ def test_inverse_gamma(self):
1269
1268
)
1270
1269
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1271
1270
# True to avoid triggering a C-level assertion in the Aesara GammaQ function
1271
+
1272
+ @pytest .mark .xfail (
1273
+ condition = (aesara .config .floatX == "float32" ),
1274
+ reason = "Fails on float32 due to numerical issues" ,
1275
+ )
1276
+ def test_inverse_gamma_logcdf (self ):
1277
+ # pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1278
+ # True to avoid triggering a C-level assertion in the Aesara GammaQ function
1272
1279
# in gamma.c file. Can be set back to False (default) once that issue is solved
1273
1280
self .check_logcdf (
1274
1281
InverseGamma ,
@@ -1313,13 +1320,19 @@ def test_pareto(self):
1313
1320
condition = (aesara .config .floatX == "float32" ),
1314
1321
reason = "Fails on float32 due to inf issues" ,
1315
1322
)
1316
- def test_weibull (self ):
1323
+ def test_weibull_logp (self ):
1317
1324
self .check_logp (
1318
1325
Weibull ,
1319
1326
Rplus ,
1320
1327
{"alpha" : Rplusbig , "beta" : Rplusbig },
1321
1328
lambda value , alpha , beta : sp .exponweib .logpdf (value , 1 , alpha , scale = beta ),
1322
1329
)
1330
+
1331
+ @pytest .mark .xfail (
1332
+ condition = (aesara .config .floatX == "float32" ),
1333
+ reason = "Fails on float32 due to inf issues" ,
1334
+ )
1335
+ def test_weibull_logcdf (self ):
1323
1336
self .check_logcdf (
1324
1337
Weibull ,
1325
1338
Rplus ,
@@ -1368,27 +1381,37 @@ def test_binomial(self):
1368
1381
1369
1382
# Too lazy to propagate decimal parameter through the whole chain of deps
1370
1383
@pytest .mark .xfail (condition = (aesara .config .floatX == "float32" ), reason = "Fails on float32" )
1371
- @pytest .mark .xfail (
1372
- condition = (SCIPY_VERSION < parse ("1.4.0" )), reason = "betabinom is new in Scipy 1.4.0"
1373
- )
1374
- def test_beta_binomial (self ):
1384
+ def test_beta_binomial_distribution (self ):
1375
1385
self .checkd (
1376
1386
BetaBinomial ,
1377
1387
Nat ,
1378
1388
{"alpha" : Rplus , "beta" : Rplus , "n" : NatSmall },
1379
1389
)
1390
+
1391
+ @pytest .mark .skipif (
1392
+ condition = (SCIPY_VERSION < parse ("1.4.0" )), reason = "betabinom is new in Scipy 1.4.0"
1393
+ )
1394
+ def test_beta_binomial_logp (self ):
1380
1395
self .check_logp (
1381
1396
BetaBinomial ,
1382
1397
Nat ,
1383
1398
{"alpha" : Rplus , "beta" : Rplus , "n" : NatSmall },
1384
1399
lambda value , alpha , beta , n : sp .betabinom .logpmf (value , a = alpha , b = beta , n = n ),
1385
1400
)
1401
+
1402
+ @pytest .mark .xfail (condition = (aesara .config .floatX == "float32" ), reason = "Fails on float32" )
1403
+ @pytest .mark .skipif (
1404
+ condition = (SCIPY_VERSION < parse ("1.4.0" )), reason = "betabinom is new in Scipy 1.4.0"
1405
+ )
1406
+ def test_beta_binomial_logcdf (self ):
1386
1407
self .check_logcdf (
1387
1408
BetaBinomial ,
1388
1409
Nat ,
1389
1410
{"alpha" : Rplus , "beta" : Rplus , "n" : NatSmall },
1390
1411
lambda value , alpha , beta , n : sp .betabinom .logcdf (value , a = alpha , b = beta , n = n ),
1391
1412
)
1413
+
1414
+ def test_beta_binomial_selfconsistency (self ):
1392
1415
self .check_selfconsistency_discrete_logcdf (
1393
1416
BetaBinomial ,
1394
1417
Nat ,
@@ -1475,27 +1498,37 @@ def test_constantdist(self):
1475
1498
self .check_logp (Constant , I , {"c" : I }, lambda value , c : np .log (c == value ))
1476
1499
1477
1500
# Too lazy to propagate decimal parameter through the whole chain of deps
1478
- @pytest .mark .xfail (condition = (aesara .config .floatX == "float32" ), reason = "Fails on float32" )
1479
- def test_zeroinflatedpoisson (self ):
1501
+ @pytest .mark .xfail (
1502
+ condition = (aesara .config .floatX == "float32" ),
1503
+ reason = "Fails on float32 due to inf issues" ,
1504
+ )
1505
+ def test_zeroinflatedpoisson_distribution (self ):
1480
1506
self .checkd (
1481
1507
ZeroInflatedPoisson ,
1482
1508
Nat ,
1483
1509
{"theta" : Rplus , "psi" : Unit },
1484
1510
)
1511
+
1512
+ def test_zeroinflatedpoisson_logcdf (self ):
1485
1513
self .check_selfconsistency_discrete_logcdf (
1486
1514
ZeroInflatedPoisson ,
1487
1515
Nat ,
1488
1516
{"theta" : Rplus , "psi" : Unit },
1489
1517
)
1490
1518
1491
1519
# Too lazy to propagate decimal parameter through the whole chain of deps
1492
- @pytest .mark .xfail (condition = (aesara .config .floatX == "float32" ), reason = "Fails on float32" )
1493
- def test_zeroinflatednegativebinomial (self ):
1520
+ @pytest .mark .xfail (
1521
+ condition = (aesara .config .floatX == "float32" ),
1522
+ reason = "Fails on float32 due to inf issues" ,
1523
+ )
1524
+ def test_zeroinflatednegativebinomial_distribution (self ):
1494
1525
self .checkd (
1495
1526
ZeroInflatedNegativeBinomial ,
1496
1527
Nat ,
1497
1528
{"mu" : Rplusbig , "alpha" : Rplusbig , "psi" : Unit },
1498
1529
)
1530
+
1531
+ def test_zeroinflatednegativebinomial_logcdf (self ):
1499
1532
self .check_selfconsistency_discrete_logcdf (
1500
1533
ZeroInflatedNegativeBinomial ,
1501
1534
Nat ,
@@ -1504,13 +1537,14 @@ def test_zeroinflatednegativebinomial(self):
1504
1537
)
1505
1538
1506
1539
# Too lazy to propagate decimal parameter through the whole chain of deps
1507
- @pytest .mark .xfail (condition = (aesara .config .floatX == "float32" ), reason = "Fails on float32" )
1508
- def test_zeroinflatedbinomial (self ):
1540
+ def test_zeroinflatedbinomial_distribution (self ):
1509
1541
self .checkd (
1510
1542
ZeroInflatedBinomial ,
1511
1543
Nat ,
1512
1544
{"n" : NatSmall , "p" : Unit , "psi" : Unit },
1513
1545
)
1546
+
1547
+ def test_zeroinflatedbinomial_logcdf (self ):
1514
1548
self .check_selfconsistency_discrete_logcdf (
1515
1549
ZeroInflatedBinomial ,
1516
1550
Nat ,
@@ -2279,14 +2313,21 @@ def test_rice(self):
2279
2313
lambda value , b , sigma : sp .rice .logpdf (value , b = b , loc = 0 , scale = sigma ),
2280
2314
)
2281
2315
2282
- @pytest .mark .xfail (condition = (aesara .config .floatX == "float32" ), reason = "Fails on float32" )
2283
- def test_moyal (self ):
2316
+ def test_moyal_logp (self ):
2317
+ # Using a custom domain, because the standard `R` domain undeflows with scipy in float64
2318
+ value_domain = Domain ([- inf , - 1.5 , - 1 , - 0.01 , 0.0 , 0.01 , 1 , 1.5 , inf ])
2284
2319
self .check_logp (
2285
2320
Moyal ,
2286
- R ,
2321
+ value_domain ,
2287
2322
{"mu" : R , "sigma" : Rplusbig },
2288
2323
lambda value , mu , sigma : floatX (sp .moyal .logpdf (value , mu , sigma )),
2289
2324
)
2325
+
2326
+ @pytest .mark .xfail (
2327
+ condition = (aesara .config .floatX == "float32" ),
2328
+ reason = "Pymc3 underflows earlier than scipy on float32" ,
2329
+ )
2330
+ def test_moyal_logcdf (self ):
2290
2331
self .check_logcdf (
2291
2332
Moyal ,
2292
2333
R ,
0 commit comments