-
Notifications
You must be signed in to change notification settings - Fork 2
/
nsloc.mod
223 lines (205 loc) · 5.5 KB
/
nsloc.mod
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
: $Id: nsloc.mod,v 1.7 2013/06/20 salvad $
: from nrn/src/nrnoc/netstim.mod
: modified to use as proprioceptive units in arm2dms model
NEURON {
ARTIFICIAL_CELL NSLOC
RANGE interval, number, start, xloc, yloc, zloc, id, type, subtype, fflag, mlenmin, mlenmax, checkInterval
RANGE noise
THREADSAFE : only true if every instance has its own distinct Random
POINTER donotuse
}
PARAMETER {
interval = 100 (ms) <1e-9,1e9>: time between spikes (msec)
number = 3000 <0,1e9> : number of spikes (independent of noise)
start = 1 (ms) : start of first spike
noise = 0 <0,1> : amount of randomness (0.0 - 1.0)
xloc = -1
yloc = -1
zloc = -1 : location
id = -1
type = -1
subtype = -1
fflag = 1 : don't change -- indicates that this is an artcell
check_interval = 1.0 (ms) : time between checking if interval has changed
}
ASSIGNED {
event (ms)
last_interval (ms)
transition
on
ispike
donotuse
}
PROCEDURE seed(x) {
set_seed(x)
}
INITIAL {
on = 0 : off
ispike = 0
if (noise < 0) {
noise = 0
}
if (noise > 1) {
noise = 1
}
if (start >= 0 && number > 0) {
on = 1
: randomize the first spike so on average it occurs at
: start + noise*interval
event = start + invl(interval) - interval*(1. - noise)
: but not earlier than 0
if (event < 0) {
event = 0
}
net_send(event, 3)
}
}
PROCEDURE init_sequence(t(ms)) {
if (number > 0) {
on = 1
event = 0
ispike = 0
}
}
FUNCTION invl(mean (ms)) (ms) {
if (mean <= 0.) {
mean = .01 (ms) : I would worry if it were 0.
}
if (noise == 0) {
invl = mean
}else{
invl = (1. - noise)*mean + noise*mean*erand()
}
}
VERBATIM
#ifndef NRN_VERSION_GTEQ_8_2_0
double nrn_random_pick(void* r);
void* nrn_random_arg(int argpos);
#define RANDCAST
#else
#define RANDCAST (Rand*)
#endif
ENDVERBATIM
FUNCTION erand() {
VERBATIM
if (_p_donotuse) {
/*
:Supports separate independent but reproducible streams for
: each instance. However, the corresponding hoc Random
: distribution MUST be set to Random.negexp(1)
*/
_lerand = nrn_random_pick(RANDCAST _p_donotuse);
}else{
/* only can be used in main thread */
if (_nt != nrn_threads) {
hoc_execerror("multithread random in NetStim"," only via hoc Random");
}
ENDVERBATIM
: the old standby. Cannot use if reproducible parallel sim
: independent of nhost or which host this instance is on
: is desired, since each instance on this cpu draws from
: the same stream
erand = exprand(1)
VERBATIM
}
ENDVERBATIM
}
PROCEDURE noiseFromRandom() {
VERBATIM
{
void** pv = (void**)(&_p_donotuse);
if (ifarg(1)) {
*pv = nrn_random_arg(1);
}else{
*pv = (void*)0;
}
}
ENDVERBATIM
}
PROCEDURE next_invl() {
if (number > 0) {
event = invl(interval)
}
if (ispike >= number) {
on = 0
}
}
NET_RECEIVE (w) {
if (flag == 0) { : external event
if (w > 0 && on == 0) { : turn on spike sequence
: but not if a netsend is on the queue
init_sequence(t)
: randomize the first spike so on average it occurs at
: noise*interval (most likely interval is always 0)
next_invl()
event = event - interval*(1. - noise)
net_send(event, 1)
}else if (w < 0) { : turn off spiking definitively
on = 0
}
}
if (flag == 3) { : from INITIAL
if (on == 1) { : but ignore if turned off by external event
init_sequence(t)
net_send(0, 1)
net_send(2*check_interval,4)
}
}
if (flag == 1 && on == 1) {
ispike = ispike + 1
net_event(t)
next_invl()
transition = 0
if (on == 1) {
net_send(event, 1)
}
}
if (flag == 5 && on == 1 && transition == 1) {
ispike = ispike + 1
net_event(t)
next_invl()
if (on == 1) {
net_send(event, 5)
}
}
if (flag == 4 && on == 1) { : check if interval has changed
if (interval < last_interval) { :if (2*interval < event || interval > 2*event) {
next_invl()
transition = 1
net_send(event,5)
}
last_interval = interval
net_send(check_interval, 4) : next check interval event
}
if (flag == 1 && on == 0) { : For external PMd inputs - .event(timeStamp, 1) in server.py
net_event(t)
}
}
COMMENT
Presynaptic spike generator
---------------------------
This mechanism has been written to be able to use synapses in a single
neuron receiving various types of presynaptic trains. This is a "fake"
presynaptic compartment containing a spike generator. The trains
of spikes can be either periodic or noisy (Poisson-distributed)
Parameters;
noise: between 0 (no noise-periodic) and 1 (fully noisy)
interval: mean time between spikes (ms)
number: number of spikes (independent of noise)
Written by Z. Mainen, modified by A. Destexhe, The Salk Institute
Modified by Michael Hines for use with CVode
The intrinsic bursting parameters have been removed since
generators can stimulate other generators to create complicated bursting
patterns with independent statistics (see below)
Modified by Michael Hines to use logical event style with NET_RECEIVE
This stimulator can also be triggered by an input event.
If the stimulator is in the on==0 state (no net_send events on queue)
and receives a positive weight
event, then the stimulator changes to the on=1 state and goes through
its entire spike sequence before changing to the on=0 state. During
that time it ignores any positive weight events. If, in an on!=0 state,
the stimulator receives a negative weight event, the stimulator will
change to the on==0 state. In the on==0 state, it will ignore any ariving
net_send events. A change to the on==1 state immediately fires the first spike of
its sequence.
ENDCOMMENT