机器学习算法2_梯度下降法

机器学习算法第二篇

主要内容:多项式回归模型之梯度下降法算法展开

通俗的讲:

算法目的:

  • 求通过训练集计算出一个最合适的线\面\超平面 h θ ( x ) h_\theta(x) hθ(x),使所有点到它的距离(误差)之和最小,
    将测试的特征向量带入该 h θ ( x ) h_\theta(x) hθ(x)所得的值即为预测值

步骤:

  1. 设一个目标函数(线\面\超平面) h θ ( x ) = θ 1 x i ( 1 ) + θ 2 x i ( 2 ) + . . . + θ n x i ( n ) h_\theta(x) = \theta_1x_i^{(1)}+\theta_2x_i^{(2)} +...+\theta_nx_i^{(n)} hθ(x)=θ1xi(1)+θ2xi(2)+...+θnxi(n) ,一个n维特征带入后可得到预测值 y ^ i \hat y_i y^i

  2. 设一个损失函数 J ( θ 1 , θ 2 . . . θ n ) = 1 2 m ∑ i = 1 m ( y ^ i − y i ) 2 J(\theta_1,\theta_2...\theta_n)=\frac{1}{2m}\sum_{i=1}^m (\hat y_i-y_i)^2 J(θ1,θ2...θn)=2m1i=1m(y^iyi)2,它表示所有点预测值 y ^ i \hat y_i y^i到真实值y之间的误差的平方和的平均,数学上可以代表目标函数的好坏,即拟合度的高低

  3. 所以我们目标可以理解为在学习阶段:求合适的 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)使损失函数最小

  4. 带入训练集数据,通过梯度下降法或标准方程法解出最合适的 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn),然后带入线\面\超平面函数 h θ ( x ) = θ 1 x i ( 1 ) + θ 2 x i ( 2 ) + . . . + θ n x i ( n ) h_\theta(x) = \theta_1x_i^{(1)}+\theta_2x_i^{(2)} +...+\theta_nx_i^{(n)} hθ(x)=θ1xi(1)+θ2xi(2)+...+θnxi(n) 得到目标函数(回归函数)

  5. 把需要测试的数据输入该回归函数,可得到预测值(也可测试回归函数的拟合度,即参数的好坏)

展开来说:
  1. 有训练集 T = { ( x 1 , y 1 ) , ( x 2 , y 2 ) , ( x 3 , y 3 ) . . . ( x m , y m ) } 由 P ( X , Y ) 独 立 同 分 布 产 生 T=\{(x_1,y_1),(x_2,y_2),(x_3,y_3)...(x_m,y_m) \}由P(X,Y)独立同分布产生 T={(x1,y1),(x2,y2),(x3,y3)...(xm,ym)}P(X,Y)
    T : [ x 1 ( 1 ) x 1 ( 2 ) . . . x 1 ( n ) y 1 x 2 ( 1 ) x 2 ( 2 ) . . . x 2 ( n ) y 2 x 3 ( 1 ) x 3 ( 2 ) . . . x 3 ( n ) y 3 . . . . . . . . . . . . . . x m ( 1 ) x m ( 2 ) . . . x m ( n ) y m ] T:\begin{bmatrix} x_1^{(1)} & x_1^{(2)} \quad ...&x_1^{(n)}& y_1 \\ x_2^{(1)} & x_2^{(2)} \quad...&x_2^{(n)}& y_2\\ x_3^{(1)} & x_3^{(2)} \quad...&x_3^{(n)}& y_3 \\ . & . \quad...& .& . \\ . & . \quad...& .& . \\ x_m^{(1)} & x_m^{(2)} \quad...&x_m^{(n)}& y_m \\ \end{bmatrix} T:x1(1)x2(1)x3(1)..xm(1)x1(2)...x2(2)...x3(2)...........xm(2)...x1(n)x2(n)x3(n)..xm(n)y1y2y3..ym

  2. 输入空间 X ⊊ R ∗ \mathscr {X}\subsetneq R^* XR为n维向量的集合

  3. 输出空间为标记集合 Y = R \mathscr{Y}=R Y=R,为全体实数标量集合

  4. 输入为特征向量 x i ( x i ( 1 ) , x i ( 2 ) . . . x i ( n ) ) ∈ X x_i(x_i^{(1)},x_i^{(2)}...x_i^{(n)})\in\mathscr {X} xi(xi(1),xi(2)...xi(n))X

  5. 输出为类标记 y ∈ Y y\in\mathscr{Y} yY

  6. X是定义在输入空间 X \mathscr {X} X上的随机向量

  7. Y是定义在输入空间 Y \mathscr {Y} Y上的随机变量

  8. 设回归函数 h θ ( x ) = θ 1 x i ( 1 ) + θ 2 x i ( 2 ) + . . . + θ n x i ( n ) h_\theta(x)=\theta_1x_i^{(1)}+\theta_2x_i^{(2)} +...+\theta_nx_i^{(n)} hθ(x)=θ1xi(1)+θ2xi(2)+...+θnxi(n)
    任意点 P i ( x i ( 1 ) , x i ( 2 ) . . . x i ( n ) ) P_i(x_i^{(1)},x_i^{(2)}...x_i^{(n)}) Pi(xi(1),xi(2)...xi(n))带入该式可得到点 P i P_i Pi到预测值 y ^ i \hat y_i y^i

  9. 带入多项式模型的损失函数 J ( θ 1 , θ 2 . . . θ n ) = 1 2 m ∑ i = 1 m ( y ^ i − y i ) 2 J(\theta_1,\theta_2...\theta_n)=\frac{1}{2m}\sum_{i=1}^m (\hat y_i-y_i)^2 J(θ1,θ2...θn)=2m1i=1m(y^iyi)2

  10. (1) J ( θ 1 , θ 2 . . . θ n ) = 1 2 m ∑ i = 1 m ( h θ ( x ) − y i ) 2 J(\theta_1,\theta_2...\theta_n)=\frac{1}{2m}\sum_{i=1}^m (h_\theta(x)-y_i)^2\tag 1 J(θ1,θ2...θn)=2m1i=1m(hθ(x)yi)2(1)

  11. 在训练阶段, 代价函数的x 与y 都是已知量 θ \theta θ为变量量
    因此算法所述的目标等价于求损失函数 J ( θ 1 , θ 2 . . . θ n ) J(\theta_1,\theta_2...\theta_n) J(θ1,θ2...θn)的值取最小值时候的变量 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)

  12. 用梯度下降法求出最适合的 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)

梯度下降法求解过程:
  • 概念:
    通过将各变量 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)不断朝函数取得极值时的变量 ( ω 1 , ω 2 . . . ω n ) (\omega_1,\omega_2...\omega_n) (ω1,ω2...ωn)方向靠拢,从而获得代价函数取最小值时候的各 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)参数
方法一:

方法一更易于理解,但计算复杂度较高,求导难度大

  \  

  1. 对变量 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)进行初始随机赋值
    θ 1 = 1 , θ 1 = 5 , θ 3 = 0.5 , θ n = 10 \theta_1=1, \\ \theta_1=5,\\ \theta_3=0.5,\\ \theta_n=10 θ1=1,θ1=5,θ3=0.5,θn=10

  \  
2. 对函数的表达式的逐个变量 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)求偏导,得到 ∇ J ( θ 1 , θ 2 . . . θ n ) = ( ∂ f ∂ θ 1 , ∂ f ∂ θ 2 , ∂ f ∂ θ 3 . . . ∂ f ∂ θ i ) ∇J(\theta_1,\theta_2...\theta_n)=\left(\frac{\partial f}{\partial\theta_1},\frac{\partial f}{\partial\theta_2},\frac{\partial f}{\partial\theta_3}...\frac{\partial f}{\partial\theta_i}\right) J(θ1,θ2...θn)=(θ1f,θ2f,θ3f...θif)

∂ f ∂ θ 1 = 1 m ∑ i = 1 m ( h θ ( x i ) − y i ) x i ( 1 ) ∂ f ∂ θ 2 = 1 m ∑ i = 1 m ( h θ ( x i ) − y i ) x i ( 2 ) . . . . . . ∂ f ∂ θ n = 1 m ∑ i = 1 m ( h θ ( x i ) − y i ) x i ( n ) \frac{\partial f}{\partial\theta_1}=\frac{1}{m}\sum_{i=1}^m\left(h_\theta(x_i)-y_i\right)x_i^{(1)} \\ \frac{\partial f}{\partial\theta_2}=\frac{1}{m}\sum_{i=1}^m\left(h_\theta(x_i)-y_i\right)x_i^{(2)}\\ ...\\...\\ \frac{\partial f}{\partial\theta_n}=\frac{1}{m}\sum_{i=1}^m\left(h_\theta(x_i)-y_i\right)x_i^{(n)} θ1f=m1i=1m(hθ(xi)yi)xi(1)θ2f=m1i=1m(hθ(xi)yi)xi(2)......θnf=m1i=1m(hθ(xi)yi)xi(n)
  \  

  1. 设定学习率 控制每次迭代 变量的移动距离
    l R = 0.001 , 该 参 数 为 示 例 , 应 按 照 实 际 情 况 调 整 lR=0.001,该参数为示例,应按照实际情况调整 lR=0.001,,
      \  

  2. 分别对每个变量进行迭代
    θ 1 = θ 1 − l R ∂ f ∂ θ 1 θ 2 = θ 2 − l R ∂ f ∂ θ 2 θ 3 = θ 3 − l R ∂ f ∂ θ 3 . . . . . . θ m = θ m − l R ∂ f ∂ θ m 1 \theta_1=\theta_1-lR\frac{\partial f}{\partial\theta_1}\\\theta_2=\theta_2-lR\frac{\partial f}{\partial\theta_2}\\\theta_3=\theta_3-lR\frac{\partial f}{\partial\theta_3}\\...\\...\\\theta_m=\theta_m-lR\frac{\partial f}{\partial\theta_m1} θ1=θ1lRθ1fθ2=θ2lRθ2fθ3=θ3lRθ3f......θm=θmlRθm1f
      \  

5.重复第四步到足够次数,可得到距离代价函数取最小值时候的变量 ( ω 1 , ω 2 . . . ω n ) (\omega_1,\omega_2...\omega_n) (ω1,ω2...ωn)极为接近的变量 ( θ 1 , θ 2 . . . θ n ) (\theta_1,\theta_2...\theta_n) (θ1,θ2...θn)

方法二

方法二:将代价函数矩阵化,从而极大化简计算复杂度和求导复杂度

  1. 子式矩阵化
  • θ = [ θ 1 θ 2 θ 3 . . θ m ] \theta= \begin{bmatrix} \theta_1 \\ \theta_2\\ \theta_3 \\ . \\ . \\ \theta_m \\ \end{bmatrix} θ=θ1θ2θ3..θm

  • J ( θ 1 , θ 2 . . . θ n ) ⇒ J ( θ ) J(\theta_1,\theta_2...\theta_n) \Rightarrow J(\theta) J(θ1,θ2...θn)J(θ)

  • y i ⇒ Y = y _ d a t a = [ y 1 y 2 y 3 . . y m ] y_i\Rightarrow Y=y\_data=\begin{bmatrix} y_1 \\ y_2\\ y_3 \\ . \\ . \\ y_m \\ \end{bmatrix} yiY=y_data=y1y2y3..ym

  • x i ⇒ X = x _ d a t a = [ x 1 ( 1 ) x 1 ( 2 ) . . . x 1 ( n ) x 2 ( 1 ) x 2 ( 2 ) . . . x 2 ( n ) x 3 ( 1 ) x 3 ( 2 ) . . . x 3 ( n ) . . . . . . . . . . . . x m ( 1 ) x m ( 2 ) . . . x m ( n ) ] x_i\Rightarrow X=x\_data=\begin{bmatrix} x_1^{(1)} & x_1^{(2)} \quad ...&x_1^{(n)} \\ x_2^{(1)} & x_2^{(2)} \quad...&x_2^{(n)}\\ x_3^{(1)} & x_3^{(2)} \quad...&x_3^{(n)} \\ . & . \quad...& . \\ . & . \quad...& . \\ x_m^{(1)} & x_m^{(2)} \quad...&x_m^{(n)} \\ \end{bmatrix} xiX=x_data=x1(1)x2(1)x3(1)..xm(1)x1(2)...x2(2)...x3(2)...........xm(2)...x1(n)x2(n)x3(n)..xm(n)

  • h θ ( x i ) ⇒ [ h θ ( x 1 ) h θ ( x 2 ) h θ ( x 3 ) . . h θ ( x m ) ] = [ θ 1 x 1 ( 1 ) + θ 2 x 1 ( 2 ) + . . . + θ n x 1 ( n ) θ 1 x 2 ( 1 ) + θ 2 x 2 2 ) + . . . + θ n x 2 ( n ) θ 1 x 3 ( 1 ) + θ 2 x 3 ( 2 ) + . . . + θ n x 3 ( n ) . . . . . . . . θ 1 x m ( 1 ) + θ 2 x m ( 2 ) + . . . + θ n x m ( n ) ] = X ⋅ θ h_\theta(x_i)\Rightarrow \begin{bmatrix} h_\theta (x_1) \\ h_\theta (x_2) \\ h_\theta (x_3 ) \\ . \\ . \\ h_\theta (x_m) \\ \end{bmatrix}=\begin{bmatrix} \theta_1x_1^{(1)}+\theta_2x_1^{(2)} +...+\theta_nx_1^{(n)}\\ \theta_1x_2^{(1)}+\theta_2x_2 ^{2)}+...+\theta_nx_2^{(n)}\\ \theta_1x_3^{(1)}+\theta_2x_3 ^{(2)}+...+\theta_nx_3^{(n)}\\ \quad... . \\ \quad... .\\ \theta_1x_m^{(1)}+\theta_2x_m^{(2)} +...+\theta_nx_m^{(n)}\\ \end{bmatrix}=X \cdot \theta hθ(xi)hθ(x1)hθ(x2)hθ(x3)..hθ(xm)=θ1x1(1)+θ2x1(2)+...+θnx1(n)θ1x2(1)+θ2x22)+...+θnx2(n)θ1x3(1)+θ2x3(2)+...+θnx3(n)........θ1xm(1)+θ2xm(2)+...+θnxm(n)=Xθ

  • ∂ f ∂ θ i ⇒ ∇ J ( θ ) = [ ∂ f ∂ θ 1 ∂ f ∂ θ 2 ∂ f ∂ θ 3 . . ∂ f ∂ θ n ] \frac{\partial f}{\partial\theta_i}\Rightarrow ∇J(\theta)=\begin{bmatrix} \frac{\partial f}{\partial\theta_1}\\ \frac{\partial f}{\partial\theta_2}\\ \frac{\partial f}{\partial\theta_3}\\ . \\ . \\ \frac{\partial f}{\partial\theta_n}\\ \end{bmatrix} θifJ(θ)=θ1fθ2fθ3f..θnf

2.变换流程

因 为 因为
∂ f ∂ θ 1 = 1 m ∑ i = 1 m ( h θ ( x i ) − y i ) x i ( 1 ) ∂ f ∂ θ 2 = 1 m ∑ i = 1 m ( h θ ( x i ) − y i ) x i ( 2 ) . . . . . . ∂ f ∂ θ n = 1 m ∑ i = 1 m ( h θ ( x i ) − y i ) x i ( n ) \frac{\partial f}{\partial\theta_1}=\frac{1}{m}\sum_{i=1}^m\left(h_\theta(x_i)-y_i\right)x_i^{(1)} \\ \frac{\partial f}{\partial\theta_2}=\frac{1}{m}\sum_{i=1}^m\left(h_\theta(x_i)-y_i\right)x_i^{(2)}\\ ...\\...\\ \frac{\partial f}{\partial\theta_n}=\frac{1}{m}\sum_{i=1}^m\left(h_\theta(x_i)-y_i\right)x_i^{(n)} θ1f=m1i=1m(hθ(xi)yi)xi(1)θ2f=m1i=1m(hθ(xi)yi)xi(2)......θnf=m1i=1m(hθ(xi)yi)xi(n)
  \  

所 以 所以
∇ J ( θ ) = [ ∂ f ∂ θ 1 ∂ f ∂ θ 2 ∂ f ∂ θ 3 . . ∂ f ∂ θ n ] = [ x 1 ( 1 ) ( h θ ( x 1 ) − y 1 ) + x 2 ( 1 ) ( h θ ( x 2 ) − y 2 ) + . . . + x m ( 1 ) ( h θ ( x m ) − y m ) x 1 ( 2 ) ( h θ ( x 1 ) − y 1 ) + x 2 ( 2 ) ( h θ ( x 2 ) − y 2 ) + . . . + x m ( 2 ) ( h θ ( x m ) − y m ) x 1 ( 3 ) ( h θ ( x 1 ) − y 1 ) + x 2 ( 3 ) ( h θ ( x 2 ) − y 2 ) + . . . + x m ( 3 ) ( h θ ( x m ) − y m ) . . . . . . . . x 1 ( n ) ( h θ ( x 1 ) − y 1 ) + x 2 ( n ) ( h θ ( x 2 ) − y 2 ) + . . . + x m ( n ) ( h θ ( x m ) − y m ) ] ∇J(\theta)=\begin{bmatrix} \frac{\partial f}{\partial\theta_1}\\ \frac{\partial f}{\partial\theta_2}\\ \frac{\partial f}{\partial\theta_3}\\ . \\ . \\ \frac{\partial f}{\partial\theta_n}\\ \end{bmatrix}=\begin{bmatrix} x_1^{(1)}(h_\theta(x_1)-y_1)+x_2^{(1)}(h_\theta(x_2)-y_2)+...+x_m^{(1)}(h_\theta(x_m)-y_m)\\ x_1^{(2)}(h_\theta(x_1)-y_1)+x_2^{(2)}(h_\theta(x_2)-y_2)+...+x_m^{(2)}(h_\theta(x_m)-y_m)\\ x_1^{(3)}(h_\theta(x_1)-y_1)+x_2^{(3)}(h_\theta(x_2)-y_2)+...+x_m^{(3)}(h_\theta(x_m)-y_m)\\ \quad... . \\ \quad... .\\ x_1^{(n)}(h_\theta(x_1)-y_1)+x_2^{(n)}(h_\theta(x_2)-y_2)+...+x_m^{(n)}(h_\theta(x_m)-y_m)\\ \end{bmatrix} J(θ)=θ1fθ2fθ3f..θnf=x1(1)(hθ(x1)y1)+x2(1)(hθ(x2)y2)+...+xm(1)(hθ(xm)ym)x1(2)(hθ(x1)y1)+x2(2)(hθ(x2)y2)+...+xm(2)(hθ(xm)ym)x1(3)(hθ(x1)y1)+x2(3)(hθ(x2)y2)+...+xm(3)(hθ(xm)ym)........x1(n)(hθ(x1)y1)+x2(n)(hθ(x2)y2)+...+xm(n)(hθ(xm)ym)

  \  
套矩阵乘法公式 [ a b c d ] [ x y ] = [ a x + b y c x + d y ] 得 : \begin{bmatrix}a& b\\ c& d \end{bmatrix}\begin{bmatrix}x\\ y \end{bmatrix}=\begin{bmatrix}ax+by\\cx+dy \end{bmatrix}得: [acbd][xy]=[ax+bycx+dy]:

  \  
∇ J ( θ ) = [ ∂ f ∂ θ 1 ∂ f ∂ θ 2 ∂ f ∂ θ 3 . . ∂ f ∂ θ n ] = = [ x 1 ( 1 ) x 1 ( 2 ) . . . x 1 ( n ) x 2 ( 1 ) x 2 ( 2 ) . . . x 2 ( n ) x 3 ( 1 ) x 3 ( 2 ) . . . x 3 ( n ) . . . . . . . . . . . . x m ( 1 ) x m ( 2 ) . . . x m ( n ) ] T [ h θ ( x 1 ) − y 1 h θ ( x 2 ) − y 2 h θ ( x 3 − y 3 . . . h θ ( x m ) − y m ] ∇J(\theta)=\begin{bmatrix} \frac{\partial f}{\partial\theta_1}\\ \frac{\partial f}{\partial\theta_2}\\ \frac{\partial f}{\partial\theta_3}\\ . \\ . \\ \frac{\partial f}{\partial\theta_n}\\ \end{bmatrix}==\begin{bmatrix} x_1^{(1)} & x_1^{(2)} \quad ...&x_1^{(n)} \\ x_2^{(1)} & x_2^{(2)} \quad...&x_2^{(n)}\\ x_3^{(1)} & x_3^{(2)} \quad...&x_3^{(n)} \\ . & . \quad...& . \\ . & . \quad...& . \\ x_m^{(1)} & x_m^{(2)} \quad...&x_m^{(n)} \\ \end{bmatrix}^T\begin{bmatrix} h_\theta(x_1)-y_1\\ h_\theta(x_2)-y_2\\ h_\theta(x_3-y_3\\ ...\\ h_\theta(x_m)-y_m\\ \end{bmatrix} J(θ)=θ1fθ2fθ3f..θnf==x1(1)x2(1)x3(1)..xm(1)x1(2)...x2(2)...x3(2)...........xm(2)...x1(n)x2(n)x3(n)..xm(n)Thθ(x1)y1hθ(x2)y2hθ(x3y3...hθ(xm)ym

右 式 分 解 得 右式分解得

∇ J ( θ ) = [ ∂ f ∂ θ 1 ∂ f ∂ θ 2 ∂ f ∂ θ 3 . . ∂ f ∂ θ n ] = = [ x 1 ( 1 ) x 1 ( 2 ) . . . x 1 ( n ) x 2 ( 1 ) x 2 ( 2 ) . . . x 2 ( n ) x 3 ( 1 ) x 3 ( 2 ) . . . x 3 ( n ) . . . . . . . . . . . . x m ( 1 ) x m ( 2 ) . . . x m ( n ) ] T ( [ h θ ( x 1 ) h θ ( x 2 ) h θ ( x 3 . . . h θ ( x m ) ] − [ y 1 y 2 y 3 . . . y m ] ) ∇J(\theta)=\begin{bmatrix} \frac{\partial f}{\partial\theta_1}\\ \frac{\partial f}{\partial\theta_2}\\ \frac{\partial f}{\partial\theta_3}\\ . \\ . \\ \frac{\partial f}{\partial\theta_n}\\ \end{bmatrix}==\begin{bmatrix} x_1^{(1)} & x_1^{(2)} \quad ...&x_1^{(n)} \\ x_2^{(1)} & x_2^{(2)} \quad...&x_2^{(n)}\\ x_3^{(1)} & x_3^{(2)} \quad...&x_3^{(n)} \\ . & . \quad...& . \\ . & . \quad...& . \\ x_m^{(1)} & x_m^{(2)} \quad...&x_m^{(n)} \\ \end{bmatrix}^T \left( \begin{bmatrix} h_\theta(x^1)\\ h_\theta(x^2)\\ h_\theta(x^3\\ ...\\ h_\theta(x^m)\\ \end{bmatrix}-\begin{bmatrix} y^1\\ y^2\\ y^3\\ ...\\ y^m\\ \end{bmatrix} \right) J(θ)=θ1fθ2fθ3f..θnf==x1(1)x2(1)x3(1)..xm(1)x1(2)...x2(2)...x3(2)...........xm(2)...x1(n)x2(n)x3(n)..xm(n)Thθ(x1)hθ(x2)hθ(x3...hθ(xm)y1y2y3...ym

代 入 子 式 们 得 到 : 代入子式们得到: :
∇ J ( θ ) = X T ( X θ − Y ) ∇J(\theta)=X^T(X\theta-Y) J(θ)=XT(XθY)

  \  
又 因 为 又因为
θ 1 = θ 1 − l R ∂ f ∂ θ 1 θ 2 = θ 2 − l R ∂ f ∂ θ 2 θ 3 = θ 3 − l R ∂ f ∂ θ 3 . . . . . . θ m = θ m − l R ∂ f ∂ θ m 1 \theta_1=\theta_1-lR\frac{\partial f}{\partial\theta_1}\\\theta_2=\theta_2-lR\frac{\partial f}{\partial\theta_2}\\\theta_3=\theta_3-lR\frac{\partial f}{\partial\theta_3}\\...\\...\\\theta_m=\theta_m-lR\frac{\partial f}{\partial\theta_m1} θ1=θ1lRθ1fθ2=θ2lRθ2fθ3=θ3lRθ3f......θm=θmlRθm1f

代 入 子 式 与 ∇ J ( θ ) 得 到 最 终 式 子 : 代入子式与∇J(\theta)得到最终式子: J(θ):
θ = θ − L R ( ∇ J ( θ ) ) \theta=\theta-LR(∇J(\theta)) θ=θLR(J(θ))
- 式 子 里 除 L R 外 都 是 矩 阵 式子里除LR外都是矩阵 LR

重 复 上 式 足 够 次 数 , 可 得 到 距 离 代 价 函 数 取 最 小 值 时 候 的 变 量 ( ω 1 , ω 2 . . . ω n ) 极 为 接 近 的 变 量 ( θ 1 , θ 2 . . . θ n ) 重复上式足够次数,可得到距离代价函数取最小值时候的变量(\omega_1,\omega_2...\omega_n)极为接近的变量(\theta_1,\theta_2...\theta_n) ,(ω1,ω2...ωn)(θ1,θ2...θn)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值