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