Table of Contents

Class GaussianProcessRegression<T>

Namespace
AiDotNet.Regression
Assembly
AiDotNet.dll

Implements a Gaussian Process Regression model, which is a non-parametric, probabilistic approach to regression that provides uncertainty estimates along with predictions.

public class GaussianProcessRegression<T> : NonLinearRegressionBase<T>, INonLinearRegression<T>, IRegression<T>, IFullModel<T, Matrix<T>, Vector<T>>, IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Matrix<T>, Vector<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>, IGradientComputable<T, Matrix<T>, Vector<T>>, IJitCompilable<T>

Type Parameters

T

The numeric type used for calculations, typically float or double.

Inheritance
GaussianProcessRegression<T>
Implements
IFullModel<T, Matrix<T>, Vector<T>>
IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>
IParameterizable<T, Matrix<T>, Vector<T>>
ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>
IGradientComputable<T, Matrix<T>, Vector<T>>
Inherited Members
Extension Methods

Remarks

Gaussian Process Regression (GPR) is a flexible, non-parametric approach to regression that models the target function as a sample from a Gaussian process. It provides not only predictions but also uncertainty estimates, making it suitable for applications where quantifying prediction uncertainty is important. The model is defined by a kernel function that determines the covariance between any two points in the input space.

For Beginners: A Gaussian Process Regression model is like a sophisticated way to draw smooth curves through data points.

Unlike simpler models that assume a specific shape (like a straight line or parabola), Gaussian Process Regression:

  • Adapts to fit the data without assuming a predefined shape
  • Provides not just predictions but also how confident it is in each prediction
  • Works well with small to medium-sized datasets
  • Can capture complex patterns in the data

You can think of it as drawing a smooth curve through your data points, where the model considers all possible curves that could fit your data and chooses the most likely one based on how similar input points are to each other (defined by a "kernel function").

A unique advantage of this model is that it tells you not just what the prediction is, but also how certain or uncertain that prediction is - like saying "I predict the value is about 42, and I'm pretty confident it's between 40 and 44."

Constructors

GaussianProcessRegression(GaussianProcessRegressionOptions?, IRegularization<T, Matrix<T>, Vector<T>>?)

Initializes a new instance of the GaussianProcessRegression<T> class.

public GaussianProcessRegression(GaussianProcessRegressionOptions? options = null, IRegularization<T, Matrix<T>, Vector<T>>? regularization = null)

Parameters

options GaussianProcessRegressionOptions

Optional configuration options for the Gaussian Process Regression algorithm.

regularization IRegularization<T, Matrix<T>, Vector<T>>

Optional regularization strategy to prevent overfitting.

Remarks

This constructor creates a new Gaussian Process Regression model with the specified options and regularization strategy. If no options are provided, default values are used. If no regularization is specified, no regularization is applied.

For Beginners: This is how you create a new Gaussian Process Regression model.

When creating a model, you can specify:

  • Options: Controls settings like kernel parameters and how much to trust the training data
  • Regularization: Helps prevent the model from becoming too complex

If you don't specify these parameters, the model will use reasonable default settings.

Example:

// Create a Gaussian Process Regression model with default settings
var gpr = new GaussianProcessRegression<double>();

// Create a model with custom options
var options = new GaussianProcessRegressionOptions { 
    NoiseLevel = 0.1,
    OptimizeHyperparameters = true
};
var customGpr = new GaussianProcessRegression<double>(options);

Methods

CreateInstance()

Creates a new instance of the Gaussian Process Regression model with the same configuration.

protected override IFullModel<T, Matrix<T>, Vector<T>> CreateInstance()

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new instance of GaussianProcessRegression<T> with the same configuration as the current instance.

Remarks

This method creates a new Gaussian Process Regression model that has the same configuration as the current instance. It's used for model persistence, cloning, and transferring the model's configuration to new instances. The new instance will have the same hyperparameters and options as the original, but will not share learned data unless explicitly trained with the same dataset.

For Beginners: This method makes a fresh copy of the current model with the same settings.

It's like creating a blueprint copy of your model that can be used to:

  • Save your model's settings
  • Create a new identical model
  • Transfer your model's configuration to another system

This is useful when you want to:

  • Create multiple similar Gaussian Process models
  • Save a model's configuration for later use
  • Reset a model while keeping its hyperparameters

Note that while the settings are copied, the training data and learned patterns are not automatically transferred, so the new instance will need training before it can make predictions.

GetModelMetadata()

Gets metadata about the Gaussian Process Regression model and its configuration.

public override ModelMetadata<T> GetModelMetadata()

Returns

ModelMetadata<T>

A ModelMetadata object containing information about the model.

Remarks

This method returns metadata about the model, including its type and configuration options. This information can be useful for model management, comparison, and documentation purposes. The metadata includes the noise level, hyperparameter optimization settings, and current hyperparameter values.

For Beginners: This method provides information about your Gaussian Process Regression model.

The metadata includes:

  • The type of model (Gaussian Process Regression)
  • Noise level: How much random noise is assumed in the data
  • Whether hyperparameter optimization was performed
  • Length scale: How quickly the correlation between points falls off with distance
  • Signal variance: The overall variance of the process

This information is helpful when:

  • Comparing different models
  • Documenting your model's configuration
  • Troubleshooting model performance
  • Understanding the model's behavior

Example:

var metadata = gpr.GetModelMetadata();
Console.WriteLine($"Model type: {metadata.ModelType}");
Console.WriteLine($"Length scale: {metadata.AdditionalInfo["LengthScale"]}");

GetModelType()

Gets the model type of the Gaussian Process Regression model.

protected override ModelType GetModelType()

Returns

ModelType

The model type enumeration value.

OptimizeModel(Matrix<T>, Vector<T>)

Optimizes the Gaussian Process model based on the provided training data.

protected override void OptimizeModel(Matrix<T> x, Vector<T> y)

Parameters

x Matrix<T>

A matrix where each row represents a sample and each column represents a feature.

y Vector<T>

A vector of target values corresponding to each sample in x.

Remarks

This method builds the Gaussian Process Regression model by computing the kernel matrix, optimizing hyperparameters if requested, and solving for the alpha coefficients that will be used for making predictions. The kernel matrix represents the similarity or covariance between all pairs of training points.

For Beginners: This method teaches the model how to make predictions using your data.

During this process:

  1. The model calculates how similar each data point is to every other data point
  2. It creates a "kernel matrix" that represents these similarities
  3. If requested, it automatically tunes the model parameters to better fit your data
  4. It solves a mathematical equation to find the best coefficients for making predictions
  5. It stores these coefficients and the training data for later use

This is a key step that prepares the model to make accurate predictions with appropriate uncertainty estimates.