예제 #1
0
파일: fann.class.php 프로젝트: 0-php/AI
 /**
  * Run ANN and get it's output values
  * @param array input vector
  * @return mixed array output vector, null in error
  */
 public function run(array $inputVector)
 {
     $this->checkIfAnnIsAssigned();
     $status = fann_run($this->annId, $inputVector);
     if ($status == true) {
         $output = array();
         $outputCount = $this->get_num_output();
         for ($i = 0; $i < $outputCount; $i++) {
             $output[] = $this->get_output($i);
         }
         return $output;
     } else {
         return null;
     }
 }
예제 #2
0
 /**
  * Run.
  * 
  * @param  array $input Input.
  * @return array
  */
 public function run(array $input)
 {
     $calc_out = fann_run($this->ann, $input);
     printf("noughtsandcrosses test (%f,%f) -> %f\n", $input[0], $input[1], $calc_out[0]);
     fann_destroy($this->ann);
     return $calc_out;
 }
예제 #3
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);
예제 #4
0
}
$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) {
    $result = fann_run($ann, $input->getInputFromComment($comment));
    printf("COMMENT : %s\n", $comment);
    printf("RESULT : %f\n", $result[0]);
    if ($result[0] > 0.9) {
        echo "!!! CODE DETECTED !!!\n";
    }
    echo "\n";
}
fann_destroy($ann);
예제 #5
0
파일: demo.php 프로젝트: 0-php/AI
 * long fann_get_total_connections(resource ann)
 *
 * If you have any questions or comments, please e-mail Evan Nemerson
 * <*****@*****.**>
 */
/* If you don't want to compile FANN into PHP... */
if (!extension_loaded('fann')) {
    if (!dl('fann.so')) {
        exit("You must install the FANN extension. You can get it from http://fann.sf.net/\n");
    }
}
/* Create an artificial neural network */
$ann = fann_create(array(2, 4, 1), 1.0, 0.7);
/* To load from a file, you can use. If your version of PHP includes the streams API (4.3.0+ ?),
 * this can be anything accessible through streams (http, ftp, https, etc) */
// $ann = fann_create("http://example.com/xor_float.net");
/* Train the network using the same data as is in the xor.data file */
fann_train($ann, array(array(array(0, 0), array(0)), array(array(0, 1), array(1)), array(array(1, 0), array(1)), array(array(1, 1), array(0))), 100000, 1.0E-5, 1000);
/* To achieve the same effect as the above with the data stored in an external file... Also works
 * with the streams API, when available. */
// fann_train($ann, '/home/tadpole/local/src/fann/examples/xor.data', 100000, 0.00001, 1000);
print_r(fann_run($ann, array(0, 0)));
// Should be ~ 0
print_r(fann_run($ann, array(0, 1)));
// Should be ~ 1
print_r(fann_run($ann, array(1, 0)));
// Should be ~ 1
print_r(fann_run($ann, array(1, 1)));
// Should be ~ 0
/* This function is pretty simple. It will use the streams API if available. */
fann_save($ann, 'xor_float.net');
예제 #6
0
 public function run($input)
 {
     return fann_run($this->ann, $input);
 }