$input){ $addon += bcmul($inputs[$key],$weights[$key],8); } return 1 / (1 + exp(-1*$addon)); } function train(&$neruons,&$weights,$input,$wout,$lr){ $errors = array(); $neruons[0] = $input; $size = sizeof($neruons); play_nn($neruons,$weights,$input); foreach($neruons[$size-1] as $key=>$o){ $errors[$size-1][$key] = $o*(1 - $o)*($wout[$key] - $o); } for($b = $size-2;$b > 0;$b--){ foreach($neruons[$b] as $key1 => $o){ $add = 0; foreach($neruons[$b+1] as $key2=>$blah){ $add += bcmul($weights[$b+1][$key2][$key1],$errors[$b+1][$key2],15); } $errors[$b][$key1] = $o*(1 - $o)*($add); } } for($b = $size-1;$b > 0;$b--){ foreach($errors[$b] as $key=>$error){ foreach($weights[$b][$key] as $pkey=>$we){ $weights[$b][$key][$pkey] = $we + ($lr * $error * $neruons[$b-1][$pkey]); } } } play_nn($neruons,$weights,$input); } function play_nn(&$neruons,$weights,$input){ $neruons[0] = $input; $size = sizeof($neruons); for($b = 1;$b < $size;$b++){ $akeys = array_keys($neruons[$b]); $asize = sizeof($akeys); for($ac=0;$ac<$asize;$ac++){ $neruons[$b][$akeys[$ac]] = get_real_value($neruons[$b-1],$weights[$b][$akeys[$ac]]); } } } function make_nn(&$neruons,&$weights,$input,$layers){ $neruons[0] = $input; $size = sizeof($layers); for($b = 1;$b < $size;$b++){ for($i = 0; $i < $layers[$b]; $i++){ $neruons[$b][$i] = 1; for($j = 0; $j < $layers[$b-1]; $j++){ $weights[$b][$i][$j] = rand(-5,5) / 100; } } } play_nn($neruons,$weights,$input); } ?> Example: [.6,.2] } print_r($neruons); ?>