Skip to content

Commit

Permalink
perceptron in python
Browse files Browse the repository at this point in the history
  • Loading branch information
doolin committed Jan 31, 2016
1 parent d0c6cd3 commit b295e9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nb/dss/nn/python/lib/neural.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# pylint: disable=missing-docstring

import numpy

def step_function(x): # pylint: disable=invalid-name
return 1 if x >= 0 else 0

def perceptron_output(weights, bias, x):
"""returns 1 if the perceptron 'fires', 0 if not"""
calculation = numpy.dot(weights, x) + bias
return step_function(calculation)
9 changes: 9 additions & 0 deletions nb/dss/nn/python/test/test_neural.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ def test_step_function(self):
actual = neural.step_function(1)
self.assertEqual(actual, expected)

def test_perceptron_output(self):
weights = [1, 1]
bias = 1.0
x = [1, 2]
expected = 1.0
actual = neural.perceptron_output(weights, bias, x)
self.assertEqual(actual, expected)


if __name__ == '__main__':
unittest.main()

0 comments on commit b295e9f

Please sign in to comment.