Fixed feed-forward algo
This commit is contained in:
parent
3d30346f2d
commit
f22e4221a1
3 changed files with 29 additions and 5 deletions
|
@ -24,10 +24,9 @@ void Layer::setOutputValues(const std::vector<double> & outputValues)
|
|||
|
||||
void Layer::feedForward(const Layer &inputLayer)
|
||||
{
|
||||
int neuronNumber = 0;
|
||||
for (auto neuronIt = begin(); neuronIt != end(); ++neuronIt)
|
||||
for (int neuronNumber = 0; neuronNumber < sizeWithoutBiasNeuron(); ++neuronNumber)
|
||||
{
|
||||
neuronIt->feedForward(inputLayer.getWeightedSum(neuronNumber++));
|
||||
at(neuronNumber).feedForward(inputLayer.getWeightedSum(neuronNumber));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +46,7 @@ void Layer::connectTo(const Layer & nextLayer)
|
|||
{
|
||||
for (Neuron &neuron : *this)
|
||||
{
|
||||
neuron.createRandomOutputWeights(nextLayer.size());
|
||||
neuron.createOutputWeights(nextLayer.sizeWithoutBiasNeuron(), 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
Neuron.cpp
20
Neuron.cpp
|
@ -50,6 +50,26 @@ void Neuron::createRandomOutputWeights(size_t numberOfWeights)
|
|||
}
|
||||
}
|
||||
|
||||
void Neuron::createOutputWeights(std::list<double> weights)
|
||||
{
|
||||
outputWeights.clear();
|
||||
|
||||
for (const double &weight : weights)
|
||||
{
|
||||
outputWeights.push_back(weight);
|
||||
}
|
||||
}
|
||||
|
||||
void Neuron::createOutputWeights(size_t numberOfWeights, double weight)
|
||||
{
|
||||
outputWeights.clear();
|
||||
|
||||
for (unsigned int i = 0; i < numberOfWeights; ++i)
|
||||
{
|
||||
outputWeights.push_back(weight);
|
||||
}
|
||||
}
|
||||
|
||||
double Neuron::getOutputValue() const
|
||||
{
|
||||
return outputValue;
|
||||
|
|
5
Neuron.h
5
Neuron.h
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
class Layer;
|
||||
|
||||
|
@ -17,7 +18,11 @@ public:
|
|||
void setOutputValue(double value);
|
||||
void feedForward(double inputValue);
|
||||
double getWeightedOutputValue(unsigned int outputNeuron) const;
|
||||
|
||||
void createRandomOutputWeights(size_t numberOfWeights);
|
||||
void createOutputWeights(std::list<double> weights);
|
||||
void createOutputWeights(size_t numberOfWeights, double weight);
|
||||
|
||||
double getOutputValue() const;
|
||||
|
||||
void calcOutputGradients(double targetValue);
|
||||
|
|
Loading…
Reference in a new issue