@@ -1177,71 +1177,6 @@ def test_logging_sampled_basic_rvs_posterior_mutable(self, mock_sample_results,
1177
1177
caplog .clear ()
1178
1178
1179
1179
1180
- @pytest .mark .xfail (
1181
- reason = "sample_posterior_predictive_w not refactored for v4" , raises = NotImplementedError
1182
- )
1183
- class TestSamplePPCW (SeededTest ):
1184
- def test_sample_posterior_predictive_w (self ):
1185
- data0 = np .random .normal (0 , 1 , size = 50 )
1186
- warning_msg = "The number of samples is too small to check convergence reliably"
1187
-
1188
- with pm .Model () as model_0 :
1189
- mu = pm .Normal ("mu" , mu = 0 , sigma = 1 )
1190
- y = pm .Normal ("y" , mu = mu , sigma = 1 , observed = data0 )
1191
- with pytest .warns (UserWarning , match = warning_msg ):
1192
- trace_0 = pm .sample (10 , tune = 0 , chains = 2 , return_inferencedata = False )
1193
- idata_0 = pm .to_inference_data (trace_0 , log_likelihood = False )
1194
-
1195
- with pm .Model () as model_1 :
1196
- mu = pm .Normal ("mu" , mu = 0 , sigma = 1 , size = len (data0 ))
1197
- y = pm .Normal ("y" , mu = mu , sigma = 1 , observed = data0 )
1198
- with pytest .warns (UserWarning , match = warning_msg ):
1199
- trace_1 = pm .sample (10 , tune = 0 , chains = 2 , return_inferencedata = False )
1200
- idata_1 = pm .to_inference_data (trace_1 , log_likelihood = False )
1201
-
1202
- with pm .Model () as model_2 :
1203
- # Model with no observed RVs.
1204
- mu = pm .Normal ("mu" , mu = 0 , sigma = 1 )
1205
- with pytest .warns (UserWarning , match = warning_msg ):
1206
- trace_2 = pm .sample (10 , tune = 0 , return_inferencedata = False )
1207
-
1208
- traces = [trace_0 , trace_1 ]
1209
- idatas = [idata_0 , idata_1 ]
1210
- models = [model_0 , model_1 ]
1211
-
1212
- ppc = pm .sample_posterior_predictive_w (traces , 100 , models )
1213
- assert ppc ["y" ].shape == (100 , 50 )
1214
-
1215
- ppc = pm .sample_posterior_predictive_w (idatas , 100 , models )
1216
- assert ppc ["y" ].shape == (100 , 50 )
1217
-
1218
- with model_0 :
1219
- ppc = pm .sample_posterior_predictive_w ([idata_0 .posterior ], None )
1220
- assert ppc ["y" ].shape == (20 , 50 )
1221
-
1222
- with pytest .raises (ValueError , match = "The number of traces and weights should be the same" ):
1223
- pm .sample_posterior_predictive_w ([idata_0 .posterior ], 100 , models , weights = [0.5 , 0.5 ])
1224
-
1225
- with pytest .raises (ValueError , match = "The number of models and weights should be the same" ):
1226
- pm .sample_posterior_predictive_w ([idata_0 .posterior ], 100 , models )
1227
-
1228
- with pytest .raises (
1229
- ValueError , match = "The number of observed RVs should be the same for all models"
1230
- ):
1231
- pm .sample_posterior_predictive_w ([trace_0 , trace_2 ], 100 , [model_0 , model_2 ])
1232
-
1233
- def test_potentials_warning (self ):
1234
- warning_msg = "The effect of Potentials on other parameters is ignored during"
1235
- with pm .Model () as m :
1236
- a = pm .Normal ("a" , 0 , 1 )
1237
- p = pm .Potential ("p" , a + 1 )
1238
- obs = pm .Normal ("obs" , a , 1 , observed = 5 )
1239
-
1240
- trace = az_from_dict ({"a" : np .random .rand (10 )})
1241
- with pytest .warns (UserWarning , match = warning_msg ):
1242
- pm .sample_posterior_predictive_w (samples = 5 , traces = [trace , trace ], models = [m , m ])
1243
-
1244
-
1245
1180
def check_exec_nuts_init (method ):
1246
1181
with pm .Model () as model :
1247
1182
pm .Normal ("a" , mu = 0 , sigma = 1 , size = 2 )
0 commit comments