OptimizerBase<T, TInput, TOutput>
Base Classes · AiDotNet.Optimizers
Represents the base class for all optimization algorithms, providing common functionality and interfaces.
Implements: IModelShape, IOptimizer<T, TInput, TOutput>
Known derived types: AntColonyOptimizer<T, TInput, TOutput>, BayesianOptimizer<T, TInput, TOutput>, CMAESOptimizer<T, TInput, TOutput>, DifferentialEvolutionOptimizer<T, TInput, TOutput>, GeneticAlgorithmOptimizer<T, TInput, TOutput>, GradientBasedOptimizerBase<T, TInput, TOutput>, NelderMeadOptimizer<T, TInput, TOutput>, NormalOptimizer<T, TInput, TOutput>, ParticleSwarmOptimizer<T, TInput, TOutput>, TabuSearchOptimizer<T, TInput, TOutput>
For Beginners
This is the blueprint that all optimization algorithms follow.
Think of OptimizerBase as the common foundation that all optimizers are built upon:
- It defines what every optimizer must be able to do (evaluate solutions, manage caching)
- It provides shared tools that all optimizers can use (like adaptive learning rates and early stopping)
- It manages the evaluation of solutions and tracks the optimization progress
- It handles saving and loading optimizer states
All specific optimizer types (like genetic algorithms, particle swarm, etc.) inherit from this class, which ensures they all work together consistently in the optimization process.
How It Works
OptimizerBase is an abstract class that serves as the foundation for all optimization algorithms. It defines the common structure and functionality that all optimizers must implement, such as solution evaluation, caching, and adaptive parameter management. This class handles the core mechanics of optimization processes, allowing derived classes to focus on their specific optimization strategies.
Properties
| Property | Summary |
|---|---|
IFullModel<T, TInput, TOutput> Model { get; } |
Gets the model that this optimizer is configured to optimize. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, Vector<T>> CalculateUpdate(Dictionary<string, Vector<T>> gradients) |
Calculates the parameter update based on the provided gradients. |
DynamicShapeInfo GetDynamicShapeInfo() |
|
OptimizationAlgorithmOptions<T, TInput, TOutput> GetOptions() |
Gets the current options for this optimizer. |
OptimizationResult<T, TInput, TOutput> Optimize(OptimizationInputData<T, TInput, TOutput> inputData) |
Performs the optimization process. |
Vector<T> CalculateUpdate(Vector<T> gradients, Vector<T> parameters) |
Calculates the parameter updates based on the gradients. |
bool ShouldEarlyStop() |
Determines whether the optimization process should stop early based on the recent history of fitness scores. |
byte[] Serialize() |
Serializes the optimizer state to a byte array. |
int[] GetInputShape() |
Saves the optimizer state to a file. |
int[] GetOutputShape() |
|
void Deserialize(byte[] data) |
Reconstructs the optimizer from a serialized byte array. |
void LoadModel(string filePath) |
Loads the optimizer state from a file. |
void Reset() |
Resets the optimizer state, clearing the model cache. |
void SaveModel(string filePath) |
|
void SetModel(IFullModel<T, TInput, TOutput> model) |
|
void Step() |
Performs a single optimization step, updating the model parameters based on gradients. |