rgpycrumbs.surfaces._base

Classes

BaseSurface

Abstract base class for standard (non-gradient) surface models.

BaseGradientSurface

Abstract base class for gradient-enhanced surface models.

Functions

safe_cholesky_solve(K, y, noise_scalar)

Solve with covariance-scaled roundoff jitter.

equilibrated_inverse_solve(K, y, noise_scalar)

Inverse and weights of a gradient-enhanced covariance matrix.

generic_negative_mll(K, y, noise_scalar)

Calculates the negative Marginal Log-Likelihood (MLL).

Module Contents

rgpycrumbs.surfaces._base.safe_cholesky_solve(K, y, noise_scalar)[source]

Solve with covariance-scaled roundoff jitter.

Added in version 1.0.0.

Changed in version 1.14.0: The jitter is the Cholesky roundoff bound of K, and the jitter_steps retries are gone. A factorization with non-finite entries returns zeros and a NaN log-determinant.

Parameters:
  • K – Covariance matrix.

  • y – Observation vector.

  • noise_scalar – Initial noise level.

Returns:

(alpha, log_det) where alpha is the solution vector and

log_det is the log determinant of the jittered matrix.

Return type:

tuple

rgpycrumbs.surfaces._base.equilibrated_inverse_solve(K, y, noise_scalar)[source]

Inverse and weights of a gradient-enhanced covariance matrix.

Added in version 1.11.1.

The value and gradient rows of K differ in scale by 1 / l**2, so a short length scale and repeated inputs leave K too ill-conditioned for a float32 inverse. The matrix is solved as K + noise * I + jitter * diag(K) after a symmetric diagonal scaling to unit diagonal, which keeps the jitter relative to each row. jitter is covariance_roundoff_factor for the order of K.

Changed in version 1.14.0: The relative jitter is the Cholesky roundoff factor for the order of K, and the jitter argument is gone.

Parameters:
  • K – Covariance matrix without noise.

  • y – Observation vector.

  • noise_scalar – Noise level added to the diagonal.

Returns:

(alpha, K_inv) for the regularized matrix.

Return type:

tuple

rgpycrumbs.surfaces._base.generic_negative_mll(K, y, noise_scalar)[source]

Calculates the negative Marginal Log-Likelihood (MLL).

Added in version 1.0.0.

Parameters:
  • K – Covariance matrix.

  • y – Observation vector.

  • noise_scalar – Noise level for regularization.

Returns:

The negative MLL value, or a high penalty if Cholesky fails.

Return type:

float

class rgpycrumbs.surfaces._base.BaseSurface(x_obs, y_obs, smoothing=None, length_scale=None, optimize=True, **_kwargs)[source]

Abstract base class for standard (non-gradient) surface models.

Added in version 1.0.0.

Changed in version 1.14.0: The default smoothing is None, which treats the data as exact.

Derived classes must implement _fit, _solve, _predict_chunk, and _var_chunk.

x_obs[source]
y_obs[source]
y_mean[source]
y_centered[source]
abstractmethod _fit(smoothing, length_scale, optimize)[source]

Internal method to perform parameter optimization.

abstractmethod _solve()[source]

Internal method to solve the linear system for weights.

__call__(x_query, chunk_size=500)[source]

Predict values at query points.

Parameters:
  • x_query – Query inputs (M, D).

  • chunk_size – Number of points to process per batch to avoid OOM.

Returns:

Predicted values (M,).

Return type:

jnp.ndarray

predict_var(x_query, chunk_size=500)[source]

Predict posterior variance at query points.

Added in version 1.1.0.

Parameters:
  • x_query – Query inputs (M, D).

  • chunk_size – Number of points to process per batch.

Returns:

Predicted variances (M,).

Return type:

jnp.ndarray

abstractmethod _predict_chunk(chunk)[source]

Internal method for batch prediction.

abstractmethod _var_chunk(chunk)[source]

Internal method for batch variance.

class rgpycrumbs.surfaces._base.BaseGradientSurface(x, y, gradients=None, smoothing=None, length_scale=None, optimize=True, noise_per_obs=None, **_kwargs)[source]

Abstract base class for gradient-enhanced surface models.

Added in version 1.1.0.

Changed in version 1.14.0: The default smoothing is None, which treats the data as exact.

Derived classes must implement _fit, _solve, _predict_chunk, and _var_chunk. These models incorporate both values and their gradients into the fit.

_noise_per_obs[source]
x[source]
y_full[source]
e_mean[source]
y_flat[source]
D_plus_1[source]
abstractmethod _fit(smoothing, length_scale, optimize)[source]

Internal method to perform parameter optimization.

abstractmethod _solve()[source]

Internal method to solve the linear system for weights.

__call__(x_query, chunk_size=500)[source]

Predict values at query points.

Parameters:
  • x_query – Query inputs (M, D).

  • chunk_size – Number of points to process per batch.

Returns:

Predicted values (M,).

Return type:

jnp.ndarray

predict_var(x_query, chunk_size=500)[source]

Predict posterior variance at query points.

Added in version 1.1.0.

Parameters:
  • x_query – Query inputs (M, D).

  • chunk_size – Number of points to process per batch.

Returns:

Predicted variances (M,).

Return type:

jnp.ndarray

abstractmethod _predict_chunk(chunk)[source]

Internal method for batch prediction.

abstractmethod _var_chunk(chunk)[source]

Internal method for batch variance.