SymbolicRegression<T>
Models & Types · AiDotNet.Regression
Implements symbolic regression, which discovers mathematical expressions that best describe the relationship between input features and target values. Unlike traditional regression methods, symbolic regression can discover both the form of the equation and its parameters.
Inheritance: NonLinearRegressionBase<T> → SymbolicRegression<T>
For Beginners
Symbolic regression is like having an AI mathematician that invents formulas.
Think of it like this:
- Instead of you telling the computer what equation to use (like y = mx + b)
- The computer tries thousands of different formulas (like y = x², y = sin(x), etc.)
- It tests each formula to see how well it predicts your data
- It combines good formulas to make even better ones
- Eventually, it finds a formula that best explains your data
For example, when modeling how a plant grows, instead of assuming it follows a linear or exponential pattern, symbolic regression might discover it follows a pattern like “growth = sunlight² × water / (1 + temperature)”.
How It Works
Symbolic regression works by:
- Creating a population of mathematical expressions (typically as expression trees)
- Evolving these expressions using genetic programming techniques
- Evaluating expressions based on how well they fit the data
- Selecting the best expressions to create new generations
- Eventually converging on an optimal or near-optimal mathematical model
This approach can discover complex, nonlinear relationships without requiring the user to specify the form of the equation in advance.
Example
using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.Regression;
using AiDotNet.Tensors.LinearAlgebra;
double[][] features =
{
new[] { 1.0, 2.0 }, new[] { 2.0, 3.0 }, new[] { 3.0, 4.0 },
new[] { 4.0, 5.0 }, new[] { 5.0, 6.0 }, new[] { 6.0, 7.0 }
};
double[] targets = { 3.0, 5.0, 7.0, 9.0, 11.0, 13.0 };
var result = await new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new SymbolicRegression<double>())
.ConfigureDataLoader(DataLoaders.FromArrays(features, targets))
.BuildAsync();
Console.WriteLine("Trained SymbolicRegression.");
Constructors
| Constructor | Summary |
|---|---|
SymbolicRegression(SymbolicRegressionOptions options, IRegularization<T, Matrix<T>, Vector<T>> regularization, IFitnessCalculator<T, Matrix<T>, Vector<T>> fitnessCalculator, IFitDetector<T, Matrix<T>, Vector<T>> fitDetector, IOutlierRemoval<T, Matrix<T>, Vector<T>> outlierRemoval, PreprocessingPipeline<T, Matrix<T>, Matrix<T>> preprocessingPipeline) |
Creates a new symbolic regression model. |
Properties
| Property | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> BestModel { get; } |
Gets the best symbolic model discovered during optimization. |
T BestFitness { get; } |
Gets the fitness score of the best model discovered during optimization. |
bool SupportsParameterInitialization { get; } |
Optimizes the symbolic regression model using the provided input data and target values. |
Methods
| Method | Summary |
|---|---|
IEnumerable<int> GetActiveFeatureIndices() |
|
ModelOptions GetOptions() |
|
Vector<T> Predict(Matrix<T> X) |
Predicts target values for a matrix of input features. |