Cypress  1.0
C++ Spiking Neural Network Simulation Framework
neurons.hpp
Go to the documentation of this file.
1 /*
2  * Cypress -- C++ Spiking Neural Network Simulation Framework
3  * Copyright (C) 2016 Andreas Stöckel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
36 #pragma once
37 
38 #ifndef CYPRESS_CORE_NEURONS_HPP
39 #define CYPRESS_CORE_NEURONS_HPP
40 
42 
47 #define NAMED_PARAMETER(NAME, IDX) \
48  static constexpr size_t idx_##NAME = IDX; \
49  auto &NAME(Real x) \
50  { \
51  for (auto &p : write_parameters()) { \
52  p[IDX] = x; \
53  } \
54  return *this; \
55  } \
56  Real NAME() const { return read_parameters()[IDX]; }
57 
61 #define NAMED_SIGNAL(NAME, IDX) \
62  static constexpr size_t idx_##NAME = IDX; \
63  auto &record_##NAME(bool x = true) \
64  { \
65  record(IDX, x); \
66  return *this; \
67  } \
68  bool is_recording_##NAME() const { return is_recording(IDX); } \
69  auto get_##NAME() { return data(IDX); } \
70  auto get_##NAME() const { return data(IDX); }
71 
72 namespace cypress {
73 /*
74  * Forward declarations
75  */
76 class SpikeSourceArray;
77 class SpikeSourceArrayParameters;
78 class SpikeSourceArraySignals;
79 class SpikeSourcePoisson;
80 class SpikeSourcePoissonParameters;
81 class SpikeSourcePoissonSignals;
82 class SpikeSourceConstFreq;
83 class SpikeSourceConstFreqParameters;
84 class SpikeSourceConstFreqSignals;
85 class SpikeSourceConstInterval;
86 class SpikeSourceConstIntervalParameters;
87 class SpikeSourceConstIntervalSignals;
88 class IfCondExp;
89 class IfCondExpParameters;
90 class IfCondExpSignals;
91 class IfFacetsHardware1;
92 class IfFacetsHardware1Parameters;
93 class IfFacetsHardware1Signals;
94 class EifCondExpIsfaIsta;
95 class EifCondExpIsfaIstaParameters;
96 class EifCondExpIsfaIstaSignals;
97 class IfCurrExp;
98 class IfCurrExpParameters;
99 class IfCurrExpSignals;
100 
101 /*
102  * SpikeSourceArray
103  */
104 
109 class SpikeSourceArray final : public NeuronTypeBase<SpikeSourceArrayParameters,
110  SpikeSourceArraySignals> {
111 private:
113 
114 public:
115  static const SpikeSourceArray &inst();
116 };
117 
123  : public NeuronParametersBase<SpikeSourceArrayParameters,
124  SpikeSourceArray> {
125 public:
128 
130 
135  SpikeSourceArrayParameters(const std::vector<Real> &spike_times)
136  : NeuronParametersBase(spike_times)
137  {
138  }
139 
143  SpikeSourceArrayParameters(std::initializer_list<Real> spike_times)
144  : NeuronParametersBase(spike_times)
145  {
146  }
147 
148  const std::vector<Real> &spike_times() const { return read_parameters(); }
149 
150  SpikeSourceArrayParameters &spike_times(
151  const std::vector<Real> &spike_times)
152  {
153  for (auto &p : write_parameters()) {
154  p = spike_times;
155  }
156  return *this;
157  }
158 };
159 
165  : public NeuronSignalsBase<SpikeSourceArraySignals, SpikeSourceArray, 1> {
166 public:
169 
170  NAMED_SIGNAL(spikes, 0);
171 };
172 
173 /*
174  * SpikeSourcePoisson
175  */
176 
182  : public NeuronTypeBase<SpikeSourcePoissonParameters,
183  SpikeSourcePoissonSignals> {
184 private:
186 
187 public:
188  static const SpikeSourcePoisson &inst();
189 };
190 
196  : public ConstantSizeNeuronParametersBase<SpikeSourcePoissonParameters,
197  SpikeSourcePoisson, 4> {
198 public:
202 
203  NAMED_PARAMETER(rate, 0); // The spike rate in Hz
204  NAMED_PARAMETER(start, 1); // The start time in ms
205  NAMED_PARAMETER(duration, 2); // Duration of the spike sequence
206  NAMED_PARAMETER(seed, 3); // Seed for the random generator
207 };
208 
214  : public NeuronSignalsBase<SpikeSourcePoissonSignals, SpikeSourcePoisson,
215  1> {
216 public:
219 
220  NAMED_SIGNAL(spikes, 0);
221 };
222 
223 /*
224  * SpikeSourceConstFreq
225  */
226 
232  : public NeuronTypeBase<SpikeSourceConstFreqParameters,
233  SpikeSourceConstFreqSignals> {
234 private:
236 
237 public:
238  static const SpikeSourceConstFreq &inst();
239 };
240 
246  : public ConstantSizeNeuronParametersBase<SpikeSourceConstFreqParameters,
247  SpikeSourceConstFreq, 5> {
248 public:
252 
253  NAMED_PARAMETER(rate, 0); // The spike rate in Hz
254  NAMED_PARAMETER(start, 1); // The start time in ms
255  NAMED_PARAMETER(duration, 2); // Duration of the spike sequence
256  NAMED_PARAMETER(sigma, 3); // Gaussian spike time standard deviation
257  NAMED_PARAMETER(seed, 4); // Seed for the random generator
258 };
259 
266  : public NeuronSignalsBase<SpikeSourceConstFreqSignals,
267  SpikeSourceConstFreq, 1> {
268 public:
271 
272  NAMED_SIGNAL(spikes, 0);
273 };
274 
275 /*
276  * SpikeSourceConstInterval
277  */
278 
284  : public NeuronTypeBase<SpikeSourceConstIntervalParameters,
285  SpikeSourceConstIntervalSignals> {
286 private:
288 
289 public:
290  static const SpikeSourceConstInterval &inst();
291 };
292 
299  SpikeSourceConstIntervalParameters, SpikeSourceConstInterval, 5> {
300 public:
304 
305  NAMED_PARAMETER(interval, 0); // The interval between spikes in ms
306  NAMED_PARAMETER(start, 1); // The start time in ms
307  NAMED_PARAMETER(duration, 2); // Duration of the spike sequence
308  NAMED_PARAMETER(sigma, 3); // Gaussian spike time standard deviation
309  NAMED_PARAMETER(seed, 4); // Seed for the random generator
310 };
311 
318  : public NeuronSignalsBase<SpikeSourceConstIntervalSignals,
319  SpikeSourceConstInterval, 1> {
320 public:
323 
324  NAMED_SIGNAL(spikes, 0);
325 };
326 
327 /*
328  * IfCondExp
329  */
330 
335 class IfCondExp final
336  : public NeuronTypeBase<IfCondExpParameters, IfCondExpSignals> {
337 private:
338  IfCondExp();
339 
340 public:
341  static const IfCondExp &inst();
342 };
343 
345  : public ConstantSizeNeuronParametersBase<IfCondExpParameters, IfCondExp,
346  11> {
347 public:
350 
351  NAMED_PARAMETER(cm, 0);
352  NAMED_PARAMETER(tau_m, 1);
353  NAMED_PARAMETER(tau_syn_E, 2);
354  NAMED_PARAMETER(tau_syn_I, 3);
355  NAMED_PARAMETER(tau_refrac, 4);
356  NAMED_PARAMETER(v_rest, 5);
357  NAMED_PARAMETER(v_thresh, 6);
358  NAMED_PARAMETER(v_reset, 7);
359  NAMED_PARAMETER(e_rev_E, 8);
360  NAMED_PARAMETER(e_rev_I, 9);
361  NAMED_PARAMETER(i_offset, 10);
362 
363  auto &g_leak(Real x) { return tau_m(cm() / x); }
364  Real g_leak() const { return cm() / tau_m(); }
365 };
366 
367 class IfCondExpSignals final
368  : public NeuronSignalsBase<IfCondExpSignals, IfCondExp, 4> {
369 public:
371 
373 
374  IfCondExpSignals(std::initializer_list<IfCondExpSignals> list)
375  : NeuronSignalsBase(PopulationDataView::from_sequence(list))
376  {
377  }
378 
379  NAMED_SIGNAL(spikes, 0);
380  NAMED_SIGNAL(v, 1);
381  NAMED_SIGNAL(gsyn_exc, 2);
382  NAMED_SIGNAL(gsyn_inh, 3);
383 };
384 
385 /*
386  * IfFacetsHardware1
387  */
388 
392 class IfFacetsHardware1 final
393  : public NeuronTypeBase<IfFacetsHardware1Parameters,
394  IfFacetsHardware1Signals> {
395 private:
397 
398 public:
399  static const IfFacetsHardware1 &inst();
400 };
401 
403  : public ConstantSizeNeuronParametersBase<IfFacetsHardware1Parameters,
404  IfFacetsHardware1, 6> {
405 public:
409 
410  NAMED_PARAMETER(g_leak, 0);
411  NAMED_PARAMETER(tau_refrac, 1);
412  NAMED_PARAMETER(v_rest, 2);
413  NAMED_PARAMETER(v_thresh, 3);
414  NAMED_PARAMETER(v_reset, 4);
415  NAMED_PARAMETER(e_rev_I, 5);
416 
417  Real cm() const { return 0.2; }
418  Real e_rev_E() const { return 0.0; }
419  Real tau_syn_E() const
420  {
421  return 2.0; // This is just a guess
422  }
423  Real tau_syn_I() const
424  {
425  return 2.0; // This is just a guess
426  }
427  Real i_offset() const { return 0.0; }
428 
429  auto &tau_m(Real x) { return g_leak(cm() / x); }
430  Real tau_m() const { return cm() / g_leak(); }
431 };
432 
434  : public NeuronSignalsBase<IfFacetsHardware1Signals, IfFacetsHardware1, 4> {
435 public:
438 
440 
442  std::initializer_list<IfFacetsHardware1Signals> list)
443  : NeuronSignalsBase(PopulationDataView::from_sequence(list))
444  {
445  }
446 
447  NAMED_SIGNAL(spikes, 0);
448  NAMED_SIGNAL(v, 1);
449 };
450 
451 /*
452  * EifCondExpIsfaIsta
453  */
454 
459  : public NeuronTypeBase<EifCondExpIsfaIstaParameters,
460  EifCondExpIsfaIstaSignals> {
461 private:
463 
464 public:
465  static const EifCondExpIsfaIsta &inst();
466 };
467 
469  : public ConstantSizeNeuronParametersBase<EifCondExpIsfaIstaParameters,
470  EifCondExpIsfaIsta, 15> {
471 public:
475 
476  NAMED_PARAMETER(cm, 0);
477  NAMED_PARAMETER(tau_m, 1);
478  NAMED_PARAMETER(tau_syn_E, 2);
479  NAMED_PARAMETER(tau_syn_I, 3);
480  NAMED_PARAMETER(tau_refrac, 4);
481  NAMED_PARAMETER(tau_w, 5);
482  NAMED_PARAMETER(v_rest, 6);
483  NAMED_PARAMETER(v_thresh, 7);
484  NAMED_PARAMETER(v_reset, 8);
485  NAMED_PARAMETER(e_rev_E, 9);
486  NAMED_PARAMETER(e_rev_I, 10);
487  NAMED_PARAMETER(i_offset, 11);
488  NAMED_PARAMETER(a, 12);
489  NAMED_PARAMETER(b, 13);
490  NAMED_PARAMETER(delta_T, 14);
491 
492  auto &g_leak(Real x) { return tau_m(cm() / x); }
493  Real g_leak() const { return cm() / tau_m(); }
494 };
495 
497  : public NeuronSignalsBase<EifCondExpIsfaIstaSignals, EifCondExpIsfaIsta,
498  4> {
499 public:
502 
503  NAMED_SIGNAL(spikes, 0);
504  NAMED_SIGNAL(v, 1);
505  NAMED_SIGNAL(gsyn_exc, 2);
506  NAMED_SIGNAL(gsyn_inh, 3);
507 };
508 
509 
510 /*
511  * IfCurrExp
512  */
513 
518 class IfCurrExp final
519  : public NeuronTypeBase<IfCurrExpParameters, IfCurrExpSignals> {
520 private:
521  IfCurrExp();
522 
523 public:
524  static const IfCurrExp &inst();
525 };
526 
528  : public ConstantSizeNeuronParametersBase<IfCurrExpParameters, IfCurrExp,
529  9> {
530 public:
533 
534  NAMED_PARAMETER(cm, 0);
535  NAMED_PARAMETER(tau_m, 1);
536  NAMED_PARAMETER(tau_syn_E, 2);
537  NAMED_PARAMETER(tau_syn_I, 3);
538  NAMED_PARAMETER(tau_refrac, 4);
539  NAMED_PARAMETER(v_rest, 5);
540  NAMED_PARAMETER(v_thresh, 6);
541  NAMED_PARAMETER(v_reset, 7);
542  NAMED_PARAMETER(i_offset, 8);
543 
544  auto &g_leak(Real x) { return tau_m(cm() / x); }
545  Real g_leak() const { return cm() / tau_m(); }
546 };
547 
548 class IfCurrExpSignals final
549  : public NeuronSignalsBase<IfCurrExpSignals, IfCurrExp, 2> {
550 public:
552 
554 
555  IfCurrExpSignals(std::initializer_list<IfCurrExpSignals> list)
556  : NeuronSignalsBase(PopulationDataView::from_sequence(list))
557  {
558  }
559 
560  NAMED_SIGNAL(spikes, 0);
561  NAMED_SIGNAL(v, 1);
562 };
563 
564 /*
565  * Define some common aliases in order to save typing.
566  */
567 using LIF = IfCondExp;
573 }
574 
575 #undef NAMED_SIGNAL
576 #undef NAMED_PARAMETER
577 
578 #endif /* CYPRESS_CORE_NEURONS_HPP */
Real i_offset() const
Definition: neurons.hpp:427
Definition: neurons.hpp:458
Definition: neurons.hpp:195
auto & g_leak(Real x)
Definition: neurons.hpp:492
Real g_leak() const
Definition: neurons.hpp:545
Definition: neurons.hpp:265
Real g_leak() const
Definition: neurons.hpp:493
Definition: neurons.hpp:181
Definition: neurons.hpp:518
Definition: neurons.hpp:468
Definition: neurons.hpp:402
Definition: neurons.hpp:213
SpikeSourceArrayParameters & spike_times(const std::vector< Real > &spike_times)
Definition: neurons.hpp:150
Definition: neurons.hpp:496
Definition: neurons.hpp:392
auto & g_leak(Real x)
Definition: neurons.hpp:363
double Real
Definition: types.hpp:56
IfCurrExpSignals(std::initializer_list< IfCurrExpSignals > list)
Definition: neurons.hpp:555
Definition: neurons.hpp:164
Definition: neurons.hpp:283
IfFacetsHardware1Signals()
Definition: neurons.hpp:439
Definition: neurons.hpp:231
Definition: neurons.hpp:433
Definition: neurons.hpp:122
#define NAMED_PARAMETER(NAME, IDX)
Definition: neurons.hpp:47
SpikeSourceArrayParameters()
Definition: neurons.hpp:129
IfCondExpSignals(std::initializer_list< IfCondExpSignals > list)
Definition: neurons.hpp:374
Definition: neurons_base.hpp:288
static const SpikeSourceArray & inst()
Real e_rev_E() const
Definition: neurons.hpp:418
Definition: neurons.hpp:548
Definition: neurons_base.hpp:423
Definition: neurons.hpp:335
Definition: neurons_base.hpp:243
Real cm() const
Definition: neurons.hpp:417
Definition: neurons.hpp:367
Definition: neurons.hpp:109
Real tau_syn_I() const
Definition: neurons.hpp:423
Definition: neurons_base.hpp:138
Definition: data.hpp:383
Definition: brainscales_lib.hpp:39
Real g_leak() const
Definition: neurons.hpp:364
auto & tau_m(Real x)
Definition: neurons.hpp:429
Real tau_m() const
Definition: neurons.hpp:430
IfFacetsHardware1Signals(std::initializer_list< IfFacetsHardware1Signals > list)
Definition: neurons.hpp:441
Real tau_syn_E() const
Definition: neurons.hpp:419
#define NAMED_SIGNAL(NAME, IDX)
Definition: neurons.hpp:61
Definition: neurons.hpp:527
SpikeSourceArrayParameters(const std::vector< Real > &spike_times)
Definition: neurons.hpp:135
Definition: neurons.hpp:344
const std::vector< Real > & spike_times() const
Definition: neurons.hpp:148
auto & g_leak(Real x)
Definition: neurons.hpp:544
Definition: neurons.hpp:245
Definition: neurons.hpp:317
IfCurrExpSignals()
Definition: neurons.hpp:553
IfCondExpSignals()
Definition: neurons.hpp:372
SpikeSourceArrayParameters(std::initializer_list< Real > spike_times)
Definition: neurons.hpp:143