bayeso.gp

bayeso.gp._check_str_cov(str_fun, str_cov, shape_X1, shape_X2=None)

It is for validating the shape of X1 (and optionally the shape of X2).

Parameters:
  • str_fun (str.) – the name of function.
  • str_cov (str.) – the name of covariance function.
  • shape_X1 (tuple) – the shape of X1.
  • shape_X2 (NoneType or tuple, optional) – None, or the shape of X2.
Returns:

None, if it is valid. Raise an error, otherwise.

Return type:

NoneType

Raises:

AssertionError, ValueError

bayeso.gp.get_kernel_cholesky(X_train, hyps, str_cov, is_fixed_noise=True, is_gradient=False, debug=False)

This function computes a kernel inverse with Cholesky decomposition.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • hyps (dict.) – dictionary of hyperparameters for Gaussian process.
  • str_cov (str.) – the name of covariance function.
  • is_fixed_noise (bool., optional) – flag for fixing a noise.
  • is_gradient (bool., optional) – flag for computing and returning gradients of negative log marginal likelihood.
  • debug (bool., optional) – flag for printing log messages.
Returns:

a tuple of kernel matrix over X_train, lower matrix computed by Cholesky decomposition, and gradients of kernel matrix. If is_gradient is False, gradients of kernel matrix would be None.

Return type:

tuple of (numpy.ndarray, numpy.ndarray, numpy.ndarray)

Raises:

AssertionError

bayeso.gp.get_kernel_inverse(X_train, hyps, str_cov, is_fixed_noise=True, is_gradient=False, debug=False)

This function computes a kernel inverse without any matrix decomposition techniques.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • hyps (dict.) – dictionary of hyperparameters for Gaussian process.
  • str_cov (str.) – the name of covariance function.
  • is_fixed_noise (bool., optional) – flag for fixing a noise.
  • is_gradient (bool., optional) – flag for computing and returning gradients of negative log marginal likelihood.
  • debug (bool., optional) – flag for printing log messages.
Returns:

a tuple of kernel matrix over X_train, kernel matrix inverse, and gradients of kernel matrix. If is_gradient is False, gradients of kernel matrix would be None.

Return type:

tuple of (numpy.ndarray, numpy.ndarray, numpy.ndarray)

Raises:

AssertionError

bayeso.gp.get_optimized_kernel(X_train, Y_train, prior_mu, str_cov, str_optimizer_method='BFGS', str_modelselection_method='ml', is_fixed_noise=True, debug=False)

This function computes the kernel matrix optimized by optimization method specified, its inverse matrix, and the optimized hyperparameters.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).
  • prior_mu (function or NoneType) – prior mean function or None.
  • str_cov (str.) – the name of covariance function.
  • str_optimizer_method (str., optional) – the name of optimization method.
  • str_modelselection_method (str., optional) – the name of model selection method.
  • is_fixed_noise (bool., optional) – flag for fixing a noise.
  • debug (bool., optional) – flag for printing log messages.
Returns:

a tuple of kernel matrix over X_train, kernel matrix inverse, and dictionary of hyperparameters.

Return type:

tuple of (numpy.ndarray, numpy.ndarray, dict.)

Raises:

AssertionError, ValueError

bayeso.gp.get_prior_mu(prior_mu, X)

It computes the prior mean function values over inputs X.

Parameters:
  • prior_mu (function or NoneType) – prior mean function or None.
  • X (numpy.ndarray) – inputs for prior mean function. Shape: (n, d) or (n, m, d).
Returns:

zero array, or array of prior mean function values. Shape: (n, 1).

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.gp.neg_log_ml(X_train, Y_train, hyps, str_cov, prior_mu_train, is_fixed_noise=True, is_cholesky=True, is_gradient=True, debug=False)

This function computes a negative log marginal likelihood.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).
  • hyps (numpy.ndarray) – hyperparameters for Gaussian process. Shape: (h, ).
  • str_cov (str.) – the name of covariance function.
  • prior_mu_train (numpy.ndarray) – the prior values computed by get_prior_mu(). Shape: (n, 1).
  • is_fixed_noise (bool., optional) – flag for fixing a noise.
  • is_cholesky (bool., optional) – flag for using a cholesky decomposition.
  • is_gradient (bool., optional) – flag for computing and returning gradients of negative log marginal likelihood.
  • debug (bool., optional) – flag for printing log messages.
Returns:

negative log marginal likelihood, or (negative log marginal likelihood, gradients of the likelihood).

Return type:

float, or tuple of (float, float)

Raises:

AssertionError

bayeso.gp.neg_log_pseudo_l_loocv(X_train, Y_train, hyps, str_cov, prior_mu_train, is_fixed_noise=True, debug=False)

It computes a negative log pseudo-likelihood using leave-one-out cross-validation.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).
  • hyps (numpy.ndarray) – hyperparameters for Gaussian process. Shape: (h, ).
  • str_cov (str.) – the name of covariance function.
  • prior_mu_train (numpy.ndarray) – the prior values computed by get_prior_mu(). Shape: (n, 1).
  • is_fixed_noise (bool., optional) – flag for fixing a noise.
  • debug (bool., optional) – flag for printing log messages.
Returns:

negative log pseudo-likelihood.

Return type:

float

Raises:

AssertionError

bayeso.gp.predict_optimized(X_train, Y_train, X_test, str_cov='matern52', prior_mu=None, is_fixed_noise=True, debug=False)

This function returns posterior mean and posterior standard deviation functions over X_test, computed by the Gaussian process regression optimized with X_train and Y_train.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).
  • X_test (numpy.ndarray) – inputs. Shape: (l, d) or (l, m, d).
  • str_cov (str., optional) – the name of covariance function.
  • prior_mu (NoneType, or function, optional) – None, or prior mean function.
  • is_fixed_noise (bool., optional) – flag for fixing a noise.
  • debug (bool., optional) – flag for printing log messages.
Returns:

a tuple of posterior mean function over X_test, posterior standard deviation function over X_test, and posterior covariance matrix over X_test. Shape: ((l, 1), (l, 1), (l, l)).

Return type:

tuple of (numpy.ndarray, numpy.ndarray, numpy.ndarray)

Raises:

AssertionError

bayeso.gp.predict_test(X_train, Y_train, X_test, hyps, str_cov='matern52', prior_mu=None, debug=False)

This function returns posterior mean and posterior standard deviation functions over X_test, computed by Gaussian process regression with X_train, Y_train, and hyps.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).
  • X_test (numpy.ndarray) – inputs. Shape: (l, d) or (l, m, d).
  • hyps (dict.) – dictionary of hyperparameters for Gaussian process.
  • str_cov (str., optional) – the name of covariance function.
  • prior_mu (NoneType, or function, optional) – None, or prior mean function.
  • debug (bool., optional) – flag for printing log messages.
Returns:

a tuple of posterior mean function over X_test, posterior standard deviation function over X_test, and posterior covariance matrix over X_test. Shape: ((l, 1), (l, 1), (l, l)).

Return type:

tuple of (numpy.ndarray, numpy.ndarray, numpy.ndarray)

Raises:

AssertionError

bayeso.gp.predict_test_(X_train, Y_train, X_test, cov_X_X, inv_cov_X_X, hyps, str_cov='matern52', prior_mu=None, debug=False)

This function returns posterior mean and posterior standard deviation functions over X_test, computed by Gaussian process regression with X_train, Y_train, cov_X_X, inv_cov_X_X, and hyps.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).
  • X_test (numpy.ndarray) – inputs. Shape: (l, d) or (l, m, d).
  • cov_X_X (numpy.ndarray) – kernel matrix over X_train. Shape: (n, n).
  • inv_cov_X_X (numpy.ndarray) – kernel matrix inverse over X_train. Shape: (n, n).
  • hyps (dict.) – dictionary of hyperparameters for Gaussian process.
  • str_cov (str., optional) – the name of covariance function.
  • prior_mu (NoneType, or function, optional) – None, or prior mean function.
  • debug (bool., optional) – flag for printing log messages.
Returns:

a tuple of posterior mean function over X_test, posterior standard deviation function over X_test, and posterior covariance matrix over X_test. Shape: ((l, 1), (l, 1), (l, l)).

Return type:

tuple of (numpy.ndarray, numpy.ndarray, numpy.ndarray)

Raises:

AssertionError

bayeso.gp.sample_functions(mu, Sigma, num_samples=1)

It samples num_samples functions from multivariate Gaussian distribution (mu, Sigma).

Parameters:
  • mu (numpy.ndarray) – mean vector. Shape: (n, ).
  • Sigma (numpy.ndarray) – covariance matrix. Shape: (n, n).
  • num_samples (int., optional) – the number of sampled functions
Returns:

sampled functions. Shape: (num_samples, n).

Return type:

numpy.ndarray

Raises:

AssertionError