大佬在写数学时候 一笔带过 在加上之前学过的东西都还给老师了 一眼看起来一脸懵
其实上面很简单 高中数学都可以解决 只不过时间过去太久了有点生疏了!
高中数学 偏导数 复合函数的偏导数
所谓复合函数 即
f
(
x
)
=
(
x
3
+
3
y
−
2
)
2
f(x)=(x^3+3y-2)^2
f(x)=(x3+3y−2)2 将内部看作一个整体z
z
=
x
3
+
3
y
−
2
z=x^3+3y-2
z=x3+3y−2
则
∂
f
∂
x
=
∂
f
∂
z
∗
∂
z
∂
x
=
2
∗
(
x
3
+
3
y
−
2
)
∗
3
x
2
\frac{\partial f}{\partial x}=\frac{\partial f}{\partial z}*\frac{\partial z}{\partial x}=2*(x^3+3y-2)*3x^2
∂x∂f=∂z∂f∗∂x∂z=2∗(x3+3y−2)∗3x2 中间的第一个的分母可以和第二个的分子约掉,链式法则
∂
f
∂
z
=
2
∗
(
x
3
+
3
y
−
2
)
\frac{\partial f}{\partial z}=2*(x^3+3y-2) \quad
∂z∂f=2∗(x3+3y−2) 因为
x
n
的
导
数
等
于
n
x
n
−
1
x^n的导数等于nx^{n-1}
xn的导数等于nxn−1
∂
z
∂
x
=
3
x
2
\frac{\partial z}{\partial x}=3x^2 \quad
∂x∂z=3x2
导数常用法则
- 常数项的导数等于零
- kx的导数等于k
- x n 导 数 等 于 n x n − 1 x^n 导数等于 nx^{n-1} xn导数等于nxn−1
- 多元导数,将另外的看作常数
那么最初的问题就好办了
∂ ∂ θ j J ( θ 0 , θ 1 ) = ∂ ∂ θ j ∗ 1 2 m ∑ i = 1 m ( h θ ( x ( i ) − y ( i ) ) 2 = ∂ ∂ θ j ∗ 1 2 m ∑ i = 1 m ( θ 0 + θ 1 x ( i ) − y ( i ) ) 2 \frac{\partial}{\partial\theta_{j}}J(\theta_{0},\theta_{1})=\frac{\partial}{\partial\theta_{j}}*\frac{1}{2m}\sum\limits^m_{i=1}(h_{\theta}(x^{(i)-y^{(i)}})^2 \\ \quad \quad= \frac{\partial}{\partial\theta_j}*\frac{1}{2m}\sum\limits^m_{i=1}(\theta_0+\theta_1x^{(i)}-y^{(i)})^2 ∂θj∂J(θ0,θ1)=∂θj∂∗2m1i=1∑m(hθ(x(i)−y(i))2=∂θj∂∗2m1i=1∑m(θ0+θ1x(i)−y(i))2
此处的求和操作并不会对求导产生影响 所以大胆的带上累加项 ∑ i = 1 m \quad\sum\limits^m_{i=1} i=1∑m
对 θ 0 \theta_0 θ0 进行求导 ∂ ∂ θ 0 J ( θ 0 , θ 1 ) = ∑ i = 1 m ∗ 2 ∗ 1 2 m ∗ ( θ 0 + θ 1 x ( i ) − y ( i ) ) ) ∗ 1 \frac{\partial}{\partial\theta_0}J(\theta_0,\theta_1)=\sum\limits^m_{i=1}*2*\frac{1}{2m}*(\theta_0+\theta_1x^{(i)}-y^{(i))})*1 ∂θ0∂J(θ0,θ1)=i=1∑m∗2∗2m1∗(θ0+θ1x(i)−y(i)))∗1
θ 0 j = 0 : ∂ ∂ θ 0 J ( θ 0 , θ 1 ) = 1 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) \theta_0j=0:\frac{\partial}{\partial\theta_0}J(\theta_0,\theta_1)=\frac{1}{m}\sum\limits^m_{i=1}( h_\theta(x^{(i)})-y^{(i)} ) θ0j=0:∂θ0∂J(θ0,θ1)=m1i=1∑m(hθ(x(i))−y(i))
对 θ 1 \theta_1 θ1 进行求导 ∂ ∂ θ 1 J ( θ 0 , θ 1 ) = ∑ i = 1 m 2 ∗ 1 2 m ∗ ( θ 0 + θ 1 x ( i ) − y ( i ) ) ∗ x ( i ) \frac{\partial}{\partial\theta_1}J(\theta_0,\theta_1)=\sum\limits^m_{i=1}2*\frac{1}{2m}*(\theta_0+\theta_1x^{(i)}-y^{(i)})*x^{(i)} ∂θ1∂J(θ0,θ1)=i=1∑m2∗2m1∗(θ0+θ1x(i)−y(i))∗x(i)
θ 1 j = 1 : ∂ ∂ θ 1 J ( θ 0 , θ 1 ) = 1 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) ∗ x ( i ) \theta_1j=1:\frac{\partial}{\partial\theta_1}J(\theta_0,\theta_1)=\frac{1}{m}\sum\limits^m_{i=1}( h_\theta(x^{(i)})-y^{(i)})*x^{(i)} θ1j=1:∂θ1∂J(θ0,θ1)=m1i=1∑m(hθ(x(i))−y(i))∗x(i)