Class: Torch::Optim::LRScheduler::CosineAnnealingLR
- Inherits:
-
LRScheduler
- Object
- LRScheduler
- Torch::Optim::LRScheduler::CosineAnnealingLR
- Defined in:
- lib/torch/optim/lr_scheduler/cosine_annealing_lr.rb
Instance Method Summary collapse
- #get_lr ⇒ Object
-
#initialize(optimizer, t_max, eta_min: 0, last_epoch: -1)) ⇒ CosineAnnealingLR
constructor
A new instance of CosineAnnealingLR.
Methods inherited from LRScheduler
Constructor Details
#initialize(optimizer, t_max, eta_min: 0, last_epoch: -1)) ⇒ CosineAnnealingLR
Returns a new instance of CosineAnnealingLR.
5 6 7 8 9 |
# File 'lib/torch/optim/lr_scheduler/cosine_annealing_lr.rb', line 5 def initialize(optimizer, t_max, eta_min: 0, last_epoch: -1) @t_max = t_max @eta_min = eta_min super(optimizer, last_epoch) end |
Instance Method Details
#get_lr ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/torch/optim/lr_scheduler/cosine_annealing_lr.rb', line 11 def get_lr if @last_epoch == 0 @base_lrs elsif (@last_epoch - 1 - @t_max) % (2 * @t_max) == 0 @base_lrs.zip(@optimizer.param_groups).map do |base_lr, group| group[:lr] + (base_lr - @eta_min) * (1 - Math.cos(Math::PI / @t_max)) / 2 end else @optimizer.param_groups.map do |group| (1 + Math.cos(Math::PI * @last_epoch / @t_max)) / (1 + Math.cos(Math::PI * (@last_epoch - 1) / @t_max)) * (group[:lr] - @eta_min) + @eta_min end end end |