Created
April 3, 2016 11:42
-
-
Save darkf/a34be6abf0afe54fbffd36b14bdb9ecb 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
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