Table of Contents

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

scheduleType TemperatureScheduleType

The type of schedule to use.

initialTemperature double

Starting temperature value.

finalTemperature double

Ending temperature value.

warmupSteps int

Number of warmup steps (for warmup schedules).

totalSteps int

Total training steps (for decay schedules).

Properties

FinalTemperature

Gets the final temperature value.

public double FinalTemperature { get; }

Property Value

double

InitialTemperature

Gets the initial temperature value.

public double InitialTemperature { get; }

Property Value

double

ScheduleType

Gets the schedule type being used.

public TemperatureScheduleType ScheduleType { get; }

Property Value

TemperatureScheduleType

Methods

Constant(double)

Creates a scheduler for constant temperature (SimCLR, MoCo default).

public static TemperatureScheduler Constant(double temperature = 0.07)

Parameters

temperature double

The constant temperature value.

Returns

TemperatureScheduler

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

highTemperature double

Starting (high) temperature.

lowTemperature double

Final (low) temperature.

totalSteps int

Total training steps.

Returns

TemperatureScheduler

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

initialTemperature double

Starting temperature (default: 0.04).

finalTemperature double

Final temperature (default: 0.07).

warmupEpochs int

Number of warmup epochs (default: 30).

totalEpochs int

Total training epochs.

Returns

TemperatureScheduler

GetTemperature(int)

Gets the temperature value for the current training step.

public double GetTemperature(int currentStep)

Parameters

currentStep int

The 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

currentEpoch int

The current training epoch.

totalEpochs int

Total training epochs.

Returns

double

The scheduled temperature value.