Skip to content

Instantly share code, notes, and snippets.

@bmwant
Created November 13, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmwant/a3aac4b1ec506547134477a1a1f3ebf3 to your computer and use it in GitHub Desktop.
Save bmwant/a3aac4b1ec506547134477a1a1f3ebf3 to your computer and use it in GitHub Desktop.
Update with predict to simple neural network
class NeuralNetwork(object):
...
def predict(self, x):
layer1 = sigmoid(np.dot(x, self.weights1))
output = sigmoid(np.dot(layer1, self.weights2))
return output
x_seen = np.array([1, 1, 0])
print(nn.predict(x_seen))
# [0.01162975]
x_unseen = np.array()
print(nn.predict(x_unseen))
# [0.84968032]
@aldwinaldwin
Copy link

@bmwant When teaching the neural network 10 times from scratch again, predicting 4 examples will return different results.

Is it unpredictable what this small neural network is learning?

if __name__ == "__main__":
    X = array([[0,0,1],
               [0,1,1],
               [1,0,1],
               [1,1,1]])
    y = array([[0],[1],[1],[0]])

    for _ in range(10):
        nn = NeuralNetwork(X,y)
        for i in range(15000):
            nn.feedforward()
            nn.backprop()
        print([ round(nn.predict(a)) for a in [ np.array([0, 0, 0]), np.array([0, 1, 0]), np.array([1, 0, 0]), np.array([1, 1, 0]) ] ])
[0.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0]
[0.0, 1.0, 1.0, 0.0]
[0.0, 1.0, 1.0, 0.0]
[0.0, 1.0, 1.0, 0.0]
[0.0, 0.0, 0.0, 0.0]
[0.0, 1.0, 1.0, 0.0]
[0.0, 1.0, 1.0, 0.0]
[0.0, 0.0, 0.0, 0.0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment