-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneuralNet.cpp
More file actions
52 lines (45 loc) · 1.02 KB
/
Copy pathneuralNet.cpp
File metadata and controls
52 lines (45 loc) · 1.02 KB
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
51
52
#include "neuralNet.h"
NeuralNetwork::NeuralNetwork(){
setWeights(_seed);
}
void NeuralNetwork::setWeights(int seed) {
if (seed){
srand(seed);
} else {
srand(time(NULL));
}
std::vector<double> row;
double num;
for (int i = 0; i < _layerSz; i++){
row = {};
for (int j = 0; j < _numInputs; j++){
num = (double) rand()/RAND_MAX;
row.push_back(num);
}
_w1.push_back(row);
}
for (int i = 0; i < _numOutputs; i++){
row = {};
for (int j = 0; j < _layerSz; j++){
num = (double) rand()/RAND_MAX;
row.push_back(num);
}
_w2.push_back(row);
}
}
void NeuralNetwork::showWeights(){
std::cout << "First weight matrix:" << std::endl;
displayMat(_w1);
std::cout << "Second weight matrix:" << std::endl;
displayMat(_w2);
}
std::vector<std::vector<double>> NeuralNetwork::getWeight(int layer){
if (layer == 1){
return _w1;
} else if (layer == 2){
return _w2;
} else {
std::cout << "Layer selection out of range." << std::endl;
return {{}};
}
}