Kernels#
- fvgp.kernels.squared_exponential_kernel(distance, length)[source]#
Function for the squared exponential kernel. kernel = np.exp(-(distance ** 2) / (2.0 * (length ** 2)))
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
length (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.squared_exponential_kernel_robust(distance, phi)[source]#
Function for the squared exponential kernel (robust version) kernel = np.exp(-(distance ** 2) * (phi ** 2))
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
phi (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.exponential_kernel(distance, length)[source]#
Function for the exponential kernel. kernel = np.exp(-(distance) / (length))
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
length (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.exponential_kernel_robust(distance, phi)[source]#
Function for the exponential kernel (robust version) kernel = np.exp(-(distance) * (phi**2))
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
phi (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.matern_kernel_diff1(distance, length)[source]#
Function for the Matern kernel, order of differentiability = 1. kernel = (1 + sqrt(3)*d/l) * exp(-sqrt(3)*d/l)
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
length (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.matern_kernel_diff1_grad(distance, dist_der)[source]#
Derivative of the Matern-1 kernel with respect to the hyperparameters. kernel_der = -sqrt(3)*d * dist_der * exp(-sqrt(3)*d)
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
dist_der (scalar or np.ndarray) – The derivative of the distance matrix. We assume here that the distance is a function of the hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.matern_kernel_diff1_robust(distance, phi)[source]#
Function for the Matern kernel, order of differentiability = 1, robust version. kernel = (1 + sqrt(3)*d*phi**2) * exp(-sqrt(3)*d*phi**2)
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
phi (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.matern_kernel_diff2(distance, length)[source]#
Function for the Matern kernel, order of differentiability = 2. kernel = (1 + sqrt(5)*d/l + 5*d**2/(3*l**2)) * exp(-sqrt(5)*d/l)
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
length (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.matern_kernel_diff2_robust(distance, phi)[source]#
Function for the Matern kernel, order of differentiability = 2, robust version. kernel = (1 + sqrt(5)*d*phi**2 + 15*d**2*phi**4) * exp(-sqrt(5)*d*phi**2)
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
phi (scalar) – The length scale hyperparameters.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.sparse_kernel(distance, radius)[source]#
Function for a compactly supported kernel.
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
radius (scalar) – Radius of support.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.periodic_kernel(distance, length, p)[source]#
Function for a periodic kernel. kernel = np.exp(-(2.0/length**2)*(np.sin(np.pi*distance/p)**2))
- Parameters:
distance (scalar or np.ndarray) – Distance between a set of points.
length (scalar) – Length scale.
p (scalar) – Period.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.linear_kernel(x1, x2, hp1, hp2, hp3)[source]#
Function for a linear kernel. kernel = hp1 + (hp2*(x1-hp3)*(x2-hp3))
- fvgp.kernels.dot_product_kernel(x1, x2, hp, matrix)[source]#
Function for a dot-product kernel. kernel = hp + x1.T @ matrix @ x2
- Parameters:
x1 (np.ndarray) – Point 1.
x2 (np.ndarray) – Point 2.
hp (float) – Offset hyperparameter.
matrix (np.ndarray) – PSD matrix defining the inner product.
- Returns:
Kernel output
- Return type:
same as distance parameter.
- fvgp.kernels.wendland_kernel(d)[source]#
Function for the Wendland kernel with a given distance matrix. The Wendland kernel is compactly supported, leading to sparse covariance matrices.
- Parameters:
d (np.ndarray) – Distance matrix.
- Returns:
Covariance matrix
- Return type:
np.ndarray
- fvgp.kernels.wendland_anisotropic(x1, x2, hyperparameters)[source]#
Function for the Wendland kernel. The Wendland kernel is compactly supported, leading to sparse covariance matrices.
- Parameters:
x1 (np.ndarray) – Numpy array of shape (U x D).
x2 (np.ndarray) – Numpy array of shape (V x D).
hyperparameters (np.ndarray) – Array of hyperparameters. For this kernel we need D + 1 hyperparameters.
- Returns:
Covariance matrix
- Return type:
np.ndarray
- fvgp.kernels.non_stat_kernel(x1, x2, x0, w, l)[source]#
Non-stationary kernel. kernel = g(x1) g(x2)
- Parameters:
x1 (np.ndarray) – Numpy array of shape (U x D).
x2 (np.ndarray) – Numpy array of shape (V x D).
x0 (np.ndarray) – Numpy array of the basis function locations.
w (np.ndarray) – 1d np.ndarray of weights. len(w) = len(x0).
l (float) – Width measure of the basis functions.
- Returns:
Covariance matrix
- Return type:
np.ndarray
- fvgp.kernels.non_stat_kernel_gradient(x1, x2, x0, w, l)[source]#
Non-stationary kernel gradient. kernel = g(x1) g(x2)
- Parameters:
x1 (np.ndarray) – Numpy array of shape (U x D).
x2 (np.ndarray) – Numpy array of shape (V x D).
x0 (np.ndarray) – Numpy array of the basis function locations.
w (np.ndarray) – 1d np.ndarray of weights. len(w) = len(x0).
l (float) – Width measure of the basis functions.
- Returns:
Covariance matrix
- Return type:
np.ndarray
- fvgp.kernels.get_distance_matrix(x1, x2)[source]#
Function to calculate the pairwise distance matrix of points in x1 and x2.
- Parameters:
x1 (np.ndarray) – Numpy array of shape (U x D).
x2 (np.ndarray) – Numpy array of shape (V x D).
- Returns:
distance matrix
- Return type:
np.ndarray
- fvgp.kernels.get_anisotropic_distance_matrix(x1, x2, hps)[source]#
Function to calculate the pairwise axial-anisotropic distance matrix of points in x1 and x2.
- Parameters:
x1 (np.ndarray) – Numpy array of shape (U x D).
x2 (np.ndarray) – Numpy array of shape (V x D).
hps (np.ndarray) – 1d array of values. The diagonal of the metric tensor describing the axial anisotropy.
- Returns:
distance matrix
- Return type:
np.ndarray
- fvgp.kernels.wendland_anisotropic_gp2Scale_cpu(x1, x2, hps)[source]#
Function for the anisotropic Wendland kernel computed on the CPU. The Wendland kernel is compactly supported, leading to sparse covariance matrices.
- Parameters:
x1 (np.ndarray) – Numpy array of shape (U x D).
x2 (np.ndarray) – Numpy array of shape (V x D).
hps (np.ndarray) – Array of hyperparameters. For this kernel we need D + 1 hyperparameters.
- Returns:
Covariance matrix
- Return type:
np.ndarray
- fvgp.kernels.wendland_anisotropic_gp2Scale_gpu(x1, x2, hps)[source]#
Function for the anisotropic Wendland kernel computed on the GPU. Picks the first usable GPU backend (torch CUDA or MPS, else cupy); falls back to the CPU implementation with a UserWarning if no GPU backend is available. The Wendland kernel is compactly supported, leading to sparse covariance matrices.
- Parameters:
x1 (np.ndarray) – Numpy array of shape (U x D).
x2 (np.ndarray) – Numpy array of shape (V x D).
hps (np.ndarray) – Array of hyperparameters. For this kernel we need D + 1 hyperparameters.
- Returns:
Covariance matrix
- Return type:
np.ndarray
- fvgp.kernels.wendland_anisotropic_gp2Scale_cpu_sparse(x1, x2, hps)[source]#
Support-aware anisotropic Wendland kernel for gp2Scale.
Preserves the usual kernel interface but performs block-local support checks and radius-search assembly internally, returning a sparse COO matrix directly. Intended for gp2Scale workflows where the batchwise kernel is assembled on sparse blocks. Sort batches by a locality-preserving column (e.g. time) for best performance.
- fvgp.kernels.wendland_anisotropic_gp2Scale_gpu_sparse(x1, x2, hps)[source]#
GPU-backed support-aware anisotropic Wendland kernel for gp2Scale.
Neighbor discovery remains host-side; only the distance/polynomial evaluation on the discovered support graph is GPU-backed when a usable backend (torch CUDA/MPS or cupy) is available. Falls back to the CPU sparse variant with a UserWarning otherwise.
- fvgp.kernels.wasserstein_1d(a, b)[source]#
The 1d Wasserstein distance.
- Parameters:
a (np.ndarray) – 1d Numpy array. Input distribution.
b (np.ndarray) – 1d Numpy array. Input distribution.
- Returns:
Wasserstein distance
- Return type:
- fvgp.kernels.wasserstein_1d_outer_vec(a, b)[source]#
Vectorized pairwise 1-D Wasserstein distance between all rows of
aandb.- Parameters:
a (np.ndarray) – Array of shape (M, K); each row is an unnormalized 1-D measure.
b (np.ndarray) – Array of shape (N, K); each row is an unnormalized 1-D measure.
- Returns:
W – Distance matrix of shape (M, N).
- Return type:
np.ndarray
- fvgp.kernels.bump(d, r, beta=1.0, ampl=1.0)[source]#
Smooth compactly-supported bump function evaluated over a distance array.
- Parameters:
- Returns:
bump – Bump values, same shape as
d.- Return type:
np.ndarray
- fvgp.kernels.sle_kernel(x1, x2, hps, args)[source]#
Sparse-Landmark-Embedding (SLE) kernel.
Embeds points via a bump-function basis centered on the training set, then applies a squared-exponential kernel on the embedded space. Requires
args["x_data"](the training locations) to construct the basis.- Parameters:
x1 (np.ndarray) – Query points, shape (N1, D).
x2 (np.ndarray) – Query points, shape (N2, D).
hps (np.ndarray) – Hyperparameters
[amplitude, radius, beta, length_scale].args (dict) – Must contain key
"x_data"with the training point locations.
- Returns:
K – Covariance matrix of shape (N1, N2).
- Return type:
np.ndarray