-
Notifications
You must be signed in to change notification settings - Fork 1
/
autoTileThresholdMap.hoc
155 lines (137 loc) · 4.04 KB
/
autoTileThresholdMap.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
{load_file("autoThresholdMap.hoc")}
objref attDv[36]
attTotalCells = 0
/////////////////////////////////////////////////////////////////////
// Tiled version of spike detector
func hasSpike() { local idx, i, hyp // parameter: cell ID to check
idx = $1
//index of 1st threshold crossing
for i = (del+dur*2+0.5)/dt,(del+35)/dt {
if (attDv[idx].x[i] >= 0) {
return i
}
}
//excessive stim causes transient hyp after stimulus
hyp = 1
for i = (del+dur*2+1.0)/dt,(del+dur*2+4.0)/dt {
if (attDv[idx].x[i] >= attDv[idx].x[0]) {
hyp = 0
break
}
}
if (hyp) { return -1 }
return 0
}
// Tally the ID of cell(s) that spiked in the tile, a -ve return value indicates
// over-stim occured.
func countActivity() { local actvCells, overStimMark, c, latency
actvCells = 0
overStimMark = 1
for c = 0,attTotalCells-1 {
latency = hasSpike(c)
if (latency < 0) {
overStimMark = -1 // -ve multiplier to note overstim
} else if (latency > 0) {
actvCells += 2^c // actvCells uses 1-based cell ID
}
}
return overStimMark * actvCells
}
// Re-implement original procedure for cell tile
func findThresholdInRange() { local xPos, yPos, aMin, aMax, actvCells
xPos = $1
yPos = $2
aMin = $3
aMax = $4
setelec(xPos, yPos, stimZ)
while (aMax - aMin > rangingResolution) {
stimAmp = (aMax+aMin)/2 * -0.001
setstim(stimDel, stimDur, stimAmp)
run()
actvCells = countActivity()
// print "> ", stimAmp, " ", actvCells
if (actvCells < 0) {
return actvCells //excessive stim
} else if (actvCells > 0) {
aMax = (aMax+aMin)/2 //over-stim
} else {
aMin = (aMax+aMin)/2 //under-stim
}
}
if (actvCells == 0) {
// re-run if last did not spike
stimAmp = aMax * -0.001
setstim(stimDel, stimDur, stimAmp)
run()
actvCells = countActivity()
}
return actvCells
}
// Re-implement original procedure for cell tile
proc findThreshold() { local id, aMin, aMax, firstRun, actvCells
xPos = $1
yPos = $2
aMax = STIM_AMP_MAX
aMin = STIM_AMP_MIN
overStimLoop = 0
while (overStimLoop < 3) {
actvCells = findThresholdInRange(xPos, yPos, aMin, aMax)
if (actvCells >= 0) {
break
}
aMax = aMax / 2
overStimLoop += 1
// print "> overstim ", actvCells
}
printf("%d %d %.5f %d\n", $1, $2, stimAmp, actvCells)
if (pc.nhost == 1) {
aFile.printf("%d %d %.5f %d\n", $1, $2, stimAmp, actvCells)
aFile.flush()
} else {
id = hoc_ac_
pc.post(id, $1, $2, stimAmp, actvCells)
}
}
// Re-implement original procedure for cell tile
proc runRegion() { local id, xpos, ypos, amp, actvCells
if (pc.nhost == 1) {
// sequential execution
for aX = $1,$2 {
for aY = $3,$4 {
findThreshold(aX * 10, aY * 10)
}
}
} else {
// parallel execution
printf("INFO: ParallelContext.host = %d\n", pc.nhost)
pc.runworker()
for aX = $1,$2 {
for aY = $3,$4 {
pc.submit("findThreshold", aX * 10, aY * 10)
}
}
while ((id = pc.working) != 0) {
pc.take(id, &xpos, &ypos, &, &actvCells)
aFile.printf("%d %d %.5f %d\n", xpos, ypos, amp, actvCells)
aFile.flush()
}
pc.done
}
}
/////////////////////////////////////////////////////////////////////
// Initialization for off cell tile
proc atmInitOffCells() { local c
for c = 0,offCells-1 {
attDv[c] = new Vector()
attDv[c].record(&off[c].soma.v(0.5))
}
attTotalCells += offCells
}
// Initialization for on cell tile
proc atmInitOnCells() { local c
for c = 0,onCells-1 {
attDv[c] = new Vector()
attDv[c].record(&on[c].soma.v(0.5))
}
attTotalCells += onCells
}