-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKTzV2_Neurons.cs
1491 lines (1341 loc) · 52.2 KB
/
KTzV2_Neurons.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
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using KTzV2.Synapses;
namespace KTzV2.Neurons
{
public enum NeuronType
{
KTH,
KTHLog,
KTz,
KTzLog,
KTz2Tanh,
KTzMF,
KTzLogMF,
SIElement,
GLNeuron,
GLNeuronLHG,
GLNeuronLHG1Par,
GLNeuronFacilitation,
GLNeuronGammaStochastic
}
public class NeuronParam
{
public Int32 ind { get; private set; }
public Double K { get; private set; }
public Double T { get; private set; }
public Double d { get; private set; }
public Double l { get; private set; }
public Double xR { get; private set; }
public Double H { get; private set; }
public Double Q { get; private set; }
public Double x0 { get; private set; }
public Double y0 { get; private set; }
public Double z0 { get; private set; }
public Double Theta { get; private set; }
public Double VB { get; private set; }
public Double VR { get; private set; }
public Double VT { get; private set; }
public Double mu { get; private set; }
public Double tau1 { get; private set; }
public Double Gamma1 { get; private set; }
public Double tau0 { get; private set; }
public Double Gamma0 { get; private set; }
public Double Gamma_init { get; private set; }
public Double V0 { get; private set; }
public Double pS { get; private set; }
public Double pR { get; private set; }
public Boolean normalizeInput { get; private set; }
public UInt64? seed { get; private set; }
/// <param name="ind">index of the neuron inside a network</param>
/// <param name="K">parameter K</param>
/// <param name="T">parameter T</param>
/// <param name="d">parameter delta</param>
/// <param name="l">parameter lambda</param>
/// <param name="xR">parameter xR</param>
/// <param name="H">parameter H</param>
/// <param name="Theta">Threshold for SIElement</param>
/// <param name="x_init">initial value of x</param>
/// <param name="y_init">initial value of y</param>
/// <param name="z_init">initial value of z</param>
public NeuronParam(Int32 ind, Double K, Double T, Double d, Double l, Double xR, Double H, Double x_init, Double y_init, Double z_init, Double Theta,
Double tau0 = 0, Double Gamma0 = 0, Double tau1 = 0, Double Gamma1 = 0, Double pS = 0, Double pR = 0, Double VR = 0, Double VT = 0, Double VB = 0,
Double mu = 0, Double V_init = 0, Double Gamma_init = 0, Boolean normalizeInput = false, UInt64? seed = null,Double Q = 0.0D)
{
this.ind = ind;
this.K = K;
this.T = T;
this.d = d;
this.l = l;
this.xR = xR;
this.H = H;
this.Q = Q;
this.x0 = x_init;
this.y0 = y_init;
this.z0 = z_init;
this.Theta = Theta;
this.tau0 = tau0;
this.Gamma0 = Gamma0;
this.tau1 = tau1;
this.Gamma1 = Gamma1;
this.pS = pS;
this.pR = pR;
this.VR = VR;
this.VT = VT;
this.VB = VB;
this.mu = mu;
this.V0 = V_init;
this.Gamma_init = Gamma_init;
this.normalizeInput = normalizeInput;
this.seed = seed;
}
}
public static class NeuronFactory
{
public static INeuron GetKTNeuron(NeuronType neuron, NeuronParam par)
{
switch (neuron)
{
case NeuronType.KTH:
return new KTSimple(par.ind, par.K, par.T, par.H, par.x0, par.y0, par.normalizeInput);
case NeuronType.KTHLog:
return new KTLogSimple(par.ind, par.K, par.T, par.H, par.x0, par.y0, par.normalizeInput);
case NeuronType.KTz:
return new KTzNeuron(par.ind, par.K, par.T, par.d, par.l, par.xR, par.x0, par.y0, par.z0, par.normalizeInput);
case NeuronType.KTz2Tanh:
return new KTz2Tanh(par.ind, par.K, par.T, par.d, par.l, par.xR, par.H, par.Q, par.x0, par.y0, par.z0, par.normalizeInput);
case NeuronType.KTzLog:
return new KTzLogNeuron(par.ind, par.K, par.T, par.d, par.l, par.xR, par.x0, par.y0, par.z0, par.normalizeInput);
/*
case NeuronType.KTzMF:
return new KTzNeuronAvgInp(par.ind, par.K, par.T, par.d, par.l, par.xR, par.x0, par.y0, par.z0);
case NeuronType.KTzLogMF:
return new KTzLogNeuronAvgInp(par.ind, par.K, par.T, par.d, par.l, par.xR, par.x0, par.y0, par.z0);
*/
case NeuronType.SIElement:
return new SIElement(par.ind, par.Theta, par.x0);
case NeuronType.GLNeuron:
return new GLNeuronLogistic(par.ind, par.VR, par.VT, par.VB, par.mu, par.x0, par.V0, par.Gamma_init, par.normalizeInput, par.seed);
case NeuronType.GLNeuronLHG:
return new GLNeuronAdaptable(par.ind, 0.0D, 1.0D / par.tau0, 0.0D, par.tau1, par.Gamma1, par.VR, par.VT, par.VB, par.mu, par.x0, par.V0, par.Gamma_init, par.normalizeInput, par.seed);
case NeuronType.GLNeuronLHG1Par:
return new GLNeuronAdaptable(par.ind, 0.0D, 1.0D, 0.0D, -par.tau1, 0.0D, par.VR, par.VT, par.VB, par.mu, par.x0, par.V0, par.Gamma_init, par.normalizeInput, par.seed);
case NeuronType.GLNeuronFacilitation:
return new GLNeuronAdaptable(par.ind, 1.0D, par.tau0, par.Gamma0, par.tau1, par.Gamma1, par.VR, par.VT, par.VB, par.mu, par.x0, par.V0, par.Gamma_init, par.normalizeInput, par.seed);
case NeuronType.GLNeuronGammaStochastic:
return new GLNeuronGammaStochastic(par.ind, par.pR, par.Gamma0, par.pS, par.Gamma1, par.VR, par.VT, par.VB, par.mu, par.x0, par.V0, par.Gamma_init, par.normalizeInput, par.seed);
default:
throw new ArgumentOutOfRangeException("Unrecognized neuron type! " + neuron.ToString());
}
}
}
public class GLNeuronAdaptable : GLNeuronLogistic
{
/// <summary>
/// growth time constant of Gamma
/// </summary>
public Double iTau1 { get; protected set; }
/// <summary>
/// Gamma superior asymptotic value
/// </summary>
public Double Gamma1 { get; protected set; }
/// <summary>
/// decay time constant of Gamma
/// </summary>
public Double iTau0 { get; protected set; }
/// <summary>
/// Gamma inferior asymptotic value
/// </summary>
public Double Gamma0 { get; protected set; }
/// <summary>
/// dynamic selector (delta == 0 -> LHG-like, delta == 1 -> Facilitation)
/// </summary>
public Double delta { get; protected set; }
public GLNeuronAdaptable(Int32 ind, Double delta, Double tau0, Double Gamma0, Double tau1, Double Gamma1, Double VR, Double VT, Double VB, Double mu, Double x_init, Double V_init, Double Gamma_init, Boolean normalizeInput = false, UInt64? seed = null)
: base(ind, VR, VT, VB, mu, x_init, V_init, Gamma_init, normalizeInput, seed)
{
this.delta = delta;
this.iTau1 = 1 / tau1;
this.iTau0 = 1 / tau0;
this.Gamma1 = Gamma1;
this.Gamma0 = Gamma0;
}
/// <summary>
/// evaluates all this neuron's variables for one timestep
/// </summary>
public override void Evolve()
{
this.Evolve(0.0D);
}
/// <summary>
/// evaluates this neuron's dynamical variables with external stimulus I
/// </summary>
/// <param name="I">the external stimulus on the membrane potential</param>
public override void Evolve(Double I)
{
this.Gamma = this.Gamma + this.iTau1 * (this.Gamma1 - this.Gamma) * (this.delta * this.x + 1 - this.delta) - this.iTau0 * (this.Gamma - this.Gamma0) * ((1 - this.delta) * this.x + this.delta);
base.Evolve(I);
}
}
public class GLNeuronGammaStochastic : GLNeuronLogistic
{
/// <summary>
/// seizure probability (p of setting Gamma == Gamma1)
/// </summary>
public Double pS { get; protected set; }
/// <summary>
/// Gamma superior asymptotic value
/// </summary>
public Double Gamma1 { get; protected set; }
/// <summary>
/// recovery probability (p of setting Gamma == Gamma0)
/// </summary>
public Double pR { get; protected set; }
/// <summary>
/// Gamma inferior asymptotic value
/// </summary>
public Double Gamma0 { get; protected set; }
/// <summary>
/// random number to decide state of Gamma
/// </summary>
private KTzV2.Maths.Random.HomogeneousRand randG { get; set; }
public GLNeuronGammaStochastic(Int32 ind, Double pR, Double Gamma0, Double pS, Double Gamma1, Double VR, Double VT, Double VB, Double mu, Double x_init, Double V_init, Double Gamma_init, Boolean normalizeInput = false, UInt64? seed = null)
: base(ind, VR, VT, VB, mu, x_init, V_init, Gamma_init, normalizeInput, seed)
{
this.pS = pS;
this.pR = pR;
this.Gamma1 = Gamma1;
this.Gamma0 = Gamma0;
UInt64 s = getSpecificSeed(pS, pR, Gamma0, Gamma1);
if (seed.HasValue)
this.randG = new KTzV2.Maths.Random.HomogeneousRand(seed.Value + s + (UInt64)ind);
else
this.randG = new KTzV2.Maths.Random.HomogeneousRand(Convert.ToUInt64(DateTime.Now.Ticks) + s + (UInt64)ind);
}
private UInt64 getSpecificSeed(Double a, Double b, Double c, Double d)
{
String s = a.ToString("0.0000000000E+000") + b.ToString("0.0000000000E+000") + c.ToString("0.0000000000E+000") + d.ToString("0.0000000000E+000");
System.Security.Cryptography.MD5 m = System.Security.Cryptography.MD5.Create();
m.Initialize();
m.ComputeHash(System.Text.Encoding.UTF8.GetBytes(s));
return UInt64.Parse(m.Hash.ToString().Substring(0, 16), System.Globalization.NumberStyles.HexNumber) + UInt64.Parse(m.Hash.ToString().Substring(16), System.Globalization.NumberStyles.HexNumber);
}
/// <summary>
/// evaluates all this neuron's variables for one timestep
/// </summary>
public override void Evolve()
{
this.Evolve(0.0D);
}
/// <summary>
/// evaluates this neuron's dynamical variables with external stimulus I
/// </summary>
/// <param name="I">the external stimulus on the membrane potential</param>
public override void Evolve(Double I)
{
Double rS = this.randG.GetRandomFull();
if (rS < this.pS) // transition to seizure state
this.Gamma = this.Gamma1;
else if ((rS >= this.pS) && (rS < (this.pS+this.pR))) // transition to healthy state
this.Gamma = this.Gamma0;
base.Evolve(I);
}
}
/// <summary>
/// GL Neuron unit using the function phi = (Gamma*V)/(1+Gamma*V)
/// </summary>
public class GLNeuronLogistic : StochasticGLElement
{
public GLNeuronLogistic(Int32 ind, Double VR, Double VT, Double VB, Double mu, Double x_init, Double V_init, Double Gamma_init, Boolean normalizeInput = false, UInt64? seed = null)
: base(ind,VR,VT,VB,mu,x_init,V_init,Gamma_init,normalizeInput,seed)
{
}
/// <summary>
/// Logistic firing probability
/// </summary>
/// <param name="V">membrane potential</param>
/// <returns></returns>
protected override Double FiringProbability(double V)
{
return this.Gamma * (this.V - this.VT) * (this.V > this.VT? 1.0D : 0.0D) / (1.0D + this.Gamma * (this.V - this.VT));
}
/// <summary>
/// evaluates all this neuron's variables for one timestep
/// </summary>
public override void Evolve()
{
this.SumInputSignal(); // sums up to this.Isyn
if (this.x == 0)
{
this.V = this.mu * (this.V - this.VB) + this.VB + this.Isyn;
}
else
{
this.V = this.VR;
}
this.x = (this.rand.GetRandomFull() < this.FiringProbability(this.V) ? 1.0D : 0.0D);
}
/// <summary>
/// evaluates this neuron's dynamical variables with external stimulus I
/// </summary>
/// <param name="I">the external stimulus on the membrane potential</param>
public override void Evolve(Double I)
{
this.SumInputSignal(); // sums up to this.Isyn
if (this.x == 0)
{
this.V = this.mu * (this.V - this.VB) + this.VB + this.Isyn + I;
}
else
{
this.V = this.VR;
}
this.x = (this.rand.GetRandomFull() < this.FiringProbability(this.V) ? 1.0D : 0.0D);
}
}
public abstract class StochasticGLElement : INeuron
{
/// <summary>
/// the index of this neuron (a number that identifies it within a network)
/// </summary>
public Int32 Index { get; protected set; }
/// <summary>
/// the list of this neuron's neighbours (only the ones that influences this one)
/// </summary>
public List<ISynapse> Input { get; private set; }
/// <summary>
/// the sum over all neighbours output signals
/// </summary>
public Double Isyn { get; private set; }
/// <summary>
/// the sum over all neighbours connection weight
/// </summary>
public Double TotalInputWeight { get; private set; }
/// <summary>
/// if normalizeInput == true, then the input signal is divided by TotalInputWeight
/// </summary>
public Boolean normalizeInput { get; private set; }
/// <summary>
/// state variable (0 or 1)
/// </summary>
public Double x { get; protected set; }
/// <summary>
/// membrane potential used to calculate firing probability
/// </summary>
public Double V { get; protected set; }
/// <summary>
/// Gain of the firing probability (parameter or variable)
/// </summary>
public Double Gamma { get; protected set; }
/// <summary>
/// Time constant for V integration
/// </summary>
public Double mu { get; protected set; }
/// <summary>
/// Baseline potential (if no activity, V = VB)
/// </summary>
public Double VB { get; protected set; }
/// <summary>
/// Reset potential (V = VR if neuron spikes)
/// </summary>
public Double VR { get; protected set; }
/// <summary>
/// Firing threshold
/// </summary>
public Double VT { get; protected set; }
protected KTzV2.Maths.Random.HomogeneousRand rand { get; private set; }
/// <summary>
/// creates a stochastic neuron of the Galves-Locherbach type
/// </summary>
/// <param name="ind">index of this neuron in the network</param>
/// <param name="VR">reset membrane potential</param>
/// <param name="VT">threshold</param>
/// <param name="VB">baseline potential</param>
/// <param name="mu">dissipation constant</param>
/// <param name="x_init">spike variable Init condition</param>
/// <param name="V_init">membrane potential initial condition</param>
/// <param name="Gamma_init">initial value for gain constant</param>
/// <param name="normalizeInput">chooses to normalize input</param>
/// <param name="seed">seed for random number generator</param>
protected StochasticGLElement(Int32 ind, Double VR, Double VT, Double VB, Double mu, Double x_init, Double V_init, Double Gamma_init, Boolean normalizeInput = false, UInt64? seed = null)
{
this.Index = ind;
this.x = x_init;
this.V = V_init;
this.Gamma = Gamma_init;
this.VB = VB;
this.VR = VR;
this.VT = VT;
this.mu = mu;
this.normalizeInput = normalizeInput;
this.SetTotalInputWeight();
if (seed.HasValue)
this.rand = new KTzV2.Maths.Random.HomogeneousRand(seed.Value + (UInt64)this.Index);
else
this.rand = new KTzV2.Maths.Random.HomogeneousRand(Convert.ToUInt64(DateTime.Now.Ticks) + (UInt64)this.Index);
this.Input = new List<ISynapse>();
}
/// <summary>
/// Phi(V) function that gives the firing probability
/// </summary>
/// <param name="V">membrane potential</param>
/// <returns>firing probability</returns>
protected abstract Double FiringProbability(Double V);
private void SetTotalInputWeight()
{
this.TotalInputWeight = 1.0D;
if (this.normalizeInput)
{
Int32 i = 0;
while (i < this.Input.Count)
{
this.TotalInputWeight += this.Input[i].GetCoupling();
i++;
}
}
}
/// <summary>
/// initializes the neighbours with the specified list
/// </summary>
/// <param name="s">the list of input synapses</param>
public void AddInput(List<ISynapse> s)
{
this.Input = s;
this.SetTotalInputWeight();
}
/// <summary>
/// adds a neighbour to this neuron...
/// </summary>
/// <param name="s">the input synapse</param>
public void AddInput(ISynapse s)
{
this.Input.Add(s);
this.SetTotalInputWeight();
}
/// <summary>
/// sums all the neighbours output signals and stores it at this.Isyn
/// </summary>
protected void SumInputSignal()
{
Int32 i = 0, n = this.Input.Count;
this.Isyn = 0.0;
while (i < n)
{
this.Isyn += this.Input[i].GetSignal();
i++;
}
}
/// <summary>
/// returns the membrane potential of the neuron
/// </summary>
/// <returns>this neuron membrane potential</returns>
public Double GetMembranePotential()
{
return this.x;
}
/// <summary>
/// evaluates all this neuron's variables for one timestep
/// </summary>
public abstract void Evolve();
/// <summary>
/// evaluates this neuron's dynamical variables with external stimulus I
/// </summary>
/// <param name="I">the external stimulus on the membrane potential</param>
public abstract void Evolve(Double I);
/// <summary>
/// resets neuron variables to the values contained in ic array
/// </summary>
/// <param name="ic">new values for neurons variables</param>
public virtual void ResetIC(Double[] ic)
{
this.x = ic[0];
}
public virtual bool SpikeDetector()
{
return this.x == 1.0;
}
/// <summary>
/// checks if x corresponds to a spike
/// </summary>
/// <param name="x">membrane potential</param>
/// <param name="x_previous">previous membrane potential</param>
/// <returns>true if there is a spike</returns>
public virtual bool SpikeDetector(Double x, Double x_previous)
{
return x == 1.0;
}
}
/// <summary>
/// implements the neuron of the reference A simple model for excitable and bursting elements
/// </summary>
public class KTz2Tanh : KTSimple
{
/// <summary>
/// parameter delta
/// </summary>
public Double d { get; private set; }
/// <summary>
/// parameter lambda
/// </summary>
public Double l { get; private set; }
/// <summary>
/// parameter x_R
/// </summary>
public Double xR { get; private set; }
/// <summary>
/// parameter H external field in Y
/// </summary>
public new Double H { get; private set; }
/// <summary>
/// parameter Q external field in X
/// </summary>
public Double Q { get; private set; }
/// <summary>
/// dynamical variable z
/// </summary>
public Double z { get; private set; }
/// <summary>
/// initial value of the variable z
/// </summary>
public Double z_init { get; private set; }
/// <summary>
/// KTzLogNeuron constructor
/// </summary>
/// <param name="K">parameter K</param>
/// <param name="T">parameter T</param>
/// <param name="d">parameter delta</param>
/// <param name="l">parameter lambda</param>
/// <param name="xR">parameter xR</param>
/// <param name="H">parameter H external field in Y</param>
/// <param name="Q">parameter Q external field in X</param>
/// <param name="x_init">initial value of x</param>
/// <param name="y_init">initial value of y</param>
/// <param name="z_init">initial value of z</param>
public KTz2Tanh(Int32 ind, Double K, Double T, Double d, Double l, Double xR, Double H, Double Q, Double x_init, Double y_init, Double z_init, bool normalizeInput)
: base(ind,K,T,H,x_init,y_init, normalizeInput)
{
this.d = d;
this.l = l;
this.xR = xR;
this.H = H;
this.Q = Q;
this.z_init = this.z = z_init;
}
/// <summary>
/// evaluates this neuron for one timestep
/// </summary>
public override void Evolve()
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = Math.Tanh((this.x - this.K * this.y + this.z + this.Q + this.Isyn) / this.T);
this.y = Math.Tanh((this.x_prev + this.H)/this.T);
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// evaluates this neuron one timestep with an external stimulus I
/// </summary>
/// <param name="I">external stimulus</param>
public override void Evolve(Double I)
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = Math.Tanh((this.x - this.K * this.y + this.z + this.Q + this.Isyn + I) / this.T);
this.y = Math.Tanh((this.x_prev + this.H) / this.T);
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// resets neuron variables to the values contained in ic array
/// </summary>
/// <param name="ic">new values for neurons variables</param>
public override void ResetIC(Double[] ic)
{
base.ResetIC(ic);
this.z_init = ic[2];
this.z = ic[2];
}
}
/// <summary>
/// implements the neuron of the reference A simple model for excitable and bursting elements
/// </summary>
public class KTzLogNeuron : KTNeuron
{
/// <summary>
/// parameter delta
/// </summary>
public Double d { get; private set; }
/// <summary>
/// parameter lambda
/// </summary>
public Double l { get; private set; }
/// <summary>
/// parameter x_R
/// </summary>
public Double xR { get; private set; }
/// <summary>
/// dynamical variable z
/// </summary>
public Double z { get; private set; }
/// <summary>
/// initial value of the variable z
/// </summary>
public Double z_init { get; private set; }
/// <summary>
/// KTzLogNeuron constructor
/// </summary>
/// <param name="K">parameter K</param>
/// <param name="T">parameter T</param>
/// <param name="d">parameter delta</param>
/// <param name="l">parameter lambda</param>
/// <param name="xR">parameter xR</param>
/// <param name="x_init">initial value of x</param>
/// <param name="y_init">initial value of y</param>
/// <param name="z_init">initial value of z</param>
public KTzLogNeuron(Int32 ind, Double K, Double T, Double d, Double l, Double xR, Double x_init, Double y_init, Double z_init, bool normalizeInput)
: base(ind, K, T, x_init, y_init, normalizeInput)
{
this.d = d;
this.l = l;
this.xR = xR;
this.z_init = this.z = z_init;
}
private Double logFun(Double u)
{
return u / (1 + (u > 0.0D ? u : -u));
}
/// <summary>
/// evaluates this neuron for one timestep
/// </summary>
public override void Evolve()
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = logFun((this.x - this.K * this.y + this.z + this.Isyn) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// evaluates this neuron one timestep with an external stimulus I
/// </summary>
/// <param name="I">external stimulus</param>
public override void Evolve(Double I)
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = logFun((this.x - this.K * this.y + this.z + this.Isyn + I) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// resets neuron variables to the values contained in ic array
/// </summary>
/// <param name="ic">new values for neurons variables</param>
public override void ResetIC(Double[] ic)
{
base.ResetIC(ic);
this.z_init = ic[2];
this.z = ic[2];
}
}
/// <summary>
/// implements the neuron of the reference A simple model for excitable and bursting elements
/// </summary>
public class KTzNeuron : KTNeuron
{
/// <summary>
/// parameter delta
/// </summary>
public Double d { get; private set; }
/// <summary>
/// parameter lambda
/// </summary>
public Double l { get; private set; }
/// <summary>
/// parameter x_R
/// </summary>
public Double xR { get; private set; }
/// <summary>
/// dynamical variable z
/// </summary>
public Double z { get; private set; }
/// <summary>
/// initial value of the variable z
/// </summary>
public Double z_init { get; private set; }
/// <summary>
/// KTzNeuron constructor
/// </summary>
/// <param name="K">parameter K</param>
/// <param name="T">parameter T</param>
/// <param name="d">parameter delta</param>
/// <param name="l">parameter lambda</param>
/// <param name="xR">parameter xR</param>
/// <param name="x_init">initial value of x</param>
/// <param name="y_init">initial value of y</param>
/// <param name="z_init">initial value of z</param>
public KTzNeuron(Int32 ind, Double K, Double T, Double d, Double l, Double xR, Double x_init, Double y_init, Double z_init, bool normalizeInput)
: base(ind, K, T, x_init, y_init, normalizeInput)
{
this.d = d;
this.l = l;
this.xR = xR;
this.z_init = this.z = z_init;
}
/// <summary>
/// evaluates this neuron for one timestep
/// </summary>
public override void Evolve()
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = Math.Tanh((this.x - this.K * this.y + this.z + this.Isyn) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// evaluates this neuron one timestep with an external stimulus I
/// </summary>
/// <param name="I">external stimulus</param>
public override void Evolve(Double I)
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = Math.Tanh((this.x - this.K * this.y + this.z + this.Isyn + I) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// resets neuron variables to the values contained in ic array
/// </summary>
/// <param name="ic">new values for neurons variables</param>
public override void ResetIC(Double[] ic)
{
base.ResetIC(ic);
this.z_init = ic[2];
this.z = ic[2];
}
}
/// <summary>
/// implements the neuron of the reference A simple model for excitable and bursting elements with average input
/// </summary>
/*public class KTzLogNeuronAvgInp : KTNeuron
{
/// <summary>
/// parameter delta
/// </summary>
public Double d { get; private set; }
/// <summary>
/// parameter lambda
/// </summary>
public Double l { get; private set; }
/// <summary>
/// parameter x_R
/// </summary>
public Double xR { get; private set; }
/// <summary>
/// dynamical variable z
/// </summary>
public Double z { get; private set; }
/// <summary>
/// initial value of the variable z
/// </summary>
public Double z_init { get; private set; }
/// <summary>
/// KTzLogNeuronAvgInp constructor
/// </summary>
/// <param name="K">parameter K</param>
/// <param name="T">parameter T</param>
/// <param name="d">parameter delta</param>
/// <param name="l">parameter lambda</param>
/// <param name="xR">parameter xR</param>
/// <param name="x_init">initial value of x</param>
/// <param name="y_init">initial value of y</param>
/// <param name="z_init">initial value of z</param>
public KTzLogNeuronAvgInp(Int32 ind, Double K, Double T, Double d, Double l, Double xR, Double x_init, Double y_init, Double z_init)
: base(ind, K, T, x_init, y_init)
{
this.d = d;
this.l = l;
this.xR = xR;
this.z_init = this.z = z_init;
}
private Double logFun(Double u)
{
return u / (1 + (u > 0.0D ? u : -u));
}
/// <summary>
/// evaluates this neuron for one timestep
/// </summary>
public override void Evolve()
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = logFun((this.x - this.K * this.y + this.z + this.Isyn / this.Input.Count) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// evaluates this neuron one timestep with an external stimulus I
/// </summary>
/// <param name="I">external stimulus</param>
public override void Evolve(Double I)
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = logFun((this.x - this.K * this.y + this.z + I + this.Isyn / this.Input.Count) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// resets neuron variables to the values contained in ic array
/// </summary>
/// <param name="ic">new values for neurons variables</param>
public override void ResetIC(Double[] ic)
{
base.ResetIC(ic);
this.z_init = ic[2];
this.z = ic[2];
}
}/**/
/// <summary>
/// implements the neuron of the reference A simple model for excitable and bursting elements with average input
/// </summary>
/*public class KTzNeuronAvgInp : KTNeuron
{
/// <summary>
/// parameter delta
/// </summary>
public Double d { get; private set; }
/// <summary>
/// parameter lambda
/// </summary>
public Double l { get; private set; }
/// <summary>
/// parameter x_R
/// </summary>
public Double xR { get; private set; }
/// <summary>
/// dynamical variable z
/// </summary>
public Double z { get; private set; }
/// <summary>
/// initial value of the variable z
/// </summary>
public Double z_init { get; private set; }
/// <summary>
/// KTzNeuron constructor
/// </summary>
/// <param name="K">parameter K</param>
/// <param name="T">parameter T</param>
/// <param name="d">parameter delta</param>
/// <param name="l">parameter lambda</param>
/// <param name="xR">parameter xR</param>
/// <param name="x_init">initial value of x</param>
/// <param name="y_init">initial value of y</param>
/// <param name="z_init">initial value of z</param>
public KTzNeuronAvgInp(Int32 ind, Double K, Double T, Double d, Double l, Double xR, Double x_init, Double y_init, Double z_init)
: base(ind, K, T, x_init, y_init)
{
this.d = d;
this.l = l;
this.xR = xR;
this.z_init = this.z = z_init;
}
/// <summary>
/// evaluates this neuron for one timestep
/// </summary>
public override void Evolve()
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = Math.Tanh((this.x - this.K * this.y + this.z + this.Isyn / this.Input.Count) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// evaluates this neuron one timestep with an external stimulus I
/// </summary>
/// <param name="I">external stimulus</param>
public override void Evolve(Double I)
{
this.SumInputSignal();
this.x_prev = this.x;
this.x = Math.Tanh((this.x - this.K * this.y + this.z + I + this.Isyn / this.Input.Count) / this.T);
this.y = this.x_prev;
this.z = (1.0 - this.d) * this.z - this.l * (this.x_prev - this.xR);
}
/// <summary>
/// resets neuron variables to the values contained in ic array
/// </summary>
/// <param name="ic">new values for neurons variables</param>
public override void ResetIC(Double[] ic)
{
base.ResetIC(ic);
this.z_init = ic[2];
this.z = ic[2];
}
}/**/
/// <summary>
/// implements the neuron of the reference Modeling Neurons by Simple Maps
/// </summary>
public class KTLogSimple : KTNeuron
{
/// <summary>
/// parameter H
/// </summary>
public Double H { get; private set; }
/// <summary>
/// KTLogSimple constructor
/// </summary>
/// <param name="K">K parameter</param>
/// <param name="T">T parameter</param>
/// <param name="H">H parameter</param>
/// <param name="x_init">x (membrane potential) initial value</param>
/// <param name="y_init">y (recurrent variable) initial value</param>
public KTLogSimple(Int32 ind, Double K, Double T, Double H, Double x_init, Double y_init, bool normalizeInput)
: base(ind, K, T, x_init, y_init, normalizeInput)
{
this.H = H;
}
private Double logFun(Double u)
{
return u / (1 + (u > 0.0D ? u : -u));
}
/// <summary>
/// evaluates this neuron for one timestep
/// </summary>
public override void Evolve()
{