covariance_functions
Methods for the covariance_functions module in hetgpy
suite of covariance functions in hetGPy
Note that most of these are not called by the user, but these functions provide the covariance kernels (and their gradients)
- cov_Gaussian(X1, X2=None, theta=None)[source]
Euclidean distances, scaled by theta
Notes
For an alternative implementation: https://stackoverflow.com/questions/27948363/numpy-broadcast-to-perform-euclidean-distance-vectorized threeSums = np.sum(np.square(A)[:,np.newaxis,:], axis=2) - 2 * A.dot(B.T) + np.sum(np.square(B), axis=1) np.exp(-threeSums/theta)
- cov_gen(X1, X2=None, theta=None, type=None)[source]
Correlation function of selected type, supporting both isotropic and product forms
- Parameters:
X1 (ndarray) – matrix of design locations, one point per row
X2 (ndarray) – matrix of design locations if correlation is calculated between X1 and X2 (otherwise calculated between X1 and itself)
theta (np.array or scalar) – vector of lengthscale parameters (either of size one if isotropic or of size d if anisotropic)
type (str) – one of “Gaussian”, “Matern5_2”, “Matern3_2”
- Return type:
matrix of covariances between design locations
Examples
>>> from hetgpy.covariance_functions import cov_gen >>> import numpy as np >>> X = np.random.default_rng(42).integers(low=1,high=20,size=(50,2)) >>> K = cov_gen(X1=X,X2=X,theta=np.array([1,2]),type="Gaussian")
Notes
Definition of univariate correlation function and hyperparameters:
“Gaussian”: \(c(x, y) = \exp(-(x-y)^2/\theta)\)
“Matern5_2”: \(c(x, y) = (1+\sqrt{5}/\theta * |x-y\ + 5/(3*\theta^2)(x-y)^2) * \exp(-\sqrt{5}*|x-y|/\theta)\)
“Matern3_2”: \(c(x, y) = (1+\sqrt{3}/\theta * |x-y|) * \exp(-\sqrt{3}*|x-y|/\theta)\)
Multivariate correlations are product of univariate ones.
- partial_d_C_Gaussian_dX_i_j(X1, theta, i1, i2)[source]
Derivative with respect to X[i,j]. Useful for pseudo inputs, to be multiplied by the covariance matrix
- Parameters:
i1 (int) – row
i2 (int) – column
- partial_d_C_Gaussian_dtheta_k(X1, theta)[source]
Partial derivative of the covariance matrix with respect to theta[k] (to be multiplied by the covariance matrix)
- partial_d_C_Matern3_2_dX_i_j(X1, theta, i1, i2)[source]
Derivative with respect to X[i,j]. Useful for pseudo inputs, to be multiplied by the covariance matrix
- Parameters:
i1 (int) – row
i2 (int) – column
- partial_d_C_Matern3_2_dtheta_k(X1, theta)[source]
Partial derivative of the covariance matrix with respect to theta[k] (to be multiplied by the covariance matrix)
- partial_d_C_Matern5_2_dX_i_j(X1, theta, i1, i2)[source]
Derivative with respect to X[i,j]. Useful for pseudo inputs, to be multiplied by the covariance matrix
- Parameters:
i1 (int) – row
i2 (int) – column
- partial_d_C_Matern5_2_dtheta_k(X1, theta)[source]
Partial derivative of the covariance matrix with respect to theta[k] (to be multiplied by the covariance matrix)
- partial_d_Cg_Gaussian_d_k_theta_g(X1, theta, k_theta_g)[source]
Partial derivative of the covariance matrix of the noise process with respect to k_theta_g (to be multiplied by the covariance matrix)
- partial_d_Cg_Matern3_2_d_k_theta_g(X1, theta, k_theta_g)[source]
Partial derivative of the covariance matrix of the noise process with respect to k_theta_g (to be multiplied by the covariance matrix)
- partial_d_Cg_Matern5_2_d_k_theta_g(X1, theta, k_theta_g)[source]
Partial derivative of the covariance matrix of the noise process with respect to k_theta_g (to be multiplied by the covariance matrix)
- partial_d_k_Gaussian_dX_i_j(X1, X2, theta, i1, i2)[source]
Derivative with respect to X[i,j]. Useful for pseudo inputs, to be multiplied by the covariance matrix
- Parameters:
i1 (int) – row
i2 (int) – column
- partial_d_k_Gaussian_dtheta_k(X1, X2, theta)[source]
Partial derivative of the covariance vector with respect to theta[k] (to be multiplied by the covariance vector)
- partial_d_k_Matern3_2_dX_i_j(X1, X2, theta, i1, i2)[source]
Derivative with respect to X[i,j]. Useful for pseudo inputs, to be multiplied by the covariance matrix
- Parameters:
i1 (int) – row
i2 (int) – column
theta (int) – lengthscales
- partial_d_k_Matern3_2_dtheta_k(X1, X2, theta)[source]
Partial derivative of the covariance vector with respect to theta[k] (to be multiplied by the covariance vector)
- partial_d_k_Matern5_2_dX_i_j(X1, X2, theta, i1, i2)[source]
Derivative with respect to X[i,j]. Useful for pseudo inputs, to be multiplied by the covariance matrix
Parameters: i1: int
row
- i2: int
column
- theta: ndarray
lengthscales
- partial_d_k_Matern5_2_dtheta_k(X1, X2, theta)[source]
Partial derivative of the covariance vector with respect to theta[k] (to be multiplied by the covariance vector)
- partial_d_kg_Gaussian_d_k_theta_g(X1, X2, theta, k_theta_g)[source]
Partial derivative of the covariance vector of the noise process with respect to k_theta_g (to be multiplied by the covariance vector)
- partial_d_kg_Matern3_2_d_k_theta_g(X1, X2, theta, k_theta_g)[source]
Partial derivative of the covariance vector of the noise process with respect to k_theta_g (to be multiplied by the covariance vector)
- partial_d_kg_Matern5_2_d_k_theta_g(X1, X2, theta, k_theta_g)[source]
Partial derivative of the covariance vector of the noise process with respect to k_theta_g (to be multiplied by the covariance vector)