added randomizeWeights function

This commit is contained in:
2016-02-07 21:40:28 +01:00
parent e118e09396
commit 59125e57f9
2 changed files with 17 additions and 2 deletions

View File

@@ -25,4 +25,18 @@ std::vector<float> NeuralNetwork::FeedForward::Network::computeOutput(const std:
partialInputPtr->resize(partialInputPtr->size()-1);
return std::vector<float>(*partialInputPtr);
}
void NeuralNetwork::FeedForward::Network::randomizeWeights() {
for(std::size_t layerIndex=1;layerIndex<layers.size();layerIndex++) {
auto &layer=layers[layerIndex];
auto &prevLayer=layers[layerIndex-1];
for(std::size_t neuron=1; neuron < layer->size(); neuron ++ ) {
for(std::size_t prevNeuron=0; prevNeuron < prevLayer->size(); prevNeuron++) {
layer->operator[](neuron).setWeight(prevLayer->operator[](prevNeuron),1.0-static_cast<float>(rand()%2001)/1000.0);
}
}
}
}