PyEGRO Co-Kriging Module API Reference¶
This document provides detailed API reference for the Co-Kriging (multi-fidelity) module in the PyEGRO package.
Table of Contents¶
- MetaTrainingCoKriging Class
- CoKrigingModel Class
- CoKrigingKernel Class
- DeviceAgnosticCoKriging Class
- Visualization Functions
MetaTrainingCoKriging Class¶
The MetaTrainingCoKriging class provides a high-level interface for training and managing Co-Kriging models that combine low and high-fidelity data sources.
Constructor¶
MetaTrainingCoKriging(
num_iterations=1000,
prefer_gpu=True,
show_progress=True,
show_hardware_info=True,
show_model_info=True,
output_dir='RESULT_MODEL_COKRIGING',
kernel='matern25',
learning_rate=0.01,
patience=50
)
Parameters¶
num_iterations(int, optional): Number of training iterations. Default:1000prefer_gpu(bool, optional): Whether to use GPU if available. Default:Trueshow_progress(bool, optional): Whether to show detailed progress. Default:Trueshow_hardware_info(bool, optional): Whether to show system hardware info. Default:Trueshow_model_info(bool, optional): Whether to show model architecture info. Default:Trueoutput_dir(str, optional): Directory for saving results. Default:'RESULT_MODEL_COKRIGING'kernel(str, optional): Kernel to use for base GP model. Options:'matern25','matern15','matern05','rbf'. Default:'matern25'learning_rate(float, optional): Learning rate for optimizer. Default:0.01patience(int, optional): Number of iterations to wait for improvement before early stopping. Default:50
Methods¶
train¶
Train the Co-Kriging model with low and high-fidelity data.
Parameters¶
X_low(numpy.ndarray or pandas.DataFrame): Low-fidelity input featuresy_low(numpy.ndarray, pandas.DataFrame, or pandas.Series): Low-fidelity target valuesX_high(numpy.ndarray or pandas.DataFrame): High-fidelity input featuresy_high(numpy.ndarray, pandas.DataFrame, or pandas.Series): High-fidelity target valuesX_test(numpy.ndarray or pandas.DataFrame, optional): Test features. Default:Noney_test(numpy.ndarray, pandas.DataFrame, or pandas.Series, optional): Test targets. Default:Nonefeature_names(list of str, optional): List of feature names. Default:None
Returns¶
model(CoKrigingModel): Trained modelscaler_X(StandardScaler): Feature scalerscaler_y(StandardScaler): Target scaler
predict¶
Make predictions with the trained Co-Kriging model.
Parameters¶
X(numpy.ndarray or pandas.DataFrame): Input features for predictionfidelity(str, optional): 'high' or 'low' to specify which fidelity level to predict. Default:'high'
Returns¶
mean(numpy.ndarray): Mean predictionsstd(numpy.ndarray): Standard deviations of predictions
load_model¶
Load a trained model from disk.
Parameters¶
model_path(str, optional): Path to the saved model file. If None, uses the default path. Default:None
Returns¶
model(CoKrigingModel): Loaded model
print_hyperparameters¶
Print the learned hyperparameters of the model.
CoKrigingModel Class¶
The CoKrigingModel class implements a Gaussian Process model for Co-Kriging/multi-fidelity modeling using the Kennedy & O'Hagan (2000) approach.
Constructor¶
Parameters¶
train_x(torch.Tensor): Training input data (with fidelity indicator as last column)train_y(torch.Tensor): Training target datalikelihood(gpytorch.likelihoods.Likelihood): GP likelihood functionkernel(str, optional): Kernel type. Options:'matern25','matern15','matern05','rbf'. Default:'matern15'
Methods¶
forward¶
Computes the mean and covariance of the GP posterior.
Parameters¶
x(torch.Tensor): Input data (with fidelity indicator as last column)
Returns¶
gpytorch.distributions.MultivariateNormal: Distribution with predicted mean and covariance
CoKrigingKernel Class¶
The CoKrigingKernel class implements a custom kernel for Co-Kriging that handles multi-fidelity data following the auto-regressive structure of the Kennedy & O'Hagan model.
Constructor¶
Parameters¶
base_kernel(gpytorch.kernels.Kernel): Base kernel to use for both low-fidelity and difference componentsnum_dims(int): Number of dimensions including the fidelity indicatoractive_dims(tuple, optional): Dimensions that the kernel operates on. Default:None
Properties¶
rho¶
Returns the scaling parameter ρ that controls the correlation between fidelity levels.
Methods¶
forward¶
Compute the covariance matrix between inputs x1 and x2 based on the Kennedy & O'Hagan multi-fidelity formulation.
Parameters¶
x1(torch.Tensor): First inputx2(torch.Tensor): Second inputdiag(bool, optional): Whether to return just the diagonal of the covariance matrix. Default:False**params: Additional parameters for the base kernels
Returns¶
torch.Tensor: Covariance matrix
DeviceAgnosticCoKriging Class¶
The DeviceAgnosticCoKriging class provides a device-agnostic handler for Co-Kriging models.
Constructor¶
Parameters¶
prefer_gpu(bool, optional): Whether to use GPU if available. Default:False
Methods¶
load_model¶
Load model using state dict approach.
Parameters¶
model_dir(str, optional): Directory containing the model files. Default:'RESULT_MODEL_COKRIGING'
Returns¶
bool: True if model was loaded successfully, False otherwise
predict¶
Make predictions with the loaded Co-Kriging model.
Parameters¶
X(numpy.ndarray): Input features (n_samples, n_features)fidelity(str, optional): 'high' or 'low' to specify which fidelity level to predict. Default:'high'batch_size(int, optional): Batch size for processing large datasets. Default:1000
Returns¶
- Tuple of
(mean_predictions, std_predictions)as numpy arrays
Visualization Functions¶
visualize_cokriging¶
Create comprehensive visualizations for Co-Kriging model performance.
visualize_cokriging(
meta,
X_low,
y_low,
X_high,
y_high,
X_test=None,
y_test=None,
variable_names=None,
bounds=None,
savefig=False,
output_dir=None
)
Parameters¶
meta(MetaTrainingCoKriging): Trained MetaTrainingCoKriging instanceX_low(numpy.ndarray or pandas.DataFrame): Low-fidelity inputsy_low(numpy.ndarray, pandas.DataFrame, or pandas.Series): Low-fidelity targetsX_high(numpy.ndarray or pandas.DataFrame): High-fidelity inputsy_high(numpy.ndarray, pandas.DataFrame, or pandas.Series): High-fidelity targetsX_test(numpy.ndarray or pandas.DataFrame, optional): Test inputs. Default:Noney_test(numpy.ndarray, pandas.DataFrame, or pandas.Series, optional): Test targets. Default:Nonevariable_names(list of str, optional): Names of input variables. Default:Nonebounds(numpy.ndarray, optional): Bounds of input variables for sampling. Default:Nonesavefig(bool, optional): Whether to save figures to disk. Default:Falseoutput_dir(str, optional): Directory to save figures. Default:None, uses meta.output_dir
Returns¶
figures(dict): Dictionary of figure handles