@@ -357,13 +357,13 @@ def test_missing_data(self):
357
357
gf = m .logp_dlogp_function ()
358
358
gf ._extra_are_set = True
359
359
360
- assert m ["x2_missing " ].type == gf ._extra_vars_shared ["x2_missing " ].type
360
+ assert m ["x2_unobserved " ].type == gf ._extra_vars_shared ["x2_unobserved " ].type
361
361
362
362
# The dtype of the merged observed/missing deterministic should match the RV dtype
363
363
assert m .deterministics [0 ].type .dtype == x2 .type .dtype
364
364
365
365
point = m .initial_point (random_seed = None ).copy ()
366
- del point ["x2_missing " ]
366
+ del point ["x2_unobserved " ]
367
367
368
368
res = [gf (DictToArrayBijection .map (Point (point , model = m ))) for i in range (5 )]
369
369
@@ -566,7 +566,7 @@ def test_make_obs_var():
566
566
assert masked_output != fake_distribution
567
567
assert not isinstance (masked_output , RandomVariable )
568
568
# Ensure it has missing values
569
- assert {"testing_inputs_missing " } == {v .name for v in fake_model .value_vars }
569
+ assert {"testing_inputs_unobserved " } == {v .name for v in fake_model .value_vars }
570
570
assert {"testing_inputs" , "testing_inputs_observed" } == {
571
571
v .name for v in fake_model .observed_RVs
572
572
}
@@ -1221,7 +1221,7 @@ def test_missing_basic(self, missing_data):
1221
1221
with pytest .warns (ImputationWarning ):
1222
1222
_ = pm .Normal ("y" , x , 1 , observed = missing_data )
1223
1223
1224
- assert "y_missing " in model .named_vars
1224
+ assert "y_unobserved " in model .named_vars
1225
1225
1226
1226
test_point = model .initial_point ()
1227
1227
assert not np .isnan (model .compile_logp ()(test_point ))
@@ -1238,7 +1238,7 @@ def test_missing_with_predictors(self):
1238
1238
with pytest .warns (ImputationWarning ):
1239
1239
y = pm .Normal ("y" , x * predictors , 1 , observed = data )
1240
1240
1241
- assert "y_missing " in model .named_vars
1241
+ assert "y_unobserved " in model .named_vars
1242
1242
1243
1243
test_point = model .initial_point ()
1244
1244
assert not np .isnan (model .compile_logp ()(test_point ))
@@ -1278,17 +1278,19 @@ def test_interval_missing_observations(self):
1278
1278
with pytest .warns (ImputationWarning ):
1279
1279
theta2 = pm .Normal ("theta2" , mu = theta1 , observed = obs2 )
1280
1280
1281
- assert isinstance (model .rvs_to_transforms [model ["theta1_missing" ]], IntervalTransform )
1281
+ assert isinstance (
1282
+ model .rvs_to_transforms [model ["theta1_unobserved" ]], IntervalTransform
1283
+ )
1282
1284
assert model .rvs_to_transforms [model ["theta1_observed" ]] is None
1283
1285
1284
1286
prior_trace = pm .sample_prior_predictive (random_seed = rng , return_inferencedata = False )
1285
1287
assert set (prior_trace .keys ()) == {
1286
1288
"theta1" ,
1287
1289
"theta1_observed" ,
1288
- "theta1_missing " ,
1290
+ "theta1_unobserved " ,
1289
1291
"theta2" ,
1290
1292
"theta2_observed" ,
1291
- "theta2_missing " ,
1293
+ "theta2_unobserved " ,
1292
1294
}
1293
1295
1294
1296
# Make sure the observed + missing combined deterministics have the
@@ -1303,14 +1305,16 @@ def test_interval_missing_observations(self):
1303
1305
# Make sure the missing parts of the combined deterministic matches the
1304
1306
# sampled missing and observed variable values
1305
1307
assert (
1306
- np .mean (prior_trace ["theta1" ][:, obs1 .mask ] - prior_trace ["theta1_missing" ]) == 0.0
1308
+ np .mean (prior_trace ["theta1" ][:, obs1 .mask ] - prior_trace ["theta1_unobserved" ])
1309
+ == 0.0
1307
1310
)
1308
1311
assert (
1309
1312
np .mean (prior_trace ["theta1" ][:, ~ obs1 .mask ] - prior_trace ["theta1_observed" ])
1310
1313
== 0.0
1311
1314
)
1312
1315
assert (
1313
- np .mean (prior_trace ["theta2" ][:, obs2 .mask ] - prior_trace ["theta2_missing" ]) == 0.0
1316
+ np .mean (prior_trace ["theta2" ][:, obs2 .mask ] - prior_trace ["theta2_unobserved" ])
1317
+ == 0.0
1314
1318
)
1315
1319
assert (
1316
1320
np .mean (prior_trace ["theta2" ][:, ~ obs2 .mask ] - prior_trace ["theta2_observed" ])
@@ -1326,18 +1330,22 @@ def test_interval_missing_observations(self):
1326
1330
)
1327
1331
assert set (trace .varnames ) == {
1328
1332
"theta1" ,
1329
- "theta1_missing " ,
1330
- "theta1_missing_interval__ " ,
1333
+ "theta1_unobserved " ,
1334
+ "theta1_unobserved_interval__ " ,
1331
1335
"theta2" ,
1332
- "theta2_missing " ,
1336
+ "theta2_unobserved " ,
1333
1337
}
1334
1338
1335
1339
# Make sure that the missing values are newly generated samples and that
1336
1340
# the observed and deterministic match
1337
- assert np .all (0 < trace ["theta1_missing" ].mean (0 ))
1338
- assert np .all (0 < trace ["theta2_missing" ].mean (0 ))
1339
- assert np .isclose (np .mean (trace ["theta1" ][:, obs1 .mask ] - trace ["theta1_missing" ]), 0 )
1340
- assert np .isclose (np .mean (trace ["theta2" ][:, obs2 .mask ] - trace ["theta2_missing" ]), 0 )
1341
+ assert np .all (0 < trace ["theta1_unobserved" ].mean (0 ))
1342
+ assert np .all (0 < trace ["theta2_unobserved" ].mean (0 ))
1343
+ assert np .isclose (
1344
+ np .mean (trace ["theta1" ][:, obs1 .mask ] - trace ["theta1_unobserved" ]), 0
1345
+ )
1346
+ assert np .isclose (
1347
+ np .mean (trace ["theta2" ][:, obs2 .mask ] - trace ["theta2_unobserved" ]), 0
1348
+ )
1341
1349
1342
1350
# Make sure that the observed values are unchanged
1343
1351
assert np .allclose (np .var (trace ["theta1" ][:, ~ obs1 .mask ], 0 ), 0.0 )
@@ -1378,7 +1386,7 @@ def test_missing_logp1(self):
1378
1386
with pytest .warns (ImputationWarning ):
1379
1387
x = pm .Gamma ("x" , 1 , 1 , observed = [1 , 1 , 1 , np .nan ])
1380
1388
1381
- logp_val = m2 .compile_logp ()({"x_missing_log__ " : np .array ([0 ])})
1389
+ logp_val = m2 .compile_logp ()({"x_unobserved_log__ " : np .array ([0 ])})
1382
1390
assert logp_val == - 4.0
1383
1391
1384
1392
def test_missing_logp2 (self ):
@@ -1394,7 +1402,7 @@ def test_missing_logp2(self):
1394
1402
"theta2" , mu = theta1 , observed = np .array ([np .nan , np .nan , 2 , np .nan , 4 ])
1395
1403
)
1396
1404
m_missing_logp = m_missing .compile_logp ()(
1397
- {"theta1_missing " : [2 , 4 ], "theta2_missing " : [0 , 1 , 3 ]}
1405
+ {"theta1_unobserved " : [2 , 4 ], "theta2_unobserved " : [0 , 1 , 3 ]}
1398
1406
)
1399
1407
1400
1408
assert m_logp == m_missing_logp
@@ -1407,15 +1415,15 @@ def test_missing_multivariate_separable(self):
1407
1415
a = [1 , 2 , 3 ],
1408
1416
observed = np .array ([[0.3 , 0.3 , 0.4 ], [np .nan , np .nan , np .nan ]]),
1409
1417
)
1410
- assert (m_miss ["x_missing " ].owner .op , pm .Dirichlet )
1418
+ assert (m_miss ["x_unobserved " ].owner .op , pm .Dirichlet )
1411
1419
assert (m_miss ["x_observed" ].owner .op , pm .Dirichlet )
1412
1420
1413
1421
with pm .Model () as m_unobs :
1414
1422
x = pm .Dirichlet ("x" , a = [1 , 2 , 3 ], shape = (1 , 3 ))
1415
1423
1416
1424
inp_vals = simplex .forward (np .array ([[0.3 , 0.3 , 0.4 ]])).eval ()
1417
1425
np .testing .assert_allclose (
1418
- m_miss .compile_logp (jacobian = False )({"x_missing_simplex__ " : inp_vals }),
1426
+ m_miss .compile_logp (jacobian = False )({"x_unobserved_simplex__ " : inp_vals }),
1419
1427
m_unobs .compile_logp (jacobian = False )({"x_simplex__" : inp_vals }) * 2 ,
1420
1428
)
1421
1429
@@ -1428,12 +1436,12 @@ def test_missing_multivariate_unseparable(self):
1428
1436
observed = np .array ([[0.3 , 0.3 , np .nan ], [np .nan , np .nan , 0.4 ]]),
1429
1437
)
1430
1438
1431
- assert isinstance (m_miss ["x_missing " ].owner .op , PartialObservedRV )
1439
+ assert isinstance (m_miss ["x_unobserved " ].owner .op , PartialObservedRV )
1432
1440
assert isinstance (m_miss ["x_observed" ].owner .op , PartialObservedRV )
1433
1441
1434
1442
inp_values = np .array ([0.3 , 0.3 , 0.4 ])
1435
1443
np .testing .assert_allclose (
1436
- m_miss .compile_logp ()({"x_missing " : [0.4 , 0.3 , 0.3 ]}),
1444
+ m_miss .compile_logp ()({"x_unobserved " : [0.4 , 0.3 , 0.3 ]}),
1437
1445
st .dirichlet .logpdf (inp_values , [1 , 2 , 3 ]) * 2 ,
1438
1446
)
1439
1447
@@ -1451,7 +1459,7 @@ def test_missing_vector_parameter(self):
1451
1459
assert np .all (x_draws [:, 0 ] < 0 )
1452
1460
assert np .all (x_draws [:, 1 ] > 0 )
1453
1461
assert np .isclose (
1454
- m .compile_logp ()({"x_missing " : np .array ([- 10 , 10 , - 10 , 10 ])}),
1462
+ m .compile_logp ()({"x_unobserved " : np .array ([- 10 , 10 , - 10 , 10 ])}),
1455
1463
st .norm (scale = 0.1 ).logpdf (0 ) * 6 ,
1456
1464
)
1457
1465
@@ -1470,7 +1478,7 @@ def test_missing_symmetric(self):
1470
1478
x_obs_rv = m ["x_observed" ]
1471
1479
x_obs_vv = m .rvs_to_values [x_obs_rv ]
1472
1480
1473
- x_unobs_rv = m ["x_missing " ]
1481
+ x_unobs_rv = m ["x_unobserved " ]
1474
1482
x_unobs_vv = m .rvs_to_values [x_unobs_rv ]
1475
1483
1476
1484
logp = transformed_conditional_logp (
@@ -1506,7 +1514,7 @@ def test_symbolic_random_variable(self):
1506
1514
observed = data ,
1507
1515
)
1508
1516
np .testing .assert_almost_equal (
1509
- model .compile_logp ()({"x_missing " : [0 ] * 3 }),
1517
+ model .compile_logp ()({"x_unobserved " : [0 ] * 3 }),
1510
1518
st .norm .logcdf (0 ) * 10 ,
1511
1519
)
1512
1520
0 commit comments