Skip to content

declearn.optimizer.modules.RMSPropModule

Bases: OptiModule

Root Mean Square Propagation (RMSProp) module.

This module implements the following algorithm:

Init(beta, eps):
    state = 0
Step(grads, step):
    state = beta*state + (1-beta)*(grads**2)
    grads /= (sqrt(state) + eps)

In other words, gradients (i.e. indirectly the learning rate) are scaled down by the square-root of the momentum-corrected sum of the past squared gradients. See reference [1].

References

[1] Tieleman and Hinton, 2012. Lecture 6.5-rmsprop: Divide the Gradient by a Running Average of its Recent Magnitude.

Source code in declearn/optimizer/modules/_adaptive.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
class RMSPropModule(OptiModule):
    """Root Mean Square Propagation (RMSProp) module.

    This module implements the following algorithm:

        Init(beta, eps):
            state = 0
        Step(grads, step):
            state = beta*state + (1-beta)*(grads**2)
            grads /= (sqrt(state) + eps)

    In other words, gradients (i.e. indirectly the learning rate)
    are scaled down by the square-root of the momentum-corrected
    sum of the past squared gradients. See reference [1].

    References
    ----------
    [1] Tieleman and Hinton, 2012.
        Lecture 6.5-rmsprop: Divide the Gradient by a Running
        Average of its Recent Magnitude.
    """

    name: ClassVar[str] = "rmsprop"

    def __init__(
        self,
        beta: float = 0.9,
        eps: float = 1e-7,
    ) -> None:
        """Instantiate the RMSProp gradients-adaptation module.

        Parameters
        ----------
        beta: float
            Beta parameter for the momentum correction
            applied to the adaptive scaling term.
        eps: float, default=1e-7
            Numerical-stability improvement term, added
            to the (divisor) adapative scaling term.
        """
        self.ewma = EWMAModule(beta=beta)
        self.eps = eps

    def get_config(
        self,
    ) -> Dict[str, Any]:
        return {"beta": self.ewma.beta, "eps": self.eps}

    def run(
        self,
        gradients: Vector,
    ) -> Vector:
        v_t = self.ewma.run(gradients**2)
        scaling = (v_t**0.5) + self.eps
        return gradients / scaling

    def get_state(
        self,
    ) -> Dict[str, Any]:
        return self.ewma.get_state()

    def set_state(
        self,
        state: Dict[str, Any],
    ) -> None:
        self.ewma.set_state(state)

__init__(beta=0.9, eps=1e-07)

Instantiate the RMSProp gradients-adaptation module.

Parameters:

Name Type Description Default
beta float

Beta parameter for the momentum correction applied to the adaptive scaling term.

0.9
eps float

Numerical-stability improvement term, added to the (divisor) adapative scaling term.

1e-07
Source code in declearn/optimizer/modules/_adaptive.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def __init__(
    self,
    beta: float = 0.9,
    eps: float = 1e-7,
) -> None:
    """Instantiate the RMSProp gradients-adaptation module.

    Parameters
    ----------
    beta: float
        Beta parameter for the momentum correction
        applied to the adaptive scaling term.
    eps: float, default=1e-7
        Numerical-stability improvement term, added
        to the (divisor) adapative scaling term.
    """
    self.ewma = EWMAModule(beta=beta)
    self.eps = eps