http://en.wikipedia.org/wiki/Gradient_descent 
http://zh.wikipedia.org/wiki/%E6%9C%80%E9%80%9F%E4%B8%8B%E9%99%8D%E6%B3%95
 Gradient descent is based on the observation that if the multivariable function F(\mathbf{x}) is defined and differentiable in a neighborhood of a point \mathbf{a}, then F(\mathbf{x}) decreases fastest if one goes from \mathbf{a} in the direction of the negative gradient of F at \mathbf{a}-\nabla F(\mathbf{a}) 
為啥步長(zhǎng)要變化?Tianyi的解釋很好:如果步長(zhǎng)過(guò)大,可能使得函數(shù)值上升,故要減小步長(zhǎng) (下面這個(gè)圖片是在紙上畫好,然后scan的)。
Andrew NG的coursera課程Machine learning的II. Linear Regression with One VariableGradient descent Intuition中的解釋很好,比如在下圖在右側(cè)的點(diǎn),則梯度是正數(shù), -\nabla F(\mathbf{a})是負(fù)數(shù),即使當(dāng)前的a減小
例1:Toward the Optimization of Normalized Graph Laplacian(TNN 2011)的Fig. 1. Normalized graph Laplacian learning algorithm是很好的梯度下降法的例子.只要看Fig1,其他不必看。Fig1陶Shuning老師課件 非線性優(yōu)化第六頁(yè)第四個(gè)ppt,對(duì)應(yīng)教材P124,關(guān)鍵直線搜索策略,應(yīng)用 非線性優(yōu)化第四頁(yè)第四個(gè)ppt,步長(zhǎng)加倍或減倍。只要目標(biāo)減少就到下一個(gè)搜索點(diǎn),并且步長(zhǎng)加倍;否則停留在原點(diǎn),將步長(zhǎng)減倍。
例2: Distance Metric Learning for Large Margin Nearest Neighbor Classification(JLMR),目標(biāo)函數(shù)就是公式14,是矩陣M的二次型,展開后就會(huì)發(fā)現(xiàn),關(guān)于M是線性的,故是凸的。對(duì)M求導(dǎo)的結(jié)果,附錄公式18和19之間的公式中沒(méi)有M

我自己額外的思考:如果是凸函數(shù),對(duì)自變量求偏導(dǎo)為0,然后將自變量求出來(lái)不就行了嘛,為啥還要梯度下降?上述例二是不行的,因?yàn)閷?duì)M求導(dǎo)后與M無(wú)關(guān)了。和tianyi討論,正因?yàn)榍髮?dǎo)為0 沒(méi)有解析解采用梯度下降,有解析解就結(jié)束了

http://blog.csdn.net/yudingjun0611/article/details/8147046

1. 梯度下降法

梯度下降法的原理可以參考:斯坦福機(jī)器學(xué)習(xí)第一講。

我實(shí)驗(yàn)所用的數(shù)據(jù)是100個(gè)二維點(diǎn)。

如果梯度下降算法不能正常運(yùn)行,考慮使用更小的步長(zhǎng)(也就是學(xué)習(xí)率),這里需要注意兩點(diǎn):

1)對(duì)于足夠小的,  能保證在每一步都減小;
2)但是如果太小,梯度下降算法收斂的會(huì)很慢;

總結(jié):
1)如果太小,就會(huì)收斂很慢;
2)如果太大,就不能保證每一次迭代都減小,也就不能保證收斂;
如何選擇-經(jīng)驗(yàn)的方法:
..., 0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1...
約3倍于前一個(gè)數(shù)。

matlab源碼:

  1. function [theta0,theta1]=Gradient_descent(X,Y);  
  2. theta0=0;  
  3. theta1=0;  
  4. t0=0;  
  5. t1=0;  
  6. while(1)  
  7.     for i=1:1:100 %100個(gè)點(diǎn)  
  8.         t0=t0+(theta0+theta1*X(i,1)-Y(i,1))*1;  
  9.         t1=t1+(theta0+theta1*X(i,1)-Y(i,1))*X(i,1);  
  10.     end  
  11.     old_theta0=theta0;  
  12.     old_theta1=theta1;  
  13.     theta0=theta0-0.000001*t0 %0.000001表示學(xué)習(xí)率  
  14.     theta1=theta1-0.000001*t1  
  15.     t0=0;  
  16.     t1=0;  
  17.     if(sqrt((old_theta0-theta0)^2+(old_theta1-theta1)^2)<0.000001) % 這里是判斷收斂的條件,當(dāng)然可以有其他方法來(lái)做  
  18.         break;  
  19.     end  
  20. end  


2. 隨機(jī)梯度下降法

隨機(jī)梯度下降法適用于樣本點(diǎn)數(shù)量非常龐大的情況,算法使得總體向著梯度下降快的方向下降。

matlab源碼:

  1. function [theta0,theta1]=Gradient_descent_rand(X,Y);  
  2. theta0=0;  
  3. theta1=0;  
  4. t0=theta0;  
  5. t1=theta1;  
  6. for i=1:1:100  
  7.     t0=theta0-0.01*(theta0+theta1*X(i,1)-Y(i,1))*1  
  8.     t1=theta1-0.01*(theta0+theta1*X(i,1)-Y(i,1))*X(i,1)  
  9.     theta0=t0  
  10.     theta1=t1  
  11. end