机器学习(11.3)--神经网络(nn)算法的深入与优化(3) -- QuadraticCost(二次方代价函数)数理分析
2018-03-07 21:20
721 查看
在前面的文章已经对神经网络的基本算法流程做了详细的介绍
机器学习(1)--神经网络初探
机器学习(10.4)--手写数字识别的不同算法比较(4)--神经网络
在这中间使用的就是QuadraticCost(二次方代价函数),其实在我们代码中并没有相关的代码,那这个所以的代价函数是什么?
在文章 机器学习(7)--梯度下降法(GradientDescent)的简单实现 使用的其实就是QuadraticCost
这篇文章我们将从数理上对QuadraticCost进行讲解:
以下是原本我们训练单条记录时的代码,def itemData(item,layers,weights,biases):
#开始正向计算
zs = []
acts = [item[0]]
for w,b in zip(weights,biases):
z = np.dot(w,acts[-1]) + b
zs.append(z)
acts.append(sigmoid(z))
#开始反向计算
item_w = [np.zeros(b.shape) for b in weights]
item_b = [np.zeros(b.shape) for b in biases]
for index in range(-1,-1 * len(layers),-1):
if index == -1:
item_b[index] = acts[index] - item[1]
else:
item_b[index] = np.dot(weights[index + 1].T,item_b[index + 1])
item_b[index] = item_b[index] * sigmoid_deriv(zs[index])
item_w[index] = np.dot(item_b[index],acts[index - 1].T)
return item_w,item_b
在正向计算的循环最后一步我们会得出我们要计算值 acts[-1] 这时我设这个值为a
而当条记录item[1] 就是实际值,也就是y或是y(x)
那么我们定义
这也就是最二次方代价意思
因此在求得最后一层神经元
这时我们对最后一层的w,b求偏导数,
其中x在程序代码对应的是a[-2],
因此直接用if index == -1:
item_b[index] = acts[index] - item[1]
else:
item_b[index] = np.dot(weights[index + 1].T,item_b[index + 1])
item_b[index] = item_b[index] * sigmoid_deriv(zs[index])
item_w[index] = np.dot(item_b[index],acts[index - 1].T)
取得detal,
看到这里,应该明白为什么我们代码中没有cost,也没有二次方,但依然把这称之为QuadraticCost(二次方代价函数)
代码没有发生任何变化,也就不再粘贴出来了
相关文章推荐
- 机器学习(11.4)--神经网络(nn)算法的深入与优化(4) -- CorssEntropyCost(交叉熵代价函数)数理分析与代码实现
- 机器学习(11.2)--神经网络(nn)算法的深入与优化(2) -- QuadraticCost、CorssEntropyCost、SoftMax的javascript数据演示测试代码
- 机器学习(11.1)--神经网络(nn)算法的深入与优化(1)--介绍
- 机器学习(11.5)--神经网络(nn)算法的深入与优化(5) -- softmax的代码实现
- NN:神经网络算法进阶优化法,进一步提高手写数字识别的准确率—Jason niu
- 神经网络优化算法
- tensorflow中神经网络相关函数算法
- 机器学习与智能优化 之 浅层和深层神经网络
- (原创)大数据时代:基于微软案例数据库数据挖掘知识点总结(Microsoft 神经网络分析算法原理篇)
- 【机器学习】神经网络-激活函数-面面观(Activation Function)
- 深度学习笔记6:神经网络优化算法之从SGD到Adam
- 神经网络与深度学习笔记(四)为什么用交叉熵代替二次代价函数
- 机器学习笔记-神经网络中激活函数(activation function)对比--Sigmoid、ReLu,tanh
- 课程笔记之六:神经网络的代价函数和误差反向传播算法
- 神经网络优化算法选择
- 【机器学习】--神经网络(NN)
- 神经网络,机器学习,算法,人工智能等 30 门免费课程
- 网络分析优化TSP算法初探
- [置顶] 【机器学习】神经网络-激活函数-面面观(Activation Function)
- 深入分析 Java I/O 的工作机制(网络 I/O 优化)