Table of Contents

Class DifferentialEvolutionOptimizer<T, TInput, TOutput>

Namespace
AiDotNet.Optimizers
Assembly
AiDotNet.dll

Implements the Differential Evolution optimization algorithm for numerical optimization problems.

public class DifferentialEvolutionOptimizer<T, TInput, TOutput> : OptimizerBase<T, TInput, TOutput>, IOptimizer<T, TInput, TOutput>, IModelSerializer

Type Parameters

T

The numeric type used for calculations (e.g., float, double).

TInput
TOutput
Inheritance
OptimizerBase<T, TInput, TOutput>
DifferentialEvolutionOptimizer<T, TInput, TOutput>
Implements
IOptimizer<T, TInput, TOutput>
Inherited Members
Extension Methods

Remarks

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.

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.

Constructors

DifferentialEvolutionOptimizer(IFullModel<T, TInput, TOutput>, DifferentialEvolutionOptions<T, TInput, TOutput>?, IEngine?)

Initializes a new instance of the DifferentialEvolutionOptimizer class.

public DifferentialEvolutionOptimizer(IFullModel<T, TInput, TOutput> model, DifferentialEvolutionOptions<T, TInput, TOutput>? options = null, IEngine? engine = null)

Parameters

model IFullModel<T, TInput, TOutput>

The model to be optimized.

options DifferentialEvolutionOptions<T, TInput, TOutput>

The options for configuring the Differential Evolution algorithm.

engine IEngine

The computation engine (CPU or GPU) for vectorized operations.

Remarks

For Beginners: This constructor sets up the Differential Evolution optimizer with its initial configuration. You can customize various aspects of how it works, or use default settings.

Methods

Deserialize(byte[])

Deserializes the Differential Evolution optimizer from a byte array.

public override void Deserialize(byte[] data)

Parameters

data byte[]

The byte array containing the serialized optimizer state.

Remarks

For Beginners: This method reconstructs the optimizer's state from a series of bytes. It's used to restore a previously saved state of the optimizer, allowing you to continue from where you left off.

The deserialization process includes:

  • Restoring base class data (from the parent OptimizerBase class)
  • Reconstructing the DifferentialEvolutionOptions
  • Resetting the random number generator to its previous state
  • Reinitializing adaptive parameters

Exceptions

InvalidOperationException

Thrown when deserialization of optimizer options fails.

GetOptions()

Retrieves the current options of the Differential Evolution optimizer.

public override OptimizationAlgorithmOptions<T, TInput, TOutput> GetOptions()

Returns

OptimizationAlgorithmOptions<T, TInput, TOutput>

The current optimization algorithm options.

Remarks

For Beginners: This method allows you to check the current settings of the optimizer. It's useful if you need to inspect or copy the current configuration.

Optimize(OptimizationInputData<T, TInput, TOutput>)

Performs the main optimization process using the Differential Evolution algorithm.

public override OptimizationResult<T, TInput, TOutput> Optimize(OptimizationInputData<T, TInput, TOutput> inputData)

Parameters

inputData OptimizationInputData<T, TInput, TOutput>

The input data for the optimization process.

Returns

OptimizationResult<T, TInput, TOutput>

The result of the optimization process.

Remarks

For Beginners: This is the heart of the Differential Evolution algorithm. It creates an initial population of solutions and then evolves them over multiple generations. In each generation, it creates new trial solutions, evaluates them, and keeps the best ones.

Serialize()

Serializes the Differential Evolution optimizer to a byte array.

public override byte[] Serialize()

Returns

byte[]

A byte array representing the serialized state of the optimizer.

Remarks

For Beginners: This method converts the current state of the optimizer into a series of bytes. This is useful for saving the optimizer's state to a file or sending it over a network. It allows you to recreate the exact state of the optimizer later.

The serialization process includes:

  • Base class data (from the parent OptimizerBase class)
  • The DifferentialEvolutionOptions
  • The current state of the random number generator

UpdateAdaptiveParameters(OptimizationStepData<T, TInput, TOutput>, OptimizationStepData<T, TInput, TOutput>)

Updates the adaptive parameters based on the optimization progress.

protected override void UpdateAdaptiveParameters(OptimizationStepData<T, TInput, TOutput> currentStepData, OptimizationStepData<T, TInput, TOutput> previousStepData)

Parameters

currentStepData OptimizationStepData<T, TInput, TOutput>

Data from the current optimization step.

previousStepData OptimizationStepData<T, TInput, TOutput>

Data from the previous optimization step.

Remarks

For Beginners: This method adjusts the crossover and mutation rates during the optimization process. It helps the algorithm adapt its behavior based on how well it's performing.

UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput>)

Updates the options for the Differential Evolution optimizer.

protected override void UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput> options)

Parameters

options OptimizationAlgorithmOptions<T, TInput, TOutput>

The new options to be set.

Remarks

For Beginners: This method allows you to change the settings of the optimizer during runtime. It ensures that only the correct type of options (specific to Differential Evolution) can be used.

Exceptions

ArgumentException

Thrown when the provided options are not of type DifferentialEvolutionOptions.