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);
/** * 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; }
/** * 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); } }
/** * @uses Maths::sigmoid() */ public function activate() { $floatSum = 0; foreach ($this->arrInputs as $intKey => $floatInput) { $floatSum += $floatInput * $this->arrWeights[$intKey]; } $this->floatOutput = Maths::sigmoid($floatSum); }
/** * @return array * @uses Maths::threshold() */ public function getThresholdOutputs() { $arrReturnOutputs = array(); foreach ($this->arrOutputs as $intKey => $floatOutput) { $arrReturnOutputs[$intKey] = Maths::threshold($floatOutput); } return $arrReturnOutputs; }
/** * 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; }