/** * 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; }
/** * 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; }