Python, HOC, and most programming languages use a
for loop to run the same code a fixed number of times. e.g. in Python, we'd write
Code: Select all
for trial in range(100):
# do stuff here
and in HOC, we might write:
Code: Select all
for (trial = 0; trial < 100; trial += 1) {
// do stuff here
}
NEURON provides the
h.Random (or just Random in HOC) class for generating pseudo-random numbers.
In Python, it's probably easiest to just let pandas write a CSV file with
to_csv. In HOC, you'd have to do it yourself using the
File class.
Putting it all together (assuming you're working in Python), you have something like
Code: Select all
from neuron import h
from neuron.units import mV, ms
import pandas as pd
# TODO: any other imports you need
# allow reproducible pseudo-randomness
random_stream_id3 = 1
rng = h.Random()
h.load_file('stdrun.hoc')
# TODO: setup model here
# setup recording
t = h.Vector().record(h._ref_t)
vm = # TODO: CONTINUE HERE
ve = # TODO: CONTINUE HERE
for trial in range(100):
# select random stream
rng.Random(trial, 0, random_stream_id3)
# TODO: set your random parameters here
# see https://www.neuron.yale.edu/neuron/static/py_doc/programming/math/random.html
# e.g.
init_v = rng.normal(-65 * mV, 3 * mV) # TODO: you'll want to change this line to your needs
h.finitialize(init_v) # or whatever
h.continuerun(100 * ms) # or whatever
# save the data
pd.DataFrame({'t': t,
'vm': vm,
've': ve
}).to_csv(f'trial{trial}.csv')
where obviously you need to fill in all the TODO stuff.