Beispiel #1
0
 /**
  * Create (load) ANN saved from file
  * @param string filename with absolute path
  * @return void
  */
 public function create_from_file($filename)
 {
     $this->annId = fann_create_from_file($filename);
     if ($this->annId < 0) {
         die('Could not initialize another ANN network.');
     }
 }
 public function __construct($inputNeurons, $outputNeurons, $hiddenLayers, $hiddenNeurons, $file = '')
 {
     $this->file = $file;
     if (!empty($this->file) && is_readable($this->file)) {
         $this->ann = fann_create_from_file($this->file);
     }
     if (!$this->ann) {
         /**
          * layers
          * layer 1 (input layer)
          * layer 2 (hidden layer 1)
          * .
          * .
          * layer 5 (output layer)
          */
         $layers = $this->createLayersArray($inputNeurons, $outputNeurons, $hiddenLayers, $hiddenNeurons);
         $this->ann = fann_create_standard_array(count($layers), $layers);
     }
     fann_set_activation_function_hidden($this->ann, FANN_SIGMOID_SYMMETRIC);
     fann_set_activation_function_output($this->ann, FANN_SIGMOID);
     fann_set_training_algorithm($this->ann, FANN_TRAIN_BATCH);
 }
 /**
  * Create From File.
  * 
  * @return bool
  */
 public function createFromFile()
 {
     # Create neural network configuration file if it doesn't already exist.
     if (!is_file($this->getConfigurationFile())) {
         $this->createStandard();
         $this->save();
     }
     # Create neural network from file.
     $this->ann = fann_create_from_file($this->getConfigurationFile());
     if ($this->ann === false) {
         throw new Exception(sprintf("Failed to create ann from network configuration file: %s.", $this->getConfigurationFile()), 1);
     }
     if ($this->ann === false) {
         return false;
     } else {
         return true;
     }
 }
Beispiel #4
0
<?php

$train_file = dirname(__FILE__) . "/xor_float.net";
if (!is_file($train_file)) {
    die("The file xor_float.net has not been created! Please run simple_train.php to generate it");
}
$ann = fann_create_from_file($train_file);
if (!$ann) {
    die("ANN could not be created");
}
$input = array(-1, 1);
$calc_out = fann_run($ann, $input);
printf("xor test (%f,%f) -> %f\n", $input[0], $input[1], $calc_out[0]);
fann_destroy($ann);
Beispiel #5
0
<?php

namespace MachineLearning;

use MachineLearning\Util\Input;
include 'Util/Input.php';
$ann = fann_create_from_file('Data/training_result');
if (!$ann) {
    die("ANN could not be created");
}
$input = new Input();
$comments[] = '//simple comment';
$comments[] = '/**
 * Returns the same version for all assets.
 *
 * @author Fabien Potencier <*****@*****.**>
 */';
$comments[] = '// $this->getAll(3);';
$comments[] = '//fix for v1.2';
$comments[] = '/* if ($path && \'/\' == $path[0]) {
            return \'/\'.$versionized;
        }*/';
$comments[] = '// We have server(s) -> apply default configuration';
$comments[] = '/* The <info>%command.name%</info> command clears the application cache for a given environment
and debug mode:

  <info>php %command.full_name% --env=dev</info>
  <info>php %command.full_name% --env=prod --no-debug</info>*/';
$comments[] = '// avoid shutting down the Kernel if no request has been performed yet
        // WebTestCase::createClient() boots the Kernel but do not handle a request';
foreach ($comments as $comment) {