-
Notifications
You must be signed in to change notification settings - Fork 1
/
atom.xml
1355 lines (1208 loc) · 64.4 KB
/
atom.xml
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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Hafsteinn</title>
<link href="http://haffi112.github.io/atom.xml" rel="self"/>
<link href="http://haffi112.github.io/"/>
<updated>2018-07-13T21:43:34+00:00</updated>
<id>http://haffi112.github.io</id>
<author>
<name>Hafsteinn Einarsson</name>
<email>[email protected]</email>
</author>
<entry>
<title>Leaky integrate and fire neurons (LIF)</title>
<link href="http://haffi112.github.io/2016/05/15/lif-neuron/"/>
<updated>2016-05-15T00:00:00+00:00</updated>
<id>http://haffi112.github.io/2016/05/15/lif-neuron</id>
<content type="html"><p class="message">
This post assumes basic understanding of neurons. For a short
introduction to neurons please see <a href="https://simple.wikipedia.org/wiki/Neuron">this</a> Wikipedia
article.
</p>
<p>There are
<a href="https://en.wikipedia.org/wiki/Biological_neuron_model">multiple</a>
existing models for biological neurons, some which even contradict each
other. In this post we explore the <em>leaky-integrate and fire</em> neuron
model (LIF) which is commonly used in simulations which mimic neural
networks found in the brain. It has the advantage of being simple while
also capturing the large scale dynamics of how a single neuron
functions.</p>
<p>Note that not all of the cells in our brains <em>spike</em> (i.e.
transmit digital signals) and behave like the one we discuss below. Most
of the cells which we call neurons do spike however. It is commonly
acknowledged that the signals they send amongst themselves form the
basis of information dissemination and computation in the brain.</p>
<p>The LIF neuron corresponds to what is called a <em>membrane voltage</em> model.
It is inspired by
<a href="https://en.wikipedia.org/wiki/Squid_giant_axon">experiments</a>, first
carried out by
<a href="https://en.wikipedia.org/wiki/Alan_Lloyd_Hodgkin">Hodgin</a> and
<a href="https://en.wikipedia.org/wiki/Andrew_Huxley">Huxley</a> in the 1950s <a href="#hodgkin1952quantitative">(Hodgkin &amp; Huxley, 1952)</a>, which measure the voltage difference
inside and outside a neuron. The model is quite simple, we can give some
input to the neuron, in the form of an electrical current, and we can
observe how the voltage across the membrane changes over time.</p>
<p>Before the experiments of Hodgin and Huxley the <em>integrate-and-fire</em>
neuron model (note that the <em>leaky</em> part is missing) had already been
proposed. It is in fact a variant of the model we have used in the
previous posts on <a href="/2016/04/25/percolation-with-inhibition/">bootstrap percolation</a>. In that model a neuron never
<em>forgets</em> the input it received in the past. If it requires two input
spikes in order to spike itself it is even allowed that these two spikes
come a year apart from each other. In reality this is a different story
and any trace of the first spike would vanish a few milliseconds later.
Note however that integrate-and-fire models are still useful, for
example when modelling phenomena which occurs at a very short timescale.</p>
<p>The fact that neurons forget old spikes corresponds to the <em>leaky</em> part
in the name. You can think of a neuron as a bucket. When it receives
input a bit of water gets added to the bucket. When the bucket is full
it spikes and that spike corresponds to adding a bit of water to all the
neighbouring buckets. However, there is a catch, the bucket has a hole
in the bottom so the water leaks out.</p>
<p>If you want to skip the math part now is the time to scroll down to the
bottom to see a live, interactive simulation of a LIF neuron.</p>
<p>The water level in the bucket corresponds to the membrane voltage of the
neuron. The neuron prefers to be a bit polarised and its <em>resting
potential</em> (corresponding to an empty bucket) is at around <script type="math/tex">-70</script> mV.
Whenever the neuron receives an input spike some channels will open on
the membrane and ions will flow through which depolarises the neuron.
The neuron has some ion pumps on the membrane which actively pump these
ions back out which corresponds to the <em>leak</em>.</p>
<p>Since the membrane voltage changes over time we can model it using a
differential equation. Such an equation tells us how the membrane
voltage changes in one moment. We denote the voltage at time <script type="math/tex">t</script> by
<script type="math/tex">V(t)</script> and we denote the resting potential by <script type="math/tex">E_L</script> (also known as the
<em>leak reversal potential</em>). Additionally we denote the input to the
neuron at time <script type="math/tex">t</script> by <script type="math/tex">g_e(t)</script> and the excitatory reversal potential
by <script type="math/tex">E_E</script> which is the membrane voltage which the input is driving the
neuron towards.</p>
<p>For a short time interval <script type="math/tex">\Delta t</script> the voltage changes as follows</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align*}
V(t+\Delta t) =& V(t)\\& - \Delta t \cdot A\cdot g_L\cdot (V(t)-E_L) \\
&- \Delta t\cdot B \cdot g_e(t)\cdot (V(t)-E_E)
\end{align*} %]]></script>
<p>where <script type="math/tex">A</script> and <script type="math/tex">B</script> are positive constants. So you see that on the one
hand the voltage, <script type="math/tex">V(t)</script> is drawn towards <script type="math/tex">E_L</script> via the constant
leak and on the other hand it is drawn towards <script type="math/tex">E_E</script> via the input
current (here modelled as conductance). One popular approach to model
the input conductance is via exponential decay, the conductance then
simply behaves as</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align*}
g_e(t+\Delta t) =& g_e(t) -\Delta t\cdot C\cdot g_e(t)
\end{align*} %]]></script>
<p>where <script type="math/tex">C</script> is also some positive constant. We additionally increase
<script type="math/tex">g_e(t)</script> by some value <script type="math/tex">w</script> whenver the neuron receives an input
where <script type="math/tex">w</script> corresponds to the weight of the incoming synapse. This
still does not capture how the neuron spikes. As in the
integrate-and-fire model it just needs to cross some threshold, which we
denote by <script type="math/tex">V_{th}</script>. So whenever <script type="math/tex">V(t)</script> exceeds <script type="math/tex">V_{th}</script> the neuron
emits a spike. Following the spike the neuron enters a <em>refractory
period</em> where it ignores all incoming spikes. After that period the
membrane voltage is reset to a fixed value, denoted by
<script type="math/tex">V_{\text{reset}}</script> which is called the <em>reset potential</em>.</p>
<p>Below you can see an interactive simulation of a LIF neuron following
the dynamics described above. You can press the input neuron on the left
to send a spike to the output neuron on the right. You can visualise the
membrane potential of the target neuron via the radius of the circle
representing it. The dynamics of the membrane potential are 100 times
slower than in reality (otherwise you would not see much happening) and
the parameters as seen above are set to somewhat realistic values. Note
however that the time to deliver the spike between the two neurons and
the time in the refractory period is exaggarated for demonstration
purposes. If you want to run large scale simulations using this type of
neuron you can do so using the
<a href="http://www.nest-initiative.org/">nest-simulator</a> and the
<a href="https://github.com/nest/nest-simulator/blob/master/models/iaf_cond_exp.cpp"><script type="math/tex">\mathtt{iaf\_cond\_exp}</script></a>
neuron model <a href="#meffin2004analytical">(Meffin, Burkitt, &amp; Grayden, 2004)</a> where the parameters are
from.</p>
<div id="neuron"></div>
<script>
var width = d3.select("#neuron").node().getBoundingClientRect().width;
var height = 300;
var delay = 250;
var neuronradius = 15;
var msgradius = 5;
var m_V = -70.0E-3; // Membrane voltage
var g_E = 0.0; // Excitatory synaptic conductance
var t_delta = 1E-4; // 0.1 ms, so we need to update every 10 ms
var spike_effect = 1.0E-3;
var membrane_capacitance = 250E-12; // Capacity of the membrance
var E_E= 0.0; // Excitatory reversal potential
var E_L = -70E-3; // Leak reversal potential
var g_L = 16.6667E-9; // Leak conductance, nS
var V_T = -55E-3 // Threshold potential
var V_reset = -60E-3 // Reset potential
var t_ref = 2.5E-3 // Refractory period
var weight = 1E-7;
var t_syn = 0.2E-3;
var realTimeDelay = 10;
var realTimeRefractoryPeriod = 1000;
var started = false;
var spiking = false;
var blowup = 3000;
var thresholdradius = neuronradius + (V_T - E_L)*blowup;
var resetradius = neuronradius + (V_reset-E_L)*blowup;
var fill = d3.scale.category20c();
var svg = d3.select("#neuron").append("svg")
.attr("width", width)
.attr("height", height);
var play = svg.append("g")
.attr("class", "play");
play.append("circle")
.attr("r", neuronradius)
.attr("stroke-width", ".5px")
.attr("transform", "translate(" + width / 4 + "," + height / 2 + ")")
.on("mousedown", function() {
play.classed("mousedown", true);
d3.select(window).on("mouseup", function() { play.classed("mousedown", false);
// Input spike
var input_spike = svg.append("circle");
input_spike.attr({
cx: width/4.0,
cy: height/2.0,
fill: fill.range()[8],
r: neuronradius + (m_V-E_L)*blowup,
opacity:1.0
})
input_spike.transition()
.duration(150)
.ease("linear") // For more easing info check http://bl.ocks.org/hunzy/9929724
.attr("r",200)
.attr("opacity",0)
.remove();
// Message
var marker = svg.append("circle");
marker.attr({
cx: width/4.0,
cy: height/2.0,
fill: fill.range()[8],
r: neuronradius,
opacity:0.5
})
marker.transition()
.duration(delay)
.ease("circle") // For more easing info check http://bl.ocks.org/hunzy/9929724
.attr("cx",3*width/4.0)
.attr("r",msgradius)
.each("end", function(){
if(!spiking) {
g_E += weight;
}
if(!started) {
started=true;
setTimeout(update,10);
}
})
.remove();
});
})
.on("click", function() {
});
var neuron = svg.append("g")
.attr("class", "neuron");
var neuron_threshold = neuron.append("circle")
.attr({fill:"none",
"stroke-width":"1.5px",
stroke:"#000",
"stroke-linejoin":"round",
"opacity": 0.5,
"stroke-dasharray":"10,10"})
.attr("r", neuronradius + (V_T - E_L)*blowup)
.attr("transform", "translate(" + 3*width / 4 + "," + height / 2 + ")");
var neuron_reset = neuron.append("circle")
.attr({fill:"none",
"stroke-width":".5px",
stroke:"#000",
"stroke-linejoin":"round"})
.attr("r", resetradius)
.attr("transform", "translate(" + 3*width / 4 + "," + height / 2 + ")");
var neuroncircle = neuron.append("circle")
.attr("r", neuronradius)
.attr("fill",d3.rgb(fill.range()[8]).brighter((m_V-E_L)*150))
.attr("transform", "translate(" + 3*width / 4 + "," + height / 2 + ")")
.attr("opacity", 0.5);
function update() {
spiking = false;
//console.log(m_V);
//console.log(g_E);
g_E = g_E - (t_delta/t_syn)*g_E;
m_V = m_V + (t_delta/membrane_capacitance)*( -g_L*(m_V - E_L) - g_E*(m_V - E_E));
neuroncircle.transition().duration(0).attr("r",neuronradius + (m_V-E_L)*blowup)
.attr("fill",d3.rgb(fill.range()[8]).brighter((m_V-E_L)*150));
if(!spiking && m_V > V_T) {
spiking = true;
m_V = V_reset;
neuroncircle.transition().duration(0)
.attr("r",neuronradius + (m_V-E_L)*blowup)
.attr("fill",fill.range()[4]);
var marker = svg.append("circle");
marker.attr({
cx: 3*width/4.0,
cy: height/2.0,
fill: fill.range()[8],
r: neuronradius + (m_V-E_L)*blowup,
opacity:1.0
})
marker.transition()
.duration(500)
.ease("linear") // For more easing info check http://bl.ocks.org/hunzy/9929724
.attr("r",200)
.attr("opacity",0)
.remove();
setTimeout(update,realTimeRefractoryPeriod);
}
else if(m_V - E_L < 0.0005) {
started = false;
}
else {
setTimeout(update,realTimeDelay);
}
}
var arc_margin = 1.1;
var arc_margin2 = 1.05;
// Threshold label
//Create an SVG path
svg.append("path")
.attr("id", "threshold_radius_margin") //very important to give the path element a unique ID to reference later
.attr("d", "M "+((3*width/4.0)-arc_margin*thresholdradius)+","+height/2.0+" A "+arc_margin*thresholdradius+","+arc_margin*thresholdradius+" 0 0,1 "+((3*width/4.0)+arc_margin*thresholdradius)+","+height/2.0+"") //Notation for an SVG path, from bl.ocks.org/mbostock/2565344
.style("fill", "none");
//Create an SVG text element and append a textPath element
svg.append("text")
.classed("unselectable",true)
.append("textPath") //append a textPath to the text element
.attr("xlink:href", "#threshold_radius_margin") //place the ID of the path here
.style("text-anchor","middle") //place the text halfway on the arc
.attr("startOffset", "50%")
.text("Spiking threshold")
.attr("font-size",14);
// Reset potential label
svg.append("path")
.attr("id", "reset_radius_margin") //very important to give the path element a unique ID to reference later
.attr("d", "M "+((3*width/4.0)-arc_margin2*resetradius)+","+height/2.0+" A "+arc_margin2*resetradius+","+arc_margin2*resetradius+" 0 0,1 "+((3*width/4.0)+arc_margin2*resetradius)+","+height/2.0+"") //Notation for an SVG path, from bl.ocks.org/mbostock/2565344
.style("fill", "none");
//Create an SVG text element and append a textPath element
svg.append("text")
.classed("unselectable",true)
.append("textPath") //append a textPath to the text element
.attr("xlink:href", "#reset_radius_margin") //place the ID of the path here
.style("text-anchor","middle") //place the text halfway on the arc
.attr("startOffset", "50%")
.text("Reset potential")
.attr("font-size",11);
play.append("text").attr("text-anchor", "middle")
.attr("x",width/4.0)
.attr("dy",4*height/5.0)
.classed("unselectable",true)
.text("Input neuron")
.attr("font-size",14);
neuron.append("text").attr("text-anchor", "middle")
.attr("x",3*width/4.0)
.attr("dy",4*height/5.0)
.classed("unselectable",true)
.text("Output neuron")
.attr("font-size",14);
</script>
<h2 id="references">References</h2>
<ol class="bibliography"><li><span id="hodgkin1952quantitative">Hodgkin, A. L., &amp; Huxley, A. F. (1952). A quantitative description of membrane current and its application to conduction and excitation in nerve. <i>The Journal of Physiology</i>, <i>117</i>(4), 500.</span></li>
<li><span id="meffin2004analytical">Meffin, H., Burkitt, A. N., &amp; Grayden, D. B. (2004). An analytical model for the ‘large, fluctuating synaptic conductance state’typical of neocortical neurons in vivo. <i>Journal of Computational Neuroscience</i>, <i>16</i>(2), 159–175.</span></li></ol>
</content>
</entry>
<entry>
<title>Percolation with inhibition - part 2</title>
<link href="http://haffi112.github.io/2016/04/29/percolation-with-inhibition-part2/"/>
<updated>2016-04-29T00:00:00+00:00</updated>
<id>http://haffi112.github.io/2016/04/29/percolation-with-inhibition-part2</id>
<content type="html"><p>This part 2 in the series on percolation with inhbition. If you have not
yet read part 1 you can find it <a href="/2016/04/25/percolation-with-inhibition/">here</a>.</p>
<p>In this post we will try to get an intuition for how many vertices
eventually turn active in the process. Let us assume that we have <script type="math/tex">n</script>
vertices in total, <script type="math/tex">n^+</script> of them which send positive messages and
<script type="math/tex">n^-</script> of them which send negative messages.</p>
<p>For a fixed vertex in the graph we can assume that it does not know if
its neighbours are positive or negative. Since it only receives at most
one message from each neighbour we can think of these messages being
independently positive with probability <script type="math/tex">n^+/n</script> and negative
with probability <script type="math/tex">n^-/n</script>. Formally these events are not independent
but the dependence is weak so you can assume they are to get some
intuition behind the process.</p>
<p>This allows us to model the process as a Markov chain. If you are
unfamiliar with Markov chains there is a great pictorial explanation
<a href="http://setosa.io/blog/2014/07/26/markov-chains/">here</a>. Our Markov
chain consists of <em>infinitely</em> many states which represent the potential
of our single vertex under consideration. The states are given by the
set <script type="math/tex">\{\ldots,-2,-1,0,1,2,\ldots,K\}</script> and correspond to the value of
the potential of the vertex. Like all vertices which are not active at
the start it starts with its potential in state 0 and it can only stop
if it ever reaches state <script type="math/tex">K</script>. The transition probabilities are given
as the probability of increasing or decreasing the potential as
explained in the previous paragraph.</p>
<p>Below you see an interactive version of the process. The fact that state
<script type="math/tex">K</script> is an absorbing state is denoted by a self-loop. Since we do not
have space for infinitely many states the left-most state represents all
states smaller or equal to <script type="math/tex">-K</script>. You can imagine the chain extending
infinitely to the left. Additionally we reset the process if it has not
finished after 10 steps (you can change this variable below). Note that
the process should always reach <script type="math/tex">K</script> if <script type="math/tex">% <![CDATA[
n^-<n^+ %]]></script> with enough many
steps. However, if <script type="math/tex">n^- > n^+</script> we have a drift to the left. This means
that if the potential becomes too small there is hardly any chance that
it will be able to recover. Try it out by choosing <script type="math/tex">n^- = 100</script> and
<script type="math/tex">n^+ = 50</script> for example.</p>
<div id="chain"></div>
<form onsubmit="change_params(); return false;" style="margin-bottom:20px">
<input type="button" value="Update parameters" onclick="change_params()" />
<table style="max-width: 720px; font-size:75%; margin-bottom:10px">
<tr>
<td>
<label for="nodeCount">Number of positive vertices</label>
</td>
<td>
<input id="nodeCount" type="text" value="50" style="width: 50px;" />
</td>
</tr>
<tr>
<td>
<label for="inodeCount">Number of negative vertices </label>
</td>
<td>
<input id="inodeCount" type="text" value="50" style="width: 50px;" />
</td>
</tr>
<tr>
<td>
<label for="maximumSteps">Maximum number of steps</label>
</td>
<td>
<input id="maximumSteps" type="text" value="10" style="width: 50px;" />
</td>
</tr>
<tr>
<td>
<label for="kPerc">Activation threshold (<i>K</i>)</label>
</td>
<td>
<input id="kPerc" type="text" value="2" style="width: 50px;" />
</td>
</tr>
<tr>
<td>
<label for="delay">Animation speed, ms (lower is faster)</label>
</td>
<td>
<input id="delay" type="text" value="50" style="width: 50px;" />
</td>
</tr>
</table>
</form>
<p>Below you can see some statistics of the simulations of the Markov chain.
The histogram shows after how many steps the potential reached <script type="math/tex">K</script>.
Observe that for <script type="math/tex">n^-\gg n^+</script> the most likely outcome is that the
process goes directly to <script type="math/tex">K</script>.</p>
<div id="hist"></div>
<p>The plot below shows which fraction of all the simulations ever reach
<script type="math/tex">K</script> within the given number of steps. You can use it to estimate which
fraction of the vertices turn active in the bootstrap percolation
process. Just set the maximum number of steps in the Markov chain to the
average degree of the graph.</p>
<p>By pressing the <em>update parameters</em> button you start a new simulation
and draw a new curve. The old one is not lost however so you can compare
different parameters.</p>
<div id="stats"></div>
<script>
var width = d3.select("#chain").node().getBoundingClientRect().width;
var height = 200;
var kThresh = 3;
var stateRadius = 15;
var trial = 0;
var n_ex = 80;
var n_in = 65;
var max_steps = 10;
var speed = 50;
var data_point = 0;
var n = 40;
//var data = Array.apply(0, Array(n)).map(Number.prototype.valueOf,0);
var data = [];
var histogram_data = [];
var fill = d3.scale.category20c();
function setup(num_exp) {
data = Array.apply(0, Array(n)).map(Number.prototype.valueOf,0);
data = [];
histogram_data = [];
d3.select("#chain").selectAll("*").remove();
d3.select("#hist").selectAll("*").remove();
var margin = width/(2.4*kThresh);
var svg = d3.select("#chain").append("svg")
.attr("width", width)
.attr("height", height);
d3.select(window)
.on("resize", function() {
var targetWidth = d3.select("#chain").node().getBoundingClientRect().width;
svg.attr("width", targetWidth);
});
defs = svg.append("defs");
defs.append("marker")
.attr({
"id":"arrow",
"viewBox":"0 -5 10 10",
"refX":5,
"refY":0,
"markerWidth":4,
"markerHeight":4,
"orient":"auto"
})
.append("path")
.attr("d", "M0,-5L10,0L0,5")
.attr("class","arrowHead");
var path_collection = [];
var xs = [], ys = [];
for(var x = 0; x <= 2*kThresh; ++x) {
if(kThresh < 3) {
xs.push(margin + x*0.8*(margin));
}
else {
xs.push(margin + x*0.8*(margin));
}
ys.push(height/2.0);
path_collection.push({});
}
var forward = [], backward = [];
for(var idx=0; idx < xs.length-1; ++idx) {
var coord=[[xs[idx],ys[idx]],[0.5*(xs[idx]+xs[idx+1])-10,ys[idx]-30],[xs[idx+1]-stateRadius,ys[idx+1]-stateRadius]];
forward.push(coord);
if(idx < xs.length-2) {
var clone=[[xs[idx+1],ys[idx+1]],[0.5*(xs[idx]+xs[idx+1])+10,ys[idx]+30],[xs[idx]+stateRadius,ys[idx]+stateRadius]];
backward.push(clone);
}
else {
var clone=[[xs[idx+1],ys[idx+1]],
[xs[idx+1]+40,ys[idx]-30],
[xs[idx+1]+50,ys[idx]],
[xs[idx+1]+40,ys[idx]+30],
[xs[idx+1]+20,ys[idx+1]+stateRadius]];
backward.push(clone);
}
}
for(var idx=0; idx < forward.length; ++idx) {
var path = svg.append("path")
.data([forward[idx]])
.attr("d", d3.svg.line()
.tension(0) // Catmull–Rom
.interpolate("basis"))
.attr({
"class":"arrow",
"marker-end":"url(#arrow)"
});
path_collection[idx]["forward"] = path;
var path2 = svg.append("path")
.data([backward[idx]])
.attr("d", d3.svg.line()
.tension(0) // Catmull–Rom
.interpolate("basis"))
.attr({
"class":"arrow",
"marker-end":"url(#arrow)"
});
path_collection[idx+1]["backward"] = path2;
}
var states = {"nodes":[]};
for(var idx=0; idx < xs.length; ++idx) {
var fillcolor;
if(idx > kThresh) {
fillcolor = d3.rgb(fill.range()[8]).brighter(idx-kThresh-2);
}
else if(idx == kThresh) {
fillcolor = fill.range()[17];
}
else {
fillcolor = d3.rgb(fill.range()[0]).darker(kThresh - idx - 2);
}
var state = {"x": xs[idx], "y": ys[idx], "r": stateRadius, "fill":
fillcolor, "label":idx-kThresh, "coord":[xs[idx],ys[idx]]};
states["nodes"].push(state);
path_collection[idx]["node"] = state;
}
var elem = svg.selectAll("g").data(states.nodes);
var elemEnter = elem.enter()
.append("g")
.attr("transform", function(d){return "translate("+d.x+","+d.y+")"});
var circle = elemEnter.append("circle")
.attr("r", function(d){return d.r})
.attr("fill", function(d) {return d.fill});
var labels = elemEnter.append("text")
.attr("dx", function(d){
if(d.label < 0) {return -stateRadius/2.0}
else {return -stateRadius/2.0 + 3.0}
})
.attr("dy", function(d){return 5})
.attr("font-size", "14px")
.attr("fill", fill.range()[19])
.text(function(d){return d.label});
var circle = svg.append("circle")
.attr("r", 13)
.attr("opacity",0.5)
.attr("transform", "translate(" + path_collection[kThresh]["node"]["coord"] + ")");
var prob_win = svg.append("text")
.attr("dx", margin/2.0)
.attr("dy", height/4.0)
.attr("font-size", "14px")
.attr("fill", fill.range()[16])
.text(function(){return "Probability of reaching "+kThresh+" in infinitely many steps: "+Math.pow(Math.min(1.0,n_ex/n_in),kThresh);});
var numFinish = 0;
var numFail = 0;
var steps = 0;
var statistics = svg.append("text")
.attr("dx", margin/2.0)
.attr("dy", 3.0*height/4.0)
.attr("font-size", "14px")
.attr("fill", fill.range()[16])
.text(function(){return "Number of times we reached "+kThresh+": "+numFinish;});
var statistics_fail = svg.append("text")
.attr("dx", margin/2.0)
.attr("dy", 3.3*height/4.0)
.attr("font-size", "14px")
.attr("fill", fill.range()[16])
.text(function(){return "Number of times we didn't reach "+kThresh+": "+numFail;});
var statistics_summary = svg.append("text")
.attr("dx", margin/2.0)
.attr("dy", 3.6*height/4.0)
.attr("font-size", "14px")
.attr("fill", fill.range()[16])
.text(function(){return "Estimated probability of reaching "+kThresh+" in "+max_steps+" steps: "+numFinish/(Math.max(1,numFail+numFinish));});
transition(kThresh);
function transition(state) {
if(num_exp != trial) {
return;
}
steps += 1;
if(steps>max_steps) {
steps = 0;
d3.select(labels[0][0]).transition().duration(100)
.text(-kThresh)
numFail++;
tick(numFinish/(numFinish+numFail));
statistics_fail
.text(function(){return "Number of times we didn't reach "+kThresh+": "+numFail;});
statistics_summary
.text(function(){return "Estimated probability of reaching "+kThresh+" in "+max_steps+" steps: "+numFinish/(numFail+numFinish);});
transition(kThresh);
return;
}
prob_win
.text(function(){return "Probability of reaching "+kThresh+" in infinitely many steps: "+Math.pow(Math.min(1.0,n_ex/n_in),2*kThresh-state);});
if(state <= 0) {
circle
.attr("opacity",0.1);
}
else {
circle
.attr("opacity",0.5);
}
if(state==xs.length-1) {
histogram_data.push(steps-1);
//console.log(histogram_data);
update_histogram();
numFinish++;
tick(numFinish/(numFinish+numFail));
steps = 0;
statistics
.text(function(){return "Number of times we reached "+kThresh+": "+numFinish;});
statistics_summary
.text(function(){return "Estimated probability of reaching "+kThresh+" in "+max_steps+" steps: "+numFinish/(numFail+numFinish);});
transition(kThresh);
return;
}
else if(state<0) {
d3.select(labels[0][0]).transition().duration(100)
.text(state-kThresh)
.attr("dy", function(d){
if (state-kThresh<-9){return 3;}
else {return 5;}})
.attr("font-size", function() {
if (state-kThresh<-9){return "10px";}
else {return "14px";}})
.each("end",function() {
if(Math.random() <= n_in/(n_ex+n_in)) {
circle.transition()
.duration(speed)
.each("end", function(){transition(state-1);});
}
else {
circle.transition()
.duration(speed)
.each("end", function() {transition(state+1);});
}
});
}
else {
circle.transition()
.duration(speed)
.attr("transform", "translate(" + path_collection[state]["node"]["coord"] + ")")
.each("end",function() {
if(Math.random() <= n_in/(n_ex+n_in)) {
if(state > 0) {
circle.transition()
.duration(2*speed)
.attrTween("transform", translateAlong(path_collection[state]["backward"].node()))
.each("end", function(){transition(state-1);});
}
else {
transition(state-1);
return;
}
}
else {
if(state == 0) {
d3.select(labels[0][0]).transition().duration(speed)
.text(state-kThresh);
}
circle.transition()
.duration(2*speed)
.attrTween("transform", translateAlong(path_collection[state]["forward"].node()))
.each("end", function() {transition(state+1);});
}
});
}
}
// Returns an attrTween for translating along the specified path element.
function translateAlong(path) {
var l = path.getTotalLength();
return function(d, i, a) {
return function(t) {
var p = path.getPointAtLength(t * l);
return "translate(" + p.x + "," + p.y + ")";
};
};
}
// Histogram of number of steps when process finishes
// A formatter for counts.
var margin_hist = {top: 10, right: 30, bottom: 30, left: 30};
var heightHist = 500;
var formatCount = d3.format(",.0f");
var svgHist = d3.select("#hist").append("svg")
.attr("width", width + margin_hist.left + margin_hist.right)
.attr("height", heightHist + margin_hist.top + margin_hist.bottom)
.append("g")
.attr("transform", "translate(" + margin_hist.left + "," + margin_hist.top + ")");
var numbins = max_steps;
var x_scale = d3.scale.linear()
.domain([1, max_steps])
.range([0, width-margin_hist.right]);
var xAxis = d3.svg.axis()
.scale(x_scale)
.orient("bottom");
var bandSize = width/(2*numbins);
function update_histogram() {
numbins = max_steps;
bandSize = width/(2*numbins);
x_scale = d3.scale.linear()
.domain([1, max_steps])
.range([0, width-margin_hist.right]);
xAxis = d3.svg.axis()
.scale(x_scale)
.orient("bottom");
svgHist.selectAll("*").remove();
var data_binned = d3.layout.histogram()
.bins(x_scale.ticks(numbins))
(histogram_data);
var y_scale = d3.scale.linear()
.domain([0, d3.max(data_binned, function(d) { return d.y; })])
.range([heightHist, 0]);
var bar = svgHist.selectAll(".bar")
.data(data_binned)
.enter().append("g")
.attr("class", "bar")
.attr("transform", function(d) { return "translate(" + x_scale(d.x) + "," + y_scale(d.y) + ")"; });
bar.append("rect")
.attr("x", 1)
.attr("width", width/numbins)
.attr("height", function(d) { return heightHist - y_scale(d.y); });
bar.append("text")
.attr("dy", ".75em")
.attr("y", 6)
.attr("x", width/(2*max_steps))
.attr("text-anchor", "middle")
.text(function(d) { return formatCount(d.y); });
var visible_axis = svgHist.append("g")
.attr("transform", "translate(-" + bandSize + "," + height + ")")
.attr("class", "x axis")
.attr("fill",d3.rgb(fill.range()[17]).darker(1))
.attr("transform", "translate(0," + heightHist + ")")
.call(xAxis)
.selectAll("text")
.style("text-anchor", "start")
.attr("transform", "translate(" + bandSize + ", 0)");
}
update_histogram();
}
setup(trial);
function change_params() {
speed = parseInt(document.getElementById('delay').value);
n_ex = parseInt(document.getElementById('nodeCount').value);
n_in = parseInt(document.getElementById('inodeCount').value);
max_steps = parseInt(document.getElementById('maximumSteps').value);
kThresh = parseInt(document.getElementById('kPerc').value);
trial++;
setup(trial);
return;
}
var margin = {top: 20, right: 20, bottom: 20, left: 80};
var width = d3.select("#chain").node().getBoundingClientRect().width;
height = 500 - margin.top - margin.bottom;
var fill2 = d3.scale.category10();
var x = d3.scale.log().base(10)//.linear()
//.domain([1, n-1])
.domain([1, 1000])
.range([0, width-100]);
var y = d3.scale.linear()
.domain([0, 1])
.range([height-30, 0]);
var line = d3.svg.line()
//.x(function(d, i) { return x(i); })
.x(function(d, i) { return x(d.x); })
//.y(function(d, i) { return y(d); });
.y(function(d, i) { return y(d.y); });
var svg = d3.select("#stats").append("svg")
.attr("width", width)
.attr("height", height+3*margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("defs").append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", width)
.attr("height", height);
svg.append("g")
.attr("class", "x axis")
.style("fill", d3.rgb(fill.range()[17]).darker(1))
.attr("transform", "translate(0," + y(0) + ")")
.call(d3.svg.axis().ticks(3).scale(x).orient("bottom").innerTickSize(-height)
.outerTickSize(0)
.tickPadding(10));
svg.append("g")
.attr("class", "y axis")
.style("fill", d3.rgb(fill.range()[17]).darker(1))
.call(d3.svg.axis().scale(y).orient("left").innerTickSize(-width)
.outerTickSize(0)
.tickPadding(10));
var graph_path = svg.append("g")
.attr("clip-path", "url(#clip)")
.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line)
.attr("stroke",fill2(trial));
svg.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ -50.0 +","+(height/2)+")rotate(-90)")
.text("Value")
.attr("fill",d3.rgb(fill.range()[17]).darker(1));
svg.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ ((width-100)/2) +","+(height+15)+")")
.text("Time")
.attr("fill",d3.rgb(fill.range()[17]).darker(1));
var old_trial = trial;
function tick(new_data) {
if(old_trial < trial) {
old_trial = trial;
graph_path = svg.append("g")
.attr("clip-path", "url(#clip)")
.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line)
.attr("stroke",fill2(trial));
}
// push a new data point onto the back
//console.log(new_data);
var t = data.length;
data.push({x:t+1,y:new_data});
//data.push(new_data);
// redraw the line, and slide it to the left
graph_path
.attr("d", line)
.attr("transform", null);
/*.transition()
.duration(100)
.ease("linear")
.attr("transform", "translate(" + x(-1) + ",0)");*/
// pop the old data point off the front
//data.shift();
}
</script>
</content>
</entry>
<entry>
<title>Percolation with inhibition - part 1</title>
<link href="http://haffi112.github.io/2016/04/25/percolation-with-inhibition/"/>
<updated>2016-04-25T00:00:00+00:00</updated>
<id>http://haffi112.github.io/2016/04/25/percolation-with-inhibition</id>
<content type="html"><p>In the previous posts we have discussed <a href="/2016/03/27/bootstrap-percolation/">synchronous</a> and <a href="/2016/04/08/asynchronous-percolation/">asynchronous</a> bootstrap percolation, processes
which model the dissemination of information in a graph.</p>
<p>In these previous models we only studied vertices which could excite
their neighbours. This is a good basic model for the spread of diseases
or gossip. However in other settings we might instead have competing
forces. For instance the messages might represent product
recommendations from friends. If all your friends recommend some brand
you might be triggered to buy it. However, if some of your friends
recommend another you might change your decision on what to buy or
simply be confused. Similarly in the brain some of the neurons are
excitatory and send positive messages while others are inhibitory and
send negative messages. The inhibitory neurons are quite important
because if excitation is abundant the activity can run out of control
which can lead to epileptic seizures.</p>
<p>Thus it becomes natural to study the question what happens if instead we
allowed some of the nodes to be negative? That is exactly what we did in
<a href="#einarsson2014bootstrap">(Einarsson, Lengler, Panagiotou, Mousset, &amp; Steger, 2014)</a>. We made some interesting observations
which I will highlight in follow up posts.</p>
<p>Below you can see an implementation of asynchronous bootstrap
percolation with inhibition made with <a href="https://d3js.org">d3js</a>. The
green nodes send positive messages and the red nodes send negative
messages. Each vertex keeps track of how many positive messages it has
seen minus the number of negative vertices. We refer to this as the
<em>potential</em> of the vertex. A vertex turns active (and remains active) if
its potential ever reaches <script type="math/tex">K</script>. You can try to control which fraction
of the green vertices turn active by changing the number of negative
vertices. When the potential of a vertex becomes negative we color the
vertex blue. Vertices which reach this state have a lower chance of ever
turning active. They can but for most of them they are essentially
frozen.</p>
<div id="simulation">
</div>
<form onsubmit="create_graph(); return false;" style="margin-bottom:20px">
<input type="button" value="Build graph" onclick="create_graph()" />
<input type="button" value="Percolate" onclick="percolate()" />
<table style="max-width: 720px; font-size:75%; margin-bottom:10px">
<tr>
<td>
<label for="nodeCount">Number of positive vertices (green)</label>
</td>
<td>
<input id="nodeCount" type="text" value="30" style="width: 50px;" />
</td>
</tr>
<tr>
<td>
<label for="inodeCount">Number of negative vertices (red) </label>
</td>
<td>
<input id="inodeCount" type="text" value="30" style="width: 50px;" />
</td>
</tr>
<tr>