Table of Contents

Class CoordinateDescentOptimizer<T, TInput, TOutput>

Namespace
AiDotNet.Optimizers
Assembly
AiDotNet.dll

Implements the Coordinate Descent optimization algorithm for numerical optimization problems.

public class CoordinateDescentOptimizer<T, TInput, TOutput> : GradientBasedOptimizerBase<T, TInput, TOutput>, IGradientBasedOptimizer<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>
GradientBasedOptimizerBase<T, TInput, TOutput>
CoordinateDescentOptimizer<T, TInput, TOutput>
Implements
IGradientBasedOptimizer<T, TInput, TOutput>
IOptimizer<T, TInput, TOutput>
Inherited Members
Extension Methods

Remarks

Coordinate Descent is an optimization algorithm that minimizes a multivariable function by solving a series of single-variable optimization problems. It cycles through each variable (coordinate) and optimizes it while holding the others constant.

For Beginners: This optimizer is like adjusting the knobs on a complex machine one at a time. It focuses on improving one aspect of the solution at a time, which can be more manageable and sometimes more effective than trying to adjust everything at once.

Constructors

CoordinateDescentOptimizer(IFullModel<T, TInput, TOutput>, CoordinateDescentOptimizerOptions<T, TInput, TOutput>?, IEngine?)

Initializes a new instance of the CoordinateDescentOptimizer class.

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

Parameters

model IFullModel<T, TInput, TOutput>

The model to optimize.

options CoordinateDescentOptimizerOptions<T, TInput, TOutput>

The options for configuring the Coordinate Descent algorithm.

engine IEngine

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

Remarks

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

Methods

Deserialize(byte[])

Deserializes the Coordinate Descent 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.

Exceptions

InvalidOperationException

Thrown when deserialization of optimizer options fails.

GetOptions()

Retrieves the current options of the Coordinate Descent 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 Coordinate Descent 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 Coordinate Descent algorithm. It iteratively improves the solution by updating one coordinate (variable) at a time. The process continues until it reaches the maximum number of iterations or meets the stopping criteria.

DataLoader Integration: This method uses the DataLoader API for epoch management. Coordinate Descent typically operates on the full dataset for derivative estimation, but notifies the sampler of epoch starts using NotifyEpochStart(int) for compatibility with curriculum learning and sampling strategies.

Serialize()

Serializes the Coordinate Descent 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.

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

Updates the adaptive parameters (learning rates and momentums) 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 how big of steps the optimizer takes for each variable. If the solution is improving, it might increase the step sizes to progress faster. If not, it might decrease them to be more careful.

UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput>)

Updates the options for the Coordinate Descent 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 Coordinate Descent) can be used.

Exceptions

ArgumentException

Thrown when the provided options are not of type CoordinateDescentOptimizerOptions.

UpdateParametersGpu(IGpuBuffer, IGpuBuffer, int, IDirectGpuBackend)

Updates parameters using GPU-accelerated coordinate descent.

public override void UpdateParametersGpu(IGpuBuffer parameters, IGpuBuffer gradients, int parameterCount, IDirectGpuBackend backend)

Parameters

parameters IGpuBuffer
gradients IGpuBuffer
parameterCount int
backend IDirectGpuBackend

Remarks

Coordinate descent optimizes one coordinate at a time sequentially. GPU implementation is not yet available because coordinate descent's sequential nature doesn't parallelize well on GPU.