Targeting specific neurons with external current using add_current_source in PyGeNN #664
-
Hello! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi there, Like most things in GeNN, the solution is to create a customised model to meet your needs - in this case a current source model. Assuming you mean Poisson-distributed inputs like those provided by the built in from pygenn import create_current_source_model
cs_model = create_current_source_model(
"cs_model",
params=["weight", "tauSyn", "rate"],
derived_params=[("ExpDecay", lambda pars, dt: np.exp(-dt / pars["tauSyn"]),
("ExpMinusLambda", lambda pars, dt: np.exp(-(pars["rate"] / 1000.0) * dt))],
vars=[("Init", "scalar"), ("current", "scalar")],
injection_code="""
scalar p = 1.0;
unsigned int numSpikes = 0;
do
{
numSpikes++;
p *= gennrand_uniform();
} while (p > ExpMinusLambda);
current += Init * (scalar)(numSpikes - 1);
injectCurrent(current);
current *= ExpDecay;
""") Then you can set up the poisson_params = {"weight": 0.1, "tauSyn": 0.5, "rate": 1000.0}
poisson_inject_inds = np.asarray([1196, 1231, 2793, 2680, 3892, 4378, 4775, 4906])
posson_init = np.zeros(num_neurons)
poisson_init[poisson_inject_inds] = poisson_params["weight"] * (1.0 - np.exp(-dt / poisson_params["tauSyn"])) * (poisson_params["tauSyn"]/ dt)
poisson_vars = {"current": 0.0, "Init": poisson_init}
model.add_current_source(pop_name + "_poisson", cs_model, neuron_pop, poisson_params, poisson_vars ) |
Beta Was this translation helpful? Give feedback.
Hi there,
Like most things in GeNN, the solution is to create a customised model to meet your needs - in this case a current source model. Assuming you mean Poisson-distributed inputs like those provided by the built in
PoissonExp
model, the easiest thing to do is create a modified version of that model (copy-pasting from https://github.com/genn-team/genn/blob/master/include/genn/genn/currentSourceModels.h#L107-L128) whereInit
is a variable (can differ across neurons) rather than a parameter (the same across all neurons):