Exemple #1
0
 public function learn()
 {
     echo '<h3>Start Learning</h3>';
     $normalization = new Normalization(1200, 17000000, 0, 1);
     $right_answers = 0;
     for ($iteration = 0; $iteration < 2000; $iteration++) {
         $captcha = new KCaptcha();
         $real_answer = intval($captcha->getKeyString());
         $expect_outs = $this->getExpects($real_answer);
         $inputs = $normalization->import($captcha->getPoints());
         unset($captcha);
         $output1 = $this->network->calculate(1, $inputs);
         $output2 = $this->network->calculate(2, $output1);
         $right_answers += $this->renderAnswer($real_answer, $output2);
         $E = $this->network->correctWeights($output2, $output1, $expect_outs);
         if ($E < 0.15) {
             echo 'Iteration ' . ($iteration + 1) . '; E=' . $E . '<br>';
         }
         if ($E < 0.1) {
             echo '<p id="finished">Learning is finished</p>';
             break;
         }
     }
     $this->network->saveState('learned-1');
     echo '<pre>';
     var_dump($this->network->getWeights(1));
     echo '</pre>';
     echo '<pre>';
     var_dump($this->network->getWeights(2));
     echo '</pre>';
     echo '<p>Iterations: ' . $iteration . '</p>';
     echo '<p>Right answers: ' . $right_answers . '</p>';
 }
Exemple #2
0
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
define('PATH', __DIR__);
require_once '/lib/Neuron.php';
require_once '/lib/Normalization.php';
require_once '/lib/kcaptcha/KCaptcha.php';
require_once '/lib/Network.php';
require_once '/lib/Teacher.php';
echo '<script type="text/javascript" src="/js/jquery-1.11.3.min.js"></script>';
echo '<script type="text/javascript" src="/js/main.js"></script>';
echo '<h1>Neural Network</h1>';
$normalization = new Normalization(1200, 17000000, 0, 1);
$captcha = new KCaptcha();
$inputs = $normalization->import($captcha->getPoints());
$network = new Network();
$network->loadState('learned-1');
//$w = $network->getWeights(2);
/*
$outs1 = $network->calculate(1, $inputs);
$outs2 = $network->calculate(2, $outs1);
*/
/*
echo '<pre>';
var_dump($outs2);
echo '</pre>';
*/
$teacher = new Teacher($network);
$teacher->learn();
/*