我一直以為兩者是相同的。。。原來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)是最常采用的方法之一,另一種常用的方法是最小二乘法。在求解損失函數的最小值時,可以通過梯度下降法來一步步的迭代求解,得到最小化的損失函數和模型參數值。反過來,如果我們需要求解損失函數的最大值,這時就需要用梯度上升法來迭代了。在機器學習中,基於基本的梯度下降法發展了兩種梯度下降方法,分別為隨機梯度下降法和批量梯度下降法。
%% 最速下降法圖示
% 設置步長為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矩陣。兩者各有優缺點。
