Class NelderMeadOptimizer<T, TInput, TOutput>
- Namespace
- AiDotNet.Optimizers
- Assembly
- AiDotNet.dll
Implements the Nelder-Mead optimization algorithm, also known as the downhill simplex method.
public class NelderMeadOptimizer<T, TInput, TOutput> : OptimizerBase<T, TInput, TOutput>, IOptimizer<T, TInput, TOutput>, IModelSerializer
Type Parameters
TThe numeric type used for calculations, typically float or double.
TInputTOutput
- Inheritance
-
OptimizerBase<T, TInput, TOutput>NelderMeadOptimizer<T, TInput, TOutput>
- Implements
-
IOptimizer<T, TInput, TOutput>
- Inherited Members
- Extension Methods
Remarks
The Nelder-Mead method is a heuristic search method that can optimize a problem with N variables. It attempts to minimize a scalar-valued nonlinear function of n real variables using only function values, without any derivative information.
For Beginners: Imagine you're trying to find the lowest point in a hilly landscape. The Nelder-Mead method is like having a group of explorers who work together, moving and reshaping their search pattern to find the lowest point. They don't need to know which way is downhill; they just compare their positions and adjust accordingly.
Constructors
NelderMeadOptimizer(IFullModel<T, TInput, TOutput>, NelderMeadOptimizerOptions<T, TInput, TOutput>?)
Initializes a new instance of the NelderMeadOptimizer class.
public NelderMeadOptimizer(IFullModel<T, TInput, TOutput> model, NelderMeadOptimizerOptions<T, TInput, TOutput>? options = null)
Parameters
modelIFullModel<T, TInput, TOutput>The model to optimize.
optionsNelderMeadOptimizerOptions<T, TInput, TOutput>The Nelder-Mead-specific optimization options.
Remarks
This constructor sets up the Nelder-Mead optimizer with the provided options and dependencies. If no options are provided, it uses default settings.
For Beginners: This is like preparing your team of explorers before they start searching the landscape. You're giving them their initial instructions and tools.
Methods
Deserialize(byte[])
Deserializes the Nelder-Mead optimizer from a byte array.
public override void Deserialize(byte[] data)
Parameters
databyte[]The byte array containing the serialized optimizer state.
Remarks
This method reconstructs the optimizer's state from a byte array, including its options and parameters. It's used to restore a previously saved or transmitted optimizer state.
For Beginners: This is like using a saved snapshot to set up the search process exactly as it was before, placing all the explorers back where they were and restoring the rules they were following.
Exceptions
- InvalidOperationException
Thrown when the optimizer options cannot be deserialized.
GetOptions()
Gets the current options of the Nelder-Mead optimizer.
public override OptimizationAlgorithmOptions<T, TInput, TOutput> GetOptions()
Returns
- OptimizationAlgorithmOptions<T, TInput, TOutput>
The current optimization algorithm options.
Remarks
This method returns the current configuration options of the optimizer.
For Beginners: This is like asking to see the current set of rules the explorers are following in their search.
InitializeAdaptiveParameters()
Initializes the adaptive parameters for the Nelder-Mead optimizer.
protected override void InitializeAdaptiveParameters()
Remarks
This method sets up the initial values for the reflection, contraction, expansion, and shrinkage coefficients. It also resets the iteration counter.
For Beginners: This is like giving your explorers their initial strategies for how to move around the landscape. You're setting up how far they should reflect, contract, expand, or shrink their search pattern.
Optimize(OptimizationInputData<T, TInput, TOutput>)
Performs the optimization process using the Nelder-Mead algorithm.
public override OptimizationResult<T, TInput, TOutput> Optimize(OptimizationInputData<T, TInput, TOutput> inputData)
Parameters
inputDataOptimizationInputData<T, TInput, TOutput>The input data for the optimization process.
Returns
- OptimizationResult<T, TInput, TOutput>
The result of the optimization process.
Remarks
This method implements the main optimization loop. It creates and manipulates a simplex (a geometric figure in N dimensions) to find the optimal solution.
For Beginners: This is the actual search process. Your team of explorers starts at different points, then repeatedly adjusts their positions based on which points are higher or lower. They reflect away from high points, expand towards promising areas, contract if they overshoot, and shrink their search area if they get stuck.
Serialize()
Serializes the Nelder-Mead optimizer to a byte array.
public override byte[] Serialize()
Returns
- byte[]
A byte array representing the serialized state of the optimizer.
Remarks
This method converts the current state of the optimizer, including its options and parameters, into a byte array. This allows the optimizer's state to be saved or transmitted.
For Beginners: This is like taking a snapshot of the entire search process, including where all the explorers are and what rules they're following, so you can save it or send it to someone else.
UpdateAdaptiveParameters(OptimizationStepData<T, TInput, TOutput>, OptimizationStepData<T, TInput, TOutput>)
Updates the adaptive parameters of the Nelder-Mead algorithm.
protected override void UpdateAdaptiveParameters(OptimizationStepData<T, TInput, TOutput> currentStepData, OptimizationStepData<T, TInput, TOutput> previousStepData)
Parameters
currentStepDataOptimizationStepData<T, TInput, TOutput>The current optimization step data.
previousStepDataOptimizationStepData<T, TInput, TOutput>The previous optimization step data.
Remarks
This method adjusts the reflection, expansion, contraction, and shrinkage coefficients based on the improvement in fitness. It's used to fine-tune the algorithm's behavior as the optimization progresses.
For Beginners: This is like adjusting how far the explorers move based on how well they're doing. If they're finding better spots, they might move more boldly.
UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput>)
Updates the optimizer's options with new settings.
protected override void UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput> options)
Parameters
optionsOptimizationAlgorithmOptions<T, TInput, TOutput>The new options to be applied to the optimizer.
Remarks
This method ensures that only compatible option types are used with this optimizer. It updates the internal options if the provided options are of the correct type.
For Beginners: This is like changing the rules for how the explorers should search. It makes sure you're only using rules that work for this specific type of search (Nelder-Mead method).
Exceptions
- ArgumentException
Thrown when the provided options are not of the correct type.