Class RadialBasisFunctionRegression<T>
- Namespace
- AiDotNet.Regression
- Assembly
- AiDotNet.dll
Implements Radial Basis Function (RBF) Regression, a technique that uses radial basis functions as the basis for approximating complex nonlinear relationships between inputs and outputs.
public class RadialBasisFunctionRegression<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
TThe numeric data type used for calculations (e.g., float, double).
- Inheritance
-
RadialBasisFunctionRegression<T>
- Implements
-
IRegression<T>
- Inherited Members
- Extension Methods
Remarks
Radial Basis Function Regression works by transforming the input space using a set of radial basis functions, each centered at a different point. These functions produce a response that depends on the distance from the input to the center point. The model then combines these responses linearly to make predictions.
The algorithm first selects a set of centers (typically using k-means clustering), computes the RBF features for each input point, and then solves a linear regression problem to find the optimal weights.
For Beginners: Think of RBF regression as placing a set of "bell curves" at strategic locations in your input space. Each curve gives a strong response when an input is close to its center and a weak response when it's far away. The model predicts by combining these responses with learned weights. This approach is particularly good at modeling complex, non-linear relationships in data.
Constructors
RadialBasisFunctionRegression(RadialBasisFunctionOptions?, IRegularization<T, Matrix<T>, Vector<T>>?)
Initializes a new instance of the RadialBasisFunctionRegression class with the specified options and regularization.
public RadialBasisFunctionRegression(RadialBasisFunctionOptions? options = null, IRegularization<T, Matrix<T>, Vector<T>>? regularization = null)
Parameters
optionsRadialBasisFunctionOptionsConfiguration options for the RBF regression model. If null, default options will be used.
regularizationIRegularization<T, Matrix<T>, Vector<T>>Regularization method to prevent overfitting. If null, no regularization will be applied.
Remarks
The constructor initializes the model with either the provided options or default settings.
For Beginners: This constructor sets up the RBF regression model with your specified settings or uses default settings if none are provided. Regularization is an optional technique to prevent the model from becoming too complex and overfitting to the training data.
Methods
CreateInstance()
Creates a new instance of the radial basis function regression model with the same options.
protected override IFullModel<T, Matrix<T>, Vector<T>> CreateInstance()
Returns
- IFullModel<T, Matrix<T>, Vector<T>>
A new instance of the RBF regression model with the same configuration but no trained parameters.
Remarks
This method creates a new instance of the radial basis function regression model with the same configuration options as the current instance, but without copying the trained parameters (centers and weights).
For Beginners: This method creates a fresh copy of the model configuration without any learned parameters. It's like getting a blank template with the same settings.
Think of it like getting a fresh copy of a form with all the same fields and settings, but without any of the data filled in. The new model has the same:
- Number of centers
- Gamma parameter (controls how quickly the influence of each center drops off)
- Regularization settings
- Other configuration options
But it doesn't have the learned centers or weights from training.
This is mainly used internally by the framework when performing operations like cross-validation or creating ensembles of similar models.
Deserialize(byte[])
Deserializes the model from a byte array.
public override void Deserialize(byte[] modelData)
Parameters
modelDatabyte[]The byte array containing the serialized model data.
Remarks
This method reconstructs the model's parameters from a serialized byte array, including base class data, options, centers, and weights.
For Beginners: Deserialization is the opposite of serialization - it takes the saved model data and reconstructs the model's internal state. This allows you to load a previously trained model and use it to make predictions without having to retrain it. It's like loading a saved game to continue where you left off.
GetModelType()
Gets the type of the model.
protected override ModelType GetModelType()
Returns
- ModelType
The model type identifier for radial basis function regression.
Remarks
This method is used for model identification and serialization purposes.
For Beginners: This method simply returns an identifier that indicates this is a radial basis function regression model. It's used internally by the library to keep track of different types of models.
OptimizeModel(Matrix<T>, Vector<T>)
Optimizes the model parameters based on the training data.
protected override void OptimizeModel(Matrix<T> x, Vector<T> y)
Parameters
xMatrix<T>The input features matrix where each row is a training example and each column is a feature.
yVector<T>The target values vector corresponding to each training example.
Remarks
This method implements the core of the RBF regression algorithm. The steps are: 1. Select centers using k-means clustering 2. Compute RBF features for each input point 3. Apply regularization to the RBF features 4. Solve a linear regression problem to find the optimal weights 5. Apply regularization to the weights
For Beginners: This is the main training method where the model learns from your data. It first finds good locations for the "bell curves" (centers) using a clustering algorithm, then calculates how each input point responds to these centers. Finally, it solves a linear equation to find the best weights for combining these responses to predict the target values.
Predict(Matrix<T>)
Makes predictions for the given input data.
public override Vector<T> Predict(Matrix<T> input)
Parameters
inputMatrix<T>The input features matrix where each row is an example and each column is a feature.
Returns
- Vector<T>
A vector of predicted values for each input example.
Remarks
This method transforms the input data using the RBF features and then applies the learned weights to make predictions.
For Beginners: After training, this method is used to make predictions on new data. It first transforms each input example using the radial basis functions (calculating how close it is to each center), then combines these transformed values using the learned weights to produce the final prediction.
PredictSingle(Vector<T>)
Predicts the value for a single input vector.
protected override T PredictSingle(Vector<T> input)
Parameters
inputVector<T>The input feature vector.
Returns
- T
The predicted value.
Remarks
This method transforms a single input vector using the RBF features and then applies the learned weights to make a prediction.
For Beginners: This is the core prediction function for a single example. It calculates how the input responds to each radial basis function (center), then combines these responses using the learned weights to produce the final prediction.
Serialize()
Serializes the model to a byte array.
public override byte[] Serialize()
Returns
- byte[]
A byte array containing the serialized model data.
Remarks
This method serializes the model's parameters, including base class data, options, centers, and weights.
For Beginners: Serialization converts the model's internal state into a format that can be saved to disk or transmitted over a network. This allows you to save a trained model and load it later without having to retrain it. Think of it like saving your progress in a video game.