GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
initVarSnippet.h
Go to the documentation of this file.
1 #pragma once
2 
3 // GeNN includes
4 #include "snippet.h"
5 
6 //----------------------------------------------------------------------------
7 // Macros
8 //----------------------------------------------------------------------------
9 #define SET_CODE(CODE) virtual std::string getCode() const override{ return CODE; }
10 
11 //----------------------------------------------------------------------------
12 // InitVarSnippet::Base
13 //----------------------------------------------------------------------------
15 namespace InitVarSnippet
16 {
18 {
19 public:
20  //----------------------------------------------------------------------------
21  // Declared virtuals
22  //----------------------------------------------------------------------------
23  virtual std::string getCode() const{ return ""; }
24 
25  //----------------------------------------------------------------------------
26  // Public API
27  //----------------------------------------------------------------------------
29  boost::uuids::detail::sha1::digest_type getHashDigest() const;
30 
33 
35  bool requiresKernel() const;
36 };
37 
38 //----------------------------------------------------------------------------
39 // InitVarSnippet::Uninitialised
40 //----------------------------------------------------------------------------
42 class Uninitialised : public Base
43 {
44 public:
46 };
47 
48 //----------------------------------------------------------------------------
49 // InitVarSnippet::Constant
50 //----------------------------------------------------------------------------
52 
58 class Constant : public Base
59 {
60 public:
62 
63  SET_CODE("$(value) = $(constant);");
64 
65  SET_PARAM_NAMES({"constant"});
66 };
67 
68 //----------------------------------------------------------------------------
69 // InitVarSnippet::Kernel
70 //----------------------------------------------------------------------------
72 class Kernel : public Base
73 {
75 
76  SET_CODE("$(value) = $(kernel)[$(id_kernel)];");
77 
78  SET_EXTRA_GLOBAL_PARAMS({{"kernel", "scalar*"}});
79 };
80 
81 //----------------------------------------------------------------------------
82 // InitVarSnippet::Uniform
83 //----------------------------------------------------------------------------
85 
89 class Uniform : public Base
90 {
91 public:
93 
94  SET_CODE(
95  "const scalar scale = $(max) - $(min);\n"
96  "$(value) = $(min) + ($(gennrand_uniform) * scale);");
97 
98  SET_PARAM_NAMES({"min", "max"});
99 };
100 
101 //----------------------------------------------------------------------------
102 // InitVarSnippet::Normal
103 //----------------------------------------------------------------------------
105 
109 class Normal : public Base
110 {
111 public:
113 
114  SET_CODE("$(value) = $(mean) + ($(gennrand_normal) * $(sd));");
115 
116  SET_PARAM_NAMES({"mean", "sd"});
117 };
118 
119 //----------------------------------------------------------------------------
120 // InitVarSnippet::NormalClipped
121 //----------------------------------------------------------------------------
124 
130 class NormalClipped : public Base
131 {
132 public:
134 
135  SET_CODE(
136  "scalar normal;\n"
137  "do\n"
138  "{\n"
139  " normal = $(mean) + ($(gennrand_normal) * $(sd));\n"
140  "} while (normal > $(max) || normal < $(min));\n"
141  "$(value) = normal;\n");
142 
143  SET_PARAM_NAMES({"mean", "sd", "min", "max"});
144 };
145 
146 //----------------------------------------------------------------------------
147 // InitVarSnippet::NormalClippedDelay
148 //----------------------------------------------------------------------------
153 
159 class NormalClippedDelay : public Base
160 {
161 public:
163 
164  SET_CODE(
165  "scalar normal;\n"
166  "do\n"
167  "{\n"
168  " normal = $(meanTimestep) + ($(gennrand_normal) * $(sdTimestep));\n"
169  "} while (normal > $(maxTimestep) || normal < $(minTimestep));\n"
170  "$(value) = rint(normal);\n");
171 
172  SET_PARAM_NAMES({"mean", "sd", "min", "max"});
174  {"meanTimestep", [](const std::vector<double> &pars, double dt){ return pars[0] / dt; }},
175  {"sdTimestep", [](const std::vector<double> &pars, double dt){ return pars[1] / dt; }},
176  {"minTimestep", [](const std::vector<double> &pars, double dt){ return pars[2] / dt; }},
177  {"maxTimestep", [](const std::vector<double> &pars, double dt){ return pars[3] / dt; }}});
178 };
179 
180 //----------------------------------------------------------------------------
181 // InitVarSnippet::Exponential
182 //----------------------------------------------------------------------------
184 
187 class Exponential : public Base
188 {
189 public:
191 
192  SET_CODE("$(value) = $(lambda) * $(gennrand_exponential);");
193 
194  SET_PARAM_NAMES({"lambda"});
195 };
196 
197 //----------------------------------------------------------------------------
198 // InitVarSnippet::Gamma
199 //----------------------------------------------------------------------------
201 
205 class Gamma : public Base
206 {
207 public:
209 
210  SET_CODE("$(value) = $(b) * $(gennrand_gamma, $(a));");
211 
212  SET_PARAM_NAMES({"a", "b"});
213 };
214 
215 //----------------------------------------------------------------------------
216 // InitVarSnippet::Binomial
217 //----------------------------------------------------------------------------
219 
223 class Binomial : public Base
224 {
225 public:
227 
228  SET_CODE("$(value) = $(gennrand_binomial, (unsigned int)$(n), $(p));");
229 
230  SET_PARAM_NAMES({"n", "p"});
231 };
232 } // namespace InitVarSnippet
Initialises variable by sampling from the exponential distribution.
Definition: initVarSnippet.h:187
Initialises variable by sampling from the gamma distribution.
Definition: initVarSnippet.h:205
Definition: initVarSnippet.h:130
Initialises variable to a constant value.
Definition: initVarSnippet.h:58
Initialises variable by sampling from the normal distribution.
Definition: initVarSnippet.h:109
#define GENN_EXPORT
Definition: gennExport.h:13
Used to mark variables as uninitialised - no initialisation code will be run.
Definition: initVarSnippet.h:42
Initialises variable by sampling from the uniform distribution.
Definition: initVarSnippet.h:89
#define DECLARE_SNIPPET(TYPE, NUM_PARAMS)
Definition: snippet.h:19
Initialises variable by sampling from the binomial distribution.
Definition: initVarSnippet.h:223
Definition: initVarSnippet.h:17
Definition: initVarSnippet.h:159
#define SET_DERIVED_PARAMS(...)
Definition: snippet.h:37
Base class for all value initialisation snippets.
Definition: initVarSnippet.h:15
Base class for all code snippets.
Definition: snippet.h:120
#define SET_PARAM_NAMES(...)
Definition: snippet.h:36
#define SET_CODE(CODE)
Definition: initVarSnippet.h:9
virtual std::string getCode() const
Definition: initVarSnippet.h:23
void validate() const
Validate names of parameters etc.
Definition: snippet.h:218
Used to initialise synapse variables from a kernel.
Definition: initVarSnippet.h:72
#define SET_EXTRA_GLOBAL_PARAMS(...)
Definition: snippet.h:38