1# -*- coding: utf-8 -*-
2#
3# evaluate_tsodyks2_synapse.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"""
23Example of the tsodyks2_synapse in NEST
24---------------------------------------
25
26This synapse model implements synaptic short-term depression and short-term f
27according to [1]_ and [2]_. It solves Eq (2) from [1]_ and modulates U according
28
29This connection merely scales the synaptic weight, based on the spike history
30parameters of the kinetic model. Thus, it is suitable for any type of synapse
31that is current or conductance based.
32
33The parameter `A_se` from the publications is represented by the
34synaptic weight. The variable `x` in the synapse properties is the
35factor that scales the synaptic weight.
36
37Parameters
38~~~~~~~~~~
39
40The following parameters can be set in the status dictionary:
41
42* U           - probability of release increment (U1) [0,1], default=0.
43* u           - Maximum probability of release (U_se) [0,1], default=0.
44* x           - current scaling factor of the weight, default=U
45* tau_rec     - time constant for depression in ms, default=800 ms
46* tau_fac     - time constant for facilitation in ms, default=0 (off)
47
48Notes
49~~~~~
50
51Under identical conditions, the ``tsodyks2_synapse`` produces slightly lower
52peak amplitudes than the ``tsodyks_synapse``. However, the qualitative behavior
53is identical.
54
55This compares the two synapse models.
56
57References
58~~~~~~~~~~
59
60.. [1] Tsodyks MV, and Markram H. (1997). The neural code between
61       neocortical depends on neurotransmitter release probability. PNAS,
62       94(2), 719-23.
63.. [2] Fuhrmann G, Segev I, Markram H, and Tsodyks MV. (2002). Coding of
64       temporal information by activity-dependent synapses. Journal of
65       Neurophysiology, 8. https://doi.org/10.1152/jn.00258.2001
66.. [3] Maass W, and Markram H. (2002). Synapses as dynamic memory buffers.
67       Neural Networks, 15(2), 155-161.
68       http://dx.doi.org/10.1016/S0893-6080(01)00144-7
69"""
70
71import nest
72import nest.voltage_trace
73import matplotlib.pyplot as plt
74
75nest.ResetKernel()
76
77###############################################################################
78# Parameter set for depression
79
80dep_params = {"U": 0.67, "u": 0.67, 'x': 1.0, "tau_rec": 450.0,
81              "tau_fac": 0.0, "weight": 250.}
82
83###############################################################################
84# Parameter set for facilitation
85
86fac_params = {"U": 0.1, "u": 0.1, 'x': 1.0, "tau_fac": 1000.,
87              "tau_rec": 100., "weight": 250.}
88
89###############################################################################
90# Now we assign the parameter set to the synapse models.
91
92tsodyks_params = dict(fac_params, synapse_model="tsodyks_synapse")  # for tsodyks_synapse
93tsodyks2_params = dict(fac_params, synapse_model="tsodyks2_synapse")  # for tsodyks2_synapse
94
95###############################################################################
96# Create three neurons.
97
98neuron = nest.Create("iaf_psc_exp", 3, params={"tau_syn_ex": 3.})
99
100###############################################################################
101# Neuron one produces spikes. Neurons 2 and 3 receive the spikes via the two
102# synapse models.
103
104nest.Connect(neuron[0], neuron[1], syn_spec=tsodyks_params)
105nest.Connect(neuron[0], neuron[2], syn_spec=tsodyks2_params)
106
107###############################################################################
108# Now create two voltmeters to record the responses.
109
110voltmeter = nest.Create("voltmeter", 2)
111
112###############################################################################
113# Connect the voltmeters to the neurons.
114
115nest.Connect(voltmeter[0], neuron[1])
116nest.Connect(voltmeter[1], neuron[2])
117
118###############################################################################
119# Now simulate the standard STP protocol: a burst of spikes, followed by a
120# pause and a recovery response.
121
122neuron[0].I_e = 376.0
123
124nest.Simulate(500.0)
125neuron[0].I_e = 0.0
126nest.Simulate(500.0)
127neuron[0].I_e = 376.0
128nest.Simulate(500.0)
129
130###############################################################################
131# Finally, generate voltage traces. Both are shown in the same plot and
132# should be almost completely overlapping.
133
134nest.voltage_trace.from_device(voltmeter[0])
135nest.voltage_trace.from_device(voltmeter[1])
136plt.show()
137