/** * Randomize one level of a neural network. * * @param * BasicNetwork network * The network to randomize * @param * int fromLayer * The from level to randomize. */ public function randomizeNetwork(BasicNetwork $network, $fromLayer) { $fromCount = $network->getLayerTotalNeuronCount($fromLayer); $toCount = $network->getLayerNeuronCount($fromLayer + 1); for ($fromNeuron = 0; $fromNeuron < $fromCount; ++$fromNeuron) { for ($toNeuron = 0; $toNeuron < $toCount; ++$toNeuron) { $v = $network->getWeight($fromLayer, $fromNeuron, $toNeuron); $v = $this->randomizeDouble($v); $network->setWeight($fromLayer, $fromNeuron, $toNeuron, $v); } } }