Skip to content

Commit bfc200c

Browse files
author
Alexander Ororbia
committed
added rk2 support for H-H cell
1 parent af283dc commit bfc200c

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

ngclearn/components/neurons/spiking/hodgkinHuxleyCell.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,28 @@ class HodgkinHuxleyCell(JaxComponent): ## Hodgkin-Huxley spiking cell
102102
103103
v_reset: voltage value to reset to after a spike (in mV)
104104
(Default: 0 mV)
105+
106+
integration_type: type of integration to use for this cell's dynamics;
107+
current supported forms include "euler" (Euler/RK-1 integration)
108+
and "midpoint" or "rk2" (midpoint method/RK-2 integration) (Default: "euler")
109+
110+
:Note: setting the integration type to the midpoint method will
111+
increase the accuracy of the estimate of the cell's evolution
112+
at an increase in computational cost (and simulation time)
105113
"""
106114

107115
# Define Functions
108116
def __init__(
109117
self, name, n_units, tau_v, resist_m=1., v_Na=115., v_K=-35., v_L=10.6, g_Na=100., g_K=5., g_L=0.3, thr=4.,
110-
spike_reset=False, v_reset=0., **kwargs
118+
spike_reset=False, v_reset=0., integration_type="euler", **kwargs
111119
):
112120
super().__init__(name, **kwargs)
113121

114-
## membrane parameter setup (affects ODE integration)
122+
## Integration properties
123+
self.integrationType = integration_type
124+
self.intgFlag = get_integrator_code(self.integrationType)
125+
126+
## cell properties / biophysical parameter setup (affects ODE integration)
115127
self.tau_v = tau_v ## membrane time constant
116128
self.R_m = resist_m ## resistance value
117129
self.spike_reset = spike_reset
@@ -140,15 +152,24 @@ def __init__(
140152

141153
@transition(output_compartments=["v", "m", "n", "h", "s", "tols"])
142154
@staticmethod
143-
def advance_state(t, dt, spike_reset, v_reset, thr, tau_v, R_m, g_Na, g_K, g_L, v_Na, v_K, v_L, j, v, m, n, h, tols):
155+
def advance_state(
156+
t, dt, spike_reset, v_reset, thr, tau_v, R_m, g_Na, g_K, g_L, v_Na, v_K, v_L, j, v, m, n, h, tols, intgFlag
157+
):
144158
_j = j * R_m
145159
alpha_n_of_v, beta_n_of_v, alpha_m_of_v, beta_m_of_v, alpha_h_of_v, beta_h_of_v = _calc_biophysical_constants(v)
146160
## integrate voltage / membrane potential
147-
_, _v = step_euler(0., v, dv_dt, dt, (_j, m + 0., n + 0., h + 0., tau_v, g_Na, g_K, g_L, v_Na, v_K, v_L))
148-
## next, integrate different channels
149-
_, _n = step_euler(0., n, dx_dt, dt, (alpha_n_of_v, beta_n_of_v))
150-
_, _m = step_euler(0., m, dx_dt, dt, (alpha_m_of_v, beta_m_of_v))
151-
_, _h = step_euler(0., h, dx_dt, dt, (alpha_h_of_v, beta_h_of_v))
161+
if intgFlag == 1:
162+
_, _v = step_rk2(0., v, dv_dt, dt, (_j, m + 0., n + 0., h + 0., tau_v, g_Na, g_K, g_L, v_Na, v_K, v_L))
163+
## next, integrate different channels
164+
_, _n = step_rk2(0., n, dx_dt, dt, (alpha_n_of_v, beta_n_of_v))
165+
_, _m = step_rk2(0., m, dx_dt, dt, (alpha_m_of_v, beta_m_of_v))
166+
_, _h = step_rk2(0., h, dx_dt, dt, (alpha_h_of_v, beta_h_of_v))
167+
else: # integType == 0 (default -- Euler)
168+
_, _v = step_euler(0., v, dv_dt, dt, (_j, m + 0., n + 0., h + 0., tau_v, g_Na, g_K, g_L, v_Na, v_K, v_L))
169+
## next, integrate different channels
170+
_, _n = step_euler(0., n, dx_dt, dt, (alpha_n_of_v, beta_n_of_v))
171+
_, _m = step_euler(0., m, dx_dt, dt, (alpha_m_of_v, beta_m_of_v))
172+
_, _h = step_euler(0., h, dx_dt, dt, (alpha_h_of_v, beta_h_of_v))
152173
## obtain action potentials/spikes/pulses
153174
s = (_v > thr) * 1.
154175
if spike_reset: ## if spike-reset used, variables snapped back to initial conditions

0 commit comments

Comments
 (0)