class_docstr: Contains unit tests for the TransportNNDistanceComputer class. 
class_docstr_tok: ["Contains","unit","tests","for","the","TransportNNDistanceComputer","class","."]
docstr: Tests marginal likelihood and prediction. 
docstr_tok: ["Tests","marginal","likelihood","and","prediction","."]
code: def test_marg_likelihood_and_prediction(self):
      """Tests marginal likelihood and prediction."""
      # pylint: disable=too-many-locals
      self.report(
          "Testing evaluation and marginal likelihood on Fitted GP."
          + " Probabilistic test, might fail."
      )
      naive_num_coeffs_vals = [2, 1, 4, 5] * 5
      num_tests = 0
      num_lml_successes = 0
      num_const_err_successes = 0
      num_naive_err_successes = 0
      for dataset_idx, dataset in enumerate(self.datasets):
          for dist_type in self.dist_types:
              for kernel_type in self.kernel_types[dist_type]:
                  # Build the naive GP
                  curr_num_coeffs = naive_num_coeffs_vals.pop(0)
                  naive_gp = build_nngp_with_dataset(
                      dataset, kernel_type, curr_num_coeffs, dist_type
                  )
                  # Obtain a fitted GP
                  fitted_gp = fit_nngp_with_dataset(
                      dataset, kernel_type, dist_type
                  )
                  # Obtain log marginal likelihoods
                  naive_lml = naive_gp.compute_log_marginal_likelihood()
                  fitted_lml = (
                      fitted_gp.compute_log_marginal_likelihood()
                  )
                  lml_succ = naive_lml < fitted_lml
                  num_lml_successes += lml_succ
                  self.report(
                      (
                          "(%s, ntr=%d, nte=%d):: naive-gp-lml=%0.4f, "
                          + "fitted-gp-lml=%0.4f, lml-succ=%d."
                      )
                      % (
                          dataset[-1][:5],
                          len(dataset[0]),
                          len(dataset[2]),
                          naive_lml,
                          fitted_lml,
                          lml_succ,
                      ),
                      "test_result",
                  )
                  # Predictions & Marginal likelihood
                  naive_preds, _ = naive_gp.eval(dataset[2], "std")
                  naive_gp_err = compute_average_prediction_error(
                      dataset, naive_preds
                  )
                  fitted_preds, _ = fitted_gp.eval(dataset[2], "std")
                  fitted_gp_err = compute_average_prediction_error(
                      dataset, fitted_preds
                  )
                  const_err = compute_average_prediction_error(
                      dataset, dataset[1].mean()
                  )
                  const_err_succ = const_err > fitted_gp_err
                  naive_err_succ = naive_gp_err > fitted_gp_err
                  num_const_err_successes += const_err_succ
                  num_naive_err_successes += naive_err_succ
                  self.report(
                      (
                          "  dataset #%d: const-err: %0.4f (%d), naive-gp-err=%0.4f (%d), "
                          + "fitted-gp-err=%0.4f."
                      )
                      % (
                          dataset_idx,
                          const_err,
                          const_err_succ,
                          naive_gp_err,
                          naive_err_succ,
                          fitted_gp_err,
                      ),
                      "test_result",
                  )
                  # Print out betas
                  self.report(
                      "  fitted kernel %s hyper-params: %s"
                      % (
                          kernel_type,
                          self._read_kernel_hyperparams(
                              fitted_gp.kernel.hyperparams
                          ),
                      ),
                      "test_result",
                  )
                  num_tests += 1
      # Print out some statistics
      lml_frac = float(num_lml_successes) / float(num_tests)
      const_err_frac = float(num_const_err_successes) / float(num_tests)
      naive_err_frac = float(num_naive_err_successes) / float(num_tests)
      self.report(
          "LML tests success fraction = %d/%d = %0.4f"
          % (num_lml_successes, num_tests, lml_frac),
          "test_result",
      )
      self.report(
          "Const-err success fraction = %d/%d = %0.4f"
          % (num_const_err_successes, num_tests, const_err_frac),
          "test_result",
      )
      self.report(
          "Naive-GP-err success fraction = %d/%d = %0.4f"
          % (num_naive_err_successes, num_tests, naive_err_frac),
          "test_result",
      )
      assert num_lml_successes == num_tests
      assert const_err_frac >= 0.5
      assert naive_err_frac >= 0.3
  
imports: import numpy
  import unittest
  from .syn_nn_functions import syn_func1_common, cnn_syn_func1, mlp_syn_func1
  from .nn_examples import generate_cnn_architectures, generate_mlp_architectures
  from .None import nn_gp
  from ..utils.ancillary_utils import get_list_of_floats_as_str
  from ..utils.base_test_class import BaseTestClass, execute_tests
  from ..utils.option_handler import load_options
label_desc: Use image node_id 3 for calling the NNGPFitterTestCase obj's underlying member method code with example usage: obj.test_marg_likelihood_and_prediction() without return types