Repository navigation
Expand file tree
/
Copy pathlearning_rate.py
More file actions
72 lines (58 loc) · 1.7 KB
/
Copy pathlearning_rate.py
File metadata and controls
72 lines (58 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
from base_module import BaseModule
from base_learning_rate import BaseLR
class FixedLR(BaseLR):
"""
Class representing a fixed learning rate
"""
def __init__(self, base_lr: float):
"""
Instantiate a fixed learning-rate object
Parameters:
-----------
base_lr: float
Learning rate value to be returned at each call
"""
super().__init__()
self.base_lr = base_lr
def lr_step(self, **lr_kwargs) -> float:
"""
Specify learning rate at call
Returns:
--------
eta: float
Fixed learning rate specified when initializing instance
Note:
-----
No arguments are expected
"""
return self.base_lr
class ExponentialLR(FixedLR):
"""
Class representing an exponentially decaying learning rate
"""
def __init__(self, base_lr: float, decay_rate: float):
"""
Instantiate an exponentially decaying learning-rate object, i.e. eta_t = eta*gamma^t
Parameters:
----------
base_lr: float
Learning to be returned at t=0 (i.e eta)
decay_rate: float
Decay rate of learning-rate (i.e. gamma)
"""
super().__init__(base_lr)
self.decay_rate = decay_rate
def lr_step(self, t: int, **lr_kwargs) -> float:
"""
Specify learning rate at call `t`
Parameters:
-----------
t: int
Step time for which to calculate learning rate
Returns:
--------
eta_t: float
Exponential decay according to eta_t = eta*gamma^t
"""
raise NotImplementedError()