Example #1
0
 function activate()
 {
     $sum = 0;
     foreach (array_keys($this->inputs) as $k) {
         $sum += $this->inputs[$k] * $this->weights[$k];
     }
     $this->setOutput(Maths::sigmoid($sum));
 }
<?php

ini_set("max_execution_time", 300);
require_once "nn.php";
$filename = "xor.dat";
$network = Network::load($filename);
if ($network == null) {
    echo "\nNetwork not found. Creating a new one...";
    $network =& new Network(1, 10, 1);
}
$inputs = array(array(0, 0), array(0, 1), array(1, 0), array(1, 1));
$outputs = array(array(0), array(1), array(1), array(0));
for ($i = 0; $i < 10000; $i++) {
    $j = Maths::random(0, 3);
    $network->setInputs($inputs[$j]);
    $network->train(0.5, $outputs[$j]);
}
$network->save($filename);
Example #3
0
 /**
  * Returns the percentage of words with more than three syllables
  * @param   string  $strText      Text to be measured
  * @param   bool    $blnCountProperNouns      Boolean - should proper nouns be included in words count
  * @return  int|float
  */
 public static function percentageWordsWithThreeSyllables($strText, $blnCountProperNouns = true, $strEncoding = '')
 {
     $intWordCount = Text::wordCount($strText, $strEncoding);
     $intLongWordCount = self::wordsWithThreeSyllables($strText, $blnCountProperNouns, $strEncoding);
     $intPercentage = Maths::bcCalc(Maths::bcCalc($intLongWordCount, '/', $intWordCount), '*', 100);
     return $intPercentage;
 }
Example #4
0
 /**
  * Gives the Spache readability score of text entered rounded to one digit
  * @param   boolean|string  $strText         Text to be checked
  * @return  int|float
  */
 public function spacheReadabilityScore($strText = false)
 {
     $strText = $this->setText($strText);
     $score = Maths::bcCalc(Maths::bcCalc(Maths::bcCalc(0.121, '*', Maths::bcCalc(Text::wordCount($strText, $this->strEncoding), '/', Text::sentenceCount($strText, $this->strEncoding))), '+', Maths::bcCalc(0.082, '*', $this->spacheDifficultWordCount($strText))), '+', 0.659);
     if ($this->normalise) {
         return Maths::normaliseScore($score, 0, 5, $this->dps);
         // Not really suitable for measuring readability above grade 4
     } else {
         return Maths::bcCalc($score, '+', 0, true, $this->dps);
     }
 }
Example #5
0
File: Neuron.php Project: 0-php/AI
 /**
  * @uses Maths::sigmoid()
  */
 public function activate()
 {
     $floatSum = 0;
     foreach ($this->arrInputs as $intKey => $floatInput) {
         $floatSum += $floatInput * $this->arrWeights[$intKey];
     }
     $this->floatOutput = Maths::sigmoid($floatSum);
 }
Example #6
0
File: Layer.php Project: 0-php/AI
 /**
  * @return array
  * @uses Maths::threshold()
  */
 public function getThresholdOutputs()
 {
     $arrReturnOutputs = array();
     foreach ($this->arrOutputs as $intKey => $floatOutput) {
         $arrReturnOutputs[$intKey] = Maths::threshold($floatOutput);
     }
     return $arrReturnOutputs;
 }
Example #7
0
 /**
  * Returns average words per sentence for text.
  * @param   string  $strText      Text to be measured
  * @param   string  $strEncoding  Encoding of text
  * @return  int|float
  */
 public static function averageWordsPerSentence($strText, $strEncoding = '')
 {
     $intSentenceCount = self::sentenceCount($strText, $strEncoding);
     $intWordCount = self::wordCount($strText, $strEncoding);
     $averageWords = Maths::bcCalc($intWordCount, '/', $intSentenceCount);
     return $averageWords;
 }