@@ -705,29 +705,53 @@ def test_variable_type(self):
705705
706706class TestSamplePPCW (SeededTest ):
707707 def test_sample_posterior_predictive_w (self ):
708- data0 = np .random .normal (0 , 1 , size = 500 )
708+ data0 = np .random .normal (0 , 1 , size = 50 )
709+ warning_msg = "The number of samples is too small to check convergence reliably"
709710
710711 with pm .Model () as model_0 :
711712 mu = pm .Normal ("mu" , mu = 0 , sigma = 1 )
712713 y = pm .Normal ("y" , mu = mu , sigma = 1 , observed = data0 )
713- trace_0 = pm .sample ()
714+ with pytest .warns (UserWarning , match = warning_msg ):
715+ trace_0 = pm .sample (10 , tune = 0 , chains = 2 , return_inferencedata = False )
714716 idata_0 = az .from_pymc3 (trace_0 )
715717
716718 with pm .Model () as model_1 :
717719 mu = pm .Normal ("mu" , mu = 0 , sigma = 1 , shape = len (data0 ))
718720 y = pm .Normal ("y" , mu = mu , sigma = 1 , observed = data0 )
719- trace_1 = pm .sample ()
721+ with pytest .warns (UserWarning , match = warning_msg ):
722+ trace_1 = pm .sample (10 , tune = 0 , chains = 2 , return_inferencedata = False )
720723 idata_1 = az .from_pymc3 (trace_1 )
721724
725+ with pm .Model () as model_2 :
726+ # Model with no observed RVs.
727+ mu = pm .Normal ("mu" , mu = 0 , sigma = 1 )
728+ with pytest .warns (UserWarning , match = warning_msg ):
729+ trace_2 = pm .sample (10 , tune = 0 , return_inferencedata = False )
730+
722731 traces = [trace_0 , trace_1 ]
723732 idatas = [idata_0 , idata_1 ]
724733 models = [model_0 , model_1 ]
725734
726735 ppc = pm .sample_posterior_predictive_w (traces , 100 , models )
727- assert ppc ["y" ].shape == (100 , 500 )
736+ assert ppc ["y" ].shape == (100 , 50 )
728737
729738 ppc = pm .sample_posterior_predictive_w (idatas , 100 , models )
730- assert ppc ["y" ].shape == (100 , 500 )
739+ assert ppc ["y" ].shape == (100 , 50 )
740+
741+ with model_0 :
742+ ppc = pm .sample_posterior_predictive_w ([idata_0 .posterior ], None )
743+ assert ppc ["y" ].shape == (20 , 50 )
744+
745+ with pytest .raises (ValueError , match = "The number of traces and weights should be the same" ):
746+ pm .sample_posterior_predictive_w ([idata_0 .posterior ], 100 , models , weights = [0.5 , 0.5 ])
747+
748+ with pytest .raises (ValueError , match = "The number of models and weights should be the same" ):
749+ pm .sample_posterior_predictive_w ([idata_0 .posterior ], 100 , models )
750+
751+ with pytest .raises (
752+ ValueError , match = "The number of observed RVs should be the same for all models"
753+ ):
754+ pm .sample_posterior_predictive_w ([trace_0 , trace_2 ], 100 , [model_0 , model_2 ])
731755
732756
733757@pytest .mark .parametrize (
0 commit comments