added randomizeWeights function
This commit is contained in:
@@ -24,8 +24,6 @@ namespace FeedForward {
|
||||
/**
|
||||
* @brief Constructor for Network
|
||||
* @param _inputSize is number of inputs to network
|
||||
* @param _outputSize is size of output from network
|
||||
* @param hiddenUnits is number of hiddenUnits to be created
|
||||
*/
|
||||
inline Network(size_t _inputSize):NeuralNetwork::Network(),layers() {
|
||||
appendLayer(_inputSize);
|
||||
@@ -53,6 +51,9 @@ namespace FeedForward {
|
||||
return *layers[id];
|
||||
}
|
||||
|
||||
void randomizeWeights();
|
||||
|
||||
std::size_t size() const { return layers.size(); };
|
||||
/**
|
||||
* @brief This is a function to compute one iterations of network
|
||||
* @param input is input of network
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user