1. Cost Function
首先定义一些需要使用的变量:
L L L = total number of layers in the network;
s l s_l sl = number of units (not counting bias unit) in layer l l l
K K K = number of output units/classes
将神经网络的分类定义为两种情况:二类分类和多类分类,
二类分类: S L = 0 , y = 0 o r 1 S_L=0, y=0\, or\, 1 SL=0,y=0or1表示哪一类;
K K K类分类: S L = k , y i = 1 S_L=k, y_i = 1 SL=k,yi=1表示分到第 i i i类; ( k > 2 ) (k>2) (k>2)
神经网络代价函数 J ( θ ) J(\theta) J(θ)将是用于逻辑回归的成本函数的推广。
逻辑回归问题中代价函数为:
J ( θ ) = − 1 m [ ∑ i = 1 m y ( i ) log h θ ( x ( i ) ) + ( 1 − y ( i ) ) l o g ( 1 − h θ ( x ( i ) ) ) ] + λ 2 m ∑ j = 1 n θ j 2 J\left(\theta \right)=-\frac{1}{m}\left[\sum_{i=1}^{m}{y}^{(i)}\log{h_\theta({x}^{(i)})}+\left(1-{y}^{(i)}\right)log\left(1-h_\theta\left({x}^{(i)}\right)\right)\right]+\frac{\lambda}{2m}\sum_{j=1}^{n}{\theta_j}^{2} J(θ)=−m1[i=1∑my(i)loghθ(x(i))+(1−y(i))log(1−hθ(x(i)))]+2mλj=1∑nθj2
在Logistic Regression中,只有一个输出变量,也只有一个因变量 y y y,但是在Neural Network中,输出层可以有多个变量, h θ ( x ) h_\theta(x) hθ(x)是一个 K ∗ 1 K*1 K∗1的列向量,故代价函数会比逻辑回归更多元,为: \newcommand{\subk}[1]{ #1_k }
h θ ( x ) ∈ R K h_\theta\left(x\right)\in \mathbb{R}^{K} hθ(x)∈RK ( h θ ( x ) ) i = i t h output {\left({h_\theta}\left(x\right)\right)}_{i}={i}^{th} \text{output} (h</