Skip to content

Instantly share code, notes, and snippets.

@darkf darkf/Perceptron.hs
Created Apr 3, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.