-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayer.cpp
More file actions
43 lines (38 loc) · 998 Bytes
/
layer.cpp
File metadata and controls
43 lines (38 loc) · 998 Bytes
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
#include "neuron.h"
#include "layer.h"
#include <stdio.h>
/*
Random Layer constructor, builds a layer of nNeurons neurons.
Each neuron will be initialized randomly with nInputs weights and a bias.
*/
Layer::Layer(int nNeurons, int nInputs, bool input){
this->nNeurons = nNeurons;
for(int i = 0; i < nNeurons; i++){
neurons.push_back(new Neuron(nInputs, input));
}
}
/*
Layer constructor for pre-defined layers. Used for loading networks.
*/
Layer::Layer(vector<Neuron*> *neurons){
this->nNeurons = neurons->size();
this->neurons = *neurons;
}
/*
Adds each neuron's output to the layer's result vector, and returns this result vector.
*/
/*void Layer::feedLayer(vector<double> &inputs){
for(int i = 0; i < (int)neurons.size(); i++){
neurons[i]->feed(inputs);
}
}*/
vector<double> Layer::getOutputs(){
vector<double> outputs;
for(int i = 0; i < nNeurons; i++){
outputs.push_back(neurons[i]->a);
}
return outputs;
}
Layer::~Layer(){
neurons.clear();
}