forked from nnrepo/LSM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNemoLSM.h
325 lines (301 loc) · 13.2 KB
/
NemoLSM.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#ifndef NEMO_LSM
#define NEMO_LSM
//General program includes
#include "Includes.h"
//LSM stuff
#include "Constructs.h"
#include "Trainings.h"
//Declarations to resolve circular references
class NemoSim;
class GeneralLayer;
class InputLayer;
class PoissonLayer;
/**
* @class LSM
* @brief An implementation of a Liquid State Machine, using NeMo.
*
* @details The class implements the liquid component of a Liquid State Machine.
* It implements several functionalities of a liquid:
* - Neurons are assigned topological positions and distributed on a 3D grid.
* - Synapse initialization is affected by the pre- and post-synaptic neuron properties
* - Storing and handling the neuron outputs
* - Sampling and filtering functions
* - Arbitrary connectivity between different parts of the liquid
* -
*
* @version 1.0
* @author Emmanouil Hourdakis
* @email [email protected]
*/
class LSM {
friend NemoSim; ///> Give access to NemoSim class
friend GeneralLayer; ///> Give access to GeneralLayer
friend PoissonLayer; ///> Give access to PoissonLayer
public:
enum netOutMode { outNone = 1ul << 0, ///> Output to (i) nothing, (ii) std::cout, (iii) file
outCout = 1ul << 1,
outFile = 1ul << 2 };
protected:
unsigned int _currentNeuronIndex; ///> Internal index, used when initializing the neurons
unsigned _mPoisson_type; ///> Nemo's ID for the Poisson type of neuron
unsigned _mInput_type; ///> Nemo's ID for the Input type of neuron
unsigned _mIF_type; ///> Nemo's ID for the Integrate and Fire type of neuron
nemo::Network _net; ///> The nemo network object
nemo::Configuration _conf; ///> The nemo network configuration
NemoSim *_sim; ///> The nemo simulation object
std::ofstream _outfile; ///> If the mode supports it, an output file to write the liquid's output
unsigned int _nNeurons; ///> The number of neurons held by the liquid
unsigned int _nConnections; ///> The number of connections maintained by the liquid
unsigned int _inputNeurons; ///> The number of input neurons to the liquid
public:
unsigned long _outMode; ///> The mode used by the liquid to printout information @see LSM::netOutMode
Eigen::MatrixXd _spikeFirings; ///> Matrix holding neurons fired as ones ... etc
vector<bool> _excitatoryConnections; ///> Vector of booleans, excitatory (true) - inhibitory (false), for each liquid connection
unsigned int _simTime; ///> The time that the liquid has been simulated
vector<GeneralLayer> _layers; ///> The liquid's layers
vector<InputLayer> _inputLayers; ///> The liquid's input layers
vector<PoissonLayer> _poissonLayers; ///> The liquid's poisson layers
std::vector<unsigned> _fired; ///> A vector of neuron firings on each simulation step
std::vector< std::vector<unsigned> > _firings; ///> A history of neuron firings (firings of firings) for the liquid
//Liquid cosntructor/destructor
LSM ( );
~LSM ( );
/**
* @function out
* @brief Function used to output information of the liquid.
* @details The function will output in different streams, depending
* on the netOutMode parameter.
* @param outInfo the string to be output.
* @see LSM::netOutMode
*/
void out (std::string outInfo);
/**
* @function addLayer
* @brief Adds a layer with Izhikevich neurons in the liquid.
* @details The function assigns topological coordinates to neurons
* within the liquid and distributes them based on the w, h and d parameters.
* It also configures the type of synapses (excitatory/inhibitory) based on
* the excitatory percent passed.
*
* @param x the x coordinate of the layer's positions
* @param y the y coordinate of the layer's positions
* @param z the z coordinate of the layer's positions
*
* @param w the width of the layer
* @param h the height of the layer
* @param d the depth of the layer
*
* @param excitatoryPercent percent of excitatory connections in the liquid
*
* @param a Nemo's Izhikevich neuron property
* @param b Nemo's Izhikevich neuron property
* @param c Nemo's Izhikevich neuron property
* @param dd Nemo's Izhikevich neuron property
* @param u Nemo's Izhikevich neuron property
* @param v Nemo's Izhikevich neuron property
* @param sigma Currently not used
*
* @see Nemo::Izhikevich class for more details on the neuron type
*/
void addLayer ( int x, int y, int z, unsigned int w, unsigned int h, unsigned int d, double excitatoryPercent,
float a, float b, float c, float dd, float u, float v, float sigma);
/**
* @function addLayerGaussian
* @brief Adds a layer with Izhikevich neurons in the liquid,
* drawing the initialization parameters of the neurons from
* a Gaussian distribution dedicated to each parameter.
* @details The function performs similarly to addLayer, but
* initializes each parameter from values that are drawn from a
* Gaussian distribution, to increase the variability within the
* neurons.
*
* @see For parameters x, y, z, w, h, d, excitatoryPercent see addLayer funciton
*
* @param meanDeviation The mean deviation for every distribution
* @param timeScaleofRecovery The mean of the time scale of recovery distribution
* @param sensitivityToSubthresholdFlucutations The mean of the sensitivity to fluctuations distribution
* @param afterSpikeResetValueOfMembranePotential The mean of the after spike membrane potential reset value distribution
* @param afterSpikeResetOfRecovery The mean of the after spike recovery distribution
* @param initialValueOfMembraneRecovery The mean of the initial membrane value distribution
* @param sigmaForRandomGaussianPerNeuronInput The mean of the random per neuron input distribution
*
* @see Nemo::Izhikevich class for more details on the neuron type
*/
void addLayerGaussian ( int x, int y, int z, unsigned int w, unsigned int h, unsigned int d,
double excitatoryPercent,
double meanDeviation, double timeScaleofRecovery,
double sensitivityToSubthresholdFlucutations, double afterSpikeResetValueOfMembranePotential,
double afterSpikeResetOfRecovery, double initialValueOfMembraneRecovery,
double initialValueOfMembranePotential, double sigmaForRandomGaussianPerNeuronInput);
/**
* @function addLayerIF
* @brief Adds a layer with Integrate and Fire neurons in the liquid.
* @details The function initializes the IF neurons using a distribution
* that has a mean for each parameter and some large standard deviation. Custom
* values for the mean of the distribution of some parameters can be specified by
* the user (see function parameters below).
*
* @see For parameters x, y, z, w, h, d, excitatoryPercent see addLayer funciton
*
* @param v_thresh Nemo's IF neuron property
* @param v_reset Nemo's IF neuron property
* @param refraq Nemo's IF neuron property
* @param tau_m Nemo's IF neuron property
* @param inhibitoryCurrent Nemo's IF neuron property
*
* @see Nemo::Izhikevich class for more details on the neuron type
* @todo Need to fix the distribution initialization for all parameter types.
*/
void addLayerIF ( int x, int y, int z, unsigned int w, unsigned int h, unsigned int d,
double excitatoryPercent, double v_thresh, double v_reset, double refraq,
double tau_m, double inhibitoryCurrent );
/**
* @function addInputLayer
* @brief Adds a layer of input neurons to the liquid
* @see For parameters x, y, z, w, h, d, excitatoryPercent see addLayer funciton
*
* @todo Need to fix the distribution initialization for all parameter types.
*/
void addInputLayer ( int x, int y, int z, unsigned int w, unsigned int h, unsigned int d,
double excitatoryPercent );
/**
* @function addPoissonLayer
* @brief Adds a layer of Poisson input neurons to the liquid
* @see For parameters x, y, z, w, h, d, excitatoryPercent see addLayer funciton
*
* @todo Need to fix the distribution initialization for all parameter types.
*/
void addPoissonLayer ( int x, int y, int z, unsigned int w, unsigned int h, unsigned int d,
double excitatoryPercent );
/**
* @function addPoissonLayer
* @brief Generic connection function, connects two layers based
* on the specifications of the parameters. The other functions
* use this one.
*
* @param fromLayerS Index of the presynaptic layer
* @param toLayerS Index of the post-synaptic layer
* @param nConnections Number of connections to form
* @param lambda How much distance affects the propability of forming a connection
* @param distanceMetric How much distance affects the synapse's delay
* @param weightMean Mean of the distribution used to draw the synapse weight initial value
* @param weightVariance Variance of the distribution used to draw the synapse weight initial value
* @param bLearning Enable learning in the connection
*/
void connectLayerGeneric ( GeneralLayer &fromLayerS, GeneralLayer &toLayerS,
unsigned int nConnections,
unsigned int lambda, double distanceMetric,
double weightMean, double weightVariance,
bool bLearning = false );
/**
* @function connectLayer
* @brief Similar to the connectLayerGeneric function, but using indices
* instead of layer pointers.
* @see connectLayerGeneric for the remaining parameters
*/
void connectLayer ( unsigned int fromLayer, unsigned int toLayer,
unsigned int nConnections,
unsigned int lambda, double distanceMetric,
double weightMean, double weightVariance,
bool bLearning = false);
/**
* @function interConnectLayer
* @brief Similar to the connectLayerGeneric function, but used for interconnecting
* the neurons within the same layer.
* @see connectLayerGeneric for the remaining parameters
*/
void interConnectLayer ( unsigned int layer,
unsigned int nConnections,
unsigned int lambda, double distanceMetric,
double weightMean, double weightVariance,
bool bLearning = false);
/**
* @function connectInput
* @brief Similar to the connectLayerGeneric function, but used for connecting input and
* liquid layers.
* @see connectLayerGeneric for the remaining parameters
*/
void connectInput ( unsigned int fromLayer, unsigned int toLayer,
unsigned int nConnections,
unsigned int lambda, double distanceMetric,
double weightMean, double weightVariance,
bool bLearning = false );
/**
* @function connectPoisson
* @brief Similar to the connectLayerGeneric function, but used for connecting poisson input and
* liquid layers.
* @see connectLayerGeneric for the remaining parameters
*/
void connectPoisson ( unsigned int fromLayer, unsigned int toLayer,
unsigned int nConnections,
unsigned int lambda, double distanceMetric,
double weightMean, double weightVariance,
bool bLearning = false );
/**
* @function connectPoissonAll
* @brief Similar to the connectLayerGeneric function, but used for connecting poisson input and
* liquid layers.
* @see connectLayerGeneric for the remaining parameters
*/
void connectPoissonAll ( double connectionPercentage,
unsigned int fromLayer, unsigned int toLayer,
double weightMean, double weightVariance,
bool bLearning = false );
/**
* @function init
* @brief Initializes the liquid network on the Nemo library.
* @details This function must be called after the creation of an LSM layer.
*/
void init ( NemoSim *sim);
/**
* @function priorToSim
* @brief Clears all network stored inputs, prior to a new simulation run.
*/
void priorToSim ( );
/**
* @function simulate
* @brief Simulates one cycle of the liquid network
* @details The function iterates through all input and poisson layers
* and setsup the neurons that need to fire within the liquid.
*/
const std::vector<unsigned> simulate ( unsigned int nsteps = 1 );
/**
* @function filter
* @brief Filters all liquid output based on the filterFun.
*/
Eigen::MatrixXd filter ( unsigned int );
/**
* @function filterFun
* @brief Filter function used to filter the neuron outputs in the liquid,
* used by the filter function.
*
* @see filter function for details on how filtering is accomplished.
*/
double filterFun ( double inValue );
};
/**
* @class NemoSim
* @brief A wrapper for class for the nemo::Simulation object
*
* @version 1.0
*/
class NemoSim {
public:
LSM *_lsm;
boost::scoped_ptr <nemo::Simulation> _sim;
/**
* @function NemoSim
* @brief Constructor of the class, used to set the LSM pointer
*/
NemoSim(LSM *lsm)
: _lsm(lsm),
_sim ( nemo :: simulation ( lsm->_net , lsm->_conf )) {
}
/**
* @function Destructor
* @brief Destructor of the class (currently does nothing)
*/
~NemoSim() {
}
};
#endif