Created
November 14, 2017 05:05
-
-
Save kuredev/2a27eb8d20f55ffe8f1524e3138f8d58 to your computer and use it in GitHub Desktop.
【ゼロから作るDeep Learning】2.5.2 XORゲートの実装(多層パーセプトロン)
This file contains hidden or 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
| <?php | |
| //echo perceptron_xor(1, 1); | |
| /** | |
| * Created by PhpStorm. | |
| * User: kure | |
| * Date: 11/14/17 | |
| * Time: 1:37 PM | |
| */ | |
| /** | |
| * @param $type and or nand or or | |
| * @param $x1 | |
| * @param $x2 | |
| * @return int | |
| */ | |
| function perceptron(string $type, int $x1, int $x2){ | |
| switch($type){ | |
| case "and": | |
| $w1 = 0.5; | |
| $w2 = 0.5; | |
| $theta = 0.7; | |
| break; | |
| case "or": | |
| $w1 = 1; | |
| $w2 = 1; | |
| $theta = 0.5; | |
| break; | |
| case "nand": | |
| $w1 = -0.5; | |
| $w2 = -0.5; | |
| $theta = -0.7; | |
| break; | |
| default: | |
| echo "Error"; | |
| } | |
| $w = $x1*$w1 + $x2*$w2; | |
| return($w > $theta) ? 1 : 0; | |
| } | |
| function perceptron_xor($x1, $x2){ | |
| $s1 = perceptron("nand", $x1, $x2); | |
| $s2 = perceptron("or", $x1, $x2); | |
| return perceptron("and", $s1, $s2); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment