Пример #1
0
 /**
  * Apply a thresholding function to the data elements.
  * This does not modify the object.
  * 
  * @param
  *        	double thesdholdValue the value to which elements are compared
  * @param
  *        	double lowValue the value to use if <= threshold
  * @param
  *        	double highValue the value to use if > threshold
  * @return MLData The result.
  */
 public function threshold($thresholdValue, $lowValue, $highValue)
 {
     $result = new BasicMLData($size());
     for ($i = 0; $i < $this->size(); ++$i) {
         if ($this->getData($i) > $thresholdValue) {
             $result->setData($i, $highValue);
         } else {
             $result->setData($i, $lowValue);
         }
     }
     return $result;
 }
Пример #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);
     }
 }
 /**
  * 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));
     }
 }