fork download
  1. <?php
  2.  
  3. $inputs = [0,0];
  4. $expectedOutput = 0;
  5.  
  6. array_push ($inputs, -1); //adding bias
  7. $neuronWeights = [0.05, -0.02, 0.02];
  8.  
  9. $inputsLength = count($inputs);
  10. $sum = 0;
  11.  
  12. for($i = 0; $i < $inputsLength; $i++){
  13. $sum += $inputs[$i] * $neuronWeights[$i];
  14. }
  15.  
  16. //echo $sum;
  17.  
  18. if($sum > 0){
  19. $ouput = 1;
  20. }
  21. else {
  22. $output = 0;
  23. }
  24.  
  25.  
  26. if($output == $expectedOutput){
  27. echo "correct weights";
  28. }
  29. //fix the weights. 0.25 is n
  30. elseif($output > $expectedOutput){
  31. for($i = 0; $i < $inputsLength; $i++){
  32. $neuronWeights[$i] = $neuronWeights[$i] - 0.25 * (1-0) * $inputs[$i];
  33. }
  34. }
  35. else {
  36. for($i = 0; $i < $inputsLength; $i++){
  37. $neuronWeights[$i] = $neuronWeights[$i] - 0.25 * (0-1) * $inputs[$i];
  38. }
  39. }
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
correct weights