-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnengo.R
63 lines (50 loc) · 1.53 KB
/
nengo.R
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
generate_gain_and_bias = function(count, rate_low, rate_high) {
intercept_low = -1
intercept_high = 1
gain = bias = NULL
intercept = intercept_low+(intercept_high-intercept_low)*runif(count)
rate = rate_low +(rate_high-rate_low)*runif(count)
z = 1.0 / (1-exp( (t_ref/1000 - (1/rate))/ (t_rc/1000) ) )
g = (1-z)/(intercept - 1.0)
b = 1 - g*intercept
return(list(g, b))
}
run_neurons = function(input, n) {
dV = dt * (input - n$v)/t_rc
n$v = n$v + dV
n$v[ n$v<0 ] <- 0
in_refr = n$ref>0
n$v[in_refr] <- 0
n$ref[in_refr] = n$ref[in_refr] - dt
fired = n$v>v_tresh
n$v[fired] <- 0
n$ref[fired] <- t_ref
return(list(n, fired))
}
compute_response = function(x, encoder, gain, bias, time_limit=0.5) {
n = list(v=rep(0, M), ref=rep(0,M))
n$v = runif(M)
count = rep(0, M)
input = x * encoder * gain + bias
for(i in seq(0, time_limit*1000, by=dt)) {
c(n, spikes) := run_neurons(input, n)
count[spikes] = count[spikes] + 1
}
return(count/time_limit)
}
plot_tuning_curves = function(encoder, gain, bias) {
x = seq(-1, 1, length.out=100)
resp = NULL
for(xv in x) {
r = compute_response(xv, encoder, gain, bias, 0.5)
resp = cbind(resp, r)
}
cols = rainbow(nrow(resp))
for(ni in 1:nrow(resp)) {
if(ni==1) {
plot(x, resp[ni,], type="l", col=cols[ni], ylim=c(min(resp), max(resp)))
} else {
lines(x, resp[ni,], col=cols[ni])
}
}
}