/**
  * Note: for Hopfield networks, you will usually want to call the "run"
  * method to compute the output.
  *
  * This method can be used to copy the input data to the current state. A
  * single iteration is then run, and the new current state is returned.
  *
  * @param
  *        	MLData input
  *        	The input pattern.
  * @return MLData The new current state.
  */
 public function compute(MLData $input)
 {
     $result = new BiPolarNeuralData($input->size());
     EngineArray\arrayCopy($input->getData(), $this->getCurrentState()->getData());
     $this->run();
     for ($i = 0; $i < $this->getCurrentState()->size(); ++$i) {
         $result->setData($i, BiPolarUtil\double2bipolar($this->getCurrentState()->getData($i)));
     }
     EngineArray\arrayCopy($this->getCurrentState()->getData(), $result->getData());
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Compute the output for a given input to the neural network.
  *
  * @param MLData input
  *            The input to the neural network.
  * @return MLData The output from the neural network.
  */
 public function compute(MLData $input)
 {
     try {
         $result = new BasicMLData($this->structure->getFlat()->getOutputCount());
         $this->structure->getFlat()->computeArray($input->getData(), $result->getData());
         return $result;
     } catch (ArrayIndexOutOfBoundsException $ex) {
         throw new NeuralNetworkError("Index exception: there was likely a mismatch between layer sizes, or the size of the input presented to the network.", $ex);
     }
 }
Ejemplo n.º 3
0
 /**
  * Subtract one data element from another.
  * This does not modify the object.
  * 
  * @param
  *        	MLData o The other data element
  * @return MLData The result.
  */
 public function minus(MLData $o)
 {
     if ($this->size() != $o->size()) {
         throw new IllegalArgumentException();
     }
     $result = new BasicMLData($this->size());
     for ($i = 0; $i < $this->size(); ++$i) {
         $result->setData($i, $this->getData($i) - $o->getData($i));
     }
     return $result;
 }