Skip to content

Instantly share code, notes, and snippets.

@junichiro
Last active January 31, 2020 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junichiro/71e2641536b29652fac88d11d7718a30 to your computer and use it in GitHub Desktop.
Save junichiro/71e2641536b29652fac88d11d7718a30 to your computer and use it in GitHub Desktop.
機械学習に必要な最急降下法の実装に必要な知識まとめ ref: https://qiita.com/junichiro/items/527b1f211ed814528ded
x := x - \frac{\partial}{\partial x}J(x, y) \\
y := y - \frac{\partial}{\partial y}J(x, y) \\
\theta_1 := \theta_1 - \frac{\partial}{\partial \theta_1}J(\theta_1, \theta_2) \\
\theta_2 := \theta_2 - \frac{\partial}{\partial \theta_2}J(\theta_1, \theta_2) \\
\theta_1 := \theta_1 - \alpha\frac{\partial}{\partial \theta_1}J(\theta_1, \theta_2) \\
\theta_2 := \theta_2 - \alpha\frac{\partial}{\partial \theta_2}J(\theta_1, \theta_2) \\
J = 目的関数
grad = 目的関数の偏微分項
% fmincg は最急降下法を解くライブラリ
[theta, cost] = fmincg([J_theta, grad], initial_theta)
\begin{bmatrix}
a & c & e\\
b & d & f
\end{bmatrix}
=>
\begin{bmatrix}
a \\
b \\
c \\
d \\
e \\
f
\end{bmatrix}
\begin{bmatrix}
a \\
b \\
c \\
d \\
e \\
f
\end{bmatrix}
=>
\begin{bmatrix}
a & c & e\\
b & d & f
\end{bmatrix}
A = [1 3 5; 2 4 6];
% unrolling
A = A(:)
ans =
1
2
3
4
5
6
% reshape
A = reshape(A, 2, 3)
>> reshape(A, 2, 3)
ans =
1 2 3
4 5 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment