-
Notifications
You must be signed in to change notification settings - Fork 1
/
bpnlayer.cpp
89 lines (67 loc) · 1.59 KB
/
bpnlayer.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "bpnlayer.h"
bpnLayer::bpnLayer(unsigned sizeNum, unsigned lowerSizeNum, bool with_bias, outFunction type, unsigned thrs) {
threads = thrs;
size = sizeNum;
lowerSize = lowerSizeNum;
func = type;
bias = with_bias;
if(size >0) {
unsigned i, j;
weights = new double*[size];
deltas = new double*[size];
if(lowerSize >0) {
for(i=0; i<size; ++i) {
weights[i] = new double[lowerSize];
deltas[i] = new double[lowerSize];
for(j=0; j<lowerSize; ++j) {
deltas[i][j] = 0;
}
}
}
else { // lowerSize ==0 -> input layer
for(i=0; i<size; ++i) {
weights[i] = new double[1]; // just to keep structure integrity
weights[i][0] = 1;
deltas[i] = new double[1];
deltas[i][0] = 0;
lowerSize = 1;
}
}
if(bias) biases = new double[size];
errors = new double[size];
// products = new double[size];
products = new double*[threads];
for(i=0; i < threads; ++i) {
products[i] = new double[size];
}
}
}
bpnLayer::~bpnLayer() {
if(size >0) {
if(lowerSize >0) delete [] errors;
unsigned i;
for (i=0; i < threads; ++i) {
delete products[i];
}
delete [] products;
if(bias) delete [] biases;
for(i=0; i<size; ++i) {
delete deltas[i];
delete weights[i];
}
delete [] deltas;
delete [] weights;
}
}
void bpnLayer::ChangeThreads (unsigned thr) {
unsigned i;
for (i=0; i < threads; ++i) {
delete products[i];
}
delete [] products;
threads = thr;
products = new double*[threads];
for(i=0; i < threads; ++i) {
products[i] = new double[size];
}
}