AStupidBear / SpikingNeuralNetworks.jl

Julia Spiking Neural Network Simulator
Other
37 stars 16 forks source link

Faster way to implement optional delay to current Injection. #15

Open russelljjarvis opened 4 years ago

russelljjarvis commented 4 years ago

I am using SpikingNeuralNetworks in the context of single neuron model optimization.To take simulated electrical measurements of the cell model I need the membrane potential to be quiescent for some duration before and after stimulation. I introduced an optional delay to the sim argument. I was wondering if there is a neater way to implement the delay without counters? I am wondering if the approach I have adopted will harm performance?

Thanks. Russell.

function sim!(P, C; dt = 0.25ms, simulation_duration = 1300ms, delay = 300ms,stimulus_duration=1000ms)
    temp = deepcopy(P[1].I)
    size = simulation_duration/dt
    cnt1 = 0
    for t = 0ms:dt:simulation_duration
        cnt1+=1
        if cnt1 < delay/dt 
           P[1].I[1] = 0.0 
        end 
        if cnt1 > (delay/dt + stimulus_duration/dt)
       P[1].I[1] = 0.0 
        end 
        if (delay/dt) < cnt1 < (stimulus_duration/dt)  
           P[1].I[1] = maximum(temp[1])
        end
        sim!(P, C, dt)
    end
end

https://github.com/russelljjarvis/NeuronUnitOpt.jl/blob/master/src/main.jl#L6-L27

AStupidBear commented 4 years ago

@russelljjarvis Your approach is fine. I can't think up a better way.

jpsamaroo commented 4 years ago

I think we'll eventually be able to do this better. I've written my own personal SNN packages in the past which have implemented this by adding callbacks to each neuron/synapse "layer"; I think once we move to using OrdinaryDiffEq for solving we'll be able to make use of their callbacks for the same purposes. Let's keep this issue open until we have a nice interface for this.