-
Notifications
You must be signed in to change notification settings - Fork 0
/
hinet.hpp
86 lines (67 loc) · 2.11 KB
/
hinet.hpp
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
/**
* @file hinet.hpp
* @brief h-as-input network - only
*
*/
#ifndef __HINET_HPP
#define __HINET_HPP
#include "data.hpp"
/**
* \brief A modulatory network architecture which uses a plain backprop network
* with an extra input to carry the modulator.
*/
class HInputNet : public BPNet {
/**
* \brief The current modulator value, which is sent to the last input
* when we train/run the network
*/
double modulator;
public:
/**
* \brief Constructor - does not initialise the weights to random values so
* that we can reinitialise networks. Uses the non-initialising constructor
* BPNet::BPNet(), changes the layer count and initialises.
* \param nlayers number of layers
* \param layerCounts array of layer counts
*/
HInputNet(int nlayers,const int *layerCounts) : BPNet() {
// replace the net type, it's not a plain net any more
type = NetType::HINPUT;
// you may have noticed that I tend to use arrays a lot rather than
// std::vector. Sorry, I do this without realising because I'm very,
// very old.
int *ll = new int[nlayers];
for(int i=0;i<nlayers;i++){
ll[i] = layerCounts[i]; // copy the layers array
}
ll[0]++; // add an extra input
init(nlayers,ll);
}
/**
* \brief destructor
*/
virtual ~HInputNet(){
}
virtual int getLayerSize(int n) const {
int ct = layerSizes[n];
// subtract one if it's the input layer, so we
// don't see the hidden input.
return (n==0)?ct-1:ct;
}
virtual void setH(double h){
modulator = h;
}
virtual double getH() const {
return modulator;
}
virtual void setInputs(double *d) {
// get the number of input which are not the modulator input
int nins = layerSizes[0]-1;
for(int i=0;i<nins;i++){
setInput(i,*d++); // set manually
}
// now set the final input
setInput(nins,modulator);
}
};
#endif /* __HINET_HPP */