PIXELBANKv8.2.1
Menu

Momentum Update Step

Problem Statement

Update velocity and parameters using Momentum optimization.

Background

Momentum helps accelerate gradients in the right direction and dampens oscillations. The update rules are:

v=βv+(1β)dWv = \beta \cdot v + (1 - \beta) \cdot dW W=WαvW = W - \alpha \cdot v

Where:

  • vv is the velocity (exponentially weighted average of gradients)
  • β\beta is the momentum coefficient (typically 0.9)
  • α\alpha is the learning rate
  • dWdW is the gradient

Your Task

Write a function momentum_step(weight, grad, velocity, beta, learning_rate) that returns a tuple of (updated_weight, updated_velocity).

Output Format

Return a tuple (weight, velocity) with values rounded to 4 decimal places.

Example:

Input:
weight=0.0, grad=1.0, velocity=0.0, beta=0.9, learning_rate=0.1
Output:
(-0.01, 0.1)
Reasoning:

v = 0.9×09 \times 0 + 0.1×11 \times 1 = 0.1; w = 0 - 0.1×01 \times 0.1 = -0.01

Constraints:

  • -1000 <= weight, grad, velocity <= 1000
  • 0 <= beta < 1
  • 0 < learning_rate <= 1
Editor

Test Results

0/0
Run code to see test results.