GeneticAlgorithmRegression<T>
Models & Types · AiDotNet.Regression
Implements a regression model that uses genetic algorithms to optimize model parameters, mimicking the process of natural selection to find the best solution.
Inheritance: RegressionBase<T> → GeneticAlgorithmRegression<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
This model uses a technique inspired by natural evolution to find the best solution.
Think of it like breeding the best solution:
- Start with a random “population” of potential solutions (different sets of coefficients)
- Test how well each solution performs on your data (fitness evaluation)
- Keep the best solutions and let them “reproduce” to create new solutions
- Occasionally introduce random changes (mutations) to explore new possibilities
- Repeat this process over multiple “generations” until you find an excellent solution
The benefit of this approach is that it can find good solutions to complex problems without getting stuck in suboptimal answers. It’s similar to how nature evolves successful organisms over time, but applied to finding the best mathematical model.
How It Works
Genetic Algorithm Regression uses evolutionary principles to find optimal model coefficients. It maintains a population of potential solutions (models) that evolve over generations through selection, crossover, and mutation operations. This approach is particularly useful for complex problems where traditional optimization methods might struggle, as it can effectively explore large solution spaces and avoid local optima.
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 GeneticAlgorithmRegression<double>())
.ConfigureDataLoader(DataLoaders.FromArrays(features, targets))
.BuildAsync();
Console.WriteLine("Trained GeneticAlgorithmRegression.");
Constructors
| Constructor | Summary |
|---|---|
GeneticAlgorithmRegression(RegressionOptions<T> options, GeneticAlgorithmOptimizerOptions<T, Matrix<T>, Vector<T>> gaOptions, IRegularization<T, Matrix<T>, Vector<T>> regularization, IOutlierRemoval<T, Matrix<T>, Vector<T>> outlierRemoval, PreprocessingPipeline<T, Matrix<T>, Matrix<T>> preprocessingPipeline) |
Initializes a new instance of the GeneticAlgorithmRegression class. |
Properties
| Property | Summary |
|---|---|
bool SupportsParameterInitialization { get; } |
Trains the Genetic Algorithm Regression model using the provided input features and target values. |
Methods
| Method | Summary |
|---|---|
Vector<T> Predict(Matrix<T> x) |
Predicts target values for the provided input features using the trained Genetic Algorithm Regression model. |
void Train(Matrix<T> x, Vector<T> y) |