Beispiel #1
0
 /**
  * Takes some input and runs the network
  * @param $inputarray Input data
  * @return The output data
  */
 function run($inputarray)
 {
     $output = array();
     $l_count = count($this->layer);
     for ($l = 0; $l < $l_count; ++$l) {
         // Now we walk through each layer of the net
         foreach ($this->layer[$l]->neuron as $neuron) {
             $inputs = $l === 0 ? $inputarray : $output[$l];
             $x = 0;
             $sum = 0;
             foreach ($neuron->synapse as $synapse) {
                 $synapse->input = $inputs[$x];
                 $sum += $synapse->weight * $synapse->input;
                 ++$x;
             }
             $value = -1 + 2 / (1 + exp(-1 * ($sum + $neuron->bias)));
             //bipolar sigmoid
             $neuron->value = $value;
             $output[$l + 1][] = $value;
         }
     }
     $data = $output[$l];
     self::$cache = $data;
     return $data;
 }
Beispiel #2
0
 /**
  * Get a nmesh instance from authkey
  * @param $authkey Unique key to network
  * @return NeuralMesh instance (singleton)
  */
 public static function getNetwork($authkey)
 {
     self::init();
     $data = self::$app->model->get("network")->getAuth($authkey);
     $nn = self::$app->model->get("network")->nn;
     nmesh::$momentumrate = $data['momentumrate'];
     return $data['networkType'] == "managed" ? new ManagedNetwork($data['networkID'], $data['learningrate'], $nn) : new UnmanagedNetwork($data['networkID'], $data['learningrate'], $nn);
 }
Beispiel #3
0
<?php

include '../nm-admin/lib/proxy/nmesh.class.php';
$inputs = 1;
$outputs = 1;
$hidden_neurons_per_layer = 1;
$hidden_layers = 1;
$inputarray = array();
$nmesh = new nmesh($inputs, $outputs, $hidden_neurons_per_layer, $hidden_layers);
$nmesh->run($inputarray);