梯度下降一步

🤖 Gradient Descent Step Simulator

Simulate a single gradient descent update from the current parameter, gradient and learning rate, and watch how the loss moves toward the minimum.

📐 计算公式 / 原理
w′ = w − lr·(grad + 2λw),其中 2λw 为 L2 正则梯度;Δw = −lr·(grad + 2λw)
带 L2(权重衰减)的 SGD 单步更新:每次先按梯度与衰减项的和反向走一小步。注意真正的 weight decay 应独立于梯度缩放施加,而 Adam 中直接把 2λw 加进梯度会被自适应学习率抵消,因此 AdamW 才把衰减挪到更新步。

📐 计算公式与说明

L2 正则化单步权重更新(与首框展开式同源):新权重 w′ = w − lr×(grad + 2λw);权重变化 Δw = −lr×(grad + 2λw);L2 惩罚项 = 2λw(Ridge 梯度贡献)。校验:无强校验,空值按 0 兜底。判据:无固定分级,λ 越大权重收缩越强、lr 控制单步步长。

L2 正则化使权重向零收缩。

📚 深度解析:梯度下降一步

💡 常见使用场景

单变量一步更新
w=2.0, 梯度 ∂L/∂w=−3.0, η=0.1 → w←2.0−0.1×(−3.0)=2.3。梯度为负说明增大 w 能降损失,故 w 向正方向移动。

❓ 常见问题(FAQ)

梯度为负为什么参数要增加?
更新式 w←w−η∇L,梯度为负时减去负数等于加正数,沿损失下降方向(负梯度方向)移动,这是梯度下降的本质。
学习率怎么初选?
常用 1e-3~1e-1 再扫描;配合学习率预热与余弦退火更稳。出现 loss 发散(NaN)立即下调 η 一个数量级。

Formula & Standard References

Item Formula / Note Source / Standard
Update rule parameters step opposite the gradient scaled by the learning rate Gradient descent theory
Learning rate too large diverges and too small crawls Gradient descent theory
Convergence convergence needs a smooth objective and a small enough step Optimisation theory