def test_feed_forward(self): xor_network = [ # hidden layer [[20, 20, -30], [20, 20, -10]], # output layer [[-60, 60, -30]], ] output = [] for x in [0, 1]: for y in [0, 1]: print x, y, neural.feed_forward(xor_network, [x, y])[-1] output.append(neural.feed_forward(xor_network, [x, y])[-1]) print output
def predict(input): return is_neural.feed_forward(network, input)[-1]
"""return a matplotlib 'patch' object with the specified location, crosshatch pattern and color""" return mpl.patches.Rectangle((x-0.5, y-0.5), 1, 1, hatch=hatch, fill=False, color=color) for i in range(5): for j in range(5): if weights[5*i + j] < 0: # add black and white hatches, so visible whether dark or light ax.add_patch(patch(j, i, '/', "white")) ax.add_patch(patch(j, i, '\\', "black")) # plt.show() left_column_only = [1, 0, 0, 0, 0] * 5 print is_neural.feed_forward(network, left_column_only)[0][0] # 10 center_middle_row = [0, 0, 0, 0, 0] * 2 + [0, 1, 1, 1, 0] + [0, 0, 0, 0, 0] * 2 print feed_forward(network, center_middle_row)[0][0] # 0.95 right_column_only = [0, 0, 0, 0, 0] * 5 print feed_forward(network, right_column_only)[0][0] # 0.0 my_three = [ 0,1,1,1,0, # .@@@ 0,0,0,1,1, # ...@@ 0,0,1,1,0, # ..@@ 0,0,0,1,1, # ...@@ 0,1,1,1,0] # .@@@. sigmoid(.121 * -11.61 + 1 * -2.17 + 1 * 9.31 - 1.38 * 1 - 0 * 11.47 - 1.92)