GeNN  3.3.0
GPU enhanced Neuronal Networks (GeNN)
newNeuronModels.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Standard includes
4 #include <array>
5 #include <functional>
6 #include <string>
7 #include <tuple>
8 #include <vector>
9 
10 // GeNN includes
11 #include "codeGenUtils.h"
12 #include "neuronModels.h"
13 #include "newModels.h"
14 
15 //----------------------------------------------------------------------------
16 // Macros
17 //----------------------------------------------------------------------------
18 #define SET_SIM_CODE(SIM_CODE) virtual std::string getSimCode() const override{ return SIM_CODE; }
19 #define SET_THRESHOLD_CONDITION_CODE(THRESHOLD_CONDITION_CODE) virtual std::string getThresholdConditionCode() const override{ return THRESHOLD_CONDITION_CODE; }
20 #define SET_RESET_CODE(RESET_CODE) virtual std::string getResetCode() const override{ return RESET_CODE; }
21 #define SET_SUPPORT_CODE(SUPPORT_CODE) virtual std::string getSupportCode() const override{ return SUPPORT_CODE; }
22 #define SET_EXTRA_GLOBAL_PARAMS(...) virtual StringPairVec getExtraGlobalParams() const override{ return __VA_ARGS__; }
23 #define SET_ADDITIONAL_INPUT_VARS(...) virtual NameTypeValVec getAdditionalInputVars() const override{ return __VA_ARGS__; }
24 
25 //----------------------------------------------------------------------------
26 // NeuronModels::Base
27 //----------------------------------------------------------------------------
28 namespace NeuronModels
29 {
31 class Base : public NewModels::Base
32 {
33 public:
34  //----------------------------------------------------------------------------
35  // Declared virtuals
36  //----------------------------------------------------------------------------
38 
40  virtual std::string getSimCode() const{ return ""; }
41 
43 
44  virtual std::string getThresholdConditionCode() const{ return ""; }
45 
47  virtual std::string getResetCode() const{ return ""; }
48 
50 
53  virtual std::string getSupportCode() const{ return ""; }
54 
58 
62 
65  virtual bool isPoisson() const{ return false; }
66 };
67 
68 //----------------------------------------------------------------------------
69 // NeuronModels::LegacyWrapper
70 //----------------------------------------------------------------------------
72 class LegacyWrapper : public NewModels::LegacyWrapper<Base, neuronModel, nModels>
73 {
74 public:
75  LegacyWrapper(unsigned int legacyTypeIndex) : NewModels::LegacyWrapper<Base, neuronModel, nModels>(legacyTypeIndex)
76  {
77  }
78 
79  //----------------------------------------------------------------------------
80  // Base virtuals
81  //----------------------------------------------------------------------------
83  virtual std::string getSimCode() const;
84 
86  virtual std::string getThresholdConditionCode() const;
87 
89  virtual std::string getResetCode() const;
90 
92  virtual std::string getSupportCode() const;
93 
96 
98  virtual bool isPoisson() const;
99 };
100 
101 //----------------------------------------------------------------------------
102 // NeuronModels::RulkovMap
103 //----------------------------------------------------------------------------
105 
131 class RulkovMap : public Base
132 {
133 public:
135 
136  SET_SIM_CODE(
137  "if ($(V) <= 0) {\n"
138  " $(preV)= $(V);\n"
139  " $(V)= $(ip0)/(($(Vspike)) - $(V) - ($(beta))*$(Isyn)) +($(ip1));\n"
140  "}\n"
141  "else {"
142  " if (($(V) < $(ip2)) && ($(preV) <= 0)) {\n"
143  " $(preV)= $(V);\n"
144  " $(V)= $(ip2);\n"
145  " }\n"
146  " else {\n"
147  " $(preV)= $(V);\n"
148  " $(V)= -($(Vspike));\n"
149  " }\n"
150  "}\n");
151 
152  SET_THRESHOLD_CONDITION_CODE("$(V) >= $(ip2)");
153 
154  SET_PARAM_NAMES({"Vspike", "alpha", "y", "beta"});
155  SET_VARS({{"V","scalar"}, {"preV", "scalar"}});
156 
158  {"ip0", [](const vector<double> &pars, double){ return pars[0] * pars[0] * pars[1]; }},
159  {"ip1", [](const vector<double> &pars, double){ return pars[0] * pars[2]; }},
160  {"ip2", [](const vector<double> &pars, double){ return (pars[0] * pars[1]) + (pars[0] * pars[2]); }}});
161 };
162 
163 //----------------------------------------------------------------------------
164 // NeuronModels::Izhikevich
165 //----------------------------------------------------------------------------
167 
184 class Izhikevich : public Base
185 {
186 public:
188 
189  SET_SIM_CODE(
190  "if ($(V) >= 30.0){\n"
191  " $(V)=$(c);\n"
192  " $(U)+=$(d);\n"
193  "} \n"
194  "$(V)+=0.5*(0.04*$(V)*$(V)+5.0*$(V)+140.0-$(U)+$(Isyn))*DT; //at two times for numerical stability\n"
195  "$(V)+=0.5*(0.04*$(V)*$(V)+5.0*$(V)+140.0-$(U)+$(Isyn))*DT;\n"
196  "$(U)+=$(a)*($(b)*$(V)-$(U))*DT;\n"
197  "if ($(V) > 30.0){ //keep this to not confuse users with unrealistiv voltage values \n"
198  " $(V)=30.0; \n"
199  "}\n");
200 
202 
203  SET_PARAM_NAMES({"a", "b", "c", "d"});
204  SET_VARS({{"V","scalar"}, {"U", "scalar"}});
205 };
206 
207 //----------------------------------------------------------------------------
208 // NeuronModels::IzhikevichVariable
209 //----------------------------------------------------------------------------
211 
225 {
226 public:
228 
230  SET_VARS({{"V","scalar"}, {"U", "scalar"}, {"a", "scalar"},
231  {"b", "scalar"}, {"c", "scalar"}, {"d", "scalar"}});
232 };
233 
234 //----------------------------------------------------------------------------
235 // NeuronModels::SpikeSource
236 //----------------------------------------------------------------------------
238 
240 class SpikeSource : public Base
241 {
242 public:
244 
246 };
247 
248 //----------------------------------------------------------------------------
249 // NeuronModels::SpikeSourceArray
250 //----------------------------------------------------------------------------
252 
263 class SpikeSourceArray : public Base
264 {
265 public:
267  SET_SIM_CODE("oldSpike = false;\n")
269  "$(startSpike) != $(endSpike) && "
270  "$(t) >= $(spikeTimes)[$(startSpike)]" );
271  SET_RESET_CODE( "$(startSpike)++;\n" );
272  SET_VARS( {{"startSpike", "unsigned int"}, {"endSpike", "unsigned int"}} );
273  SET_EXTRA_GLOBAL_PARAMS( {{"spikeTimes", "scalar*"}} );
274 };
275 
276 //----------------------------------------------------------------------------
277 // NeuronModels::Poisson
278 //----------------------------------------------------------------------------
280 
322 class Poisson : public Base
323 {
324 public:
326 
327  SET_SIM_CODE(
328  "uint64_t theRnd;\n"
329  "if ($(V) > $(Vrest)) {\n"
330  " $(V)= $(Vrest);\n"
331  "}"
332  "else if ($(t) - $(spikeTime) > ($(trefract))) {\n"
333  " MYRAND($(seed),theRnd);\n"
334  " if (theRnd < *($(rates)+$(offset)+$(id))) {\n"
335  " $(V)= $(Vspike);\n"
336  " $(spikeTime)= $(t);\n"
337  " }\n"
338  "}\n");
339  SET_THRESHOLD_CONDITION_CODE("$(V) >= $(Vspike)");
340 
341  SET_PARAM_NAMES({"therate", "trefract", "Vspike", "Vrest"});
342  SET_VARS({{"V", "scalar"}, {"seed", "uint64_t"}, {"spikeTime", "scalar"}});
343  SET_EXTRA_GLOBAL_PARAMS({{"rates", "uint64_t *"}, {"offset", "unsigned int"}});
344 
345  virtual bool isPoisson() const override{ return true; }
346 };
347 
348 //----------------------------------------------------------------------------
349 // NeuronModels::PoissonNew
350 //----------------------------------------------------------------------------
352 
363 class PoissonNew : public Base
364 {
365 public:
367 
368  SET_SIM_CODE(
369  "if($(timeStepToSpike) <= 0.0f) {\n"
370  " $(timeStepToSpike) += $(isi) * $(gennrand_exponential);\n"
371  "}\n"
372  "$(timeStepToSpike) -= 1.0;\n"
373  );
374 
375  SET_THRESHOLD_CONDITION_CODE("$(timeStepToSpike) <= 0.0");
376 
377  SET_PARAM_NAMES({"rate"});
378  SET_VARS({{"timeStepToSpike", "scalar"}});
379  SET_DERIVED_PARAMS({{"isi", [](const vector<double> &pars, double dt){ return 1000.0 / (pars[0] * dt); }}});
380 };
381 
382 //----------------------------------------------------------------------------
383 // NeuronModels::TraubMiles
384 //----------------------------------------------------------------------------
386 
430 class TraubMiles : public Base
431 {
432 public:
434 
435  SET_SIM_CODE(
436  "scalar Imem;\n"
437  "unsigned int mt;\n"
438  "scalar mdt= DT/25.0;\n"
439  "for (mt=0; mt < 25; mt++) {\n"
440  " Imem= -($(m)*$(m)*$(m)*$(h)*$(gNa)*($(V)-($(ENa)))+\n"
441  " $(n)*$(n)*$(n)*$(n)*$(gK)*($(V)-($(EK)))+\n"
442  " $(gl)*($(V)-($(El)))-$(Isyn));\n"
443  " scalar _a;\n"
444  " if (lV == -52.0) {\n"
445  " _a= 1.28;\n"
446  " }\n"
447  " else {\n"
448  " _a= 0.32*(-52.0-$(V))/(exp((-52.0-$(V))/4.0)-1.0);\n"
449  " }\n"
450  " scalar _b;\n"
451  " if (lV == -25.0) {\n"
452  " _b= 1.4;\n"
453  " }\n"
454  " else {\n"
455  " _b= 0.28*($(V)+25.0)/(exp(($(V)+25.0)/5.0)-1.0);\n"
456  " }\n"
457  " $(m)+= (_a*(1.0-$(m))-_b*$(m))*mdt;\n"
458  " _a= 0.128*exp((-48.0-$(V))/18.0);\n"
459  " _b= 4.0 / (exp((-25.0-$(V))/5.0)+1.0);\n"
460  " $(h)+= (_a*(1.0-$(h))-_b*$(h))*mdt;\n"
461  " if (lV == -50.0) {\n"
462  " _a= 0.16;\n"
463  " }\n"
464  " else {\n"
465  " _a= 0.032*(-50.0-$(V))/(exp((-50.0-$(V))/5.0)-1.0);\n"
466  " }\n"
467  " _b= 0.5*exp((-55.0-$(V))/40.0);\n"
468  " $(n)+= (_a*(1.0-$(n))-_b*$(n))*mdt;\n"
469  " $(V)+= Imem/$(C)*mdt;\n"
470  "}\n");
471 
473 
474  SET_PARAM_NAMES({"gNa", "ENa", "gK", "EK", "gl", "El", "C"});
475  SET_VARS({{"V", "scalar"}, {"m", "scalar"}, {"h", "scalar"}, {"n", "scalar"}});
476 };
477 
478 //----------------------------------------------------------------------------
479 // NeuronModels::TraubMilesFast
480 //----------------------------------------------------------------------------
482 
484 {
485 public:
487 
488  SET_SIM_CODE(
489  "scalar Imem;\n"
490  "unsigned int mt;\n"
491  "scalar mdt= DT/25.0;\n"
492  "for (mt=0; mt < 25; mt++) {\n"
493  " Imem= -($(m)*$(m)*$(m)*$(h)*$(gNa)*($(V)-($(ENa)))+\n"
494  " $(n)*$(n)*$(n)*$(n)*$(gK)*($(V)-($(EK)))+\n"
495  " $(gl)*($(V)-($(El)))-$(Isyn));\n"
496  " scalar _a= 0.32*(-52.0-$(V))/(exp((-52.0-$(V))/4.0)-1.0);\n"
497  " scalar _b= 0.28*($(V)+25.0)/(exp(($(V)+25.0)/5.0)-1.0);\n"
498  " $(m)+= (_a*(1.0-$(m))-_b*$(m))*mdt;\n"
499  " _a= 0.128*exp((-48.0-$(V))/18.0);\n"
500  " _b= 4.0 / (exp((-25.0-$(V))/5.0)+1.0);\n"
501  " $(h)+= (_a*(1.0-$(h))-_b*$(h))*mdt;\n"
502  " _a= 0.032*(-50.0-$(V))/(exp((-50.0-$(V))/5.0)-1.0);\n"
503  " _b= 0.5*exp((-55.0-$(V))/40.0);\n"
504  " $(n)+= (_a*(1.0-$(n))-_b*$(n))*mdt;\n"
505  " $(V)+= Imem/$(C)*mdt;\n"
506  "}\n");
507 };
508 
509 //----------------------------------------------------------------------------
510 // NeuronModels::TraubMilesAlt
511 //----------------------------------------------------------------------------
513 
514 class TraubMilesAlt : public TraubMiles
515 {
516 public:
518 
519  SET_SIM_CODE(
520  "scalar Imem;\n"
521  "unsigned int mt;\n"
522  "scalar mdt= DT/25.0;\n"
523  "for (mt=0; mt < 25; mt++) {\n"
524  " Imem= -($(m)*$(m)*$(m)*$(h)*$(gNa)*($(V)-($(ENa)))+\n"
525  " $(n)*$(n)*$(n)*$(n)*$(gK)*($(V)-($(EK)))+\n"
526  " $(gl)*($(V)-($(El)))-$(Isyn));\n"
527  " scalar volatile _tmp= abs(exp((-52.0-$(V))/4.0)-1.0);\n"
528  " scalar _a= 0.32*abs(-52.0-$(V))/(_tmp+SCALAR_MIN);\n"
529  " _tmp= abs(exp(($(V)+25.0)/5.0)-1.0);\n"
530  " scalar _b= 0.28*abs($(V)+25.0)/(_tmp+SCALAR_MIN);\n"
531  " $(m)+= (_a*(1.0-$(m))-_b*$(m))*mdt;\n"
532  " _a= 0.128*exp((-48.0-$(V))/18.0);\n"
533  " _b= 4.0 / (exp((-25.0-$(V))/5.0)+1.0);\n"
534  " $(h)+= (_a*(1.0-$(h))-_b*$(h))*mdt;\n"
535  " _tmp= abs(exp((-50.0-$(V))/5.0)-1.0);\n"
536  " _a= 0.032*abs(-50.0-$(V))/(_tmp+SCALAR_MIN);\n"
537  " _b= 0.5*exp((-55.0-$(V))/40.0);\n"
538  " $(n)+= (_a*(1.0-$(n))-_b*$(n))*mdt;\n"
539  " $(V)+= Imem/$(C)*mdt;\n"
540  "}\n");
541 };
542 
543 //----------------------------------------------------------------------------
544 // NeuronModels::TraubMilesNStep
545 //----------------------------------------------------------------------------
547 
549 {
550 public:
552 
553  SET_SIM_CODE(
554  "scalar Imem;\n"
555  "unsigned int mt;\n"
556  "scalar mdt= DT/scalar($(ntimes));\n"
557  "for (mt=0; mt < $(ntimes); mt++) {\n"
558  " Imem= -($(m)*$(m)*$(m)*$(h)*$(gNa)*($(V)-($(ENa)))+\n"
559  " $(n)*$(n)*$(n)*$(n)*$(gK)*($(V)-($(EK)))+\n"
560  " $(gl)*($(V)-($(El)))-$(Isyn));\n"
561  " scalar _a;\n"
562  " if (lV == -52.0) {\n"
563  " _a= 1.28;\n"
564  " }\n"
565  " else {\n"
566  " _a= 0.32*(-52.0-$(V))/(exp((-52.0-$(V))/4.0)-1.0);\n"
567  " }\n"
568  " scalar _b;\n"
569  " if (lV == -25.0) {\n"
570  " _b= 1.4;\n"
571  " }\n"
572  " else {\n"
573  " _b= 0.28*($(V)+25.0)/(exp(($(V)+25.0)/5.0)-1.0);\n"
574  " }\n"
575  " $(m)+= (_a*(1.0-$(m))-_b*$(m))*mdt;\n"
576  " _a= 0.128*exp((-48.0-$(V))/18.0);\n"
577  " _b= 4.0 / (exp((-25.0-$(V))/5.0)+1.0);\n"
578  " $(h)+= (_a*(1.0-$(h))-_b*$(h))*mdt;\n"
579  " if (lV == -50.0) {\n"
580  " _a= 0.16;\n"
581  " }\n"
582  " else {\n"
583  " _a= 0.032*(-50.0-$(V))/(exp((-50.0-$(V))/5.0)-1.0);\n"
584  " }\n"
585  " _b= 0.5*exp((-55.0-$(V))/40.0);\n"
586  " $(n)+= (_a*(1.0-$(n))-_b*$(n))*mdt;\n"
587  " $(V)+= Imem/$(C)*mdt;\n"
588  "}\n");
589 
590  SET_PARAM_NAMES({"gNa", "ENa", "gK", "EK", "gl", "El", "C", "ntimes"});
591 };
592 } // NeuronModels
virtual std::string getSupportCode() const
Gets support code to be made available within the neuron kernel/funcion.
Definition: newNeuronModels.h:53
Izhikevich neuron with fixed parameters .
Definition: newNeuronModels.h:184
Hodgkin-Huxley neurons with Traub & Miles algorithm.
Definition: newNeuronModels.h:548
Hodgkin-Huxley neurons with Traub & Miles algorithm: Original fast implementation, using 25 inner iterations.
Definition: newNeuronModels.h:483
Hodgkin-Huxley neurons with Traub & Miles algorithm.
Definition: newNeuronModels.h:430
class for specifying a neuron model.
Definition: neuronModels.h:16
virtual std::string getResetCode() const
Gets code that defines the reset action taken after a spike occurred. This can be empty...
Definition: newNeuronModels.h:47
LegacyWrapper(unsigned int legacyTypeIndex)
Definition: newNeuronModels.h:75
std::vector< std::pair< std::string, std::pair< std::string, double > > > NameTypeValVec
Definition: snippet.h:118
virtual bool isPoisson() const override
Definition: newNeuronModels.h:345
Wrapper around old-style models stored in global arrays and referenced by index.
Definition: newModels.h:170
virtual std::string getSimCode() const
Gets the code that defines the execution of one timestep of integration of the neuron model...
Definition: newNeuronModels.h:40
Poisson neurons.
Definition: newNeuronModels.h:363
Poisson neurons.
Definition: newNeuronModels.h:322
#define SET_RESET_CODE(RESET_CODE)
Definition: newNeuronModels.h:20
Rulkov Map neuron.
Definition: newNeuronModels.h:131
Spike source array.
Definition: newNeuronModels.h:263
virtual NewModels::Base::NameTypeValVec getAdditionalInputVars() const
Definition: newNeuronModels.h:61
#define SET_THRESHOLD_CONDITION_CODE(THRESHOLD_CONDITION_CODE)
Definition: newNeuronModels.h:19
#define SET_SIM_CODE(SIM_CODE)
Definition: newNeuronModels.h:18
Base class for all models - in addition to the parameters snippets have, models can have state variab...
Definition: newModels.h:132
virtual std::string getThresholdConditionCode() const
Gets code which defines the condition for a true spike in the described neuron model.
Definition: newNeuronModels.h:44
#define SET_DERIVED_PARAMS(...)
Definition: snippet.h:29
#define DECLARE_MODEL(TYPE, NUM_PARAMS, NUM_VARS)
Definition: newModels.h:18
Wrapper around legacy weight update models stored in nModels array of neuronModel objects...
Definition: newNeuronModels.h:72
Izhikevich neuron with variable parameters .
Definition: newNeuronModels.h:224
Hodgkin-Huxley neurons with Traub & Miles algorithm.
Definition: newNeuronModels.h:514
virtual NewModels::Base::StringPairVec getExtraGlobalParams() const
Definition: newNeuronModels.h:57
vector< neuronModel > nModels
Global C++ vector containing all neuron model descriptions.
Definition: neuronModels.cc:28
#define SET_PARAM_NAMES(...)
Definition: snippet.h:28
#define SET_VARS(...)
Definition: newModels.h:26
Base class for all neuron models.
Definition: newNeuronModels.h:31
Definition: codeGenUtils.h:19
std::vector< std::pair< std::string, std::string > > StringPairVec
Definition: snippet.h:117
Definition: codeGenUtils.h:24
#define SET_EXTRA_GLOBAL_PARAMS(...)
Definition: newNeuronModels.h:22
Empty neuron which allows setting spikes from external sources.
Definition: newNeuronModels.h:240