PyEGRO GPR Module API Reference¶
This document provides detailed API reference for the Gaussian Process Regression (GPR) module in the PyEGRO package.
Table of Contents¶
MetaTraining Class¶
The MetaTraining class provides a high-level interface for training and managing Gaussian Process Regression models.
Constructor¶
MetaTraining(
test_size=0.3,
num_iterations=1000,
prefer_gpu=True,
show_progress=True,
show_hardware_info=True,
show_model_info=True,
output_dir='RESULT_MODEL_GPR',
data_dir='DATA_PREPARATION',
data_info_file=None,
data_training_file=None,
kernel='matern15',
learning_rate=0.01,
patience=50
)
Parameters¶
test_size(float, optional): Fraction of data to use for testing if no test data is provided. Default:0.3num_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_GPR'data_dir(str, optional): Directory containing input data. Default:'DATA_PREPARATION'data_info_file(str, optional): Path to data info JSON file. Default:Nonedata_training_file(str, optional): Path to training data CSV file. Default:Nonekernel(str, optional): Kernel to use for GPR model. Options:'matern25','matern15','matern05','rbf'. Default:'matern15'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 GPR model with more flexible data options.
Parameters¶
X(numpy.ndarray, pandas.DataFrame, or str, optional): Training features or path to training data CSV. Default:Noney(numpy.ndarray, pandas.DataFrame, or pandas.Series, optional): Training targets (only needed if custom_data=True). Default:NoneX_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:Nonecustom_data(bool, optional): Whether using custom data instead of loading from files. Default:False
Returns¶
model(GPRegressionModel): Trained modelscaler_X(StandardScaler): Feature scalerscaler_y(StandardScaler): Target scaler
predict¶
Make predictions using the trained model.
Parameters¶
X(numpy.ndarray or pandas.DataFrame): Input features
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(GPRegressionModel): Loaded model
print_hyperparameters¶
Print the learned hyperparameters of the model.
GPRegressionModel Class¶
The GPRegressionModel class implements a Gaussian Process Regression model with configurable kernels.
Constructor¶
Parameters¶
train_x(torch.Tensor): Training input datatrain_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
Returns¶
gpytorch.distributions.MultivariateNormal: Distribution with predicted mean and covariance
DeviceAgnosticGPR Class¶
The DeviceAgnosticGPR class provides a device-agnostic handler for GPR models, making it easier to use models on both CPU and GPU.
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_GPR'
Returns¶
bool: True if model was loaded successfully, False otherwise
predict¶
Make predictions with the loaded GPR model.
Parameters¶
X(numpy.ndarray): Input features (n_samples, n_features)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_gpr¶
Create comprehensive visualizations for GPR model performance.
visualize_gpr(
meta,
X_train,
y_train,
X_test=None,
y_test=None,
variable_names=None,
bounds=None,
savefig=False,
output_dir=None
)
Parameters¶
meta(MetaTraining): Trained MetaTraining instanceX_train(numpy.ndarray or pandas.DataFrame): Training inputsy_train(numpy.ndarray, pandas.DataFrame, or pandas.Series): Training 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