One Gradient-Descent Update
Beginner classical-mllinear-regressiongradient-descentoptimization
Implement:
def gd_step(
weight: np.ndarray,
bias: np.ndarray | None,
grad_weight: np.ndarray,
grad_bias: np.ndarray | None,
lr: float,
) -> tuple[np.ndarray, np.ndarray | None]:
"""
Apply one gradient-descent update.
Returns:
updated_weight, updated_bias
"""
Your function should:
- Move
weight and bias a step in the direction that reduces loss, scaled by lr, using the update rule from Theory.
- Return new values rather than mutating the input arrays in place.
- If
bias is None (no bias parameter, matching 01-hypothesis-function and 03-mse-gradient), return None for updated_bias too, there is nothing to step.