Full GDDEGP#

class jetgp.full_gddegp.gddegp.gddegp(x_train, y_train, n_order, rays_list, der_indices, derivative_locations=None, n_bases=None, normalize=True, sigma_data=None, kernel='SE', kernel_type='anisotropic', smoothness_parameter=None)[source]#

Bases: object

Global Directional Derivative-Enhanced Gaussian Process (GDDEGP) model.

Supports point-wise directional derivatives with unique rays per point, hypercomplex representation, and automatic normalization. Includes methods for training, prediction, and uncertainty quantification using kernel methods.

Parameters:
  • x_train (ndarray) – Training input data of shape (n_samples, n_features).

  • y_train (list or ndarray) – Training targets or list of directional derivatives.

  • n_order (int) – Maximum derivative order.

  • rays_list (list of ndarray) – List of ray arrays. rays_list[i] has shape (d, len(derivative_locations[i])).

  • der_indices (list of lists) – Derivative multi-indices corresponding to each derivative term.

  • derivative_locations (list of lists) – Which training points have which derivatives.

  • n_bases (int, optional) – Override the OTI space size. By default 2 * n_direction_types (inferred from der_indices). Pass explicitly when training on function values only (der_indices=[]) and you still want to predict directional derivatives: set n_bases = 2 * n_prediction_direction_types.

  • normalize (bool, default=True) – Whether to normalize inputs and outputs.

  • sigma_data (float or array-like, optional) – Observation noise standard deviation or diagonal noise values.

  • kernel (str, default='SE') – Kernel type (‘SE’, ‘RQ’, ‘Matern’, etc.).

  • kernel_type (str, default='anisotropic') – Kernel anisotropy (‘anisotropic’ or ‘isotropic’).

  • smoothness_parameter (float, optional) – Smoothness parameter for Matern kernel.

optimize_hyperparameters(*args, **kwargs)[source]#

Run the optimizer to find the best kernel hyperparameters. Returns optimized hyperparameter vector.

predict(X_test, params, rays_predict=None, calc_cov=False, return_deriv=False, derivs_to_predict=None)[source]#

Predict posterior mean and optional variance at test points.

Parameters:
  • X_test (ndarray) – Test input points of shape (n_test, n_features).

  • params (ndarray) – Log-scaled kernel hyperparameters.

  • rays_predict (list of ndarray, optional) – Rays at test points for derivative predictions.

  • calc_cov (bool, default=False) – Whether to compute predictive variance.

  • return_deriv (bool, default=False) – Whether to return derivative predictions.

  • derivs_to_predict (list, optional) – Specific derivatives to predict. Can include derivatives not present in the training set — the cross-covariance K_* is constructed from kernel derivatives and does not require the requested derivative to have been observed during training. Each entry must be a valid derivative spec within n_bases and n_order. If None, defaults to all derivatives used in training.

Returns:

  • f_mean (ndarray) – Predictive mean vector.

  • f_var (ndarray, optional) – Predictive variance vector (only if calc_cov=True).

jetgp.full_gddegp.gddegp_utils.compute_dimension_differences(k, X1, X2, n1, n2, rays_X1, rays_X2, derivative_locations_X1, derivative_locations_X2, e_tags_1, e_tags_2, oti_module)[source]#

Compute differences for a single dimension k. Only perturbs points at specified derivative_locations with their corresponding rays.

Parameters:
  • k (int) – Dimension index.

  • X1 (oti.array) – Input point arrays of shape (n1, d) and (n2, d).

  • X2 (oti.array) – Input point arrays of shape (n1, d) and (n2, d).

  • n1 (int) – Number of points in X1, X2.

  • n2 (int) – Number of points in X1, X2.

  • rays_X1 (list of ndarray or None) – rays_X1[i] has shape (d, len(derivative_locations_X1[i])).

  • rays_X2 (list of ndarray or None) – rays_X2[i] has shape (d, len(derivative_locations_X2[i])).

  • derivative_locations_X1 (list of list) – derivative_locations_X1[i] contains indices of X1 points with direction i.

  • derivative_locations_X2 (list of list) – derivative_locations_X2[i] contains indices of X2 points with direction i.

  • e_tags_1 (list) – OTI basis elements for each direction.

  • e_tags_2 (list) – OTI basis elements for each direction.

  • oti_module (module) – The PyOTI static module.

Returns:

diffs_k – Differences for dimension k with shape (n1, n2).

Return type:

oti.array

jetgp.full_gddegp.gddegp_utils.deriv_map(nbases, order)[source]#

Create mapping from (order, index) to flattened index.

jetgp.full_gddegp.gddegp_utils.differences_by_dim_func(X1, X2, rays_X1, rays_X2, derivative_locations_X1, derivative_locations_X2, n_order, oti_module, return_deriv=True)[source]#

Compute dimension-wise differences with OTI tagging on both X1 and X2.

GDDEGP uses a dual-tag OTI scheme: X1 points are tagged with odd bases (e_1, e_3, e_5, …) and X2 points with even bases (e_2, e_4, e_6, …). This requires n_bases = 2 * n_direction_types.

The dual-tag approach is necessary because each point can have a unique directional ray, and the kernel matrix requires derivatives with respect to both sets of directions simultaneously. In the difference X1 - X2, the OTI coefficient for basis e_i at position (a, b) encodes only the ray of the point that was tagged with e_i. A single-tag scheme (tagging both X1 and X2 with the same basis) would conflate the two rays in the difference, making it impossible to recover the correct cross-derivative v_i(a)^T H v_j(b) needed for K_dd blocks, and producing an asymmetric K_fd block when rays vary per point.

Parameters:
  • X1 (ndarray of shape (n1, d)) – First set of input points.

  • X2 (ndarray of shape (n2, d)) – Second set of input points.

  • rays_X1 (list of ndarray or None) – List of ray arrays for X1. rays_X1[i] has shape (d, len(derivative_locations_X1[i])).

  • rays_X2 (list of ndarray or None) – List of ray arrays for X2. rays_X2[i] has shape (d, len(derivative_locations_X2[i])).

  • derivative_locations_X1 (list of list) – derivative_locations_X1[i] contains indices of X1 points with derivative direction i.

  • derivative_locations_X2 (list of list) – derivative_locations_X2[i] contains indices of X2 points with derivative direction i.

  • n_order (int) – Derivative order for OTI tagging.

  • oti_module (module) – The PyOTI static module (e.g., pyoti.static.onumm4n2).

  • return_deriv (bool, optional) – If True, use order 2*n_order for derivative-derivative blocks.

Returns:

differences_by_dim – List of length d, each element is an (n1, n2) OTI array.

Return type:

list of oti.array

jetgp.full_gddegp.gddegp_utils.extract_and_assign(content_full, row_indices, col_indices, K, row_start, col_start)[source]#

Extract submatrix and assign directly to K.

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols_full)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract.

  • col_indices (ndarray of int64) – Column indices to extract.

  • K (ndarray) – Target matrix to fill.

  • row_start (int) – Starting row index in K.

  • col_start (int) – Starting column index in K.

jetgp.full_gddegp.gddegp_utils.extract_and_assign_transposed(content_full, row_indices, col_indices, K, row_start, col_start)[source]#

Extract submatrix and assign its transpose directly to K. Replaces K[…] = content_full[np.ix_(row_indices, col_indices)].T

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols_full)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract from content_full.

  • col_indices (ndarray of int64) – Column indices to extract from content_full.

  • K (ndarray) – Target matrix to fill.

  • row_start (int) – Starting row index in K.

  • col_start (int) – Starting column index in K.

jetgp.full_gddegp.gddegp_utils.extract_cols(content_full, col_indices, n_rows)[source]#

Extract columns from content_full at specified indices.

Parameters:
  • content_full (ndarray of shape (n_rows, n_cols_full)) – Source matrix.

  • col_indices (ndarray of int64) – Column indices to extract.

  • n_rows (int) – Number of rows.

Returns:

result – Extracted columns.

Return type:

ndarray of shape (n_rows, len(col_indices))

jetgp.full_gddegp.gddegp_utils.extract_cols_and_assign(content_full, col_indices, K, row_start, col_start, n_rows)[source]#

Extract columns and assign directly to K.

Parameters:
  • content_full (ndarray of shape (n_rows, n_cols_full)) – Source matrix.

  • col_indices (ndarray of int64) – Column indices to extract.

  • K (ndarray) – Target matrix to fill.

  • row_start (int) – Starting row index in K.

  • col_start (int) – Starting column index in K.

  • n_rows (int) – Number of rows to copy.

jetgp.full_gddegp.gddegp_utils.extract_cols_and_assign_transposed(content_full, col_indices, K, row_start, col_start, n_rows)[source]#

Extract columns and assign transposed result directly to K. Replaces K[…] = content_full[:, col_indices].T

Parameters:
  • content_full (ndarray of shape (n_rows, n_cols_full)) – Source matrix.

  • col_indices (ndarray of int64) – Column indices to extract.

  • K (ndarray) – Target matrix to fill.

  • row_start (int) – Starting row index in K.

  • col_start (int) – Starting column index in K.

  • n_rows (int) – Number of rows in content_full.

jetgp.full_gddegp.gddegp_utils.extract_cols_transposed(content_full, col_indices, n_rows)[source]#

Extract columns and return transposed result. Replaces content_full[:, col_indices].T

Parameters:
  • content_full (ndarray of shape (n_rows, n_cols_full)) – Source matrix.

  • col_indices (ndarray of int64) – Column indices to extract.

  • n_rows (int) – Number of rows.

Returns:

result – Transposed extracted columns.

Return type:

ndarray of shape (len(col_indices), n_rows)

jetgp.full_gddegp.gddegp_utils.extract_rows(content_full, row_indices, n_cols)[source]#

Extract rows from content_full at specified indices.

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract.

  • n_cols (int) – Number of columns.

Returns:

result – Extracted rows.

Return type:

ndarray of shape (len(row_indices), n_cols)

jetgp.full_gddegp.gddegp_utils.extract_rows_and_assign(content_full, row_indices, K, row_start, col_start, n_cols)[source]#

Extract rows and assign directly to K.

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract.

  • K (ndarray) – Target matrix to fill.

  • row_start (int) – Starting row index in K.

  • col_start (int) – Starting column index in K.

  • n_cols (int) – Number of columns to copy.

jetgp.full_gddegp.gddegp_utils.extract_rows_and_assign_transposed(content_full, row_indices, K, row_start, col_start, n_cols)[source]#

Extract rows and assign transposed result directly to K. Replaces K[…] = content_full[row_indices, :].T

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract.

  • K (ndarray) – Target matrix to fill.

  • row_start (int) – Starting row index in K.

  • col_start (int) – Starting column index in K.

  • n_cols (int) – Number of columns in content_full.

jetgp.full_gddegp.gddegp_utils.extract_rows_transposed(content_full, row_indices, n_cols)[source]#

Extract rows and return transposed result. Replaces content_full[row_indices, :].T

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract.

  • n_cols (int) – Number of columns.

Returns:

result – Transposed extracted rows.

Return type:

ndarray of shape (n_cols, len(row_indices))

jetgp.full_gddegp.gddegp_utils.extract_submatrix(content_full, row_indices, col_indices)[source]#

Extract submatrix from content_full at specified row and column indices. Replaces the expensive np.ix_ operation.

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols_full)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract.

  • col_indices (ndarray of int64) – Column indices to extract.

Returns:

result – Extracted submatrix.

Return type:

ndarray of shape (len(row_indices), len(col_indices))

jetgp.full_gddegp.gddegp_utils.extract_submatrix_transposed(content_full, row_indices, col_indices)[source]#

Extract submatrix and return its transpose. Replaces content_full[np.ix_(row_indices, col_indices)].T

Parameters:
  • content_full (ndarray of shape (n_rows_full, n_cols_full)) – Source matrix.

  • row_indices (ndarray of int64) – Row indices to extract.

  • col_indices (ndarray of int64) – Column indices to extract.

Returns:

result – Transposed extracted submatrix.

Return type:

ndarray of shape (len(col_indices), len(row_indices))

jetgp.full_gddegp.gddegp_utils.make_first_even(der_indices)[source]#

Transform derivative indices to use even bases (2, 4, 6, …).

jetgp.full_gddegp.gddegp_utils.make_first_odd(der_indices)[source]#

Transform derivative indices to use odd bases (1, 3, 5, …).

jetgp.full_gddegp.gddegp_utils.precompute_kernel_plan(n_order, n_bases, der_indices, powers, index)[source]#

Precompute structural info for rbf_kernel_fast (GDDEGP even/odd variant).

jetgp.full_gddegp.gddegp_utils.rbf_kernel(phi, phi_exp, n_order, n_bases, der_indices, index=None)[source]#

Assembles the full GDDEGP covariance matrix with selective derivative coverage.

This version uses Numba-accelerated functions for efficient matrix slicing, replacing expensive np.ix_ operations.

Parameters:
  • phi (OTI array) – Base kernel matrix from kernel_func(differences, length_scales).

  • phi_exp (ndarray) – Expanded derivative array from phi.get_all_derivs().

  • n_order (int) – Maximum derivative order.

  • n_bases (int) – Number of OTI bases (must be even).

  • der_indices (list) – Derivative index specifications.

  • index (list of list) – index[i] contains indices of points with derivative direction i.

Returns:

K – Kernel matrix with block structure based on derivative locations.

Return type:

ndarray

jetgp.full_gddegp.gddegp_utils.rbf_kernel_fast(phi_exp_3d, plan, out=None)[source]#

Fast kernel assembly using precomputed plan and fused numba kernel.

jetgp.full_gddegp.gddegp_utils.rbf_kernel_predictions(phi, phi_exp, n_order, n_bases, der_indices, return_deriv, index=None, common_derivs=None, calc_cov=False)[source]#

Constructs the RBF kernel matrix for predictions with selective derivative coverage.

This version uses Numba-accelerated functions for efficient matrix slicing.

Parameters:
  • phi (OTI array) – Base kernel matrix between test and training points.

  • phi_exp (ndarray) – Expanded derivative array from phi.get_all_derivs().

  • n_order (int) – Maximum derivative order.

  • n_bases (int) – Number of OTI bases.

  • der_indices (list) – Derivative specifications for training data.

  • return_deriv (bool) – If True, predict derivatives at test points.

  • index (list of list) – Training point indices for each derivative type.

  • common_derivs (list) – Common derivative indices to predict.

  • calc_cov (bool) – If True, computing covariance.

Returns:

K – Prediction kernel matrix.

Return type:

ndarray

jetgp.full_gddegp.gddegp_utils.transform_der_indices(der_indices, der_map)[source]#

Transform derivative indices to flattened format.

class jetgp.full_gddegp.optimizer.Optimizer(model)[source]#

Bases: object

Optimizer class to perform hyperparameter tuning for derivative-enhanced Gaussian Process models by minimizing the negative log marginal likelihood (NLL).

Parameters:

model (object) – An instance of a model (e.g., ddegp) containing the necessary training data and kernel configuration.

negative_log_marginal_likelihood(x0)[source]#

Compute the negative log marginal likelihood (NLL) of the model.

NLL = 0.5 * y^T K^-1 y + 0.5 * log|K| + 0.5 * N * log(2π)

Parameters:

x0 (ndarray) – Vector of log-scaled hyperparameters (length scales and noise).

Returns:

Value of the negative log marginal likelihood.

Return type:

float

nll_and_grad(x0)[source]#

Compute NLL and its gradient in a single pass, sharing one Cholesky.

nll_grad(x0)[source]#

Analytic gradient of the NLL w.r.t. log10-scaled hyperparameters.

nll_wrapper(x0)[source]#

Wrapper function to compute NLL for optimizer.

Parameters:

x0 (ndarray) – Hyperparameter vector.

Returns:

NLL evaluated at x0.

Return type:

float

optimize_hyperparameters(optimizer='pso', **kwargs)[source]#

Optimize the DEGP model hyperparameters using Particle Swarm Optimization (PSO).

Parameters:#

n_restart_optimizerint, default=20

Maximum number of iterations for PSO.

swarm_sizeint, default=20

Number of particles in the swarm.

verbosebool, default=True

Controls verbosity of PSO output.

Returns:#

best_xndarray

The optimal set of hyperparameters found.