-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlapicque1.js
78 lines (69 loc) · 1.75 KB
/
lapicque1.js
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
var A=40; // action potential
var vres=0;
var vthr=A*0.6; // firing threshold
var W=10/1000.0; // Connection weight
var N=0.4; // noise amplitude
var G=0.2; // leak constant
function lapicque() {
var i,j;
// integrate
for(i=0;i<neurones.length;i++)
for(j=0;j<neurones[i].neighbours.length;j++)
neurones[i].state+=W*neurones[i].neighbours[j].output;
// noise
for(i=0;i<neurones.length;i++)
neurones[i].state+=N*(14-2*Math.random());
// fire
for(i=0;i<neurones.length;i++)
if(neurones[i].state>vthr) {
neurones[i].state=-10;
neurones[i].output=A;
}
else
neurones[i].output=0;
// leak
for(i=0;i<neurones.length;i++)
neurones[i].state+=-neurones[i].state*G;
// update color
for(i=0;i<neurones.length;i++) {
neurones[i].material.color.r=
neurones[i].material.color.g=
neurones[i].material.color.b=neurones[i].state/A;
if(neurones[i]==lastSelected)
neurones[i].material.color.g=
neurones[i].material.color.b=0;
}
}
function addNeuroneRandom() {
lastSelected=addNeurone(Math.random()*1000-500,Math.random()*600-300,0);
}
function addNeuroneGrid() {
var D=60;
var n=24,m=16;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
lastSelected=addNeurone((i-n/2.0)*D,(j-m/2.0)*D+200,0);
}
function autoWire() {
var D=100;
for(i=0;i<neurones.length;i++)
for(j=i+1;j<neurones.length;j++) {
d= Math.pow(neurones[i].position.x-neurones[j].position.x,2)+
Math.pow(neurones[i].position.y-neurones[j].position.y,2)+
Math.pow(neurones[i].position.z-neurones[j].position.z,2);
if(d<Math.pow(D,2)) {
n1=neurones[i];
n2=neurones[j];
wireNeurones(n1,n2);
n1.neighbours.push(n2);
n2.neighbours.push(n1);
}
}
}
function reset() {
var i;
for(i=0;i<neurones.length;i++) {
neurones[i].state=A*Math.random();
neurones[i].output=0;
}
}