Take a centered RMSProp step

Why it matters Centered RMSProp was the optimizer of choice for early deep RL agents such as DQN variants.

Centered RMSProp divides by an estimate of the gradient's variance instead of its raw second moment.

Write rmsprop_centered(w, g, s, m, lr, rho=0.9, eps=1e-8). Update s = rho * s + (1 - rho) * g^2 and m = rho * m + (1 - rho) * g, then w = w - lr * g / sqrt(s - m^2 + eps). Return (w, s, m).

Signaturedef rmsprop_centered(w, g, s, m, lr, rho=0.9, eps=1e-8)

Example

w [1], g [1], s [0], m [0], lr 0.1 gives s 0.1, m 0.1, and w = 1 - 0.1 / sqrt(0.09), about 0.6667.

Understand the idea

RMSProp divides each gradient by a running root mean square, so parameters with big gradients take smaller steps. The centered version also tracks the running mean of the gradient and subtracts its square, giving a variance estimate. That way a gradient that is large but steady is not over-shrunk. Worked example: w = [1], g = [2], s = [1], m = [0.5], lr 0.1, rho 0.9. s = 0.9 * 1 + 0.1 * 4 = 1.3. m = 0.9 * 0.5 + 0.1 * 2 = 0.65. Variance = 1.3 - 0.65^2 = 1.3 - 0.4225 = 0.8775, whose root is 0.9367. w = 1 - 0.1 * 2 / 0.9367 = about 0.786. Rule: s = rho * s + (1 - rho) * g^2; m = rho * m + (1 - rho) * g; w = w - lr * g / sqrt(s - m^2 + eps). Return the new w, s and m. Without the m^2 term you get plain RMSProp. Used in: reinforcement learning (older Atari agents) and recurrent networks, and as an option in TensorFlow and PyTorch.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 3.

  • Sample 1: examplermsprop_centered([1.0], [1.0], [0.0], [0.0], 0.1)
  • Sample 2: vectorrmsprop_centered([1.0, 2.0], [0.5, -1.0], [0.2, 0.3], [0.1, -0.2], 0.01)
  • Test 3: rhormsprop_centered([0.0], [2.0], [1.0], [0.5], 0.1, 0.5)