声明: 此笔记为吴恩达(Andrew Ng)的深度学习课程学习后的总结,会根据自己的学习进度更新。
深度神经网络
What is a deep neural network?
Deep neural network notation
l = 4 (layers) l = 4 \tag{layers} l=4(layers)
n [ l ] (units in layer l) n^{[l]} \tag{units in layer l} n[l](units in layer l)
a [ l ] (activations in layer l) a^{[l]} \tag{activations in layer l} a[l](activations in layer l)
Forward propagation for layer l
I n p u t : a [ a [ l − 1 ] ] Input : \ a^{[a^{[l-1]}]} Input: a[a[l−1]]
O u t p u t : a [ l ] , c a c h e ( z [ l ] ) Output : \ a^{[l]} \ , cache(z^{[l]}) Output: a[l] ,cache(z[l])
向量化的过程:
Z
[
l
]
=
W
[
l
]
⋅
A
[
l
−
1
]
+
b
[
l
]
Z^{[l]} = W^{[l]} \cdot A^{[l-1]} + b^{[l]}
Z[l]=W[l]⋅A[l−1]+b[l]
A [ l ] = g [ l ] ( Z [ l ] ) A^{[l]} = g^{[l]}(Z^{[l]}) A[l]=g[l](Z[l])
Backward propagation for layer l
I n p u t : d a [ l ] Input : \ da^{[l]} Input: da[l]
O u t p u t : d a [ l − 1 ] , d W [ l ] , d b [ l ] Output : \ da^{[l-1]} \ , dW^{[l]} , db^{[l]} Output: da[l−1] ,dW[l],db[l]
向量化过程:
d
Z
[
l
]
=
d
A
[
l
]
⋅
g
[
l
]
′
(
Z
[
l
]
)
dZ^{[l]} = dA^{[l]} \cdot g^{[l]'}(Z^{[l]})
dZ[l]=dA[l]⋅g[l]′(Z[l])
d W [ l ] = 1 m ⋅ d Z [ l ] ⋅ A [ l − 1 ] T dW^{[l]} = \frac1 m \cdot dZ^{[l]} \cdot A^{[l-1]T} dW[l]=m1⋅dZ[l]⋅A[l−1]T
d b [ l ] = 1 m ⋅ n p . s u m ( d z [ l ] , a x i s = 1 , k e e p d i m s = T r u e ) db^{[l]} = \frac 1 m \cdot np.sum(dz^{[l]},axis =1, keepdims = True) db[l]=m1⋅np.sum(dz[l],axis=1,keepdims=True)
d A [ l − 1 ] = W [ l ] T ⋅ d Z [ l ] dA^{[l-1]} = W^{[l]T} \cdot dZ^{[l]} dA[l−1]=W[l]T⋅dZ[l]
Summary
Getting the matrix dimensions right
Z
[
i
]
=
W
[
i
]
⋅
X
+
b
[
i
]
Z^{[i]} = W^{[i]} \cdot X + b^{[i]}
Z[i]=W[i]⋅X+b[i]
第一层 :输入的 X 维度为 (2 ,1 )
第二层 :输入的为计算后的 Z ,及 Z 的维度为 (3 ,1)
由此第一层的 W 的维度就是(3,2)
由此类推:
W
[
1
]
:
(
n
[
1
]
,
n
[
0
]
)
=
(
3
,
2
)
W^{[1]} :(n^{[1]},n^{[0]}) \ = (3,2)
W[1]:(n[1],n[0]) =(3,2)
W
[
2
]
:
(
n
[
2
]
,
n
[
1
]
)
=
(
5
,
3
)
W^{[2]} :(n^{[2]},n^{[1]}) \ = (5,3)
W[2]:(n[2],n[1]) =(5,3)
.
.
.
...
...
W
[
i
]
:
(
n
[
i
]
,
n
[
i
−
1
]
)
W^{[i]} :(n^{[i]},n^{[i-1]})
W[i]:(n[i],n[i−1])
另外 b 的维度和同层的 Z 相等。
不是越复杂的网络就越好,只有最适合解决当时实际问题的网络,切勿小看只有几层隐藏层的网络