-
Notifications
You must be signed in to change notification settings - Fork 1
/
AGLIF_model_nest.patch
1649 lines (1648 loc) · 56 KB
/
AGLIF_model_nest.patch
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
diff --git a/models/CMakeLists.txt b/models/CMakeLists.txt
index 01012b56a..37fb79c10 100644
--- a/models/CMakeLists.txt
+++ b/models/CMakeLists.txt
@@ -78,6 +78,7 @@ set( models_sources
iaf_psc_exp_ps.cpp iaf_psc_exp_ps.h
iaf_psc_exp_ps_lossless.cpp iaf_psc_exp_ps_lossless.h
izhikevich.h izhikevich.cpp
+ migliore.h migliore.cpp
jonke_synapse.h
lin_rate.h lin_rate.cpp
mat2_psc_exp.h mat2_psc_exp.cpp
diff --git a/models/migliore.cpp b/models/migliore.cpp
new file mode 100644
index 000000000..ba597ea27
--- /dev/null
+++ b/models/migliore.cpp
@@ -0,0 +1,1033 @@
+/*
+ * migliore.cpp
+ *
+ * This file is part of NEST.
+ *
+ * Copyright (C) 2004 The NEST Initiative
+ *
+ * NEST is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * NEST is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NEST. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "migliore.h"
+
+// C++ includes:
+#include <limits>
+
+// Includes from libnestutil:
+#include "dict_util.h"
+#include "numerics.h"
+#include "propagator_stability.h"
+
+// Includes from nestkernel:
+//#include "event_delivery_manager_impl.h"
+#include "exceptions.h"
+#include "kernel_manager.h"
+#include "universal_data_logger_impl.h"
+
+// Includes from sli:
+#include "dict.h"
+#include "dictutils.h"
+#include "doubledatum.h"
+#include "integerdatum.h"
+
+/* ----------------------------------------------------------------
+ * Recordables map
+ * ---------------------------------------------------------------- */
+
+//nest::RecordablesMap< nest::migliore > nest::migliore::recordablesMap_;
+
+namespace nest
+{
+ // Override the create() method with one call to RecordablesMap::insert_()
+ // for each quantity to be recorded.
+ template <>
+ void
+ DynamicRecordablesMap< migliore >::create( migliore& host )
+ {
+ // use standard names wherever you can for consistency!
+ insert( names::V_m, host.get_data_access_functor( migliore::State_::V_M ) );
+ // insert( names::I, host.get_data_access_functor( migliore::State_::I ) );
+ insert( names::I_syn, host.get_data_access_functor( migliore::State_::I_ve ) );
+
+ insert( names::Iadap_ini, host.get_data_access_functor( migliore::State_::Iadap ) );
+ insert( names::Idep_ini, host.get_data_access_functor( migliore::State_::Idep ) );
+
+ host.insert_current_recordables();
+ }
+ // void
+ // RecordablesMap< migliore >::create()
+ // {
+ // // use standard names whereever you can for consistency!
+ // insert_( names::V_m, &migliore::get_V_m_ );
+ // insert_( names::I, &migliore::get_I_inj_ );
+ // insert_( names::init_sign, &migliore::get_init_sign_ );
+ // insert_( names::Iadap_ini, &migliore::get_Iadap_ini_ );
+ // insert_( names::Idep_ini, &migliore::get_Idep_ini_ );
+ // insert_( names::sis, &migliore::get_sis_ );
+ // insert_( names::I_syn, &migliore::get_I_syn_ );
+ // }
+
+
+ Name
+ nest::migliore::get_i_syn_name( size_t elem )
+ {
+ std::stringstream i_syn_name;
+ i_syn_name << "I_syn_" << elem + 1;
+ return Name( i_syn_name.str() );
+ }
+
+ void
+ migliore::insert_current_recordables( size_t first )
+ {
+ // std::cout << "migliore taus syn size " << P_.tau_syn_.size() << "\n";
+ for ( size_t receptor = first; receptor < P_.tau_syn_.size(); ++receptor )
+ {
+ size_t elem = migliore::State_::I_SYN
+ + receptor * migliore::State_::NUM_STATE_ELEMENTS_PER_RECEPTOR;
+ Name a = get_i_syn_name( receptor );
+ recordablesMap_.insert( a , this->get_data_access_functor( elem ) );
+ }
+ }
+
+ DataAccessFunctor< migliore >
+ migliore::get_data_access_functor( size_t elem )
+ {
+ return DataAccessFunctor< migliore >( *this, elem );
+ }
+
+ /* ----------------------------------------------------------------
+ * Default constructors defining default parameters and state
+ * ---------------------------------------------------------------- */
+
+ nest::migliore::Parameters_::Parameters_()
+ : E_L_( -72.5 )
+ , vres_( -65.0 )
+ , vtm_( -52.0 )
+ , Cm_( 2047.4164432004916 )
+ , ith_( 300.9987901902274 )
+ , tao_m_( 3310.462136574088 )
+ , sc_( 4526.328798037026 )
+ , bet_( 0.24522251335200956 )
+ , delta1_( 0.009906254244852036 )
+ , cost_idep_ini_( 0.017625482908326662 )
+ , Idep_ini_vr_( 1.0122905259090516 )
+ , psi1_( 0.1975362978159442 )
+ , a_( 14.2787 )
+ , b_( -2.10966 )
+ , c_( 0.0608809 )
+ , alp_( 225.491 )
+ , istim_min_spikinig_exp_( 400 )
+ , istim_max_spikinig_exp_( 1000 )
+ , corrcostatratti_( 1 )
+ , corrcost_( 0 )
+ , Delta_T( 2.0 ) // mV
+ , I_e_( 0.0 ) // pA
+ , V_th_( -52.0 ) // mV
+ , V_min_( -90.0 ) //-std::numeric_limits< double >::max() ) // mV
+ , t_ref_( 2.0 ) // in ms
+ , tau_syn_( 3, 2.0 ) // in ms
+ , firstSpikeFlag_( false)
+ , has_connections_( false )
+ {
+ }
+
+ nest::migliore::State_::State_()
+ : V_m_( -72.5 ) // membrane potential (E_L_+(1-exp(-S_.current_/1000))*(vtm-E_L_))/V_.Vconvfact TOBEFIXED
+ , init_sign_( 0.0 ) // membrane adaptation variable
+ , Iadap_ini_( 0.0 ) // membrane adaptation variable
+ , Idep_ini_( 0.0 ) // membrane dependent variable
+ , sis_( 0.0 ) // counter variable
+ , counter_( 0.0 ) // counter variable
+ , I_inj_( 0.0 ) // input current
+ , r_ref_( 0 )
+ {
+ i_syn_.clear();
+ }
+
+ /* ----------------------------------------------------------------
+ * Parameter and state extractions and manipulation functions
+ * ---------------------------------------------------------------- */
+
+ void
+ nest::migliore::Parameters_::get( DictionaryDatum& d ) const
+ {
+ def< double >( d, names::I_e, I_e_ );
+ def< double >( d, names::V_th, V_th_ ); // threshold value
+ def< double >( d, names::V_min, V_min_ );
+ def< double >( d, names::E_L, E_L_ );
+ def< double >( d, names::vres, vres_ );
+ def< double >( d, names::vtm, vtm_);
+ def< double >( d, names::Cm, Cm_);
+ def< double >( d, names::ith, ith_);
+ def< double >( d, names::tao_m, tao_m_);
+ def< double >( d, names::sc, sc_);
+ def< double >( d, names::bet, bet_);
+ def< double >( d, names::delta1, delta1_);
+ def< double >( d, names::cost_idep_ini, cost_idep_ini_);
+ def< double >( d, names::Idep_ini_vr, Idep_ini_vr_);
+ def< double >( d, names::psi1, psi1_);
+ def< double >( d, names::a, a_);
+ def< double >( d, names::b, b_);
+ def< double >( d, names::c, c_);
+ def< double >( d, names::alp, alp_);
+ def< double >( d, names::istim_min_spikinig_exp, istim_min_spikinig_exp_);
+ def< double >( d, names::istim_max_spikinig_exp, istim_max_spikinig_exp_);
+ def< double >( d, names::corrcostatratti, corrcostatratti_);
+ def< double >( d, names::corrcost, corrcost_);
+ def< double >( d, names::Delta_T, Delta_T );
+ def< double >( d, names::t_ref, t_ref_ );
+ def< int >( d, names::n_synapses, n_receptors_() );
+ def< bool >( d, names::has_connections, has_connections_ );
+
+ ArrayDatum tau_syn_ad( tau_syn_ );
+ def< ArrayDatum >( d, names::tau_syn, tau_syn_ad );
+ }
+
+ void
+ nest::migliore::Parameters_::set( const DictionaryDatum& d, Node* node )
+ {
+ updateValueParam< double >( d, names::V_th, V_th_, node );
+ updateValueParam< double >( d, names::V_min, V_min_, node );
+ updateValueParam< double >( d, names::I_e, I_e_, node );
+ updateValueParam< double >( d, names::E_L, E_L_, node );
+ updateValueParam< double >( d, names::vres, vres_, node );
+ updateValueParam< double >( d, names::vtm, vtm_, node );
+ updateValueParam< double >( d, names::Cm, Cm_, node );
+ updateValueParam< double >( d, names::ith, ith_, node );
+ updateValueParam< double >( d, names::tao_m, tao_m_, node );
+ updateValueParam< double >( d, names::sc, sc_, node );
+ updateValueParam< double >( d, names::bet, bet_, node );
+ updateValueParam< double >( d, names::delta1, delta1_, node );
+ updateValueParam< double >( d, names::cost_idep_ini, cost_idep_ini_, node );
+ updateValueParam< double >( d, names::Idep_ini_vr, Idep_ini_vr_, node );
+ updateValueParam< double >( d, names::psi1, psi1_, node );
+ updateValueParam< double >( d, names::a, a_, node );
+ updateValueParam< double >( d, names::b, b_, node );
+ updateValueParam< double >( d, names::c, c_, node );
+ updateValueParam< double >( d, names::alp, alp_, node );
+ updateValueParam< double >( d, names::istim_min_spikinig_exp, istim_min_spikinig_exp_, node );
+ updateValueParam< double >( d, names::istim_max_spikinig_exp, istim_max_spikinig_exp_, node );
+ updateValueParam< double >( d, names::corrcostatratti, corrcostatratti_, node );
+ updateValueParam< double >( d, names::corrcost, corrcost_, node );
+ updateValueParam< double >( d, names::Delta_T, Delta_T, node );
+ updateValueParam< double >( d, names::t_ref, t_ref_, node );
+ // updateValueParam< double >( d, names::miglp1, miglp1_, node );
+ // updateValueParam< double >( d, names::miglp2, miglp2_, node );
+ // updateValueParam< double >( d, names::miglp3, miglp3_, node );
+ // updateValueParam< double >( d, names::miglp4, miglp4_, node );
+ if ( t_ref_ < 0 )
+ {
+ throw BadProperty( "Refractory time must not be negative." );
+ }
+
+ const size_t old_n_receptors = this->n_receptors_();
+ if ( updateValue< std::vector< double > >( d, "tau_syn", tau_syn_ ) )
+ {
+ if ( this->n_receptors_() != old_n_receptors && has_connections_ == true )
+ {
+ throw BadProperty( "The neuron has connections, therefore the number of ports cannot be reduced." );
+ }
+ for ( size_t i = 0; i < tau_syn_.size(); ++i )
+ {
+ if ( tau_syn_[ i ] <= 0 )
+ {
+ throw BadProperty( "All synaptic time constants must be strictly positive." );
+ }
+ if ( tau_syn_[ i ] == tao_m_ )
+ {
+ throw BadProperty( "Membrane and synapse time constant(s) must differ. See note in documentation." );
+ }
+ }
+ }
+ // std::cout << "migliore set taus syn size " << tau_syn_.size() << "\n";
+ // std::cout << "migliore n_receptors " << this->n_receptors_() << "\n";
+ }
+
+ void
+ nest::migliore::State_::get( DictionaryDatum& d, const Parameters_& ) const
+ {
+ def< double >( d, names::init_sign, init_sign_ ); // Membrane potential adaptationariable
+ def< double >( d, names::Iadap_ini, Iadap_ini_ ); // Membrane potential adaptationariable
+ def< double >( d, names::Idep_ini , Idep_ini_ ); // Membrane potential adaptationariable
+ def< double >( d, names::sis , sis_ ); // Membrane potential adaptationariable
+ def< double >( d, names::I, I_inj_ ); // Membrane potential
+ def< double >( d, names::V_m, V_m_ ); // Membrane potential
+ }
+
+ void
+ nest::migliore::State_::set( const DictionaryDatum& d, const Parameters_&, Node* node )
+ {
+ updateValueParam< double >( d, names::init_sign, init_sign_, node );
+ updateValueParam< double >( d, names::Iadap_ini, Iadap_ini_, node );
+ updateValueParam< double >( d, names::Idep_ini, Idep_ini_, node );
+ updateValueParam< double >( d, names::sis, sis_, node );
+ updateValueParam< double >( d, names::V_m, V_m_, node );
+ updateValueParam< double >( d, names::I, I_inj_, node );
+ }
+
+ nest::migliore::Buffers_::Buffers_( migliore& n )
+ : logger_( n )
+ {
+ }
+
+ nest::migliore::Buffers_::Buffers_( const Buffers_&, migliore& n )
+ : logger_( n )
+ {
+ }
+
+ /* ----------------------------------------------------------------
+ * Default and copy constructor for node
+ * ---------------------------------------------------------------- */
+
+ nest::migliore::migliore()
+ : ArchivingNode()
+ , P_()
+ , S_()
+ , B_( *this )
+ {
+ recordablesMap_.create( *this );
+ }
+
+ nest::migliore::migliore( const migliore& n )
+ : ArchivingNode( n )
+ , P_( n.P_ )
+ , S_( n.S_ )
+ , B_( n.B_, *this )
+ {
+ recordablesMap_.create( *this );
+ }
+
+ /* ----------------------------------------------------------------
+ * Node initialization functions
+ * ---------------------------------------------------------------- */
+
+ void
+ nest::migliore::init_buffers_()
+ {
+ B_.spikes_.clear(); // includes resize
+ B_.currents_.clear(); // includes resize
+ B_.logger_.reset(); // includes resize
+ ArchivingNode::clear_history();
+ }
+
+ void
+ nest::migliore::calibrate()
+ {
+ B_.logger_.init();
+
+ // t_ref_ specifies the length of the absolute refractory period as
+ // a double in ms. The grid based iaf_psc_exp can only handle refractory
+ // periods that are integer multiples of the computation step size (h).
+ // To ensure consistency with the overall simulation scheme such conversion
+ // should be carried out via objects of class nest::Time. The conversion
+ // requires 2 steps:
+ // 1. A time object r is constructed, defining representation of
+ // t_ref_ in tics. This representation is then converted to computation
+ // time steps again by a strategy defined by class nest::Time.
+ // 2. The refractory time in units of steps is read out get_steps(), a
+ // member function of class nest::Time.
+ //
+ // Choosing a t_ref_ that is not an integer multiple of the computation time
+ // step h will lead to accurate (up to the resolution h) and self-consistent
+ // results. However, a neuron model capable of operating with real valued
+ // spike time may exhibit a different effective refractory time.
+
+ const double h = Time::get_resolution().get_ms();
+
+ V_.P11_syn_.resize( P_.n_receptors_() );
+ V_.P21_syn_.resize( P_.n_receptors_() );
+
+ S_.i_syn_.resize( P_.n_receptors_() );
+
+ B_.spikes_.resize( P_.n_receptors_() );
+
+ V_.P22_ = std::exp( -h / P_.tao_m_ );
+ V_.P20_ = P_.tao_m_ / P_.Cm_ * ( 1.0 - V_.P22_ );
+
+ for ( size_t i = 0; i < P_.n_receptors_(); i++ )
+ {
+ V_.P11_syn_[ i ] = std::exp( -h / P_.tau_syn_[ i ] );
+ // std::cout << "tau syn " << P_.tau_syn_[ i] << "\n";
+ // these are determined according to a numeric stability criterion
+ V_.P21_syn_[ i ] = propagator_32( P_.tau_syn_[ i ], P_.tao_m_, P_.Cm_, h );
+
+ B_.spikes_[ i ].resize();
+ }
+
+ V_.RefractoryCounts_ = Time( Time::ms( P_.t_ref_ ) ).get_steps();
+ // since t_ref_ >= 0, this can only fail in error
+ assert( V_.RefractoryCounts_ >= 0 );
+
+ V_.time_scale_ = 1 / (-P_.sc_ / (P_.Cm_ * P_.E_L_));
+ V_.d_dt = h;
+ V_.dt = V_.d_dt/V_.time_scale_;
+
+ V_.beta2 = pow(P_.bet_,2);
+ V_.t_step = V_.dt;
+ V_.t_spk = -0.3;
+
+ V_.H = (90+P_.E_L_)*P_.sc_*(P_.bet_-P_.delta1_)/(P_.E_L_*(-200));
+ V_.Vconvfact = -P_.E_L_;
+ V_.vrm = P_.vres_/V_.Vconvfact;
+ V_.psi1 = pow((-4)*P_.bet_+pow(1+P_.delta1_,2.0),0.5);
+ // t_step = t - t0
+ V_.VV_1 = 0.5 / ((P_.bet_ -P_.delta1_) * (pow(P_.bet_,2.0) + (P_.bet_-1.0) * P_.delta1_) * (4.0 * P_.bet_ - pow((1.0 + P_.delta1_), 2.0))) * P_.psi1_;
+ V_.VV_2 = 2.0 * exp(-V_.t_step * P_.bet_) * (P_.bet_-1.0) * P_.bet_ * (P_.bet_ - P_.delta1_) * P_.psi1_;
+ V_.VV_3 = (pow(P_.bet_,2) + ((- 1.0) + P_.bet_) * P_.delta1_) * P_.psi1_;
+ V_.VV_4 = exp((1.0 / 2.0) * V_.t_step * (-1.0 + P_.delta1_ -P_.psi1_));
+ V_.VV_5 = P_.bet_ * (P_.bet_ -P_.delta1_) * (-1.0 -P_.delta1_ + P_.bet_ * (3.0 + P_.delta1_ -P_.psi1_) + P_.psi1_);
+ V_.VV_6 = (pow(P_.bet_,2) -P_.delta1_ + P_.bet_ * P_.delta1_);
+ V_.VV_7 = (1.0 + (-2.0) * P_.bet_ + P_.delta1_ -P_.psi1_);
+ V_.VV_8 = exp((1.0 / 2.0) * V_.t_step * (-1.0 + P_.delta1_ + P_.psi1_));
+ V_.VV_9 = P_.bet_ * (P_.bet_-P_.delta1_) * (-1.0 -P_.delta1_ -P_.psi1_ + P_.bet_ * (3.0 + P_.delta1_ + P_.psi1_));
+ V_.VV_10 = (pow(P_.bet_,2) - P_.delta1_ + P_.bet_ * P_.delta1_);
+ V_.VV_11 = (1.0 + (-2.0) * P_.bet_ + P_.delta1_ + P_.psi1_);
+ // V_.GG = P_.bet_ * (P_.bet_ - P_.delta1_) * (-1 - P_.delta1_ - P_.psi1_ + P_.bet_ * (3 + P_.delta1_ + P_.psi1_));
+ V_.C = P_.bet_ - P_.delta1_;
+ // V_.JJ = 2 * exp(-V_.t_step * P_.bet_) * (P_.bet_ - 1) * P_.bet_ * V_.C * P_.psi1_;
+ // V_.JJ_1 = exp(0.5 * V_.t_step * (-1 + P_.delta1_ - P_.psi1_));
+ // V_.JJ_2 = (-1 - P_.delta1_ + P_.bet_ * (3 + P_.delta1_ - P_.psi1_) + P_.psi1_);
+ // V_.JJ_3 = (V_.beta2 + (P_.bet_ - 1) * P_.delta1_) * P_.psi1_;
+ // V_.JJ_4 = (V_.beta2 - P_.delta1_ + P_.bet_ * P_.delta1_);
+ // V_.JJ_5 = (1 + (-2) * P_.bet_ + P_.delta1_ - P_.psi1_);
+ // V_.JJ_6 = exp(0.5 * V_.t_step * (-1 + P_.delta1_ + P_.psi1_));
+ // V_.JJ_7 = 0.5 / V_.C / (V_.beta2 + (P_.bet_ - 1) * P_.delta1_) / (4 * P_.bet_ - pow((1 + P_.delta1_), 2)) * P_.psi1_;
+
+ V_.pdelta = pow((1 + P_.delta1_), 2);
+
+ // V_.AA_4 = P_.bet_ * V_.C * (-V_.pdelta + (-1.0 + P_.delta1_) * P_.psi1_ + 2.0 * P_.bet_ * (2.0 + P_.psi1_));
+ // V_.AA_5 = V_.beta2 + (-1.0 + P_.bet_) * P_.delta1_;
+ // V_.AA_6 = 1.0 -4.0 * P_.bet_ + P_.delta1_ * (2.0 + P_.delta1_ - P_.psi1_) + P_.psi1_;
+ // V_.AA_7 = (1.0 + P_.delta1_) * (-1.0 - P_.delta1_ + P_.psi1_);
+
+ // V_.AA_9 = P_.bet_ * V_.C * (V_.pdelta + 2.0 * P_.bet_ * (-2.0 + P_.psi1_) + (-1.0 + P_.delta1_) * P_.psi1_);
+ // V_.AA_10 = V_.beta2 + (-1.0 + P_.bet_) * P_.delta1_;
+ // V_.AA_11 = -4.0 * P_.bet_ + V_.pdelta + (-1.0 + P_.delta1_) * P_.psi1_;
+ // V_.AA_12 = (1.0 + P_.delta1_) * (1.0 + P_.delta1_ + P_.psi1_);
+
+ V_.AA_1 = -4.0 * pow(P_.bet_,3.0) + pow(P_.bet_,2.0) * pow((-1.0+P_.delta1_),2.0) - P_.delta1_ * pow((1.0 + P_.delta1_),2.0) + P_.bet_ * P_.delta1_ * (5 + 2.0 * P_.delta1_ + pow(P_.delta1_,2.0));
+ V_.AA_2 = 2.0 * exp(-V_.t_step * P_.bet_) * P_.bet_ * (4.0 * pow(P_.bet_,2.0) + P_.delta1_ * pow((1.0+P_.delta1_),2.0) - P_.bet_ * (1.0 + 6 * P_.delta1_ + pow(P_.delta1_,2.0)));
+ V_.AA_3 = exp((1.0 / 2.0)*V_.t_step*(-1.0+P_.delta1_+P_.psi1_));
+ V_.AA_4 = -1.0-2.0*P_.delta1_ - pow(P_.delta1_,2.0) - P_.psi1_ + P_.delta1_ * P_.psi1_+2.0*P_.bet_*(2.0+P_.psi1_);
+ V_.AA_5 = (pow(P_.bet_,2.0)-P_.delta1_+P_.bet_*P_.delta1_);
+ V_.AA_6 = (1.0-4.0*P_.bet_+2.0*P_.delta1_+pow(P_.delta1_,2.0)+P_.psi1_-P_.delta1_*P_.psi1_);
+ V_.AA_7 = (1.0+P_.delta1_)*(-1.0-P_.delta1_+P_.psi1_);
+ V_.AA_8 = exp((-1.0)*(1.0 / 2.0) * V_.t_step * (1.0-P_.delta1_+P_.psi1_));
+ V_.AA_9 = P_.bet_ * (P_.bet_-P_.delta1_)*(1.0+2.0*P_.delta1_+ pow(P_.delta1_,2.0)-P_.psi1_+P_.delta1_*P_.psi1_+2.0*P_.bet_*(-2.0+P_.psi1_));
+ V_.AA_10 = (pow(P_.bet_,2.0)-P_.delta1_+P_.bet_*P_.delta1_);
+ V_.AA_11 = (1.0-4.0*P_.bet_+2.0*P_.delta1_ + pow(P_.delta1_,2.0) - P_.psi1_+P_.delta1_*P_.psi1_);
+ V_.AA_12 = (2.0*(P_.bet_-P_.delta1_)*(pow(P_.bet_,2.0)+(-1.0+P_.bet_)*P_.delta1_)*(4.0*P_.bet_-pow((1.0+P_.delta1_),2.0)));
+
+ V_.DD_1 = exp(-V_.t_step * P_.bet_);
+ }
+
+ /* ----------------------------------------------------------------
+ * Update and spike handling functions
+ */
+
+ double
+ nest::migliore::tagliorette(double corr)
+ {
+ double dur_sign = std::numeric_limits<double>::infinity();
+ //# I = sym.Symbol('I')
+ double vinc_inf = 700;
+ double lin_func_sup;
+ // # lin_func_inf=0.68*I - 190.0
+ // # if corr<vinc_inf and corr>0:
+ // # dur_sign=lin_func_inf.subs(I,corr)
+ if (corr < vinc_inf && corr > 0)
+ {
+ dur_sign = 0.68*corr - 190.0;
+ // lin_func_inf = 0.68*corr - 190.0;
+ }
+ double vinc_sup = 1300;
+ if (corr > vinc_sup)
+ {
+ lin_func_sup = 76.86-0.028*corr;
+ dur_sign = lin_func_sup;
+ // dur_sign = corr + std::numeric_limits<double>::infinity();
+ //double lin_func_sup = corr + std::numeric_limits<double>::infinity();
+ }
+ return dur_sign;
+ }
+
+ double
+ nest::migliore::migliV(double t, double delta, double Psi,
+ double alpha, double beta, double IaA0,
+ double IdA0, double t0, double V0,
+ int r_ref_, double vrm)
+ {
+ double to_return = V_.VV_1 * (V_.VV_2 * IdA0 + -2.0 * (alpha -beta + delta) * V_.VV_3 + V_.VV_4 * (IdA0 * V_.VV_5 - V_.VV_6 * (alpha * V_.VV_7 + (beta -delta) * (-1.0 + 2.0 * IaA0 * beta -delta + Psi + V0 * (-1.0 -delta + Psi)))) + V_.VV_8 * (-IdA0 * V_.VV_9 + V_.VV_10 * (alpha * V_.VV_11 + (beta -delta) * (-1.0 + 2.0 * IaA0 * beta-delta -Psi -V0 * (1.0 + delta + Psi)))));
+ // double G = (V_.beta2 - delta + beta * delta) * (alpha * (1 + (-2) * beta + delta + Psi) + V_.C * (-1 + 2 * IaA0 * beta - delta - Psi - V0 * (1 + delta + Psi)));
+ // double F = -IdA0 * V_.GG + G;
+ // double D = V_.JJ * IdA0 - 2 * (alpha - beta + delta) * V_.JJ_3 + V_.JJ_1 * (IdA0 * beta * V_.C * V_.JJ_2 - V_.JJ_4 * (alpha * V_.JJ_5 + V_.C * (-1 + 2 * IaA0 * beta - delta + Psi + V0 * (-1 - delta + Psi)))) + V_.JJ_6 * F;
+ // double D = (2 * exp(((-1) * t + t0) * beta) * IdA0 * (beta - 1) * beta * C * Psi -2 * (alpha - beta + delta) * (beta2 + (beta - 1) * delta) * Psi + exp(0.5 * (t - t0) * ((-1) + delta - Psi)) * (IdA0 * beta * C * ((-1) - delta + beta * (3 + delta - Psi) + Psi) - (beta2 - delta + beta * delta) * (alpha * (1 + (-2) * beta + delta - Psi) + C * ((-1) + 2 * IaA0 * beta - delta + Psi + V0 * ((-1) - delta + Psi)))) + exp(0.5 * (t - t0) * ((-1) + delta + Psi)) * ((-1) * IdA0 * beta * (beta+(-1) * delta) * ((-1) - delta - Psi + beta * (3 + delta + Psi)) + (beta2 - delta+beta * delta) * (alpha * (1 + (-2) * beta + delta + Psi) + C * ((-1) + 2 * IaA0 * beta+(-1) * delta - Psi - V0 * (1 + delta + Psi)))));
+ if (r_ref_ == 0)
+ {
+ //return 0.5 / C / (beta2 + (beta - 1) * delta) / (4 * beta + (- 1) * pow((1 + delta),2)) * Psi * D;
+ // return V_.JJ_7 * D;
+ return to_return;
+ }
+ else
+ {
+ return vrm;
+ }
+ }
+
+ double
+ nest::migliore::set_v_ini(double to_v_ini,
+ int r_ref_, double vrm)
+ {
+ if (r_ref_ == 0)
+ {
+ return to_v_ini;
+ }
+ else
+ {
+ return vrm;
+ }
+ }
+
+
+
+ double
+ nest::migliore::Iadap(double t, double delta, double Psi, double alpha,
+ double beta, double IaA0, double IdA0, double t0,
+ double V0, int r_ref_)
+ {
+ double to_return = (-2.0 * alpha * V_.AA_1 + IdA0 * V_.AA_2 + V_.AA_3 * (-IdA0 * beta * (beta - delta) * V_.AA_4 + V_.AA_5 * (alpha * V_.AA_6 + (beta - delta) * (4.0 * IaA0 * beta -2.0 * (1.0 + V0) * Psi + IaA0 * V_.AA_7))) + V_.AA_8 * (IdA0 * V_.AA_9 + V_.AA_10 * (alpha * V_.AA_11 - (beta-delta) * (-4.0 * IaA0 * beta - 2.0*(1.0+V0)*Psi+IaA0*(1.0+delta)*(1.0+delta+Psi)))))/ V_.AA_12;
+ if (r_ref_ == 0)
+ {
+ return to_return;
+ }
+ else
+ {
+ // std::cout << "465 Refractrory\n";
+ return IaA0;
+ }
+ }
+
+ double
+ nest::migliore::Idep(double t, double beta, double IdA0, double t0, int r_ref_)
+ {
+ if (r_ref_ == 0)
+ {
+ return V_.DD_1 * IdA0;
+ }
+ else
+ {
+ return IdA0;
+ }
+ }
+
+ double
+ nest::migliore::exp_cum(double x, double a, double b)
+ {
+ return a * (1 - exp(-b * x));
+ }
+
+ double
+ nest::migliore::monod(double x, double a, double b, double c, double alp)
+ {
+ double to_return = c + (a * exp(b) * x) / (alp + x);
+ return to_return;
+ }
+
+ void
+ nest::migliore::update( Time const& origin, const long from, const long to )
+ {
+ assert( to >= 0 && ( delay ) from < kernel().connection_manager.get_min_delay() );
+ assert( from < to );
+
+ // const double h = Time::get_resolution().get_ms();
+ // double v_old;
+ // double Iadap_ini_old, Idep_ini_old;
+ double t0_val = origin.get_ms() / V_.time_scale_;
+ double local_time_step = V_.dt;
+ double t_final = t0_val + local_time_step;
+
+ // For breakpoint conditions
+ double timess;
+ double current;
+ double vmss;
+
+ // double afirst = 0;
+ double meancorlastis = 0;
+ double stdcorlastis = 0;
+ double meancorlastprec = 0;
+ double stdcorlastprec = 0;
+ double v_ini = S_.V_m_ / V_.Vconvfact;
+ double vini_prec = v_ini;
+ double teta;
+ double c_aux;
+ double paramL_;
+
+
+
+ for ( long lag = from; lag < to; ++lag )
+ {
+ // neuron is never refractory
+ // use standard forward Euler numerics
+ // double I_syn = B_.spikes_.get_value( lag );
+ double corpre = S_.I_inj_; // + S_.I;
+ // set new input current
+ S_.I_inj_ = B_.currents_.get_value( lag );
+ S_.current_ = S_.I_inj_; // + S_.I;
+ // std::cout << "\n";
+ // std::cout << "552 Begin " << " cor " << S_.current_ << " Inj " << S_.I_inj_ << " syn " << S_.i_syn_[1] << "\n";
+
+ if ( S_.r_ref_ == 0 ) // neuron not refractory, so evolve add synaptic currents
+ for ( size_t i = 0; i < P_.n_receptors_(); i++ )
+ {
+ // S_.V_m_ += V_.P21_syn_[ i ] * S_.i_syn_[ i ];
+ // std::cout << "syn " << S_.i_syn_[ i ] << "\n";
+ S_.current_ += S_.i_syn_[ i ]; // not sure about this
+ }
+ for ( size_t i = 0; i < P_.n_receptors_(); i++ )
+ {
+ // exponential decaying PSCs
+ S_.i_syn_[ i ] *= V_.P11_syn_[ i ];
+
+ // collect spikes
+ S_.i_syn_[ i ] += B_.spikes_[ i ].get_value( lag ); // not sure about this
+ }
+
+
+ // For Breakpoint conditions
+ current = S_.current_;
+ vmss = S_.V_m_;
+ timess = t_final * V_.time_scale_;
+
+ // Update integration time window
+ t0_val = t_final;
+ t_final = t0_val + local_time_step;
+
+ // t0_val = origin.get_ms() / V_.time_scale_;
+ // t_final = t0_val + (lag + 1) * V_.dt ;//Time::step( origin.get_steps() + lag + 1 );
+ // timess = t_final * V_.time_scale_;
+ // std::cout << "t_final =" << t_final*V_.time_scale_ << " ms. " << "Vm " << S_.V_m_ << " V_ini " << v_ini << "\n";
+ // std::cout << "\n439 Time from (" << from << ") =" << t0_val*V_.time_scale_ << " ms to (" << to<< ") =" << t_final*V_.time_scale_ << " ms.\n";
+ // v_old = v_ini;
+ // Iadap_ini_old = S_.Iadap_ini_;
+ // Idep_ini_old = S_.Idep_ini_;
+ // std::cout << "Vm " << v_ini * V_.Vconvfact << "\n";
+ // v_ini +=
+ // h * ( 0.04 * v_old * v_old + 5.0 * v_old + 140.0 - miglv1_old + S_.I_inj_ + P_.I_e_ ) + I_syn;
+ // S_.miglv1_ += h * P_.miglp1_ * ( P_.miglp2_ * v_old - miglv1_old );
+
+ // if (S_.current_ > 0)
+ // {
+ // // std::cout << "591 corr > 0 \n";
+ // S_.sis_ = S_.sis_+1;
+ // if (S_.sis_ >= 2)
+ // {
+ // meancorlastprec = meancorlastis;
+ // stdcorlastprec = stdcorlastis;
+ // stdcorlastis = ((S_.sis_-2)*stdcorlastis+(S_.sis_-1)*pow(meancorlastis,2) + pow(S_.current_,2)-S_.sis_*pow(((S_.sis_-1)*meancorlastis+S_.current_)/S_.sis_,2))/(S_.sis_-1);
+ // meancorlastis = ((S_.sis_-1)*meancorlastis+S_.current_)/S_.sis_;
+ // }
+ // else
+ // {
+ // stdcorlastis = 0;
+ // meancorlastis = S_.current_;
+ // }
+ // }
+ if ((t_final-S_.init_sign_)*V_.time_scale_ >= nest::migliore::tagliorette(S_.current_))
+ {
+ // std::cout << "604 tagliorette " << nest::migliore::tagliorette(S_.current_) << " cor " << S_.current_ << "\n";
+ if (P_.corrcostatratti_)
+ {
+ // std::cout << "611 corrcostatratti " << " cor " << S_.current_ << "\n";
+ if (S_.current_ > P_.ith_)
+ {
+ // std::cout << "614 cor > ith " << S_.current_ << "\n";
+ if (corpre < P_.ith_ ) //|| i == 0)
+ {
+ S_.init_sign_ = t_final;
+ S_.Idep_ini_ = P_.cost_idep_ini_*(S_.current_-P_.ith_);
+ S_.Iadap_ini_ = 0;
+ }
+ if (corpre > P_.ith_ && corpre < S_.current_)
+ {
+ S_.init_sign_ = S_.init_sign_*(1+(corpre-P_.ith_)/corpre);
+ S_.Idep_ini_ = P_.cost_idep_ini_*(S_.current_-P_.ith_);
+ }
+ }
+ }
+ if (P_.corrcost_)
+ {
+ if (S_.current_ > P_.ith_)
+ {
+ if (corpre < P_.ith_ )
+ {
+ S_.init_sign_ = t_final;
+ S_.Idep_ini_ = P_.cost_idep_ini_*(S_.current_-P_.ith_);
+ S_.Iadap_ini_ = 0;
+ }
+ }
+ }
+ if (corpre == 0)
+ {
+ v_ini = vini_prec;
+ }
+ else
+ {
+ // Set the v_ini depending on the refractory period
+ v_ini = set_v_ini((P_.E_L_+(1-exp(-S_.current_/1000))*(P_.vtm_-P_.E_L_))/V_.Vconvfact, S_.r_ref_, V_.vrm);
+ }
+ vini_prec = v_ini;
+ V_.out.push_back(v_ini);
+ // t_out.append(t_final);
+ // Iada.append(S_.Iadap_ini_);
+ // Ide.append(S_.Idep_ini_);
+ }
+ else
+ {
+ // std::cout << "688 NO tagliorette " << S_.current_ << "\n";
+ vini_prec = v_ini;
+ if ((S_.current_ < P_.ith_ && S_.current_ >= 0) ) //|| i == 0)
+ {
+ // std::cout << "691 cor < ith " << S_.current_ << "\n";
+ if (corpre < 0)
+ {
+ S_.Iadap_ini_ = 90/P_.E_L_ + 1;
+ S_.Idep_ini_ = 0;
+ v_ini = set_v_ini(vini_prec, S_.r_ref_, V_.vrm);
+ }
+ if (((S_.current_ / P_.sc_) / (P_.bet_ - P_.delta1_) - 1) <= v_ini)
+ {
+ S_.Idep_ini_ = 0;
+ S_.Iadap_ini_ = (S_.current_ / P_.sc_) / (P_.bet_ - P_.delta1_);
+ v_ini = set_v_ini(((S_.current_ / P_.sc_) / (P_.bet_ - P_.delta1_) - 1), S_.r_ref_, V_.vrm);
+ }
+ else
+ {
+ v_ini = migliV(t_final, P_.delta1_, V_.psi1, S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_, V_.vrm);
+ S_.Iadap_ini_ = Iadap(t_final, P_.delta1_, V_.psi1, S_.current_ / P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_);
+ S_.Idep_ini_ = Idep(t_final, P_.bet_, S_.Idep_ini_, t0_val, S_.r_ref_);
+ }
+ if (v_ini * V_.Vconvfact < -90)
+ {
+ v_ini = set_v_ini(-90 / V_.Vconvfact, S_.r_ref_, V_.vrm);
+ S_.Iadap_ini_ = 0;
+ }
+ V_.out.push_back(v_ini);
+ }
+ else
+ {
+ if (S_.current_ < corpre && S_.current_ > 0 && (V_.t_spk+2*V_.d_dt) < t_final*V_.time_scale_ && V_.out.size() > 2)
+ {
+ // std::cout << "726 v_ini " << v_ini << "\n";
+ teta = (V_.out[V_.out.size()-1]/(corpre / P_.sc_))*(1/V_.dt-P_.delta1_) - (V_.out[V_.out.size()-2]/((corpre / P_.sc_)*V_.dt))-P_.delta1_/(corpre / P_.sc_)-1;
+ if (teta < 0)
+ {
+ teta = 0;
+ }
+ S_.Idep_ini_ = S_.Iadap_ini_ + teta * (S_.current_ / P_.sc_) / P_.bet_;
+ // tetalist.append(teta);
+ v_ini = migliV(t_final, P_.delta1_, V_.psi1,
+ S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_, V_.vrm);
+ S_.Iadap_ini_ = Iadap(t_final, P_.delta1_, V_.psi1,
+ S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_);
+ S_.Idep_ini_ = Idep(t_final, P_.bet_,
+ S_.Idep_ini_, t0_val, S_.r_ref_);
+ }
+ else
+ {
+ if (S_.current_ > 0)
+ {
+ v_ini = migliV(t_final, P_.delta1_, V_.psi1,
+ S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_, V_.vrm);
+ S_.Iadap_ini_ = Iadap(t_final, P_.delta1_, V_.psi1,
+ S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_);
+ S_.Idep_ini_ = Idep(t_final, P_.bet_, S_.Idep_ini_, t0_val, S_.r_ref_);
+ }
+ }
+ if (corpre != S_.current_ and (S_.current_ < 0 and S_.current_ > -200))
+ {
+ S_.Iadap_ini_ = (90+P_.E_L_)*S_.current_/(P_.E_L_*(-200));
+ S_.Idep_ini_ = 0;
+ v_ini = set_v_ini(vini_prec, S_.r_ref_, V_.vrm);
+ }
+ if (S_.current_ < 0 and S_.current_ > -200)
+ {
+ // std::cout << "785 v_ini " << v_ini << "\n";
+ v_ini = migliV(t_final, P_.delta1_, V_.psi1, V_.H * S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_, V_.vrm);
+ S_.Iadap_ini_ = Iadap(t_final, P_.delta1_, V_.psi1, V_.H * S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_);
+ S_.Idep_ini_ = Idep(t_final, P_.bet_,
+ S_.Idep_ini_, t0_val, S_.r_ref_);
+ }
+ if (corpre != S_.current_ and S_.current_ <= -200)
+ {
+ // std::cout << "793 v_ini " << v_ini << "\n";
+ S_.Iadap_ini_ = 90/P_.E_L_ + 1;
+ S_.Idep_ini_ = 0;
+ v_ini = set_v_ini(vini_prec, S_.r_ref_, V_.vrm);
+ }
+ if (S_.current_ <= -200)
+ {
+ v_ini = migliV(t_final, P_.delta1_, V_.psi1, V_.H * S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_, V_.vrm);
+ S_.Iadap_ini_ = Iadap(t_final, P_.delta1_, V_.psi1, V_.H * S_.current_/P_.sc_, P_.bet_, S_.Iadap_ini_, S_.Idep_ini_, t0_val, v_ini, S_.r_ref_);
+ S_.Idep_ini_ = Idep(t_final, P_.bet_, S_.Idep_ini_, t0_val, S_.r_ref_);
+ }
+ if (v_ini*V_.Vconvfact < -90)
+ {
+ v_ini = set_v_ini(-90/V_.Vconvfact, S_.r_ref_, V_.vrm);
+ S_.Iadap_ini_ = 0;
+ }
+ V_.out.push_back(v_ini);
+ }
+ // t_out.append(t_final);
+ // Iada.append(S_.Iadap_ini_);
+ // Ide.append(S_.Idep_ini_);
+ if (P_.corrcostatratti_)
+ {
+ // std::cout << "817 corrcostatratti_\n";
+ if (S_.current_ > P_.ith_)
+ {
+ if (corpre < P_.ith_) // || i == 0)
+ {
+ // std::cout << "822 cor > P_.ith_ " << S_.current_ << "," << P_.ith_ << "\n";
+ S_.init_sign_ = t_final;
+ S_.Idep_ini_ = P_.cost_idep_ini_*(S_.current_-P_.ith_);
+ S_.Iadap_ini_ = 0;
+ }
+
+ if (corpre > P_.ith_ && corpre < S_.current_)
+ {
+ S_.init_sign_ = S_.init_sign_*(1+(corpre-P_.ith_)/corpre);
+ S_.Idep_ini_ = P_.cost_idep_ini_*(S_.current_-P_.ith_);
+ S_.Iadap_ini_ = 0;
+ }
+ }
+ }
+ if (P_.corrcost_)
+ {
+ if (S_.current_ > P_.ith_)
+ {
+ if (corpre < P_.ith_) // || i == 0)
+ {
+ S_.init_sign_ = t_final;
+ S_.Idep_ini_ = P_.cost_idep_ini_*(S_.current_-P_.ith_);
+ S_.Iadap_ini_ = 0;
+ }
+ }
+ }
+ // vini_prec = v_ini;
+ }
+ // i = i + 1;
+ // t0_val = t_final;
+ // t_final = t0_val+V_.dt;
+
+ S_.V_m_ = v_ini * V_.Vconvfact;
+ // std::cout << "655 S_.v_ v_ini final " << S_.v_ << " Iadap_ini_ " << S_.Iadap_ini_ << "\n";
+
+ while (V_.out.size() > 3)
+ {
+ V_.out.erase(V_.out.begin());
+ }
+ // lower bound of membrane potential
+ S_.V_m_ = ( S_.V_m_ < P_.V_min_ ? P_.V_min_ : S_.V_m_ );
+ // std::cout << "665 S_.v_ v_ini lower bound " << S_.V_m_ << "\n";
+
+ // Count down for refractory period
+ if (S_.r_ref_ > 0) {--S_.r_ref_;}
+
+ // threshold crossing
+ if ( S_.V_m_ > P_.V_th_ ) // V_th_ = -52
+ {
+ S_.r_ref_ = V_.RefractoryCounts_; // Inizialize refractory
+ V_.t_spk = t_final*V_.time_scale_;
+ // f.write(str(round(V_.t_spk, 3)) + ' \n')
+ S_.V_m_ = V_.vrm * V_.Vconvfact; // -65
+
+ // print('^*spike^*')
+ // print('t ', t_final, 'val_ist V', V_m_ * V_.Vconvfact, 'adap',
+ // S_.Iadap_ini_, 'adap', S_.Iadap_ini_, 't_ini', S_.init_sign_)
+ // print('^^^^^^')
+ c_aux = P_.c_;
+ if (S_.current_ < P_.istim_min_spikinig_exp_ || S_.current_ > P_.istim_max_spikinig_exp_)
+ {
+ if (P_.corrcost_ or P_.corrcostatratti_)
+ {
+ // check solo al primo spike
+ if (P_.firstSpikeFlag_ == false or corpre != S_.current_)
+ {
+ P_.firstSpikeFlag_ = true;
+ paramL_ = monod((t_final-S_.init_sign_)*V_.time_scale_,P_.a_,P_.b_*S_.current_/1000,P_.c_,P_.alp_);
+ if (paramL_ < 0)
+ {
+ // print('monod negativa, paramL: '+str(paramL));
+ if (P_.a_ > 0)
+ {
+ //c*
+ c_aux = P_.c_ - paramL_;
+ // print(c_aux)
+ }
+ else
+ {
+ // a<0
+ // c**
+ c_aux = -P_.a_* exp(P_.b_ * S_.current_/1000);
+ // print(c_aux)
+ }
+ }
+ else
+ {
+ c_aux = P_.c_;
+ }
+ }
+ S_.Iadap_ini_ = monod((t_final-S_.init_sign_) * V_.time_scale_, P_.a_, P_.b_ * S_.current_/1000, c_aux, P_.alp_);
+ }
+ else
+ {
+ // sinapt
+ c_aux = P_.c_;
+ S_.Iadap_ini_ = monod((t_final-S_.init_sign_) *
+ V_.time_scale_, P_.a_, P_.b_ * S_.current_/1000, c_aux, P_.alp_);
+ }
+ }
+ else
+ {
+ // std::cout << "899 Monod\n";
+ S_.Iadap_ini_ = monod((t_final-S_.init_sign_) * V_.time_scale_, P_.a_, P_.b_*S_.current_/1000, P_.c_, P_.alp_);
+ if (S_.Iadap_ini_<0)
+ {
+ // print('monod negativa');
+ if (P_.firstSpikeFlag_ == false or corpre!=S_.current_)
+ {
+ P_.firstSpikeFlag_ = true;
+ paramL_ = monod((t_final-S_.init_sign_)*V_.time_scale_, P_.a_,P_.b_*S_.current_/1000,P_.c_,P_.alp_);
+ //print('paramL: ',paramL)
+ }
+ if (S_.counter_<2)
+ {
+ //print('monod a zero - ',S_.counter_)
+ S_.Iadap_ini_ = 0;
+ S_.counter_ = S_.counter_ + 1;
+ }
+ else if (S_.counter_ == 2)
+ {
+ c_aux = P_.c_;
+ if (P_.a_ > 0)
+ {
+ c_aux = P_.c_ - paramL_;
+ // print(c_aux)
+ }
+ else
+ {
+ c_aux = -P_.a_* exp(P_.b_ * S_.current_/1000);
+ // print(c_aux)
+ }
+ S_.Iadap_ini_ = monod((t_final-S_.init_sign_) * V_.time_scale_, P_.a_, P_.b_ * S_.current_/1000, c_aux, P_.alp_);
+ S_.counter_ = S_.counter_ + 1;
+ }
+ else
+ {
+ // print('S_.counter_ > 3 - c_aux: ',c_aux)
+ S_.Iadap_ini_ = monod((t_final-S_.init_sign_) * V_.time_scale_, P_.a_, P_.b_ * S_.current_/1000, c_aux, P_.alp_);
+ // print('monod traslata: ',Iadap_ini)
+ }
+ }
+ }
+ if (S_.current_ < P_.ith_)
+ {
+ S_.Idep_ini_ = 0;
+ S_.Iadap_ini_ = 0;
+ }
+ else
+ {
+ S_.Idep_ini_ = P_.Idep_ini_vr_;
+ }
+ // // Refractory time management
+ // for (k in range(int(ref_t / V_.d_dt)))
+ // {
+ // // out.append(V_m_);
+ // t_final = t_final + V_.dt;
+ // // t_out.append(t_final);
+ // // Iada.append(S_.Iadap_ini_);
+ // // Ide.append(S_.Idep_ini_);
+ // i = i + 1;
+ // S_.sis_ = S_.sis_+1;
+ // if (S_.sis_ >= 2)
+ // {
+ // stdcorlastis = ((S_.sis_-2)*stdcorlastis+(S_.sis_-1)*meancorlastis^2 +
+ // S_.current_^2-S_.sis_*(((S_.sis_-1)*meancorlastis+S_.current_)/S_.sis_)^2)/(S_.sis_-1);
+ // meancorlastis = ((S_.sis_-1)*meancorlastis+S_.current_)/S_.sis_;
+ // }
+ // else
+ // {
+ // stdcorlastis = 0;
+ // meancorlastis = S_.current_;
+ // }
+ // }
+
+ // compute spike time
+ set_spiketime( Time::step( origin.get_steps() + lag + 1 ) );
+
+ SpikeEvent se;
+ kernel().event_delivery_manager.send( *this, se, lag );
+ }