Last active
March 28, 2018 21:52
-
-
Save t-nissie/1ced405cff775f73c80bee75b21e029d to your computer and use it in GitHub Desktop.
ゼロからOCamlで作るDeep Learning
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
(* perceptron : float -> float -> float -> float -> float -> float *) | |
(* description: perceptron with two inputs x1 and x2*) | |
let perceptron b w1 w2 x1 x2 = if b +. w1 *. x1 +. w2 *. x2 >= 0.0 then 1.0 else 0.0 | |
let and_gate = perceptron ~-.0.7 0.5 0.5 | |
let nand_gate = perceptron 0.7 ~-.0.5 ~-.0.5 | |
let or_gate = perceptron ~-.0.5 1.0 1.0 | |
let nor_gate = perceptron 0.5 ~-.1.0 ~-.1.0 | |
let xor_gate x1 x2 = and_gate (nand_gate x1 x2) (or_gate x1 x2) | |
(* tests *) | |
let and_00 = and_gate 0.0 0.0 = 0.0 | |
let and_10 = and_gate 1.0 0.0 = 0.0 | |
let and_01 = and_gate 0.0 1.0 = 0.0 | |
let and_11 = and_gate 1.0 1.0 = 1.0 | |
let nand_00 = nand_gate 0.0 0.0 = 1.0 | |
let nand_10 = nand_gate 1.0 0.0 = 1.0 | |
let nand_01 = nand_gate 0.0 1.0 = 1.0 | |
let nand_11 = nand_gate 1.0 1.0 = 0.0 | |
let or_00 = or_gate 0.0 0.0 = 0.0 | |
let or_10 = or_gate 1.0 0.0 = 1.0 | |
let or_01 = or_gate 0.0 1.0 = 1.0 | |
let or_11 = or_gate 1.0 1.0 = 1.0 | |
let nor_00 = nor_gate 0.0 0.0 = 1.0 | |
let nor_10 = nor_gate 1.0 0.0 = 0.0 | |
let nor_01 = nor_gate 0.0 1.0 = 0.0 | |
let nor_11 = nor_gate 1.0 1.0 = 0.0 | |
let xor_00 = xor_gate 0.0 0.0 = 0.0 | |
let xor_10 = xor_gate 1.0 0.0 = 1.0 | |
let xor_01 = xor_gate 0.0 1.0 = 1.0 | |
let xor_11 = xor_gate 1.0 1.0 = 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment