def __build_positive_phase(self):
n_iterations = T.iscalar('n_iterations')
alphas = [T.fscalar("alpha_W"+str(r+1)) for r in range(len(self.weights))]
def backprop(*layers):
layers_new = [layers[-1]]
for k in range(len(self.layers)-2,0,-1):
layers_new += [pi(T.dot(layers[k-1], self.weights[k-1]) + T.dot(layers_new[-1], self.weights[k].T) + self.biases[k])]
layers_new += [layers[0]]
layers_new.reverse()
return layers_new
( layers, updates ) = theano.scan(
backprop,
outputs_info=self.layers[:-1]+[self.y_data_one_hot],
n_steps=n_iterations
)
layers_new = [layer[-1] for layer in layers]
Delta_layers = [(layer_new-layer) for layer_new,layer in zip(layers_new[1:],self.layers[1:])]
biases_new = [b + alpha * T.mean(Delta, axis=0) for b,alpha,Delta in zip(self.biases[1:],alphas,Delta_layers)]
weights_new = [W + alpha * T.dot(layer.T, Delta) / T.cast(self.layers[0].shape[0], dtype=theano.config.floatX) for W, alpha, layer, Delta in zip(self.weights, alphas, self.layers[:-1], Delta_layers)]
for bias, bias_new in zip(self.biases[1:],biases_new):
updates[bias]=bias_new
for weight, weight_new in zip(self.weights,weights_new):
updates[weight]=weight_new
positive_phase = theano.function(
inputs=[n_iterations]+alphas,
outputs=[],
updates=updates
)
return positive_phase
model2.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录