@@ -863,42 +863,48 @@ def setup_method(self):
863
863
self .map_full = pm .find_MAP (method = "bfgs" ) # bfgs seems to work much better than lbfgsb
864
864
865
865
self .x_new = np .linspace (- 6 , 6 , 20 )
866
+
867
+ # Include additive Gaussian noise, return diagonal of predicted covariance matrix
866
868
with model :
867
869
self .pred_mu , self .pred_var = self .gp .predict (
868
870
self .x_new [:, None ], point = self .map_full , pred_noise = True , diag = True
869
871
)
870
872
873
+ # Dont include additive Gaussian noise, return full predicted covariance matrix
871
874
with model :
872
875
self .pred_mu , self .pred_covar = self .gp .predict (
873
876
self .x_new [:, None ], point = self .map_full , pred_noise = False , diag = False
874
877
)
875
878
876
879
@pytest .mark .parametrize ("approx" , ["FITC" , "VFE" , "DTC" ])
877
880
def test_fits_and_preds (self , approx ):
878
- # check logp & dlogp, optimization gets approximately correct result
881
+ """Get MAP estimate for GP approximation, compare results and predictions to what's returned
882
+ by an unapproximated GP. The tolerances are fairly wide, but narrow relative to initial
883
+ values of the unknown parameters.
884
+ """
885
+
879
886
with pm .Model () as model :
880
887
cov_func = pm .gp .cov .Linear (1 , c = 0.0 )
881
888
c = pm .Normal ("c" , mu = 20.0 , sigma = 100.0 , initval = - 500.0 )
882
889
mean_func = pm .gp .mean .Constant (c )
883
- gp = pm .gp .MarginalApprox (mean_func = mean_func , cov_func = cov_func , approx = "VFE" )
890
+ gp = pm .gp .MarginalApprox (mean_func = mean_func , cov_func = cov_func , approx = approx )
884
891
sigma = pm .HalfNormal ("sigma" , sigma = 100 , initval = 50.0 )
885
892
gp .marginal_likelihood ("lik" , self .x [:, None ], self .x [:, None ], self .y , sigma )
886
893
map_approx = pm .find_MAP (method = "bfgs" )
887
894
888
- # use wide tolerances (but narrow relative to initial values of unknown parameters) because
889
- # test is likely flakey
895
+ # Check MAP gets approximately correct result
890
896
npt .assert_allclose (self .map_full ["c" ], map_approx ["c" ], atol = 0.01 , rtol = 0.1 )
891
897
npt .assert_allclose (self .map_full ["sigma" ], map_approx ["sigma" ], atol = 0.01 , rtol = 0.1 )
892
898
893
- # check that predict (and conditional) work, include noise, with diagonal non-full pred var
899
+ # Check that predict (and conditional) work, include noise, with diagonal non-full pred var.
894
900
with model :
895
901
pred_mu_approx , pred_var_approx = gp .predict (
896
902
self .x_new [:, None ], point = map_approx , pred_noise = True , diag = True
897
903
)
898
904
npt .assert_allclose (self .pred_mu , pred_mu_approx , atol = 0.0 , rtol = 0.1 )
899
905
npt .assert_allclose (self .pred_var , pred_var_approx , atol = 0.0 , rtol = 0.1 )
900
906
901
- # check that predict (and conditional) work, no noise, full pred covariance
907
+ # Check that predict (and conditional) work, no noise, full pred covariance.
902
908
with model :
903
909
pred_mu_approx , pred_var_approx = gp .predict (
904
910
self .x_new [:, None ], point = map_approx , pred_noise = True , diag = True
0 commit comments