本博客主要内容为图书《神经网络与深度学习》和National Taiwan University (NTU)林轩田老师的《Machine Learning》的学习笔记,因此在全文中对它们多次引用。初出茅庐,学艺不精,有不足之处还望大家不吝赐教。
本节结合之前几节《改进神经网络的学习方法》系列中提到的方法进行实现。我们将写出一个新的程序,network2.py, 这是一个对第一章中开发的 network.py 的改进版本。获取完整的代码请点击这里,我们首先看看函数的初始化。
class Network(object):
def __init__(self, sizes, cost=CrossEntropyCost):
"""The list ``sizes`` contains the number of neurons in the respective
layers of the network. For example, if the list was [2, 3, 1]
then it would be a three-layer network, with the first layer
containing 2 neurons, the second layer 3 neurons, and the
third layer 1 neuron. The biases and weights for the network
are initialized randomly, using
``self.default_weight_initializer`` (see docstring for that
method).
"""
self.num_layers = len(sizes)
self.sizes = sizes
self.default_weight_initializer()
self.cost=cost
其中self.default_weight_initializer()
是默认权重初始化函数,它采用的为在《八、改进神经网络的学习方法(4):权重初始化》所提到的方法,使用均值为0,方差为 1n