我一直以为两者是相同的。。。原来SGD是一阶梯度,而牛顿迭代法是二阶梯度。
SGD(Stochastic Gradient Descent,随机梯度下降法)和New-ton Method(牛顿迭代法)
梯度下降法,牛顿法,高斯-牛顿迭代法,附代码实现:https://blog.csdn.net/piaoxuezhong/article/details/60135153
梯度下降法与牛顿法的解释与对比:https://www.cnblogs.com/happylion/p/4172632.html
梯度下降法、牛顿迭代法、共轭梯度法:https://wenku.baidu.com/view/81ba70fc915f804d2a16c149.html
梯度下降和牛顿迭代:https://blog.csdn.net/qjzcy/article/details/51946304
SGD(Stochastic Gradient Descent,随机梯度下降法)中随机一词是指的样本随机选取,没有特别含义。
Stochastic gradient descent (often shortened to SGD), also known as incremental gradient descent, is a stochastic approximation of the gradient descent optimization and iterative method for minimizing an objective function that is written as a sum of differentiable functions. In other words, SGD tries to find minima or maxima by iteration.
SGD,又称为增量梯度递减,是一种随机梯度下降优化逼*以及使目标函数最小的迭代方法,目标函数可写为差分函数之和。换句话说,SGD努力通过迭代寻找最小或最大。
Both statistical estimation and machine learning consider the problem of minimizing an objective function that has the form of a sum:
统计估计和机器学习都考虑最小化目标函数的问题:
where the parameter w which minimizes Q(w) is to be estimated. Each summand function Qi is typically associated with the i-th observation in the data set (used for training).
其中使Q(w)最小的参数w是需要估计的。每一个相加的sum函数Qi一般与数据集中的第i个观测(用于训练的数据)相关。
In classical statistics, sum-minimization problems arise in least squares and in maximum-likelihood estimation (for independent observations). The general class of estimators that arise as minimizers of sums are called M-estimators. However, in statistics, it has been long recognized that requiring even local minimization is too restrictive for some problems of maximum-likelihood estimation.[1] Therefore, contemporary statistical theorists often consider stationary points of the likelihood function (or zeros of its derivative, the score function, and other estimating equations).
在典型的统计学中,总和最小问题出现在最小二乘和最大似然估计(独立观测)中。通常的一类作为总和最小的估计者叫M-估计者。然而,在统计学中,一直以来认识到哪怕是要求局部最小对于最大似然估计也太严格了。因此,当代统计理论者通常考虑似然函数的*稳点(或导数为零的点,得分函数,和其他的估计等式)。
The sum-minimization problem also arises for empirical risk minimization. In this case, Qi(w) is the value of the loss function at i-th example, and Q(w) is the empirical risk.
这类总和最小问题也出现在最小风险估计中。在这种例子中,Qi(w)是损失函数在第i个例子的值,而Q(w)是最小风险。
When used to minimize the above function, a standard (or "batch") gradient descent method would perform the following iterations :
当用于最小化上式时,一个标准的(或“包”)梯度下降方法将如下面的迭代进行:
(推导方法参加机器学习课程)
where η is a step size (sometimes called the learning rate in machine learning).
其中η是步长(有时在机器学习中称为学习率)。
In many cases, the summand functions have a simple form that enables inexpensive evaluations of the sum-function and the sum gradient. For example, in statistics, one-parameter exponential families allow economical function-evaluations and gradient-evaluations.
在很多情况下,被加函数有简单的形式,使不费时。
However, in other cases, evaluating the sum-gradient may require expensive evaluations of the gradients from all summand functions. When the training set is enormous and no simple formulas exist, evaluating the sums of gradients becomes very expensive, because evaluating the gradient requires evaluating all the summand functions' gradients. To economize on the computational cost at every iteration, stochastic gradient descent samples a subset of summand functions at every step. This is very effective in the case of large-scale machine learning problems.
Newton's method(牛顿迭代法)
牛顿迭代法(Newton's method)又称为牛顿-拉夫逊(拉弗森)方法(Newton-Raphson method),它是牛顿在17世纪提出的一种在实数域和复数域上*似求解方程的方法。多数方程不存在求根公式,因此求精确根非常困难,甚至不可能,从而寻找方程的*似根就显得特别重要。方法使用函数f(x)的泰勒级数的前面几项来寻找方程f(x) = 0的根。牛顿迭代法是求方程根的重要方法之一,其最大优点是在方程f(x) = 0的单根附*具有*方收敛,而且该法还可以用来求方程的重根、复根,此时线性收敛,但是可通过一些方法变成超线性收敛。另外该方法广泛用于计算机编程中。
设r是 的根,选取
作为r的初始*似值,过点
做曲线
的切线L,L的方程为
,求出L与x轴交点的横坐标
,称x1为r的一次*似值。过点
做曲线
的切线,并求该切线与x轴交点的横坐标
,称
为r的二次*似值。重复以上过程,得r的*似值序列,其中,
称为r的
次*似值,上式称为牛顿迭代公式。










为什么非得用二次泰勒公式而不用第一次的泰勒公式*似法呢(牛顿迭代用于求*似和求最优以及与泰勒公式的关系)?(函数为Loss函数,求Loss最小)Loss=y-Estimate(w,x)
方向一定要是使Loss最小的方向。也就是梯度方向,那么大小呢?步长。(梯度与导数的关系)
那么梯度下降法跟牛顿迭代法有什么不同呢?
梯度下降是迭代法的一种,可以用于求解最小二乘问题(线性和非线性都可以)。在求解机器学习算法的模型参数,即无约束优化问题时,梯度下降(Gradient Descent)是最常采用的方法之一,另一种常用的方法是最小二乘法。在求解损失函数的最小值时,可以通过梯度下降法来一步步的迭代求解,得到最小化的损失函数和模型参数值。反过来,如果我们需要求解损失函数的最大值,这时就需要用梯度上升法来迭代了。在机器学习中,基于基本的梯度下降法发展了两种梯度下降方法,分别为随机梯度下降法和批量梯度下降法。


















1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | %% 最速下降法图示 % 设置步长为0.1,f_change为改变前后的y值变化,仅设置了一个退出条件。 syms x;f=x^2; step=0.1;x=2;k=0; %设置步长,初始值,迭代记录数 f_change=x^2; %初始化差值 f_current=x^2; %计算当前函数值 ezplot (@(x,f)f-x.^2) %画出函数图像 axis ([-2,2,-0.2,3]) %固定坐标轴 hold on while f_change>0.000000001 %设置条件,两次计算的值之差小于某个数,跳出循环 x=x-step*2*x; %-2*x为梯度反方向,step为步长,!最速下降法! f_change = f_current - x^2; %计算两次函数值之差 f_current = x^2 ; %重新计算当前的函数值 plot (x,f_current, 'ro' , 'markersize' ,7) %标记当前的位置 drawnow ; pause (0.2); k=k+1; end hold off fprintf ( '在迭代%d次后找到函数最小值为%e,对应的x值为%e\n' ,k,x^2,x) |
综上所述,梯度下降法与牛顿迭代法都属于迭代法,但是梯度下降法是一阶偏导,而牛顿迭代法是二阶微分而且有Hessian矩阵。两者各有优缺点。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)