-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWNeuralLayer.cpp
executable file
·50 lines (40 loc) · 1.35 KB
/
WNeuralLayer.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "WNeuralLayer.h"
WNeuralLayer::WNeuralLayer(int nbNeurons, double bias) {
this->bias = bias;
for(int i = 0; i < nbNeurons; i++)
neurons.append(new WNeuron(bias));
}
WNeuralLayer::~WNeuralLayer() {
}
void WNeuralLayer::initSynapses(int nbPrevNeurons) {
foreach(WNeuron *neuron, neurons)
neuron->initSynapses(nbPrevNeurons);
}
QList<double> WNeuralLayer::activate(QList<double> inputs) {
QList<double> outputs;
foreach(WNeuron *neuron, neurons)
outputs.append(neuron->activate(inputs));
return outputs;
}
QList<double> WNeuralLayer::getOutputDeltas(QList<double> trainOutputs) {
QList<double> deltas;
for(int i = 0; i < neurons.size(); i++)
deltas.append(neurons.at(i)->getError(trainOutputs.at(i)));
return deltas;
}
QList<double> WNeuralLayer::getHiddenDeltas(WNeuralLayer *nextLayer, QList<double> nextLayerDeltas) {
QList<double> deltas;
for(int i = 0; i < neurons.size(); i++)
deltas.append(nextLayer->getError(nextLayerDeltas, i) * neurons.at(i)->getDeriv());
return deltas;
}
double WNeuralLayer::getError(QList<double> deltas, int neuronId) {
double error = 0;
for(int i = 0; i < neurons.size(); i++)
error += deltas.at(i) * neurons.at(i)->getSynapse(neuronId);
return error;
}
void WNeuralLayer::updateSynapses(QList<double> deltas) {
for(int i = 0; i < neurons.size(); i++)
neurons.at(i)->updateSynapses(deltas.at(i));
}