Class TemperatureScheduler
- Namespace
- AiDotNet.SelfSupervisedLearning
- Assembly
- AiDotNet.dll
Schedules temperature parameters during self-supervised learning training.
public class TemperatureScheduler
- Inheritance
-
TemperatureScheduler
- Inherited Members
Remarks
For Beginners: Temperature controls how "sharp" or "soft" the probability distribution is in contrastive learning. Different methods schedule temperature differently during training to improve learning dynamics.
Temperature effects:
- Low temperature (0.01-0.1): Sharp distribution, hard negatives, more discriminative
- High temperature (0.5-1.0): Soft distribution, easier optimization, smoother gradients
Common scheduling strategies:
- Constant: Fixed temperature throughout training (SimCLR, MoCo)
- Linear warmup: Start low, increase linearly (DINO teacher)
- Cosine decay: Start high, decay to final value
Constructors
TemperatureScheduler(TemperatureScheduleType, double, double, int, int)
Initializes a new instance of the TemperatureScheduler class.
public TemperatureScheduler(TemperatureScheduleType scheduleType = TemperatureScheduleType.Constant, double initialTemperature = 0.07, double finalTemperature = 0.07, int warmupSteps = 0, int totalSteps = 100000)
Parameters
scheduleTypeTemperatureScheduleTypeThe type of schedule to use.
initialTemperaturedoubleStarting temperature value.
finalTemperaturedoubleEnding temperature value.
warmupStepsintNumber of warmup steps (for warmup schedules).
totalStepsintTotal training steps (for decay schedules).
Properties
FinalTemperature
Gets the final temperature value.
public double FinalTemperature { get; }
Property Value
InitialTemperature
Gets the initial temperature value.
public double InitialTemperature { get; }
Property Value
ScheduleType
Gets the schedule type being used.
public TemperatureScheduleType ScheduleType { get; }
Property Value
Methods
Constant(double)
Creates a scheduler for constant temperature (SimCLR, MoCo default).
public static TemperatureScheduler Constant(double temperature = 0.07)
Parameters
temperaturedoubleThe constant temperature value.
Returns
CosineAnneal(double, double, int)
Creates a scheduler with cosine annealing from high to low temperature.
public static TemperatureScheduler CosineAnneal(double highTemperature = 0.5, double lowTemperature = 0.07, int totalSteps = 100000)
Parameters
highTemperaturedoubleStarting (high) temperature.
lowTemperaturedoubleFinal (low) temperature.
totalStepsintTotal training steps.
Returns
ForDINOTeacher(double, double, int, int)
Creates a scheduler for DINO teacher temperature warmup.
public static TemperatureScheduler ForDINOTeacher(double initialTemperature = 0.04, double finalTemperature = 0.07, int warmupEpochs = 30, int totalEpochs = 100)
Parameters
initialTemperaturedoubleStarting temperature (default: 0.04).
finalTemperaturedoubleFinal temperature (default: 0.07).
warmupEpochsintNumber of warmup epochs (default: 30).
totalEpochsintTotal training epochs.
Returns
GetTemperature(int)
Gets the temperature value for the current training step.
public double GetTemperature(int currentStep)
Parameters
currentStepintThe current training step.
Returns
- double
The scheduled temperature value.
GetTemperatureForEpoch(int, int)
Gets the temperature value for the current epoch.
public double GetTemperatureForEpoch(int currentEpoch, int totalEpochs)
Parameters
Returns
- double
The scheduled temperature value.