Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- err = np.array([])
- print (err)
- def sigm(x):
- return (1 / (np.exp(-x) + 1))
- train_in = np.array ([ [1, 0, 1, 0],
- [1, 1, 1, 1],
- [0, 0, 0, 0],
- [1, 1, 1, 1],
- [0, 1, 0, 1],
- [0, 0, 0, 1],
- [0, 1, 0, 0],
- [1, 0, 0, 1],
- [1, 0, 0, 1] ])
- train_out = np.array ([1, 1, 0, 1, 0, 0, 0, 1, 1])
- np.random.seed(1)
- weight = 2 * np.random.random((4, 1)) - 1
- #print(weight)
- for i in range (20000):
- input = train_in
- output = sigm(np.dot(input, weight))
- print("out ", output)
- for a in output.shape:
- #
- err = np.add(train_out[a] - output[a])
- print(err)
- d_weight = np.dot(train_in.T, err * (output * (1- output)))
- print("weight ", d_weight)
- weight += d_weight
- #print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement