forked from ModelDBRepository/127388
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pBGburstSearch.hoc
216 lines (162 loc) · 3.79 KB
/
pBGburstSearch.hoc
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
//These default search parameters may be changed by assigning new values to the variables
BS_SPIKES_MIN = 3
BS_SI_MIN = 3
objref facTable
facTable = new Vector(171)
facTable.x(0) = 1
tmp = 1
for i=1,170 {
tmp = tmp*i
facTable.x(i) = tmp
}
func factorial() { //$1:n
if ($1 > 170) {
// print "factorial over limit ", $1
return facTable.x(170)
} else {
return facTable.x($1)
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
proc surpriseIndex() {local i,j,tmp,SI_MAX,lambda,explambda,poisscdf //$1:nSpikes, $2:timeInterval, $3:meanIsi, $&4:si, $&5:prb
////////////////
//function [si prb]=surpriseIndex(nSpikes, timeInterval, meanIsi)
SI_MAX = 100
prbMIN = exp(-SI_MAX)
//prb = 1 - poisscdf(nSpikes-1, timeInterval/ meanIsi);
lambda = $2/$3
if (lambda < 0) {
print "surpriseIndex() lambda < 0"
explambda = 0
} else {
explambda = exp(-lambda)
}
//poisscdf = 0
//for i=0,$1-1 {
// poisscdf = poisscdf + (explambda*lambda^i)/factorial(i)
//}
poisscdf = explambda
tmp = explambda
for i=1,$1-1 {
tmp = tmp*(lambda/i)
poisscdf = poisscdf + tmp
}
$&5 = 1 - poisscdf
if ($&5 <= prbMIN) {
$&4 = SI_MAX
} else {
$&4 = -log($&5)
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
func findBurst() {local i,j,isiMean,bStart,bEnd,numSpikes,siMax,found,si,prb localobj x,ebIsi,b0bf //$o1:x, $o2:ebIsi, $3:isiMean, $4:bStart, $o5:b0bf
////////////////
//function [b_0, b_f]=findBurst(x, params, ebIsi, bStart)
x = $o1
ebIsi = $o2
isiMean = $3
bStart = $4
b0bf = $o5
b0bf.x(0) = bStart
b0bf.x(1) = bStart
bEnd = ebIsi.indwhere(">", bStart)
if (bEnd < 0) {
bEnd = x.size()-1
} else {
bEnd = ebIsi.x(bEnd)
}
//reject this burst segment if not enough spikes
numSpikes = bEnd - bStart + 1
if (numSpikes < BS_SPIKES_MIN) {
b0bf.x(1) = b0bf.x(0)
return -1
}
//find least probable (highest surprise) string of spikes in burst segment
siMax = 0
numSpikes = 0
for i=bStart,bEnd-BS_SPIKES_MIN+1 {
for j=i+BS_SPIKES_MIN-1,bEnd {
numIsi = j - i
dur = x.x(j) - x.x(i)
surpriseIndex(numIsi, dur, isiMean, &si, &prb)
if (si > siMax) {
found = 1
} else {
if ((si == siMax) && ((j-i+1) > numSpikes)) {
found = 1
} else {
found = 0
}
}
if (found > 0) {
b0bf.x(0) = i
b0bf.x(1) = j
siMax = si
numSpikes = j - i + 1
}
}
}
if (siMax < BS_SI_MIN) {
//No burst above surprise minimum in current burst segment
b0bf.x(1) = b0bf.x(0)
return -1
}
return 1
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
proc burstSearch() {local isiMean,flag,tmp,n localobj x,xIsi,res,bIsi,ebIsi,b0bf //$o1:x, $o2:xIsi, $o3:result
////////////////
//function res=burstSearch(x, xIsi, isiMean)
x = $o1
xIsi = $o2
res = $o3
bIsi = new Vector()
ebIsi = new Vector()
b0bf = new Vector(2,0)
res.resize(1,1)
res.x[0][0] = 0
if (xIsi.size > 0) {
isiMean = xIsi.mean()
} else {
print "burstSearch xIsi.size() == 0"
return
}
bIsi.indvwhere(xIsi, "()", 0, isiMean)
ebIsi.indvwhere(xIsi, "[)", isiMean, 1e9)
if (bIsi.size() > 0) {
nextBurst = bIsi.x(0)
flag = 1
} else {
flag = 0
}
//keep finding bursts until starting points are exhausted
while (flag > 0) {
tmp = findBurst(x, ebIsi, isiMean, nextBurst, b0bf)
if (tmp > 0) {
n = res.nrow
if (res.x[0][0] == 0) {
res.resize(1,2)
} else {
n = n + 1
res.resize(n, 2)
}
res.x[n-1][0] = b0bf.x(0)
res.x[n-1][1] = b0bf.x(1)
}
//next potential burst start
tmp = ebIsi.indwhere(">=", b0bf.x(1))
if (tmp >= 0) {
tmp = ebIsi.x(tmp)
tmp = bIsi.indwhere(">", tmp)
if (tmp >= 0) {
nextBurst = bIsi.x(tmp)
} else {
nextBurst = -1
}
} else {
nextBurst = -1
}
flag = (nextBurst > 0)
}
return
}