DifferentialEvolutionOptimizer<T, TInput, TOutput>

Models & Types · AiDotNet.Optimizers

Implements the Differential Evolution optimization algorithm for numerical optimization problems.

Inheritance: OptimizerBase<T, TInput, TOutput> → DifferentialEvolutionOptimizer<T, TInput, TOutput>

Implements: IDerivativeFreeFunctionOptimizer<T>

For Beginners

This optimizer works by evolving a population of candidate solutions over time. It’s inspired by biological evolution and is good at finding global optima in complex problem spaces.

How It Works

Differential Evolution is a population-based optimization algorithm that is particularly well-suited for solving non-linear, non-differentiable continuous space functions. It’s known for its simplicity, robustness, and effectiveness in various optimization scenarios.

Example

using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.Enums;
using AiDotNet.NeuralNetworks;
using AiDotNet.Optimizers;
using AiDotNet.Tensors.LinearAlgebra;

var rng = new Random(0);
var trainX = new Tensor<double>(new[] { 32, 8 });
var trainY = new Tensor<double>(new[] { 32, 2 });
for (int i = 0; i < 32; i++)
{
    for (int j = 0; j < 8; j++) trainX[new[] { i, j }] = rng.NextDouble();
    trainY[new[] { i, i % 2 }] = 1.0;
}

var model = new NeuralNetwork<double>(new NeuralNetworkArchitecture<double>(
    inputFeatures: 8, numClasses: 2, complexity: NetworkComplexity.Simple));

var result = await new AiModelBuilder<double, Tensor<double>, Tensor<double>>()
    .ConfigureModel(model)
    .ConfigureOptimizer(new DifferentialEvolutionOptimizer<double, Tensor<double>, Tensor<double>>(model))
    .ConfigureDataLoader(DataLoaders.FromTensors(trainX, trainY))
    .BuildAsync();

Console.WriteLine("Trained with DifferentialEvolutionOptimizer.");

Constructors

Constructor Summary
DifferentialEvolutionOptimizer(IFullModel<T, TInput, TOutput> model, DifferentialEvolutionOptions<T, TInput, TOutput> options, IEngine engine) Initializes a new instance of the DifferentialEvolutionOptimizer class.

Methods

Method Summary
DifferentialEvolutionOptimizer<T, TInput, TOutput> CreateForFunction(DifferentialEvolutionOptions<T, TInput, TOutput> options) Creates a differential evolution optimizer for minimizing a plain function, with no model.
OptimizationAlgorithmOptions<T, TInput, TOutput> GetOptions() Retrieves the current options of the Differential Evolution optimizer.
OptimizationResult<T, TInput, TOutput> Optimize(OptimizationInputData<T, TInput, TOutput> inputData) Performs the main optimization process using the Differential Evolution algorithm.
Vector<T> Minimize(Vector<T> initialParameters, Func<Vector<T>, T> objective, int maxIterations, T tolerance)