-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayer.cpp
35 lines (27 loc) · 879 Bytes
/
Layer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "Layer.h"
Layer::Layer(int numNeurons, int numInputs, ActivationFunction* activationFunction) {
for (int i = 0; i < numNeurons; i++) {
neurons.push_back(new Neuron(numInputs, numNeurons, activationFunction));
}
}
std::vector<double> Layer::feedForward(const std::vector<double>& inputs) {
std::vector<double> outputs;
this->zValues.clear();
for (Neuron* neuron : neurons) {
// z = dotProduct(inputs, weights) + bias
double z = neuron->dotProduct(inputs, neuron->getWeights()) + neuron->getBias();
zValues.push_back(z);
outputs.push_back(neuron->activate(z));
}
this->aValues = outputs;
return outputs;
}
std::vector<Neuron*> Layer::getNeurons() const {
return neurons;
}
std::vector<double> Layer::getZValues() const {
return aValues;
}
std::vector<double> Layer::getAValues() const {
return aValues;
}