Miind
Response.cpp
Go to the documentation of this file.
1 // Copyright (c) 2005 - 2009 Marc de Kamps
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 //
6 // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
8 // and/or other materials provided with the distribution.
9 // * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
10 // without specific prior written permission.
11 //
12 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
14 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
15 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
16 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 
18 #include "Response.hpp"
19 #include "GeomLibException.hpp"
20 #include <limits>
21 #include <gsl/gsl_integration.h>
22 #include <gsl/gsl_sf_erf.h>
23 #include <gsl/gsl_errno.h>
24 #include <cassert>
25 
26 
27 namespace {
28  const double SQRTPI = sqrt(4*atan(1.0));
29  const double EPSILON_RESPONSE_FUNCTION = 1e-6; // absolute/relative error on spike response function
30  const double MAXIMUM_INVERSE_RESPONSE_FUNCTION = 5; // if upper limit is above this value, it might just as well be infinite
31  const double F_ABS_REL_BOUNDARY = 1; // if upper limit > F_ABS_REL_BOUNDARY, use relative error
32 
33  double _Abru_negative( double x ){
34 
35  // Based on Abramowitz & Stegun
36  // Rational approximation of erf(x)
37  // equation 7.1.26, Dover edition
38 
39  assert (x < 0);
40  x = -x;
41 
42  const double p = 0.3275911;
43  const double a[5] =
44  { 0.254829592, -0.284496736, 1.421413741, -1.453152027, 1.061405429 };
45 
46  double t = 1/(1+p*x);
47 
48  double res = 0;
49 
50  res = (a[0] + ( a[1] + (a[2] + (a[3] + a[4]*t )*t )*t )*t )*t;
51  return res;
52  }
53 
54  double _Abru_positive ( double x ){
55  assert( x >= 0 );
56 
57  double erf = gsl_sf_erf(x);
58 
59  return exp(x*x)*(1 + erf);
60 
61  }
62 
63  double Abru( double x, void* ){
64  if ( x >= 0 )
65  return _Abru_positive(x);
66  else
67  return _Abru_negative(x);
68  }
69 
70 
71 
72  double IntegralValue( double f_lower, double f_upper, double tau)
73  {
74  if ( f_upper < MAXIMUM_INVERSE_RESPONSE_FUNCTION )
75  {
76  double f_integral;
77  double f_error;
78  size_t number_of_evaluations;
79 
80  gsl_function F;
81 
82  F.function = &Abru;
83  F.params = 0;
84 
85  double f_absolute_error;
86  double f_relative_error;
87 
88  // if f_upper > F_ABS_REL_BOUNDARY, the integral is big, and the
89  // relative error is a more sensible measure
90  if ( f_upper > F_ABS_REL_BOUNDARY)
91  {
92  f_absolute_error = 0;
93  f_relative_error = EPSILON_RESPONSE_FUNCTION;
94  }
95  else
96  {
97  f_absolute_error = EPSILON_RESPONSE_FUNCTION;
98  f_relative_error = 0;
99  }
100 
101  int integration_result =
102  gsl_integration_qng
103  (
104  &F,
105  f_lower,
106  f_upper,
107  f_absolute_error,
108  f_relative_error,
109  &f_integral,
110  &f_error,
111  &number_of_evaluations
112  );
113 
114  if (integration_result != GSL_SUCCESS)
115  throw GeomLib::GeomLibException("Rate integrator problem");
116  return SQRTPI*tau*f_integral;
117  }
118  else
119  return std::numeric_limits<double>::max();
120  }
121 
122  double InterspikeTime
123  (
124  double theta,
125  double mu,
126  double sigma,
127  double V_reset,
128  double tau
129  ){
130 
131  double f_upper = (theta - mu) /sigma;
132  double f_lower = (V_reset - mu)/sigma;
133 
134  return IntegralValue(f_lower, f_upper, tau);
135  }
136 
137 } // end of unnamed namespace
138 
139 
141  return 1/( par.tau_refractive + InterspikeTime(par.theta, par.mu, par.sigma, par.V_reset, par.tau) );
142 }
143 
double tau
Membrane time constant.
double ResponseFunction(const GeomLib::ResponseParameter &)
Definition: Response.cpp:140
const double EPSILON_RESPONSE_FUNCTION
Definition: Response.cpp:29
double _Abru_positive(double x)
Definition: Response.cpp:54
Response functions often feature in the work of Amit and Brunel (1997), and are useful for comparing ...
double InterspikeTime(double theta, double mu, double sigma, double V_reset, double tau)
Definition: Response.cpp:123
The objective is find a numerical solution for this equation This requires a numerical representation of the density We will work in the state space of a two dimensional and define a mesh there We first give two examples and then define the general procedure and given in Table for given fixed Delta g see Fig and we will denote coordinates in this dimension by a small letter $v The second dimension can be used to represent parameters as varied as and will represented by $w A strip is constructed by choosing two neighbouring points in state e g and integrating the vector field for a time $T that is assumed to be an integer multiple of a period of time Delta t
Definition: 2D.hpp:101
Base class for all exceptions thrown in GeomLib.
double tau_refractive
Refractive period.
const double MAXIMUM_INVERSE_RESPONSE_FUNCTION
Definition: Response.cpp:30
double V_reset
Reset Potential.
double _Abru_negative(double x)
Definition: Response.cpp:33
double IntegralValue(double f_lower, double f_upper, double tau)
Definition: Response.cpp:72
double theta
Threshold Potential.
double mu
Expected input.
double Abru(double x, void *)
Definition: Response.cpp:63