bayeso.covariance
It defines covariance functions and their associated functions. Derivatives of covariance functions with respect to hyperparameters are described in these notes.
- 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: ndarray, Xp: ndarray, hyps: dict, same_X_Xp: bool, jitter: float = 1e-05) 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: ndarray, Xp: ndarray, lengthscales: ndarray | float, signal: float) 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: ndarray, Xp: ndarray, lengthscales: ndarray | float, signal: float) 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: ndarray, Xp: ndarray, lengthscales: ndarray | float, signal: float) 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: ndarray, Xp: ndarray, lengthscales: ndarray | float, signal: float) 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: ndarray, hyps: dict, str_cov: str, fix_noise: bool = True, use_gradient: bool = False, debug: bool = False) Tuple[ndarray, ndarray, 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, ValueError
- bayeso.covariance.get_kernel_inverse(X_train: ndarray, hyps: dict, str_cov: str, fix_noise: bool = True, use_gradient: bool = False, debug: bool = False) Tuple[ndarray, ndarray, 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: ndarray, Xp: ndarray, hyps: dict, fix_noise: bool, same_X_Xp: bool = True, jitter: float = 1e-05) 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: ndarray, X: ndarray, Xp: ndarray, hyps: dict, num_hyps: int, fix_noise: bool) 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: ndarray, X: ndarray, Xp: ndarray, hyps: dict, num_hyps: int, fix_noise: bool) 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: ndarray, X: ndarray, Xp: ndarray, hyps: dict, num_hyps: int, fix_noise: bool) 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