def unit_test2(): mlp = MLP([1,2,1]); mlp.layers[1].set_params([[-.3],[4]],[.15,-2]) mlp.layers[2].set_params([[0,2]],[-1]) num_labels=1 data= [1.0, 1.0] predicted = mlp.predict(data[:-num_labels]) print 'predicted: ', predicted mlp.output_error_calculation(data[-num_labels:]) mlp.backpropagation() print 'errors:' for layer in mlp.layers: print layer.e mlp.gradient_descend(.5) print 'weights:' for layer in mlp.layers: print zip( layer.b, layer.weight)
def unit_test(): mlp = MLP([2,2,2,2]); mlp.layers[1].set_params([[.2,-.1],[.3,-.3]],[.1,-.2]) mlp.layers[2].set_params([[-.2,-.3],[-.1,.3]],[.1,.2]) mlp.layers[3].set_params([[-.1,.3],[-.2,-.3]],[.2,.1]) num_labels=2 data= [.3, .7, .1, 1.0] predicted = mlp.predict(data[:-num_labels]) print 'predicted: ', predicted mlp.output_error_calculation(data[-num_labels:]) mlp.backpropagation() print 'errors:' for layer in mlp.layers: print layer.e mlp.gradient_descend(.1) print 'weights:' for layer in mlp.layers: print zip( layer.b, layer.weight)