class_docstr: Compare test fits of models Marginal and MarginalApprox.
class_docstr_tok: ["Compare","test","fits","of","models","Marginal","and","MarginalApprox","."]
docstr: Get MAP estimate for GP approximation, compare results and predictions to what's returned
  by an unapproximated GP.  The tolerances are fairly wide, but narrow relative to initial
  values of the unknown parameters.
docstr_tok: ["Get","MAP","estimate","for","GP","approximation",",","compare","results","and","predictions","to","what","'s","returned","by","an","unapproximated","GP",".","The","tolerances","are","fairly","wide",",","but","narrow","relative","to","initial","values","of","the","unknown","parameters","."]
code: def test_fits_and_preds(self, approx):
      """Get MAP estimate for GP approximation, compare results and predictions to what's returned
      by an unapproximated GP.  The tolerances are fairly wide, but narrow relative to initial
      values of the unknown parameters.
      """
  
      with pm.Model() as model:
          cov_func = pm.gp.cov.Linear(1, c=0.0)
          c = pm.Normal("c", mu=20.0, sigma=100.0, initval=-500.0)
          mean_func = pm.gp.mean.Constant(c)
          gp = pm.gp.MarginalApprox(
              mean_func=mean_func, cov_func=cov_func, approx=approx
          )
          sigma = pm.HalfNormal("sigma", sigma=100, initval=50.0)
          gp.marginal_likelihood(
              "lik", self.x[:, None], self.x[:, None], self.y, sigma
          )
          map_approx = pm.find_MAP(method="bfgs")
  
      # Check MAP gets approximately correct result
      npt.assert_allclose(
          self.map_full["c"], map_approx["c"], atol=0.01, rtol=0.1
      )
      npt.assert_allclose(
          self.map_full["sigma"],
          map_approx["sigma"],
          atol=0.01,
          rtol=0.1,
      )
  
      # Check that predict (and conditional) work, include noise, with diagonal non-full pred var.
      with model:
          pred_mu_approx, pred_var_approx = gp.predict(
              self.x_new[:, None],
              point=map_approx,
              pred_noise=True,
              diag=True,
          )
      npt.assert_allclose(
          self.pred_mu, pred_mu_approx, atol=0.0, rtol=0.1
      )
      npt.assert_allclose(
          self.pred_var, pred_var_approx, atol=0.0, rtol=0.1
      )
  
      # Check that predict (and conditional) work, no noise, full pred covariance.
      with model:
          pred_mu_approx, pred_var_approx = gp.predict(
              self.x_new[:, None],
              point=map_approx,
              pred_noise=True,
              diag=True,
          )
      npt.assert_allclose(
          self.pred_mu, pred_mu_approx, atol=0.0, rtol=0.1
      )
      npt.assert_allclose(
          self.pred_var, pred_var_approx, atol=0.0, rtol=0.1
      )
  
imports: from functools import reduce
  from operator import add
  import numpy
  import numpy.testing
  import pytest
  import pymc
  from pymc.math import cartesian
label_desc: Use image node_id 2 for calling the TestMarginalVsMarginalApprox obj's underlying member method code with example usage: obj.test_fits_and_preds(approx) without return types