/*
 *  test_tsodyks_facilitating.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

 /* BeginDocumentation
Name: test_tsodyks_facilitating - sli script for overall test of tsodyks synapse models

Synopsis:(test_tsodyks_facilitating) run -> compare cout with comments in file

Description:
Script to test Tsodyks short term plasticity facilitating synapses according to
'Neural Networks with Dynamic Synapses'
Misha Tsodyks, Klaus Pawelzik, Henry Markram
Neural computation 10, 821--853 (1998)

Reproduces figure 1 B, (C)

Revised by Hans Ekkehard Plesser 2016 using explicit input spike train.

Author:  Markus Diesmann, Moritz Helias
FirstVersion: March 2006
*/

(unittest) run
/unittest using

% -------
%
% Expected solution
%
% -------

/vm_expected
[
[25 0]
[50 0]
[75 0]
[100 4.739750000000000e-01]
[125 7.706030000000000e-01]
[150 1.297120000000000e+00]
[175 1.757990000000000e+00]
[200 2.114420000000000e+00]
[225 2.714490000000000e+00]
[250 2.785530000000000e+00]
[275 3.546150000000000e+00]
[300 3.272710000000000e+00]
[325 4.233240000000000e+00]
[350 3.583070000000000e+00]
[375 4.788130000000000e+00]
[400 3.739560000000000e+00]
[425 5.233850000000000e+00]
[450 3.767230000000000e+00]
[475 5.593890000000000e+00]
[500 3.687720000000000e+00]
[525 5.888270000000000e+00]
[550 3.881790000000000e+00]
[575 6.132580000000000e+00]
[600 4.042850000000000e+00]
[625 6.338430000000000e+00]
[650 4.178550000000000e+00]
[675 6.514250000000000e+00]
[700 4.294460000000000e+00]
[725 6.666160000000000e+00]
[750 4.394600000000000e+00]
[775 6.798620000000000e+00]
[800 4.481930000000000e+00]
[825 6.914990000000000e+00]
[850 4.558640000000000e+00]
[875 7.017830000000000e+00]
[900 4.626440000000000e+00]
[925 7.109160000000000e+00]
[950 4.686650000000000e+00]
[975 7.190620000000000e+00]
[1000 4.740350000000000e+00]
[1025 7.263560000000000e+00]
[1050 4.788430000000000e+00]
[1075 7.329110000000000e+00]
[1100 4.831650000000000e+00]
[1125 3.185220000000000e+00]
[1150 2.099830000000000e+00]
[1175 1.384290000000000e+00]
]
def

% ---------
% Model parameters
% ---------

/local_num_threads 1 def
/h 0.1 def

/Tau 60.0 def        % membrane time constant
/Theta 15.0 def      % threshold
/E_L 0.0 def         % reset potential of Vm
/R 1.0 def
/C Tau R div def     % Tau [ms] / 1.0 GOhm in NEST units
/TauR 2.0 def        % refractory time
/Tau_psc 1.5 def     % time constant of PSC (=Tau_inact)
/Tau_rec 130.0 def   % recovery time
/Tau_fac 530.0 def   % facilitation time
/U 0.03 def          % facilitation parameter U
/A 1540.0 def        % PSC weight in pA

/input_train 
[
    98.1             % first spike [ms]
  1050.0             % last spike [ms]
    50.1             % interspike interval [ms]
] Range def

/T_sim 1200. def     % simulation time [ms]     

% ---------

[/tsodyks_synapse /tsodyks_synapse_hom] 
{
  /synapse_model Set

  ResetKernel      % clear all existing network elements

  
  % set resolution and limits on delays
  % limits must be set BEFORE connecting any elements
  0
  <<
    /resolution h
    /local_num_threads local_num_threads
  >> SetStatus

  /sg /spike_generator << /spike_times input_train >> Create def
  /pn /parrot_neuron Create def
  
  /neuron 
    /iaf_tum_2000
    << /tau_m Tau
       /t_ref_tot TauR
       /t_ref_abs TauR
       /tau_syn_ex Tau_psc
       /tau_syn_in Tau_psc
       /C_m C
       /V_reset E_L
       /E_L E_L
       /V_th Theta
       /V_m E_L >>
  Create def

  /vm 
    /voltmeter 
    << /withtime true
       /to_memory true
       /interval 25.0
    >>
  Create def

  synapse_model 
  << /tau_psc Tau_psc 
     /tau_rec Tau_rec
  	 /tau_fac Tau_fac
  	 /U U
  	 /delay 0.1
  	 /weight A
  	 /u 0.0
  	 /x 1.0
  >> SetDefaults

  sg pn Connect   % pn required, devices cannot project to plastic synapses
  pn neuron synapse_model Connect
  vm neuron Connect

  T_sim Simulate

  % compare results to expected voltage trace
  vm [/events [/times /V_m]] get cva
  6 ToUnitTestPrecision
  Transpose /vm_sim Set  % array of recorded data

  % to print to screen
  vm_sim {
    ==	  
  } forall

  vm_sim vm_expected eq assert_or_die

} forall % tsodyks models

endusing % unittest

