-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKTzV2_Synapses.cs
860 lines (764 loc) · 31.2 KB
/
KTzV2_Synapses.cs
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
using System;
using KTzV2.Neurons;
using KTzV2.Maths.Random;
namespace KTzV2.Synapses
{
/// <summary>
/// improvised enum to select synapse
/// </summary>
public enum SynapseType
{
KTChemicalSynapse,
KTNoisyChemicalSynapse,
KTDynamicChemicalSynapse,
GapJunction,
GapJunctionNoisy,
GapJunctionRectifying,
GapJunctionRectifyingNoisy,
PulseCoupling,
PulseCouplingNoisy,
PulseCouplingSpike,
PulseCouplingSpikeNoisy
}
public enum NoiseType
{
ProportionalAmplitude,
GreaterThanJ
}
public class SynapseParam
{
public INeuron preSynNeuron { get; private set; }
public INeuron postSynNeuron { get; private set; }
public Double J { get; private set; }
public Double J0 { get; private set; }
public Double noiseAmp { get; private set; }
public Double noiseRatio { get; private set; }
public NoiseType noiseType { get; private set; }
public Double tauf { get; private set; }
public Double taug { get; private set; }
public UInt64 seed { get; private set; }
public Double alpha { get; private set; }
public Double u { get; private set; }
public Double tauJ { get; private set; }
public Double dt { get; private set; }
public SynapseParam(INeuron preNeu, INeuron postNeu, Double tauf, Double taug, Double J, Double noiseAmp, Double noiseRatio, UInt64 seed, NoiseType noiseType, Double J0, Double tauJ, Double alpha, Double u, Double dt)
{
this.preSynNeuron = preNeu;
this.postSynNeuron = postNeu;
this.tauf = tauf;
this.taug = taug;
this.J = J;
this.noiseAmp = noiseAmp;
this.noiseRatio = noiseRatio;
this.seed = seed;
this.noiseType = noiseType;
this.J0 = J0;
this.tauJ = tauJ;
this.alpha = alpha;
this.u = u;
this.dt = dt;
}
}
public static class SynapseFactory
{
public static ISynapse GetSynapse(SynapseType synType, SynapseParam par)
{
switch (synType)
{
case SynapseType.KTChemicalSynapse:
return new KTChemicalSynapse(par.preSynNeuron, par.postSynNeuron, par.J, par.tauf, par.taug);
case SynapseType.KTNoisyChemicalSynapse:
return new KTNoisyChemicalSynapse(par.preSynNeuron, par.postSynNeuron, par.J, par.tauf, par.taug, par.noiseAmp, par.noiseRatio, par.seed, par.noiseType);
case SynapseType.KTDynamicChemicalSynapse:
return new KTDynamicChemicalSynapse(par.preSynNeuron, par.postSynNeuron, par.J0, par.tauf, par.taug, par.alpha, par.u, par.tauJ, par.dt);
case SynapseType.GapJunction:
case SynapseType.GapJunctionRectifying:
return new GapJunction(par.preSynNeuron, par.postSynNeuron, par.J, synType == SynapseType.GapJunctionRectifying);
case SynapseType.GapJunctionNoisy:
case SynapseType.GapJunctionRectifyingNoisy:
return new NoisyGapJunction(par.preSynNeuron, par.postSynNeuron, par.J, par.noiseAmp, par.noiseRatio, par.seed, par.noiseType, synType == SynapseType.GapJunctionRectifyingNoisy);
case SynapseType.PulseCoupling:
case SynapseType.PulseCouplingSpike:
return new PulseCoupling(par.preSynNeuron, par.J, synType == SynapseType.PulseCouplingSpike);
case SynapseType.PulseCouplingNoisy:
case SynapseType.PulseCouplingSpikeNoisy:
return new NoisyPulseCoupling(par.preSynNeuron, par.J, par.noiseAmp, par.noiseRatio, par.seed, par.noiseType, synType == SynapseType.PulseCouplingSpikeNoisy);
default:
throw new ArgumentOutOfRangeException("Unrecognized synapse type! " + synType.ToString());
}
}
}
/// <summary>
/// class to handle an output synapse according to the reference:
/// SM Kuva, AC Roque, MHR Tragtenberg, O Kinouchi: A minimal model for excitable and bursting elements. Neurocomputing.
/// </summary>
public class KTChemicalSynapse : KTSynapse
{
/// <summary>
/// dynamical variable with output signal
/// </summary>
public Double f { get; private set; }
/// <summary>
/// dynamical auxiliary variable
/// </summary>
private Double g { get; set; }
/// <summary>
/// parameter - time constant for f variable
/// </summary>
public Double oneOverTau_f { get; private set; }
/// <summary>
/// parameter - time constant for g variable
/// </summary>
public Double oneOverTau_g { get; private set; }
/// <summary>
/// step function to decide if this synapse should act (for membrane potential of the presyn neuron > 0)
/// </summary>
private Double thetaJ { get; set; }
/// <summary>
/// creates a double exponential synapse with constant coupling conductance
/// </summary>
/// <param name="nPre">presynaptic neuron</param>
/// <param name="nPost">postsynaptic neuron</param>
/// <param name="J">coupling intensity</param>
/// <param name="tau_f">rise time constant</param>
/// <param name="tau_g">decay time constant</param>
public KTChemicalSynapse(INeuron nPre, INeuron nPost, Double J, Double tau_f, Double tau_g)
: base(nPre, nPost, J)
{
this.oneOverTau_f = 1.0 / tau_f;
this.oneOverTau_g = 1.0 / tau_g;
this.f = 0.0;
this.g = 0.0;
}
/// <summary>
/// evaluates this synaptic signal for one timestep
/// </summary>
public override void EvolveLocal()
{
this.thetaJ = (this.PreSynapticNeuron.GetMembranePotential() > 0.0 ? this.J : 0.0);
this.f = (1.0 - this.oneOverTau_f) * this.f + this.g;
this.g = (1.0 - this.oneOverTau_g) * this.g + this.thetaJ;
}
/// <summary>
/// gets the signal that this synapse generates (the f variable)
/// </summary>
/// <returns>f variable - a double value with the signal of this synapse</returns>
public override Double GetSignal()
{
return this.f;
}
/// <summary>
/// Resets output synaptic signal
/// </summary>
public override void ResetSignal()
{
this.f = 0.0D;
this.g = 0.0D;
}
}
/// <summary>
/// class to handle an output synapse according to the reference:
/// SM Kuva, AC Roque, MHR Tragtenberg, O Kinouchi: A minimal model for excitable and bursting elements. Neurocomputing.
/// </summary>
public class KTDynamicChemicalSynapse : KTSynapse
{
/// <summary>
/// dynamical variable with output signal
/// </summary>
public Double f { get; private set; }
/// <summary>
/// dynamical auxiliary variable
/// </summary>
private Double g { get; set; }
/// <summary>
/// parameter - time constant for f variable
/// </summary>
public Double oneOverTau_f { get; private set; }
/// <summary>
/// parameter - time constant for g variable
/// </summary>
public Double oneOverTau_g { get; private set; }
/// <summary>
/// parameter - time constant of the coupling parameter
/// </summary>
public Double oneOverTau_J { get; private set; }
/// <summary>
/// parameter - maximum amplitude of the synapse
/// </summary>
public Double alphaOverU { get; private set; }
/// <summary>
/// parameter - amount of coupling lost when a spike occurs
/// </summary>
public Double u { get; private set; }
/// <summary>
/// step function to decide if this synapse should act (for membrane potential of the presyn neuron > 0)
/// </summary>
private Double thetaJ { get; set; }
/// <summary>
/// Creates a KT Dynamic Chemical Synapse
/// </summary>
/// <param name="nPre">the pre-syn neuron</param>
/// <param name="J0">the initial value of the coupling</param>
/// <param name="tau_f">the time constant of f variable</param>
/// <param name="tau_g">the time constant of g variable</param>
/// <param name="alpha">the alpha parameter: alpha/u is the maximum value of J (the coupling parameter)</param>
/// <param name="u">the u parameter: the decrease on the coupling when a spike occurs</param>
/// <param name="tau_J">the time constant of J (coupling). It should be of the order of tau*N, where N is the number of neurons and tau is the time constant of the stimulus</param>
/// <param name="dt">the timestep to rescale the parameters, as this is a discretization of a differential equation</param>
public KTDynamicChemicalSynapse(INeuron nPre, INeuron nPost, Double J0, Double tau_f, Double tau_g, Double alpha, Double u, Double tau_J, Double dt)
: base(nPre, nPost, J0)
{
this.oneOverTau_f = 1.0 / tau_f;
this.oneOverTau_g = 1.0 / tau_g;
this.oneOverTau_J = dt / tau_J; // rescaling this term according to dt
this.alphaOverU = alpha / u; // this term needs not to be rescaled because it is a constant which is multiplied by dt when it is multiplied by oneOverTau_J
this.u = dt * u; // rescaling this term according to dt
this.f = 0.0;
this.g = 0.0;
}
/// <summary>
/// evaluates this synaptic signal for one timestep
/// </summary>
public override void EvolveLocal()
{
this.thetaJ = this.J + (this.PreSynapticNeuron.GetMembranePotential() > 0.0 ? (this.alphaOverU - this.J) * this.oneOverTau_J : (this.alphaOverU - this.J) * this.oneOverTau_J - this.u * this.J);
this.f = (1.0 - this.oneOverTau_f) * this.f + this.g;
this.g = (1.0 - this.oneOverTau_g) * this.g + this.thetaJ;
}
/// <summary>
/// gets the signal that this synapse generates (the f variable)
/// </summary>
/// <returns>f variable - a double value with the signal of this synapse</returns>
public override Double GetSignal()
{
return this.f;
}
/// <summary>
/// Resets output synaptic signal
/// </summary>
public override void ResetSignal()
{
this.f = 0.0D;
this.g = 0.0D;
}
}
/// <summary>
/// class to handle an output chemical synapse with noise. The chemical synapse is according to the reference:
/// SM Kuva, AC Roque, MHR Tragtenberg, O Kinouchi: A minimal model for excitable and bursting elements. Neurocomputing.
/// </summary>
public class KTNoisyChemicalSynapse : KTSynapse
{
/// <summary>
/// dynamical variable with output signal
/// </summary>
public Double f { get; private set; }
/// <summary>
/// dynamical auxiliary variable
/// </summary>
private Double g { get; set; }
/// <summary>
/// parameter - time constant for f variable
/// </summary>
public Double oneOverTau_f { get; private set; }
/// <summary>
/// parameter - time constant for g variable
/// </summary>
public Double oneOverTau_g { get; private set; }
/// <summary>
/// step function to decide if this synapse should act (for membrane potential of the presyn neuron > 0)
/// </summary>
private Double thetaJ { get; set; }
/// <summary>
/// random number to generate noise over J
/// </summary>
private HomogeneousRand Jnoise { get; set; }
private Func<Double> GetJ { get; set; }
//private Int32 JSign { get; set; }
/// <summary>
/// the bounds of the noise signal
/// </summary>
private Double NoiseAmp { get; set; }
/// <summary>
/// creates a double exponential synapse with noisy coupling conductance
/// </summary>
/// <param name="nPre">presynaptic neuron</param>
/// <param name="nPost">postsynaptic neuron</param>
/// <param name="J">coupling intensity</param>
/// <param name="tau_f">rise time constant</param>
/// <param name="tau_g">decay time constant</param>
/// <param name="noiseAmp">absolute amplitude of noise</param>
/// <param name="noiseRatio">fraction of J to use as noise amplitude</param>
/// <param name="seed">seed for random number generator</param>
/// <param name="nt">noise type parameter (must be enum)</param>
/// <exception cref="ArgumentOutOfRangeException">thrown when unrecognized noise type</exception>
public KTNoisyChemicalSynapse(INeuron nPre, INeuron nPost, Double J, Double tau_f, Double tau_g, Double noiseAmp, Double noiseRatio, UInt64 seed, NoiseType nt)
: base(nPre, nPost, J)
{
this.Jnoise = new HomogeneousRand(seed);
if (nt == NoiseType.ProportionalAmplitude)
{
this.NoiseAmp = Math.Abs(J * noiseRatio);
this.GetJ = this.GetJProportionalAmplitude;
}
else if (nt == NoiseType.GreaterThanJ)
{
this.NoiseAmp = Math.Abs(noiseAmp) * Math.Sign(J);
this.GetJ = this.GetJGreaterThanJ;
}
else
{
throw new ArgumentOutOfRangeException("Unrecognized NoiseType! " + nt.ToString());
}
this.oneOverTau_f = 1.0 / tau_f;
this.oneOverTau_g = 1.0 / tau_g;
this.f = 0.0;
this.g = 0.0;
}
private Double GetJProportionalAmplitude()
{
return this.J + (this.NoiseAmp * (2.0D * this.Jnoise.GetRandomFull() - 1.0D));
}
private Double GetJGreaterThanJ()
{
return this.J + (this.NoiseAmp * this.Jnoise.GetRandomFull());
}
/// <summary>
/// evaluates this synaptic signal for one timestep
/// </summary>
public override void EvolveLocal()
{
// otimizar esta parte... ajustar no construtor this.NoiseAmp = Math.Abs(noiseAmp) * this.JSign
//this.thetaJ = (this.PreSynapticNeuron.GetMembranePotential() > 0.0 ? this.J + (this.JSign * this.NoiseAmp * this.Jnoise.GetRandomFull()) : 0.0);
this.thetaJ = (this.PreSynapticNeuron.GetMembranePotential() > 0.0D ? this.GetJ() : 0.0D);
this.f = (1.0 - this.oneOverTau_f) * this.f + this.g;
this.g = (1.0 - this.oneOverTau_g) * this.g + this.thetaJ;
}
/// <summary>
/// gets the signal that this synapse generates (the f variable)
/// </summary>
/// <returns>f variable - a double value with the signal of this synapse</returns>
public override Double GetSignal()
{
return this.f;
}
/// <summary>
/// Resets output synaptic signal
/// </summary>
public override void ResetSignal()
{
this.f = 0.0D;
this.g = 0.0D;
}
}
/// <summary>
/// common class for all KT synapses
/// </summary>
public abstract class KTSynapse : ISynapse//FromPreSynaptic//<INeuron>/*, ISynapse*/
{
/// <summary>
/// the neuron which generates this synapse
/// </summary>
public INeuron PreSynapticNeuron { get; protected set; }
/// <summary>
/// the neuron which generates this synapse
/// </summary>
public INeuron PostSynapticNeuron { get; protected set; }
/// <summary>
/// parameter or variable - influence of the presyn neuron over its' neighbours
/// </summary>
public Double J { get; protected set; }
public Action Evolve { get; private set; }
/// <summary>
/// constructor of a KTSynapse
/// </summary>
/// <param name="nPre">the presynaptic neuron</param>
/// <param name="nPost">the postsynaptic neuron</param>
/// <param name="J">the coupling of the presynaptic neuron with its neighbours</param>
protected KTSynapse(INeuron nPre, INeuron nPost, Double J)
{
this.J = J;
this.PreSynapticNeuron = nPre;
this.PostSynapticNeuron = nPost;
this.Evolve = this.EvolveLocal;
}
/// <summary>
/// evaluating method - evaluates one timestep of this synapse
/// </summary>
public abstract void EvolveLocal();
/// <summary>
/// gets the signal that this synapse generates
/// </summary>
/// <returns>a double value with the signal of this synapse</returns>
public abstract Double GetSignal();
public Double GetCoupling()
{
return this.J;
}
/// <summary>
/// Resets output synaptic signal
/// </summary>
public abstract void ResetSignal();
}
/// <summary>
/// creates a Gap Junction synapse
/// according to:
/// Deterministic excitable media under Poisson drive: Power law responses,
/// spiral waves, and dynamic range
/// PHYSICAL REVIEW E77, 051911 (2008)
/// Tiago L. Ribeiro and Mauro Copelli
/// rectifying -> see Erik de Schutter book
/// </summary>
public class NoisyGapJunction : GapJunction
{
/// <summary>
/// random number to generate noise over J
/// </summary>
private HomogeneousRand Jnoise { get; set; }
/// <summary>
/// the bounds of the noise signal
/// </summary>
private Double NoiseAmp { get; set; }
/// <summary>
/// noisy gap junction synapse, Y = J * (Vpre - Vpost) [[ if rectifying, then Y is zero if Vpost>Vpre ]]
/// according to Erik de Schutter book
/// </summary>
/// <param name="nPre">the presynaptic neuron</param>
/// <param name="nPost">the postsynaptic neuron</param>
/// <param name="J">the coupling (conductance of the channel) of the presynaptic neuron with its neighbours</param>
/// <param name="noiseAmp">absolute amplitude of noise</param>
/// <param name="noiseRatio">fraction of J to use as noise amplitude</param>
/// <param name="seed">seed for random number generator</param>
/// <param name="nt">noise type parameter (must be enum)</param>
/// <param name="rectifying">if true, then only activates when the presynaptic potential is greater than postsynaptic potential</param>
/// <exception cref="ArgumentOutOfRangeException">thrown when unrecognized noise type</exception>
public NoisyGapJunction(INeuron nPre, INeuron nPost, Double J, Double noiseAmp, Double noiseRatio, UInt64 seed, NoiseType nt, bool rectifying=false)
: base(nPre, nPost, J, rectifying)
{
this.Jnoise = new HomogeneousRand(seed);
if (nt == NoiseType.ProportionalAmplitude)
{
this.NoiseAmp = Math.Abs(J * noiseRatio);
this.GetJ = this.GetJProportionalAmplitude;
}
else if (nt == NoiseType.GreaterThanJ)
{
this.NoiseAmp = Math.Abs(noiseAmp) * Math.Sign(J);
this.GetJ = this.GetJGreaterThanJ;
}
else
{
throw new ArgumentOutOfRangeException("Unrecognized NoiseType! " + nt.ToString());
}
}
/// <summary>
/// gets synaptic coupling
/// </summary>
/// <returns></returns>
public new Double GetCoupling()
{
return this.GetJ();
}
/// <summary>
/// returns the synaptic coupling with proportional amplitude noise
/// </summary>
/// <returns>synaptic coupling intensity</returns>
private Double GetJProportionalAmplitude()
{
return this.J + (this.NoiseAmp * (2.0D * this.Jnoise.GetRandomFull() - 1.0D));
}
/// <summary>
/// returns the synaptic coupling with free amplitude noise
/// </summary>
/// <returns>synaptic coupling intensity</returns>
private Double GetJGreaterThanJ()
{
return this.J + (this.NoiseAmp * this.Jnoise.GetRandomFull());
}
}
/// <summary>
/// creates a Gap Junction synapse
/// according to:
/// Deterministic excitable media under Poisson drive: Power law responses,
/// spiral waves, and dynamic range
/// PHYSICAL REVIEW E77, 051911 (2008)
/// Tiago L. Ribeiro and Mauro Copelli
/// rectifying -> see Erik de Schutter book
/// </summary>
public class GapJunction : ISynapse
{
/// <summary>
/// the presyn neuron
/// </summary>
public INeuron PreSynapticNeuron { get; private set; }
/// <summary>
/// the post syn neuron
/// </summary>
public INeuron PostSynapticNeuron { get; private set; }
/// <summary>
/// channel conductance
/// </summary>
public Double J { get; private set; }
/// <summary>
/// stores the state of the synapse according to neuron states in the previous timestep in order to correct interaction timing
/// </summary>
private Double f { get; set; }
/// <summary>
/// evolves 1 time step of this synapse
/// </summary>
public Action Evolve { get; private set; }
/// <summary>
/// gets current J value with noise
/// </summary>
protected Func<Double> GetJ { get; set; }
private Double dV { get; set; }
/// <summary>
/// noisy gap junction synapse, Y = J * (Vpre - Vpost) [[ if rectifying, then Y is zero if Vpost>Vpre ]]
/// according to Erik de Schutter book
/// </summary>
/// <param name="nPre">the presynaptic neuron</param>
/// <param name="nPost">the postsynaptic neuron</param>
/// <param name="J">the coupling (conductance of the channel) of the presynaptic neuron with its neighbours</param>
/// <param name="rectifying">if true, then only activates when the presynaptic potential is greater than postsynaptic potential</param>
public GapJunction(INeuron nPre, INeuron nPost, Double J, bool rectifying=false)
{
this.J = J;
this.PreSynapticNeuron = nPre;
this.PostSynapticNeuron = nPost;
this.f = 0.0;
if (rectifying)
{
this.Evolve = this.EvolveRectifying;
}
else
{
this.Evolve = this.EvolveNonRectifying;
}
this.GetJ = this.GetCoupling;
}
/// <summary>
/// evolve a rectifying gap junction -- Erik de Schutter book (Calabrese & Prinz, p.288)
/// </summary>
public void EvolveRectifying()
{
// I'm doing pre - post because of the "-" sign in the definition of Calabrese & Prinz, eq 12.1, book Computational Modeling for Neuroscientists, p. 286
// in this way, it must enter as a "+" term in the sum of currents of the "dV/dT" equation
// for the same reason, I inverted the sign to be < 0.0 in the condition check (instead of > 0.0)
dV = this.PreSynapticNeuron.GetMembranePotential() - this.PostSynapticNeuron.GetMembranePotential();
this.f = this.GetJ() * dV * (dV < 0.0D ? 0.0D : 1.0D);
}
/// <summary>
/// evolve a non-rectifying gap junction -- Erik de Schutter book (Calabrese & Prinz, p.288)
/// </summary>
public void EvolveNonRectifying()
{
// I'm doing pre - post because of the "-" sign in the definition of Calabrese & Prinz, eq 12.1, book Computational Modeling for Neuroscientists, p. 286
// in this way, it must enter as a "+" term in the sum of currents of the "dV/dT" equation
this.f = this.GetJ() * (this.PreSynapticNeuron.GetMembranePotential() - this.PostSynapticNeuron.GetMembranePotential());
}
/// <summary>
/// gets synaptic signal j->i
/// </summary>
/// <returns>J * (Vj - Vi)</returns>
public Double GetSignal()
{
return this.f;
}
public virtual Double GetCoupling()
{
return this.J;
}
/// <summary>
/// Resets output synaptic signal
/// </summary>
public void ResetSignal()
{
this.f = 0.0;
}
}
/// <summary>
/// pulse coupling
/// I(t) = J*V_pre
/// </summary>
public class NoisyPulseCoupling : PulseCoupling
{
/// <summary>
/// random number to generate noise over J
/// </summary>
private HomogeneousRand Jnoise { get; set; }
/// <summary>
/// the bounds of the noise signal
/// </summary>
private Double NoiseAmp { get; set; }
/// <summary>
/// pulse coupling
/// </summary>
/// <param name="nPre">presynaptic neuron</param>
/// <param name="J">conductance of the channel</param>
public NoisyPulseCoupling(INeuron nPre, Double J, Double noiseAmp, Double noiseRatio, UInt64 seed, NoiseType nt, bool normalizePulse = false)
: base(nPre, J, normalizePulse)
{
this.Jnoise = new HomogeneousRand(seed);
if (nt == NoiseType.ProportionalAmplitude)
{
this.NoiseAmp = Math.Abs(J * noiseRatio);
this.GetJ = this.GetJProportionalAmplitude;
}
else if (nt == NoiseType.GreaterThanJ)
{
this.NoiseAmp = Math.Abs(noiseAmp) * Math.Sign(J);
this.GetJ = this.GetJGreaterThanJ;
}
else
{
throw new ArgumentOutOfRangeException("Unrecognized NoiseType! " + nt.ToString());
}
}
/// <summary>
/// gets coupling intensity of this synapse
/// </summary>
/// <returns>coupling intensity</returns>
public new Double GetCoupling()
{
return this.GetJ();
}
/// <summary>
/// returns the synaptic coupling with proportional amplitude noise
/// </summary>
/// <returns>synaptic coupling intensity</returns>
private Double GetJProportionalAmplitude()
{
return this.J + (this.NoiseAmp * (2.0D * this.Jnoise.GetRandomFull() - 1.0D));
}
/// <summary>
/// returns the synaptic coupling with free amplitude noise
/// </summary>
/// <returns>synaptic coupling intensity</returns>
private Double GetJGreaterThanJ()
{
return this.J + (this.NoiseAmp * this.Jnoise.GetRandomFull());
}
}
/// <summary>
/// pulse coupling
/// I(t) = J*V_pre
/// </summary>
public class PulseCoupling : ISynapse
{
/// <summary>
/// a reference to the neuron which generates this synapse
/// </summary>
public INeuron PreSynapticNeuron { get; private set; }
/// <summary>
/// a reference to the neuron which reads this signal
/// </summary>
public INeuron PostSynapticNeuron { get; private set; }
/// <summary>
/// parameter - influence of the presyn neuron over its' neighbours
/// </summary>
public Double J { get; private set; }
/// <summary>
/// stores the state of the synapse according to neuron states in the previous timestep in order to correct interaction timing
/// </summary>
protected Double f { get; set; }
/// <summary>
/// Evolves 1 time step of this synapse
/// </summary>
public Action Evolve { get; private set; }
/// <summary>
/// gets current J value with noise
/// </summary>
protected Func<Double> GetJ { get; set; }
/// <summary>
/// pulse coupling
/// </summary>
/// <param name="nPre">presynaptic neuron</param>
/// <param name="J">conductance of the channel</param>
public PulseCoupling(INeuron nPre, Double J, bool normalizePulse = false)
{
this.PreSynapticNeuron = nPre;
this.J = J;
this.f = 0.0;
if (normalizePulse)
{
this.Evolve = this.EvolveLocalNormalized;
}
else
{
this.Evolve = this.EvolveLocal;
}
this.GetJ = this.GetCoupling;
}
/// <summary>
/// evaluates one timestep of this synapse
/// considering a spike input (1=spike, 0=no spike)
/// </summary>
public void EvolveLocalNormalized()
{
this.f = this.GetJ() * (this.PreSynapticNeuron.GetMembranePotential()>0.0?1.0D:0.0D);
}
/// <summary>
/// evaluates one timestep of this synapse
/// considering a membrane potential input
/// </summary>
public void EvolveLocal()
{
this.f = this.GetJ() * this.PreSynapticNeuron.GetMembranePotential();
}
/// <summary>
/// gets the signal that this synapse generates
/// </summary>
/// <returns>a double value with the signal of this synapse</returns>
public Double GetSignal()
{
return this.f;
}
/// <summary>
/// gets coupling intensity of this synapse
/// </summary>
/// <returns>coupling intensity</returns>
public virtual Double GetCoupling()
{
return this.J;
}
/// <summary>
/// Resets output synaptic signal
/// </summary>
public void ResetSignal()
{
this.f = 0.0;
}
}
public interface ISynapse
{
/// <summary>
/// a reference to the neuron which generates this synapse
/// </summary>
INeuron PreSynapticNeuron { get; }
/// <summary>
/// a reference to the neuron which reads this signal
/// </summary>
INeuron PostSynapticNeuron { get; }
/// <summary>
/// parameter - influence of the presyn neuron over its' neighbours
/// </summary>
Double J { get; }
/// <summary>
/// evaluates one timestep of this synapse
/// </summary>
Action Evolve { get; }
/// <summary>
/// gets the signal that this synapse generates
/// </summary>
/// <returns>a double value with the signal of this synapse</returns>
Double GetSignal();
/// <summary>
/// gets the coupling intensity (J) of this synapse
/// </summary>
/// <returns>value of J parameter</returns>
Double GetCoupling();
/// <summary>
/// Resets output synaptic signal
/// </summary>
void ResetSignal();
}
}