Class NelderMeadOptimizer<TInput, TMetric>
- Namespace
- SignalSharp.Optimization.NelderMead
- Assembly
- SignalSharp.dll
Implements the Nelder-Mead simplex optimization algorithm. It is a direct search method suitable for non-differentiable objective functions and does not use gradient information. This implementation handles parameter bounds by clamping.
public class NelderMeadOptimizer<TInput, TMetric> : IParameterOptimizer<TInput, TMetric> where TMetric : IFloatingPointIeee754<TMetric>
Type Parameters
TInputThe type of the input data provided to the objective function.
TMetricThe type of the objective metric (e.g., SSE), which must be a floating-point type.
- Inheritance
-
NelderMeadOptimizer<TInput, TMetric>
- Implements
-
IParameterOptimizer<TInput, TMetric>
- Inherited Members
Remarks
Instances keep mutable run state (evaluation counters) and are not thread-safe: use a separate instance per concurrent optimization.
Constructors
NelderMeadOptimizer(NelderMeadOptimizerOptions?, ILogger<NelderMeadOptimizer<TInput, TMetric>>?, Random?)
Implements the Nelder-Mead simplex optimization algorithm. It is a direct search method suitable for non-differentiable objective functions and does not use gradient information. This implementation handles parameter bounds by clamping.
public NelderMeadOptimizer(NelderMeadOptimizerOptions? options = null, ILogger<NelderMeadOptimizer<TInput, TMetric>>? logger = null, Random? random = null)
Parameters
optionsNelderMeadOptimizerOptionsloggerILogger<NelderMeadOptimizer<TInput, TMetric>>randomRandom
Remarks
Instances keep mutable run state (evaluation counters) and are not thread-safe: use a separate instance per concurrent optimization.
Methods
Optimize(TInput, IEnumerable<ParameterDefinition>, Func<TInput, IReadOnlyDictionary<string, double>, ObjectiveEvaluation<TMetric>>)
Optimizes the objective function synchronously.
public OptimizationResult<TMetric> Optimize(TInput inputData, IEnumerable<ParameterDefinition> parametersToOptimize, Func<TInput, IReadOnlyDictionary<string, double>, ObjectiveEvaluation<TMetric>> objectiveFunction)
Parameters
inputDataTInputThe input data passed to the objective function.
parametersToOptimizeIEnumerable<ParameterDefinition>The parameters to optimize, with unique names.
objectiveFunctionFunc<TInput, IReadOnlyDictionary<string, double>, ObjectiveEvaluation<TMetric>>The objective function to minimize.
Returns
- OptimizationResult<TMetric>
The optimization result.
Exceptions
- ArgumentNullException
Thrown when the parameters or objective function are null.
- ArgumentException
Thrown when parameter names are duplicated.
OptimizeAsync(TInput, IEnumerable<ParameterDefinition>, Func<TInput, IReadOnlyDictionary<string, double>, ObjectiveEvaluation<TMetric>>, CancellationToken)
Asynchronously optimizes the objective function. The computation is CPU-bound and executes synchronously on the calling thread; the returned task is already completed when the method returns. Cancellation is observed between objective evaluations.
public Task<OptimizationResult<TMetric>> OptimizeAsync(TInput inputData, IEnumerable<ParameterDefinition> parametersToOptimize, Func<TInput, IReadOnlyDictionary<string, double>, ObjectiveEvaluation<TMetric>> objectiveFunction, CancellationToken cancellationToken)
Parameters
inputDataTInputThe input data passed to the objective function.
parametersToOptimizeIEnumerable<ParameterDefinition>The parameters to optimize, with unique names.
objectiveFunctionFunc<TInput, IReadOnlyDictionary<string, double>, ObjectiveEvaluation<TMetric>>The objective function to minimize.
cancellationTokenCancellationTokenToken to cancel the optimization process.
Returns
- Task<OptimizationResult<TMetric>>
A task containing the optimization result.
Exceptions
- ArgumentNullException
Thrown when the parameters or objective function are null.
- ArgumentException
Thrown when parameter names are duplicated.