API Reference

Surrogate API

Surrogate API

UQPyL.surrogate

The surrogate module trains predictive models for expensive simulations, objectives, or intermediate response surfaces.

Import

python
from UQPyL.surrogate.rbf import RBF
from UQPyL.surrogate.kriging import KRG
from UQPyL.surrogate.gp import GPR
from UQPyL.surrogate import MinMaxScaler, StandardScaler, KFold, AutoTuner

Public Objects

Top-level objects:

ObjectRole
SurrogateABCBase class for surrogate models.
MultiSurrogateContainer for one surrogate per output column.
AutoTunerHyper-parameter tuning helper.
PolyFeaturePolynomial feature expansion.
KFoldK-fold index splitter.
RandSelectRandom train/test splitter.
ScalerBase scaler interface.
MinMaxScalerMin-max scaler.
StandardScalerStandard scaler.

Model subpackages:

SubpackageImport pathMain objects
RBFUQPyL.surrogate.rbfRBF, Cubic, Linear, Multiquadric, ThinPlateSpline, Gaussian
Gaussian processUQPyL.surrogate.gpGPR
KrigingUQPyL.surrogate.krigingKRG
RegressionUQPyL.surrogate.regressionLinearRegression, PolynomialRegression
MARSUQPyL.surrogate.marsMARS
SVRUQPyL.surrogate.svrSVR

mars and svr may be unavailable when optional compiled dependencies are not installed.

Fit and Predict

All surrogate models follow the same high-level protocol:

python
model.fit(xTrain, yTrain)
yPred = model.predict(xPred)

Input and output arrays are normalized to 2D internally. yTrain may be 1D or 2D.

Example:

python
import numpy as np

from UQPyL.surrogate.rbf import RBF


X = np.linspace(0.0, 1.0, 8).reshape(-1, 1)
Y = np.sin(2 * np.pi * X)

model = RBF()
model.fit(X, Y)

pred = model.predict([[0.25], [0.75]])
print(pred)

Uncertainty output uses the common flags:

python
mean = model.predict(X)
mean, std = model.predict(X, returnStd=True)
mean, var = model.predict(X, returnVar=True)

Only models with supportsUncertainty=True support returnStd or returnVar.

SurrogateABC

Base class for surrogate models.

python
SurrogateABC(scalers=(None, None), polyFeature=None)
ParameterMeaning
scalersPair of optional (xScaler, yScaler).
polyFeatureOptional PolyFeature applied after input scaling.

Common methods:

MethodReturnsMeaning
fit(xTrain, yTrain)modelPrepare data, fit hyper-parameters, and fit the model.
predict(xPred, returnStd=False, returnVar=False)np.ndarray or tuplePredict output values, optionally with uncertainty.
prepareTrainingData(xTrain, yTrain)(X, Y)Validate, scale, and transform training data.
storeTrainingData(xTrain, yTrain)modelStore prepared training data.
requireFitted(*stateKeys)modelRaise if the model is not fitted.
getParaList()listReturn active tunable parameter names.
applyParameterValues(paraList, values, ignoreInactive=True)modelApply tuned parameter values.
getParameterValues(*args, ignoreInactive=False)value or tupleReturn current parameter values.

MultiSurrogate

Container for multi-output surrogate prediction.

python
MultiSurrogate(n_surrogates, models_list=[])
MethodReturnsMeaning
append(model)NoneAppend one SurrogateABC model.
fit(trainX, trainY)NoneFit one model per output column.
predict(testX)np.ndarrayHorizontally stack predictions from all models.

trainY.shape[1] and len(models_list) must match n_surrogates.

Models

RBF

Radial basis function surrogate.

python
RBF(
    scalers=(None, None),
    polyFeature=None,
    kernel=Cubic(),
    C_smooth=0.0,
    C_smooth_attr={...},
)
ParameterMeaning
kernelRBF kernel object.
C_smoothSmoothing parameter.
C_smooth_attrTuning metadata for C_smooth.

Additional methods:

MethodMeaning
setKernel(kernel)Replace the active kernel.
setKernelChoices(kernels)Register tunable kernel choices.

Available RBF kernels:

Kernel
Cubic
Linear
Multiquadric
ThinPlateSpline
Gaussian

GPR

Gaussian process regression surrogate.

python
GPR(
    scalers=(None, None),
    polyFeature=None,
    kernel=RBFKernel(),
    optimizer="Boxmin",
    nRestartTimes=5,
    C=1e-9,
    C_attr={...},
)
ParameterMeaning
kernelGaussian process kernel.
optimizerHyper-parameter optimizer.
nRestartTimesNumber of hyper-parameter optimization restarts.
CNumerical regularization parameter.
C_attrTuning metadata for C.

Additional methods:

MethodMeaning
setKernel(kernel)Replace the active kernel.
setKernelChoices(kernels)Register tunable kernel choices.

GPR supports uncertainty output.

KRG

Kriging surrogate.

python
KRG(
    scalers=(None, None),
    polyFeature=None,
    kernel=Guass(),
    regression="poly0",
    optimizer="Boxmin",
    nRestartTimes=5,
)
ParameterMeaning
kernelKriging correlation kernel.
regressionRegression trend. One of "poly0", "poly1", or "poly2".
optimizerHyper-parameter optimizer.
nRestartTimesNumber of hyper-parameter optimization restarts.

Additional methods:

MethodMeaning
setKernel(kernel)Replace the active kernel.
setKernelChoices(kernels)Register tunable kernel choices.

KRG supports uncertainty output.

LinearRegression

Linear regression surrogate.

python
LinearRegression(
    scalers=(None, None),
    polyFeature=None,
    lossType="Origin",
    fitIntercept=True,
    C=0.1,
    C_attr={...},
    maxIter=100,
    maxEpoch=500000.0,
    tolerance=0.001,
    p0=10,
)
ParameterMeaning
lossTypeRegression loss. One of "Origin", "Ridge", or "Lasso".
fitInterceptWhether to fit an intercept term.
CRegularization parameter.
maxIterMaximum outer iterations.
maxEpochMaximum Lasso epochs.
toleranceConvergence tolerance.
p0Lasso working-set parameter.

PolynomialRegression

Polynomial regression surrogate.

python
PolynomialRegression(
    scalers=(None, None),
    degree=2,
    degree_attr={...},
    onlyInteraction=False,
    lossType="Origin",
    fitIntercept=True,
    C=0.1,
    C_attr={...},
    maxIter=100,
    maxEpoch=500000.0,
    tolerance=0.001,
    p0=10,
)
ParameterMeaning
degreePolynomial degree.
onlyInteractionWhether to use interaction-only polynomial terms.
lossTypeRegression loss. One of "Origin", "Ridge", or "Lasso".

MARS

Multivariate adaptive regression splines surrogate.

python
MARS(
    scalers=(None, None),
    polyFeature=None,
    max_terms=400,
    max_degree=1,
    penalty=3.0,
    endspan_alpha=0.05,
    endspan=-1,
    minspan_alpha=0.05,
    minspan=-1,
    thresh=0.001,
    zero_tol=1e-12,
    min_search_points=100,
    check_every=-1,
    allow_linear=True,
    use_fast=False,
    fast_K=5,
    fast_h=1,
    smooth=False,
    enable_pruning=True,
    feature_importance_type="gcv",
)
ParameterMeaning
max_termsMaximum number of basis terms.
max_degreeMaximum interaction degree.
penaltyGeneralized cross-validation penalty.
enable_pruningWhether to prune basis terms.
feature_importance_typeFeature-importance calculation mode.

SVR

Support vector regression surrogate.

python
SVR(
    scalers=(None, None),
    polyFeature=None,
    symbol="epsilon-SVR",
    kernel="rbf",
    nu=0.5,
    C=0.1,
    epsilon=0.1,
    gamma=1.0,
    coe0=0.1,
    degree=3,
    maxIter=100000.0,
    eps=0.001,
)
ParameterMeaning
symbolSVR type. One of "epsilon-SVR" or "nu-SVR".
kernelKernel. One of "linear", "rbf", "sigmoid", or "polynomial".
nuNu-SVR parameter.
CRegularization parameter.
epsilonEpsilon-SVR tube width.
gammaKernel gamma.
coe0Kernel coefficient.
degreePolynomial kernel degree.
maxIterMaximum solver iterations.
epsSolver tolerance.

Scaling and Features

MinMaxScaler

python
MinMaxScaler(min_=0, max_=1)

Maps each feature to [min_, max_].

StandardScaler

python
StandardScaler(muX=0, sitaX=1)

Maps each feature to the requested mean and standard deviation scale.

Scaler methods:

MethodMeaning
fit(trainX)Fit scaler statistics.
transform(trainX)Transform data.
fit_transform(trainX)Fit and transform data.
inverse_transform(trainX)Reverse the transformation.

PolyFeature

python
PolyFeature(degree=2, includeBias=False, onlyInteraction=False)
MethodReturnsMeaning
transform(trainX)np.ndarrayExpand polynomial features.

Splitting and Metrics

KFold

python
KFold(n_splits=5)
MethodReturnsMeaning
split(X, mode="full")(train, test)Return fold indices. mode is "full" or "single".

RandSelect

python
RandSelect(pTest=5)
MethodReturnsMeaning
split(X)(train, test)Return one random train/test split. pTest is a percentage.

Metrics:

FunctionMeaning
r_square(true_Y, pre_Y)R-squared score.
nse(true_Y, pre_Y)Nash-Sutcliffe efficiency.
mse(true_Y, pre_Y)Mean squared error.
rank_score(true_Y, pre_Y)Kendall-style rank score.
sort_score(true_Y, pre_Y)Sorted-index distance score.

AutoTuner

Hyper-parameter tuning helper for surrogate models.

python
AutoTuner(model, optimizer=None)
MethodReturnsMeaning
optTune(xData, yData, paraList=None, owner=None, obj="mse", split=None, tuneMode="fit")modelTune parameters with an optimizer.
gridTune(xData, yData, paraGrid=None, obj="mse", split=None, tuneMode="fit")modelTune parameters by grid search.

paraList defaults to active model parameters. paraGrid maps parameter names to candidate values.