def __init__(self, dim_list, eta = 0.1): """ Constructor for network. Params: dim_list: a list of the number of dimension for each layer. eta: learning rate for each gradient descent step """ depth = len(dim_list) self.depth = depth self.dim_list = dim_list self.eta = eta # 1. Initiate each layer: output, partial_output and weight, # although partial_output is useless for the input layer, similarly # weight and bias are useless for the output layer. # # 2. Partial_weight is an internal variable and will not be stored in # a layer. # self.layers = [ {'output':Vector.fromIterable(0 for i in xrange(dim_list[l])), 'partial_output':Vector.fromIterable(0 for i in xrange(dim_list[l])), 'weight':Matrix.fromRandom(dim_list[l + 1], dim_list[l]), 'bias':Vector.fromRandom(dim_list[l + 1])} for l in xrange(depth - 1) ] # output layer self.layers.append({'output':Vector.fromList([0] * dim_list[depth - 1]), 'partial_output':Vector.fromList([0] * dim_list[depth - 1]), 'weight': None, 'bias': None})