Skip to content

Commit 62cd73f

Browse files
author
janeirik
committed
Add test, remove old
1 parent d5aa3fe commit 62cd73f

File tree

2 files changed

+97
-172
lines changed

2 files changed

+97
-172
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# test_iaf_psc_exp_ps.py
4+
#
5+
# This file is part of NEST.
6+
#
7+
# Copyright (C) 2004 The NEST Initiative
8+
#
9+
# NEST is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# NEST is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
21+
22+
"""
23+
Name: testsuite::test_iaf_psc_exp_ps
24+
25+
Synopsis: (test_iaf_psc_exp_ps) run -> compares response to current step with analytical solution
26+
27+
Description:
28+
A DC current is injected into the neuron using a current generator
29+
device. The membrane potential is recorder, and compared to the expected
30+
analytical solution, with a spike happening off-grid.
31+
"""
32+
33+
import nest
34+
import numpy as np
35+
import numpy.testing as nptest
36+
import pytest
37+
38+
39+
def test_iaf_psc_exp_ps_dc_input():
40+
dt = 0.1
41+
dc_amp = 1010.0
42+
43+
nest.ResetKernel()
44+
nest.set(resolution=dt, local_num_threads=1)
45+
46+
dc_gen = nest.Create("dc_generator", {"amplitude": dc_amp})
47+
nrn = nest.Create("iaf_psc_exp_ps", 1)
48+
vm = nest.Create("voltmeter", {"interval": 0.1})
49+
50+
syn_spec = {"synapse_model": "static_synapse", "weight": 1.0, "delay": dt}
51+
nest.Connect(dc_gen, nrn, syn_spec=syn_spec)
52+
nest.Connect(vm, nrn, syn_spec=syn_spec)
53+
54+
nest.Simulate(8.0)
55+
56+
times = vm.get("events", "times")
57+
times -= dt # account for delay to multimeter
58+
59+
tau_m = nrn.get("tau_m")
60+
R = tau_m / nrn.get("C_m")
61+
theta = nrn.get("V_th")
62+
E_L = nrn.get("E_L")
63+
64+
# array for analytical solution
65+
V_m_analytical = np.empty_like(times)
66+
V_m_analytical[:] = nrn.get("E_L")
67+
68+
# first index for which the DC current is received by neuron.
69+
# DC current will be integrated from this time step
70+
start_index = 1
71+
72+
# analytical solution without delay and threshold on a grid
73+
vm_soln = E_L + (1 - np.exp(-times / tau_m)) * R * dc_amp
74+
75+
# exact time at which the neuron will spike
76+
exact_spiketime = -tau_m * np.log(1 - (theta - E_L) / (R * dc_amp))
77+
78+
# offset from grid point
79+
time_offset = exact_spiketime - (exact_spiketime // dt) * dt
80+
81+
# solution calculated on the grid, with t0 being the exact spike time
82+
vm_soln_offset = E_L + (1 - np.exp(-(times - time_offset + dt) / tau_m)) * R * dc_amp
83+
84+
# rise until threshold
85+
V_m_analytical[start_index:] = vm_soln[:-start_index]
86+
87+
# set refractory potential
88+
# first index after spike, offset by time at which DC current arrives
89+
crossing_ind = int(exact_spiketime // dt + 1) + start_index
90+
num_ref = int(nrn.get("t_ref") / dt)
91+
V_m_analytical[crossing_ind : crossing_ind + num_ref] = nrn.get("V_reset")
92+
93+
# rise after refractory period
94+
num_inds = len(times) - crossing_ind - num_ref
95+
V_m_analytical[crossing_ind + num_ref :] = vm_soln_offset[:num_inds]
96+
97+
nptest.assert_array_almost_equal(V_m_analytical, vm.get("events", "V_m"))

testsuite/unittests/test_iaf_psc_exp_ps.sli

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)