code: def test_equivalence(approximate_model: GPModel) -> None:
      """
      With a Gaussian likelihood, and inducing points (where appropriate)
      positioned at the data, many of the gpflow methods are equivalent (perhaps
      subject to some optimization).
      """
  
      def optimize(model: GPModel) -> None:
          opt = gpflow.optimizers.Scipy()
          loss = training_loss_closure(model, Datum.data)
          opt.minimize(
              loss,
              model.trainable_variables,
              options=dict(maxiter=3000),
          )
          if isinstance(model, gpflow.models.SVGP) and not model.whiten:
              # The (S)VGP model in non-whitened representation has significantly
              # worse optimization behaviour. To get the tests to pass, we need
              # to optimize much harder: we set ftol=gtol=0.0 to enforce
              # continued optimization.
              opt.minimize(
                  loss,
                  model.trainable_variables,
                  options=dict(maxiter=7000, ftol=0.0, gtol=0.0),
              )
  
      gpr_model = _create_full_gp_model()
      optimize(gpr_model)
      optimize(approximate_model)
  
      gpr_likelihood = gpr_model.log_marginal_likelihood()
      approximate_likelihood = maximum_log_likelihood_objective(
          approximate_model, Datum.data
      )
      assert_allclose(approximate_likelihood, gpr_likelihood, rtol=1e-6)
  
      gpr_kernel_ls = gpr_model.kernel.lengthscales.numpy()
      gpr_kernel_var = gpr_model.kernel.variance.numpy()
  
      approximate_kernel_ls = (
          approximate_model.kernel.lengthscales.numpy()
      )
      approximate_kernel_var = approximate_model.kernel.variance.numpy()
  
      assert_allclose(gpr_kernel_ls, approximate_kernel_ls, 2e-4)
      assert_allclose(gpr_kernel_var, approximate_kernel_var, 1e-3)
  
      gpr_mu, gpr_var = gpr_model.predict_y(Datum.Xtest)
      approximate_mu, approximate_var = approximate_model.predict_y(
          Datum.Xtest
      )
  
      assert_allclose(gpr_mu, approximate_mu, 1e-3)
      assert_allclose(gpr_var, approximate_var, 1e-4)
  
imports: from typing import Optional, Tuple
  import numpy
  import pytest
  from check_shapes import ShapeChecker
  from numpy.testing import assert_allclose
  import gpflow
  from gpflow.base import AnyNDArray, TensorType
  from gpflow.config import default_jitter
  from gpflow.kernels import Kernel
  from gpflow.likelihoods import Likelihood
  from gpflow.mean_functions import Constant
  from gpflow.models import GPModel, maximum_log_likelihood_objective, training_loss_closure
label_desc: Use image node_id 6 for calling a global function with example usage: test_equivalence(approximate_model) without return types