Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function encodeToArray(array $encoded)
 {
     $this->structure->requireFlat();
     $weights = $this->structure->getFlat()->getWeights();
     if (count($weights) != count($encoded)) {
         throw new NeuralNetworkError("Size mismatch, encoded array should be of length " + count($weights));
     }
     EngineArray\arrayCopy($weights, $encoded);
 }
 /**
  * Copy whatever dataset type is specified into a memory dataset.
  *
  * @param
  *        	MLDataSet set
  *        	The dataset to copy.
  */
 public function copy(MLDataSet $set)
 {
     $inputCount = $set->getInputSize();
     $idealCount = $set->getIdealSize();
     foreach ($set as $pair) {
         $input = null;
         $ideal = null;
         if ($inputCount > 0) {
             $input = new BasicMLData($inputCount);
             EngineArray\arrayCopy($pair->getInputArray(), $input->getData());
         }
         if ($idealCount > 0) {
             $ideal = new BasicMLData($idealCount);
             EngineArray\arrayCopy($pair->getIdealArray(), $ideal->getData());
         }
         $this->add(new BasicMLDataPair($input, $ideal));
     }
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Set the layer sums.
  *
  * @param
  *        	double[] d The layer sums.
  */
 public function setLayerSums(array $d)
 {
     $this->layerSums = EngineArray\arrayCopy($d);
 }