Added forward-feeding of double-ptrs
This commit is contained in:
parent
ec654c0e5f
commit
650b4be9fc
4 changed files with 28 additions and 2 deletions
10
Layer.cpp
10
Layer.cpp
|
@ -21,7 +21,15 @@ void Layer::setOutputValues(const std::vector<double> & outputValues)
|
||||||
for (const double &value : outputValues)
|
for (const double &value : outputValues)
|
||||||
{
|
{
|
||||||
(neuronIt++)->setOutputValue(value);
|
(neuronIt++)->setOutputValue(value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layer::setOutputValues(const double *outputValues)
|
||||||
|
{
|
||||||
|
for (size_t neuronIndex = 0; neuronIndex < size(); ++neuronIndex)
|
||||||
|
{
|
||||||
|
at(neuronIndex).setOutputValue(outputValues[neuronIndex]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::feedForward(const Layer &inputLayer)
|
void Layer::feedForward(const Layer &inputLayer)
|
||||||
|
|
2
Layer.h
2
Layer.h
|
@ -13,6 +13,8 @@ public:
|
||||||
Layer(size_t numNeurons);
|
Layer(size_t numNeurons);
|
||||||
|
|
||||||
void setOutputValues(const std::vector<double> & outputValues);
|
void setOutputValues(const std::vector<double> & outputValues);
|
||||||
|
void setOutputValues(const double *outputValues);
|
||||||
|
|
||||||
void feedForward(const Layer &inputLayer);
|
void feedForward(const Layer &inputLayer);
|
||||||
double getWeightedSum(size_t outputNeuron) const;
|
double getWeightedSum(size_t outputNeuron) const;
|
||||||
void connectTo(const Layer & nextLayer);
|
void connectTo(const Layer & nextLayer);
|
||||||
|
|
17
Net.cpp
17
Net.cpp
|
@ -63,7 +63,22 @@ void Net::feedForward(const std::vector<double> &inputValues)
|
||||||
Layer &nextLayer = *(layerIt + 1);
|
Layer &nextLayer = *(layerIt + 1);
|
||||||
|
|
||||||
nextLayer.feedForward(currentLayer);
|
nextLayer.feedForward(currentLayer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Net::feedForward(const double *inputValues)
|
||||||
|
{
|
||||||
|
Layer &inputLayer = front();
|
||||||
|
|
||||||
|
inputLayer.setOutputValues(inputValues);
|
||||||
|
|
||||||
|
for (auto layerIt = begin(); layerIt != end() - 1; ++layerIt)
|
||||||
|
{
|
||||||
|
const Layer ¤tLayer = *layerIt;
|
||||||
|
Layer &nextLayer = *(layerIt + 1);
|
||||||
|
|
||||||
|
nextLayer.feedForward(currentLayer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<double> Net::getOutput()
|
std::vector<double> Net::getOutput()
|
||||||
|
|
1
Net.h
1
Net.h
|
@ -15,6 +15,7 @@ public:
|
||||||
void initialize(std::initializer_list<size_t> layerSizes);
|
void initialize(std::initializer_list<size_t> layerSizes);
|
||||||
|
|
||||||
void feedForward(const std::vector<double> &inputValues);
|
void feedForward(const std::vector<double> &inputValues);
|
||||||
|
void feedForward(const double *inputValues);
|
||||||
std::vector<double> getOutput();
|
std::vector<double> getOutput();
|
||||||
void backProp(const std::vector<double> &targetValues);
|
void backProp(const std::vector<double> &targetValues);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue