bayeso.covariance

It defines covariance functions and their associated functions.

bayeso.covariance.choose_fun_cov(str_cov: str, choose_grad: bool) → callable

It is for choosing a covariance function or a function for computing gradients of covariance function.

Parameters:
  • str_cov (str.) – the name of covariance function.
  • choose_grad (bool.) – flag for returning a function for the gradients
Returns:

covariance function, or function for computing gradients of covariance function.

Return type:

function

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.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