@@ -843,30 +843,31 @@ def testLatent2(self):
843
843
latent_logp = model .compile_logp ()({"f_rotated_" : y_rotated , "p" : self .pnew })
844
844
npt .assert_allclose (latent_logp , self .logp , atol = 5 )
845
845
846
-
846
+
847
847
class TestMarginalVsMarginalApprox :
848
848
R"""
849
849
Compare test fits of models Marginal and MarginalApprox.
850
850
"""
851
+
851
852
def setup_method (self ):
852
853
self .sigma = 0.1
853
854
self .x = np .linspace (- 5 , 5 , 30 )
854
- self .y = 0.25 * self .x + self .sigma * np .random .randn (len (self .x ))
855
+ self .y = 0.25 * self .x + self .sigma * np .random .randn (len (self .x ))
855
856
with pm .Model () as model :
856
857
cov_func = pm .gp .cov .Linear (1 , c = 0.0 )
857
- c = pm .Normal ("c" , mu = 20.0 , sigma = 100.0 ) # far from true value
858
+ c = pm .Normal ("c" , mu = 20.0 , sigma = 100.0 ) # far from true value
858
859
mean_func = pm .gp .mean .Constant (c )
859
860
self .gp = pm .gp .Marginal (mean_func = mean_func , cov_func = cov_func )
860
861
sigma = pm .HalfNormal ("sigma" , sigma = 100 )
861
862
self .gp .marginal_likelihood ("lik" , self .x [:, None ], self .y , sigma )
862
- self .map_full = pm .find_MAP (method = "bfgs" ) # bfgs seems to work much better than lbfgsb
863
-
863
+ self .map_full = pm .find_MAP (method = "bfgs" ) # bfgs seems to work much better than lbfgsb
864
+
864
865
self .x_new = np .linspace (- 6 , 6 , 20 )
865
866
with model :
866
867
self .pred_mu , self .pred_var = self .gp .predict (
867
868
self .x_new [:, None ], point = self .map_full , pred_noise = True , diag = True
868
869
)
869
-
870
+
870
871
with model :
871
872
self .pred_mu , self .pred_covar = self .gp .predict (
872
873
self .x_new [:, None ], point = self .map_full , pred_noise = False , diag = False
@@ -883,29 +884,28 @@ def test_fits_and_preds(self, approx):
883
884
sigma = pm .HalfNormal ("sigma" , sigma = 100 , initval = 50.0 )
884
885
gp .marginal_likelihood ("lik" , self .x [:, None ], self .x [:, None ], self .y , sigma )
885
886
map_approx = pm .find_MAP (method = "bfgs" )
886
-
887
+
887
888
# use wide tolerances (but narrow relative to initial values of unknown parameters) because
888
889
# test is likely flakey
889
890
npt .assert_allclose (self .map_full ["c" ], map_approx ["c" ], atol = 0.01 , rtol = 0.1 )
890
891
npt .assert_allclose (self .map_full ["sigma" ], map_approx ["sigma" ], atol = 0.01 , rtol = 0.1 )
891
-
892
+
892
893
# check that predict (and conditional) work, include noise, with diagonal non-full pred var
893
894
with model :
894
895
pred_mu_approx , pred_var_approx = gp .predict (
895
896
self .x_new [:, None ], point = map_approx , pred_noise = True , diag = True
896
897
)
897
898
npt .assert_allclose (self .pred_mu , pred_mu_approx , atol = 0.0 , rtol = 0.1 )
898
899
npt .assert_allclose (self .pred_var , pred_var_approx , atol = 0.0 , rtol = 0.1 )
899
-
900
+
900
901
# check that predict (and conditional) work, no noise, full pred covariance
901
902
with model :
902
903
pred_mu_approx , pred_var_approx = gp .predict (
903
904
self .x_new [:, None ], point = map_approx , pred_noise = True , diag = True
904
905
)
905
906
npt .assert_allclose (self .pred_mu , pred_mu_approx , atol = 0.0 , rtol = 0.1 )
906
907
npt .assert_allclose (self .pred_var , pred_var_approx , atol = 0.0 , rtol = 0.1 )
907
-
908
-
908
+
909
909
910
910
class TestGPAdditive :
911
911
def setup_method (self ):
0 commit comments