LambdaLRScheduler
Models & Types · AiDotNet.LearningRateSchedulers
Sets the learning rate using a user-defined lambda function.
Inheritance: LearningRateSchedulerBase → LambdaLRScheduler
For Beginners
This scheduler lets you define your own custom learning rate schedule using a function. The function receives the current step number and returns a value that gets multiplied with the initial learning rate. For example, returning 0.5 would give half the initial learning rate. This is useful when you want a schedule that doesn’t fit any of the standard patterns.
How It Works
LambdaLR provides maximum flexibility by allowing you to define any learning rate schedule as a function of the current step. The lambda function takes the step number and returns a multiplier that is applied to the base learning rate.
Example
using AiDotNet.LearningRateSchedulers;
// Custom schedule: lr = base_lr * (0.95 ^ epoch)
var scheduler = new LambdaLRScheduler(
baseLearningRate: 0.1,
lrLambda: step => Math.Pow(0.95, step)
);
// Warmup for 10 steps, then constant
var warmupScheduler = new LambdaLRScheduler(
baseLearningRate: 0.001,
lrLambda: step => step < 10 ? (step + 1) / 10.0 : 1.0
);
Constructors
| Constructor | Summary |
|---|---|
LambdaLRScheduler(double baseLearningRate, Func<int, double> lrLambda, double minLearningRate) |
Initializes a new instance of the LambdaLRScheduler class. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, object> GetState() |
|
void Reset() |