Created
March 26, 2016 03:31
-
-
Save startselect/7d932ed6b1dfba0e8052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class Neuron: | |
def __init__(self, w, b, f): | |
self.w = np.concatenate((w, b), axis =1) | |
self.f = f | |
def output(self, x): | |
x = np.concatenate((x, [[1,],])) | |
return self.f(self.w.dot(x)) | |
def f(u): | |
u[u>0] = 1 | |
u[u<=0] = -1 | |
return u | |
if __name__ == '__main__': | |
neuron = Neuron([[1,],],[[0.1,],], f) | |
print(neuron.output([[-0.1,],])) | |
neuron = Neuron ([[0.5, 0.8, ],[-0.1, -0.3,]],[[0.1,],[0.1, ]], f) | |
print(neuron.output([[-1,],[0.2, ]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment