bayeso.covariance

It defines covariance functions and their associated functions.

bayeso.covariance.choose_fun_cov(str_cov: str) → Callable

It chooses a covariance function.

Parameters:str_cov (str.) – the name of covariance function.
Returns:covariance function.
Return type:callable
Raises:AssertionError
bayeso.covariance.choose_fun_grad_cov(str_cov: str) → Callable

It chooses a function for computing gradients of covariance function.

Parameters:str_cov (str.) – the name of covariance function.
Returns:function for computing gradients of covariance function.
Return type:callable
Raises:AssertionError
bayeso.covariance.cov_main(str_cov: str, X: numpy.ndarray, Xp: numpy.ndarray, hyps: dict, same_X_Xp: bool, jitter: float = 1e-05) → numpy.ndarray

It computes kernel matrix over X and Xp, where hyps is given.

Parameters:
  • str_cov (str.) – the name of covariance function.
  • X (numpy.ndarray) – one inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • hyps (dict.) – dictionary of hyperparameters for covariance function.
  • same_X_Xp (bool.) – flag for checking X and Xp are same.
  • jitter (float, optional) – jitter for diagonal entries.
Returns:

kernel matrix over X and Xp. Shape: (n, m).

Return type:

numpy.ndarray

Raises:

AssertionError, ValueError

bayeso.covariance.cov_matern32(X: numpy.ndarray, Xp: numpy.ndarray, lengthscales: Union[numpy.ndarray, float], signal: float) → numpy.ndarray

It computes Matern 3/2 kernel over X and Xp, where lengthscales and signal are given.

Parameters:
  • X (numpy.ndarray) – inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • lengthscales (numpy.ndarray, or float) – length scales. Shape: (d, ) or ().
  • signal (float) – coefficient for signal.
Returns:

kernel values over X and Xp. Shape: (n, m).

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.covariance.cov_matern52(X: numpy.ndarray, Xp: numpy.ndarray, lengthscales: Union[numpy.ndarray, float], signal: float) → numpy.ndarray

It computes Matern 5/2 kernel over X and Xp, where lengthscales and signal are given.

Parameters:
  • X (numpy.ndarray) – inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • lengthscales (numpy.ndarray, or float) – length scales. Shape: (d, ) or ().
  • signal (float) – coefficient for signal.
Returns:

kernel values over X and Xp. Shape: (n, m).

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.covariance.cov_se(X: numpy.ndarray, Xp: numpy.ndarray, lengthscales: Union[numpy.ndarray, float], signal: float) → numpy.ndarray

It computes squared exponential kernel over X and Xp, where lengthscales and signal are given.

Parameters:
  • X (numpy.ndarray) – inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • lengthscales (numpy.ndarray, or float) – length scales. Shape: (d, ) or ().
  • signal (float) – coefficient for signal.
Returns:

kernel values over X and Xp. Shape: (n, m).

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.covariance.cov_set(str_cov: str, X: numpy.ndarray, Xp: numpy.ndarray, lengthscales: Union[numpy.ndarray, float], signal: float) → numpy.ndarray

It computes set kernel matrix over X and Xp, where lengthscales and signal are given.

Parameters:
  • str_cov (str.) – the name of covariance function.
  • X (numpy.ndarray) – one inputs. Shape: (n, m, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (l, m, d).
  • lengthscales (numpy.ndarray, or float) – length scales. Shape: (d, ) or ().
  • signal (float) – coefficient for signal.
Returns:

set kernel matrix over X and Xp. Shape: (n, l).

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.covariance.get_kernel_cholesky(X_train: numpy.ndarray, hyps: dict, str_cov: str, fix_noise: bool = True, use_gradient: bool = False, debug: bool = False) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

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.
  • fix_noise (bool., optional) – flag for fixing a noise.
  • use_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 use_gradient is False, gradients of kernel matrix would be None.

Return type:

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

Raises:

AssertionError

bayeso.covariance.get_kernel_inverse(X_train: numpy.ndarray, hyps: dict, str_cov: str, fix_noise: bool = True, use_gradient: bool = False, debug: bool = False) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

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.
  • fix_noise (bool., optional) – flag for fixing a noise.
  • use_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 use_gradient is False, gradients of kernel matrix would be None.

Return type:

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

Raises:

AssertionError

bayeso.covariance.grad_cov_main(str_cov: str, X: numpy.ndarray, Xp: numpy.ndarray, hyps: dict, fix_noise: bool, same_X_Xp: bool = True, jitter: float = 1e-05) → numpy.ndarray

It computes gradients of kernel matrix over hyperparameters, where hyps is given.

Parameters:
  • str_cov (str.) – the name of covariance function.
  • X (numpy.ndarray) – one inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • hyps (dict.) – dictionary of hyperparameters for covariance function.
  • fix_noise (bool.) – flag for fixing a noise.
  • same_X_Xp (bool., optional) – flag for checking X and Xp are same.
  • jitter (float, optional) – jitter for diagonal entries.
Returns:

gradient matrix over hyperparameters. Shape: (n, m, l) where l is the number of hyperparameters.

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.covariance.grad_cov_matern32(cov_X_Xp: numpy.ndarray, X: numpy.ndarray, Xp: numpy.ndarray, hyps: dict, num_hyps: int, fix_noise: bool) → numpy.ndarray

It computes gradients of Matern 3/2 kernel over X and Xp, where hyps is given.

Parameters:
  • cov_X_Xp (numpy.ndarray) – covariance matrix. Shape: (n, m).
  • X (numpy.ndarray) – one inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • hyps (dict.) – dictionary of hyperparameters for covariance function.
  • num_hyps (int.) – the number of hyperparameters == l.
  • fix_noise (bool.) – flag for fixing a noise.
Returns:

gradient matrix over hyperparameters. Shape: (n, m, l).

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.covariance.grad_cov_matern52(cov_X_Xp: numpy.ndarray, X: numpy.ndarray, Xp: numpy.ndarray, hyps: dict, num_hyps: int, fix_noise: bool) → numpy.ndarray

It computes gradients of Matern 5/2 kernel over X and Xp, where hyps is given.

Parameters:
  • cov_X_Xp (numpy.ndarray) – covariance matrix. Shape: (n, m).
  • X (numpy.ndarray) – one inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • hyps (dict.) – dictionary of hyperparameters for covariance function.
  • num_hyps (int.) – the number of hyperparameters == l.
  • fix_noise (bool.) – flag for fixing a noise.
Returns:

gradient matrix over hyperparameters. Shape: (n, m, l).

Return type:

numpy.ndarray

Raises:

AssertionError

bayeso.covariance.grad_cov_se(cov_X_Xp: numpy.ndarray, X: numpy.ndarray, Xp: numpy.ndarray, hyps: dict, num_hyps: int, fix_noise: bool) → numpy.ndarray

It computes gradients of squared exponential kernel over X and Xp, where hyps is given.

Parameters:
  • cov_X_Xp (numpy.ndarray) – covariance matrix. Shape: (n, m).
  • X (numpy.ndarray) – one inputs. Shape: (n, d).
  • Xp (numpy.ndarray) – another inputs. Shape: (m, d).
  • hyps (dict.) – dictionary of hyperparameters for covariance function.
  • num_hyps (int.) – the number of hyperparameters == l.
  • fix_noise (bool.) – flag for fixing a noise.
Returns:

gradient matrix over hyperparameters. Shape: (n, m, l).

Return type:

numpy.ndarray

Raises:

AssertionError