Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution of HH depends on dt #149

Open
coschroeder opened this issue Jul 27, 2023 · 2 comments
Open

Solution of HH depends on dt #149

coschroeder opened this issue Jul 27, 2023 · 2 comments
Labels

Comments

@coschroeder
Copy link
Contributor

coschroeder commented Jul 27, 2023

I played around with dt of the stimulus and realized that the number of spikes in the standard HH model depends on the stepsize.
Code to reproduce:

from neurax.channels import HHChannel

# Number of segments per branch.
nseg_per_branch = 1
comp = nx.Compartment()
branch = nx.Branch([comp for _ in range(nseg_per_branch)])

# point neuron:
cell = nx.Cell([branch for _ in range(1)], parents=jnp.asarray([-1]))

cell.insert(HH())

# Stimulus.
i_delay = 20.0  # ms
i_amp = 3.7  # nA 0.08
i_dur = 20.0  # ms

# Duration and step size.
dt = 0.0025  # ms # Changing dt here, changes the HH solution
t_max = 60.0  # ms

time_vec: jnp.Array = jnp.arange(0.0, t_max+dt, dt)
stim: jnp.Array = jx.step_current(i_delay, i_dur, i_amp, dt, t_max)

cell.branch(0).comp(0).stimulate(stim)
# Solve HH
s = nx.integrate(cell)

Am I doing something wrong here?
Or is there a bug in the solver?

@michaeldeistler
Copy link
Contributor

michaeldeistler commented Jul 27, 2023

Passing dt to the solver fixes the issue:

s = nx.integrate(cell, stims, recs, delta_t=dt)

@michaeldeistler michaeldeistler added the documentation Improvements or additions to documentation label Feb 14, 2024
@michaeldeistler
Copy link
Contributor

michaeldeistler commented Dec 12, 2024

To make this behavior clear, we could do:

stim, t = jx.step_current(i_delay, i_dur, i_amp, dt, t_max)
cell.branch(0).comp(0).stimulate(stim, t)

v = jx.integrate(cell)[:, 1:]  # To make `t` and `v` equally long.
plot(t, v)

This has the advantage that stim and t can both be arrays, which makes handling this very intuitive. @jnsbck @huangziwei @kyralianaka

@michaeldeistler michaeldeistler added v1.0 and removed documentation Improvements or additions to documentation labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants