You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Building a dynamic synapse can be done by importing the [exponential synapse](ngclearn.components.synapses.exponentialSynapse),
25
-
the [double-exponential synapse](ngclearn.components.synapses.doubleExpSynapse), or the [alpha synapse](ngclearn.components.synapses.alphaSynapse) from ngc-learn's in-built components and setting them up within a model context for easy analysis. Go ahead and create a Python script named `probe_synapses.py` to place
25
+
the [double-exponential synapse](ngclearn.components.synapses.doubleExpSynapse), or the [alpha synapse](ngclearn.components.synapses.alphaSynapse) from ngc-learn's in-built components and setting them up within a model context for easy analysis. Go ahead and create a Python script named `probe_dynamic_synapses.py` to place
26
26
the code you will write within.
27
27
For the first part of this lesson, we will import all three dynamic synapse models and compare their behavior.
28
28
This can be done as follows (using the meta-parameters we provide in the code block below to ensure reasonable dynamics):
In effect, the FitzHugh–Nagumo `F-N` two-dimensional differential
58
-
equation system (developed by [1] and [2]) is
59
-
a useful simplification of the more intricate Hodgkin–Huxley (H-H) squid axon
60
-
model, attempting to extract some of the benefits of its more detailed modeling
61
-
of the spiking cellular activation and deactivation dynamics (specifically
62
-
attempting to isolate the properties related to sodium/potassium ion flow
63
-
from cellular properties of excitation and propagation). Notably, the `F-N`
64
-
cell models membrane potential `v` with a cubic function (which facilitates
65
-
self-excitation through positive feedback) in tandem with a recovery variable `w`
66
-
that provides a slower form of negative feedback. The linear dynamics that govern
67
-
`w` are controlled by (dimensionless) coefficients `alpha` and `beta`, which
68
-
control its shift and scale, respectively (another factor `gamma` is introduced
69
-
in our implementation, which divides the cubic term in the voltage dynamics, but
70
-
generally this can usually be set to either a value of `1` or `3` as in [1]).
71
-
The value `tau_w` controls the time constant for the recovery variable (and,
72
-
technically, ngc-learn implements `tau_m` to control the membrane potential,
73
-
but this is default set to `1` since [1] and [2] typically only use a time
74
-
constant for the recovery variable).
75
-
76
-
The initial conditions for the voltage (i.e., `v0`) and the recovery (i.e., `w0`)
77
-
have been set to particular interesting values above for the demonstration
78
-
purposes of this tutorial but, by default, are `0` in the `F-N` cell component.
53
+
In effect, the FitzHugh–Nagumo `F-N` two-dimensional differential equation system (developed by [1] and [2]) is a useful simplification of the more intricate Hodgkin–Huxley (H-H) squid axon model, attempting to extract some of the benefits of its more detailed modeling of the spiking cellular activation and deactivation dynamics (specifically attempting to isolate the properties related to sodium/potassium ion flow from cellular properties of excitation and propagation). Notably, the `F-N` cell models membrane potential `v` with a cubic function (which facilitates self-excitation through positive feedback) in tandem with a recovery variable `w` that provides a slower form of negative feedback. The linear dynamics that govern `w` are controlled by (dimensionless) coefficients `alpha` and `beta`, which control its shift and scale, respectively (another factor `gamma` is introduced in our implementation, which divides the cubic term in the voltage dynamics, but generally this can usually be set to either a value of `1` or `3` as in [1]).
54
+
The value `tau_w` controls the time constant for the recovery variable (and, technically, ngc-learn implements `tau_m` to control the membrane potential, but this is default set to `1` since [1] and [2] typically only use a time constant for the recovery variable).
55
+
56
+
The initial conditions for the voltage (i.e., `v0`) and the recovery (i.e., `w0`) have been set to particular interesting values above for the demonstration purposes of this tutorial but, by default, are `0` in the `F-N` cell component.
79
57
80
58
Formally, the core dynamics of the `F-N` can be written out as follows:
81
59
@@ -84,24 +62,13 @@ $$
84
62
\tau_w \frac{\partial \mathbf{w}_t}{\partial t} &= \mathbf{v}_t + a - b\mathbf{w}_t
85
63
$$
86
64
87
-
where $a$ and $b$ are factors that drive the recovery variable's dynamics
88
-
(shift and scaling, respectively), $R$ is the membrane resistance, $\tau_m$ is the
89
-
membrane time constant, and $\tau_w$ is the recovery time constant ($g$ is a
90
-
dividing constant meant to dampen the effects of the cubic term, but is generally
91
-
set to $g = 1$ to adhere to [1] and [2])
65
+
where $a$ and $b$ are factors that drive the recovery variable's dynamics (shift and scaling, respectively), $R$ is the membrane resistance, $\tau_m$ is the membrane time constant, and $\tau_w$ is the recovery time constant ($g$ is a dividing constant meant to dampen the effects of the cubic term, but is generally set to $g = 1$ to adhere to [1] and [2])
92
66
93
67
94
68
### Simulating a FitzHugh–Nagumo Neuronal Cell
95
69
96
-
Given that we have a single-cell dynamical system set up as above, we can next
97
-
write some code for visualizing how the `F-N` node's membrane potential and
98
-
coupled recovery variable evolve with time (specifically over a period of about
99
-
`200` milliseconds). We will, much as we did with the leaky integrators in
100
-
prior tutorials, inject an electrical current `j` into the `F-N` cell (this time
101
-
just a constant current value of `0.23` amperes) and observe how the cell
102
-
produces action potentials.
103
-
Specifically, we can plot the neuron's voltage `v` and recovery variable `w`
104
-
as follows:
70
+
Given that we have a single-cell dynamical system set up as above, we can next write some code for visualizing how the `F-N` node's membrane potential and coupled recovery variable evolve with time (specifically over a period of about `200` milliseconds). We will, much as we did with the leaky integrators in prior tutorials, inject an electrical current `j` into the `F-N` cell (this time just a constant current value of `0.23` amperes) and observe how the cell produces action potentials.
71
+
Specifically, we can plot the neuron's voltage `v` and recovery variable `w` as follows:
A useful note is that the `F-N` above used Euler integration to step through its
178
-
dynamics (this is the default/base routine for all cell components in ngc-learn);
179
-
however, one could configure it to use the midpoint method for integration
180
-
by setting its argument `integration_type = rk2` in cases where more
181
-
accuracy in the dynamics is needed (at the cost of additional computational time).
182
-
183
-
## Optional: Setting Up The Components with a JSON Configuration
184
-
185
-
While you are not required to create a JSON configuration file for ngc-learn,
186
-
to get rid of the warning that ngc-learn will throw at the start of your
187
-
program's execution (indicating that you do not have a configuration set up yet),
188
-
all you need to do is create a sub-directory for your JSON configuration
189
-
inside of your project code's directory, i.e., `json_files/modules.json`.
190
-
Inside the JSON file, you would write the following:
191
-
192
-
```json
193
-
[
194
-
{"absolute_path": "ngclearn.components",
195
-
"attributes": [
196
-
{"name": "FitzHughNagumoCell"}]
197
-
},
198
-
{"absolute_path": "ngcsimlib.operations",
199
-
"attributes": [
200
-
{"name": "overwrite"}]
201
-
}
202
-
]
203
-
```
143
+
A useful note is that the `F-N` above used Euler integration to step through its dynamics (this is the default/base routine for all cell components in ngc-learn); however, one could configure it to use the midpoint method for integration by setting its argument `integration_type = rk2` in cases where more accuracy in the dynamics is needed (at the cost of additional computational time).
Copy file name to clipboardExpand all lines: docs/tutorials/neurocog/hodgkin_huxley_cell.md
+26-68Lines changed: 26 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,12 @@
1
1
# Lecture 2E: The Hodgkin-Huxley Cell
2
2
3
-
In this tutorial, we will study/setup one of the most important biophysical
4
-
neuronal models in computational neuroscience -- the Hodgkin-Huxley (H-H) spiking
5
-
cell model.
3
+
In this tutorial, we will study/setup one of the most important and sophisticated biophysical neuronal models in computational neuroscience -- the Hodgkin-Huxley (H-H) spiking cell model.
6
4
7
5
## Using and Probing the H-H Cell
8
6
9
-
Go ahead and make a new folder for this study and create a Python script,
10
-
i.e., `run_hhcell.py`, to write your code for this part of the tutorial.
7
+
Go ahead and make a new folder for this study and create a Python script, i.e., `run_hhcell.py`, to write your code for this part of the tutorial.
11
8
12
-
Now let's set up the controller for this lesson's simulation and construct a
13
-
single component system made up of an H-H cell.
9
+
Now let's set up the controller for this lesson's simulation and construct a single component system made up of an H-H cell.
14
10
15
11
16
12
### Instantiating the H-H Neuronal Cell
@@ -22,9 +18,7 @@ H-H cell amounts to the following:
22
18
from jax import numpy as jnp, random, jit
23
19
import numpy as np
24
20
25
-
from ngclearn.utils.model_utils import scanner
26
-
from ngcsimlib.context import Context
27
-
from ngclearn.utils import JaxProcess
21
+
from ngclearn import Context, MethodProcess
28
22
## import model-specific mechanisms
29
23
from ngclearn.components.neurons.spiking.hodgkinHuxleyCell import HodgkinHuxleyCell
30
24
@@ -52,18 +46,15 @@ with Context("Model") as model:
where we observe that the above four-dimensional set of dynamics is composed of nonlinear ODEs. Notice that, in each gate or channel probability ODE, there are two generator functions (each of which is a function of the membrane potential $\mathbf{v}_t$) that produces the necessary dynamic coefficients at time $t$; $\alpha_x(\mathbf{v}_t)$ and $\beta_x(\mathbf{v}_t)$ produce different biopphysical weighting values depending on which channel $x = \{n, m, h\}$ they are related to.
82
+
where we observe that the above four-dimensional set of dynamics is composed of nonlinear ODEs. Notice that, in each gate or channel probability ODE, there are two generator functions (each of which is a function of the membrane potential $\mathbf{v}_t$) that produces the necessary dynamic coefficients at time $t$; $\alpha_x(\mathbf{v}_t)$ and $\beta_x(\mathbf{v}_t)$ produce different biophysical weighting values depending on which channel $x = \{n, m, h\}$ they are related to.
92
83
Note that, in ngc-learn's implementation of the H-H cell model, most of the core coefficients have been generally set according to Hodgkin and Huxley's 1952 work but can be configured by the experimenter to obtain different kinds of behavior/dynamics.
93
84
94
85
### Simulating the H-H Neuronal Cell
95
86
96
-
To see how the H-H cell works, we next write some code for visualizing how
97
-
the node's membrane potential and core related gates/channels evolve with time
98
-
(over a period of about `200` milliseconds). We will inject a square input pulse current
99
-
into our H-H cell (specifically into its `j` compartment) and observe how the cell behaves in response.
87
+
To see how the H-H cell works, we next write some code for visualizing how the node's membrane potential and core related gates/channels evolve with time (over a period of about `200` milliseconds). We will inject a square input pulse current into our H-H cell (specifically into its `j` compartment) and observe how the cell behaves in response.
100
88
Specifically, we simulate the injection of this kind of current via the code below:
101
89
102
90
```python
@@ -112,26 +100,25 @@ v = []
112
100
n = []
113
101
m = []
114
102
h = []
115
-
model.reset()
103
+
reset_process.run()
116
104
for ts inrange(x_seq.shape[1]):
117
105
x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t
118
-
model.clamp(x_t)
119
-
model.run(t=ts * dt, dt=dt)
120
-
outs.append(a.s.value)
121
-
n.append(cell.n.value[0, 0])
122
-
m.append(cell.m.value[0, 0])
123
-
h.append(cell.h.value[0, 0])
124
-
v.append(cell.v.value[0, 0])
125
-
print(f"\r{ts} v = {cell.v.value}", end="")
106
+
clamp(x_t)
107
+
advance_process.run(t=ts * dt, dt=dt)
108
+
outs.append(cell.s.get())
109
+
n.append(cell.n.get()[0, 0])
110
+
m.append(cell.m.get()[0, 0])
111
+
h.append(cell.h.get()[0, 0])
112
+
v.append(cell.v.get()[0, 0])
113
+
print(f"\r{ts} v = {cell.v.get()}", end="")
126
114
time_span.append(ts*dt)
127
115
outs = jnp.concatenate(outs, axis=1)
128
116
v = jnp.array(v)
129
117
time_span = jnp.array(time_span)
130
118
outs = jnp.squeeze(outs)
131
119
```
132
120
133
-
and we can plot the dynamics of the neuron's voltage `v` and its three gate/channel
134
-
variables, `h`, `m`, and `n`, with the following:
121
+
and we can plot the dynamics of the neuron's voltage `v` and its three gate/channel variables, `h`, `m`, and `n`, with the following:
You should get a compound plot that depict the evolution of the H-H cell's voltage
165
-
and channel/gate variables, i.e., saved as `hh_plot.jpg` locally to
166
-
disk, like the one below:
151
+
You should get a compound plot that depict the evolution of the H-H cell's voltage and channel/gate variables, i.e., saved as `hh_plot.jpg` locally to disk, like the one below:
A useful note is that the H-H cell above used Euler integration to step through its
180
-
dynamics (this is the default/base routine for all cell components in ngc-learn).
181
-
However, one could configure the cell to use the midpoint method for integration
182
-
by setting its argument `integration_type = rk2` or the Runge-Kutta fourth-order
183
-
routine via `integration_type=rk4` for cases where, at the cost of increased
184
-
compute time, more accurate dynamics are possible.
185
-
186
-
## Optional: Setting Up The Components with a JSON Configuration
187
-
188
-
While you are not required to create a JSON configuration file for ngc-learn,
189
-
to get rid of the warning that ngc-learn will throw at the start of your
190
-
program's execution (indicating that you do not have a configuration set up yet),
191
-
all you need to do is create a sub-directory for your JSON configuration
192
-
inside of your project code's directory, i.e., `json_files/modules.json`.
193
-
Inside the JSON file, you would write the following:
194
-
195
-
```json
196
-
[
197
-
{"absolute_path": "ngclearn.components",
198
-
"attributes": [
199
-
{"name": "HodgkinHuxleyCell"}]
200
-
},
201
-
{"absolute_path": "ngcsimlib.operations",
202
-
"attributes": [
203
-
{"name": "overwrite"}]
204
-
}
205
-
]
206
-
```
164
+
A useful note is that the H-H cell above used Euler integration to step through its dynamics (this is the default/base routine for all cell components in ngc-learn).
165
+
However, one could configure the cell to use the midpoint method for integration by setting its argument `integration_type = rk2` or the Runge-Kutta fourth-order routine via `integration_type=rk4` for cases where, at the cost of increased compute time, more accurate dynamics are possible.
166
+
207
167
208
168
## References
209
169
210
-
<b>[1]</b> Hodgkin, Alan L., and Andrew F. Huxley. "A quantitative description
211
-
of membrane current and its application to conduction and excitation in nerve."
212
-
The Journal of physiology 117.4 (1952): 500.
170
+
<b>[1]</b> Hodgkin, Alan L., and Andrew F. Huxley. "A quantitative description of membrane current and its application to conduction and excitation in nerve." The Journal of physiology 117.4 (1952): 500.
0 commit comments