Skip to content

Instantly share code, notes, and snippets.

@startselect
Created March 26, 2016 03:31
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 startselect/7d932ed6b1dfba0e8052 to your computer and use it in GitHub Desktop.
Save startselect/7d932ed6b1dfba0e8052 to your computer and use it in GitHub Desktop.
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