concept

Gradient descent updates

Gradient descent subtracts a scaled gradient evaluated at the current parameters. For the scalar loss (w−3)², constant rates 0 < η < 1 shrink distance in exact arithmetic; these bounds do not transfer to arbitrary objectives.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
w_next = w − η ∇L(w), η > 0

Working Example

Example Snippetartificial-intelligence
def step(w, rate):    if not 0 <= rate <= 2:        raise ValueError("Rate outside teaching range")    return w - rate * 2 * (w - 3)
for rate in (0.25, 0.75, 1.0, 1.1):    w = step(1, rate)    print(rate, round(w, 2), round((w - 3) ** 2, 2))