Skip to main content

emulators.fast_predict

emulators.fast_predict

Fast GPR prediction using numba, with no TensorFlow call at prediction time.

Extracts kernel hyperparameters from a trained GPflow model, precomputes alpha = (K + noise I)^-1 (y - c) and the inverse Cholesky factor once, then predicts the SE-kernel GP mean and variance in numpy/numba.

Not currently used by the engine, which filters through GPR.predict. Measured against GPR.predict on 20,000 points (Apple M1 Max), it is 2.6x faster with 180 training points in 4 dimensions and 1.1x with 1,800 in 21, so it is kept for a future, faster GPR.predict rather than as a separate filter.

Usage:

from historymatching.emulators.fast_predict import FastGPRPredictor

fast = FastGPRPredictor.from_emulator(emulator)   # a trained GPR emulator
mean, var = fast.predict(X_test)                  # numpy arrays; var includes the noise

Classes

Name Description
FastGPRPredictor Fast GPR predictor extracted from a trained GPflow model.

FastGPRPredictor

emulators.fast_predict.FastGPRPredictor(
    X_train,
    kernel_var,
    kernel_ls,
    noise_var,
    mean_c,
    alpha,
    L_inv,
    x_min,
    x_range,
    y_mean,
    y_std,
)

Fast GPR predictor extracted from a trained GPflow model.

Precomputes alpha = (K + σ²I)^{-1} (y - c) at construction time. Predictions are pure numpy/numba — no TensorFlow calls.

Methods

Name Description
from_emulator Extract a fast predictor from a trained GPR emulator.
predict Predict mean and variance in original output space.
predict_mean Predict mean in original (un-normalized) output space.
from_emulator
emulators.fast_predict.FastGPRPredictor.from_emulator(emulator)

Extract a fast predictor from a trained GPR emulator.

predict
emulators.fast_predict.FastGPRPredictor.predict(X_raw)

Predict mean and variance in original output space.

Parameters
Name Type Description Default
X_raw (n_test, n_dims) array in original parameter space. required
Returns
Name Type Description
(mean, var) tuple of (n_test,) arrays.
predict_mean
emulators.fast_predict.FastGPRPredictor.predict_mean(X_raw)

Predict mean in original (un-normalized) output space.

Parameters
Name Type Description Default
X_raw (n_test, n_dims) array in original parameter space. required
Returns
Name Type Description
(n_test,) array of predicted means.