Skip to content

Instantly share code, notes, and snippets.

@darkf
Created April 3, 2016 11:42
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 darkf/a34be6abf0afe54fbffd36b14bdb9ecb to your computer and use it in GitHub Desktop.
Save darkf/a34be6abf0afe54fbffd36b14bdb9ecb to your computer and use it in GitHub Desktop.
type Weight = Float
type Threshold = Float
perceptron :: [Weight] -> Threshold -> [Float] -> Bool
perceptron ws t xs = sum (zipWith (*) ws xs) >= t
-- OR gate
or_p = perceptron [1, 1] 1
-- AND gate
and_p = perceptron [1, 1] 2
-- NOT gate
not_p = perceptron [-1] 0
-- NAND gate
nand_p xs = not_p [if and_p xs then 1 else 0]
-- true
true_p = perceptron [] 0
-- false
false_p = perceptron [] 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment