RMSprop Optimizer
RMSprop (Root Mean Square Propagation) is an adaptive gradient-based optimizer that normalizes each parameter's update by the root of an exponentially weighted moving average (EWMA) of its squared gradients. Unlike AdaGrad, whose monotonically growing gradient accumulation prematurely shrinks learning rates toward zero, RMSprop's moving average forgets distant history, dampening oscillations in steep directions while sustaining progress along flatter dimensions.
Study Card: RMSprop Optimizer
Direct Answer
RMSprop (Root Mean Square Propagation) is an adaptive per-parameter learning rate algorithm proposed by Tieleman and Hinton to improve stochastic gradient optimization across ill-conditioned loss surfaces. At iteration with gradient , RMSprop maintains an exponentially weighted moving average of squared gradients and scales updates element-wise:
where is the decay factor (typically 0.9 or 0.99), is the base learning rate, and (e.g., 1e-8) prevents division by zero.
Dividing by the recent root-mean-square gradient dampens oscillations along steep, high-curvature coordinates while taking relatively larger steps along gentle, flat directions. Crucially, unlike AdaGrad—which sums all past squared gradients so step sizes decay monotonically toward zero—RMSprop’s EWMA adapts smoothly to local curvature in non-convex deep learning landscapes.
Key Terms
- Exponentially Weighted Moving Average (EWMA): Running average emphasizing recent gradient magnitudes and decaying older history geometrically.
- Per-Parameter Scaling: Dividing each coordinate’s gradient by its own , giving every weight an adaptive effective step size.
- Learning Rate (): Base step size scaling the normalized gradient updates.
- Decay Rate (): Controls the memory window of past squared gradients (higher smooths across more steps).
Example
Suppose one parameter consistently experiences large oscillating gradients () while another weight has consistently gentle gradients (). Plain SGD with a single learning rate either diverges along the steep coordinate or crawls along the flat one. RMSprop divides the first parameter’s update by and the second parameter’s update by , keeping step magnitudes balanced across axes—and because is a moving average rather than an unbounded cumulative sum, effective step sizes remain active throughout long training runs.
Code Implementation
import numpy as np
def rmsprop(weights, gradients, learning_rate=0.001, decay_rate=0.9, epsilon=1e-8, squared_grad_avg=None):
"""
Single step of RMSprop optimization.
Args:
weights (np.ndarray): Current model parameters.
gradients (np.ndarray): Loss gradients with respect to weights.
learning_rate (float): Base learning rate.
decay_rate (float): EWMA decay rate (beta).
epsilon (float): Numerical stability constant.
squared_grad_avg (np.ndarray or None): Previous EWMA of squared gradients.
Returns:
updated_weights, updated_squared_grad_avg
"""
if squared_grad_avg is None:
squared_grad_avg = np.zeros_like(weights)
# Update moving average of squared gradients
squared_grad_avg = decay_rate * squared_grad_avg + (1.0 - decay_rate) * (gradients ** 2)
# Normalize gradient update per coordinate
scaled_gradients = gradients / (np.sqrt(squared_grad_avg) + epsilon)
updated_weights = weights - learning_rate * scaled_gradients
return updated_weights, squared_grad_avg
# Sample usage
weights = np.array([0.5, -0.2, 0.1])
gradients = np.array([0.1, -0.05, 0.02])
squared_grad_avg = None
for i in range(5):
weights, squared_grad_avg = rmsprop(
weights, gradients, learning_rate=0.1, squared_grad_avg=squared_grad_avg
)
print(f"Step {i + 1}: Weights = {weights}")
Related Concepts
- AdaGrad vs. RMSprop vs. Adam: AdaGrad accumulates all historical squared gradients without decay (useful for sparse features, stalls on deep non-convex tasks); RMSprop replaces the sum with an EWMA; Adam combines RMSprop’s second-moment scaling with first-moment momentum and initial bias correction.
- Momentum with RMSprop:
torch.optim.RMSprop(..., momentum=0.9)adds heavy-ball momentum on top of RMSprop normalization to smooth step trajectories further. - Hyperparameter Tuning: Learning rate , decay , and all affect convergence; (sometimes set larger, e.g.,
1e-5in some settings) prevents overly aggressive steps when gradients are tiny. - Generalization vs. SGD+Momentum: Adaptive methods like RMSprop and Adam converge rapidly, though carefully tuned SGD with momentum and cosine decay remains competitive on certain vision benchmarks.