Miind
AbstractOdeSystem.cpp
Go to the documentation of this file.
1 // Copyright (c) 2005 - 2011 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 // If you use this software in work leading to a scientific publication, you should include a reference there to
19 // the 'currently valid reference', which can be found at http://miind.sourceforge.net
20 #include <cmath>
21 #include <iostream>
22 #include "AbstractOdeSystem.hpp"
23 #include "GeomLibException.hpp"
24 
25 using namespace GeomLib;
26 
28 (
29  const AbstractNeuralDynamics& dyn
30 ):
31 _p_dyn (boost::shared_ptr<AbstractNeuralDynamics>(dyn.Clone())),
32 _t_period (_p_dyn->TPeriod()),
33 _t_step (_p_dyn->TStep()),
34 _par (_p_dyn->Par()),
35 _buffer_interpretation (dyn.InterpretationArray()),
36 _buffer_mass (this->InitializeDensity()),
37 _i_reset (this->InitializeResetBin()),
38 _i_reversal (this->InitializeReversalBin()),
39 _t_current (0.0),
40 _map_cache (vector<MPILib::Index>(0)),
41 _number_of_bins (_buffer_interpretation.size())
42 {
43 }
44 
46 (
47  const AbstractOdeSystem& sys
48 ):
49 _p_dyn (boost::shared_ptr<AbstractNeuralDynamics>(sys._p_dyn->Clone())),
50 _t_period (sys._t_period),
51 _t_step (sys._t_step),
52 _par (sys._par),
53 _buffer_interpretation (sys._buffer_interpretation),
54 _buffer_mass (sys._buffer_mass),
55 _i_reset (sys._i_reset),
56 _i_reversal (sys._i_reversal),
57 _t_current (sys._t_current),
58 _map_cache (sys._map_cache),
59 _number_of_bins (sys._number_of_bins)
60 {
61 }
62 
64 {
65 }
66 
68 {
69  MPILib::Index i_ret;
70  i_ret = this->FindBin(_par._par_pop._V_reset);
71  return i_ret;
72 }
73 
75 {
76  MPILib::Index i_ret;
77  i_ret = this->FindBin(_par._par_pop._V_reversal);
78  return i_ret;
79 }
80 
82 {
83  MPILib::Index i_reset_bin;
84  if ( V < _par._V_min || V > _par._par_pop._theta)
85  throw GeomLibException("Reset potential doesn't make sense");
86 
87  if ( V > _buffer_interpretation.back()){
88  i_reset_bin = _buffer_interpretation.size() - 1;
89  return i_reset_bin;
90  } else
91  for (MPILib::Index i = 0; i < _buffer_interpretation.size() - 1; i++ ){
92  if ( V >= _buffer_interpretation[i] && V < _buffer_interpretation[i+1] ){
93  i_reset_bin = i;
94  return i_reset_bin;
95  }
96  }
97  throw GeomLibException("LeakingOdeSystem couldn't resolve reset bin");
98 }
99 
101 (
102  double* array_interpretation,
103  double* array_mass
104 ) const
105 {
106  MPILib::Number n_bins = this->NumberOfBins();
107 
108  for (MPILib::Index i = 0; i < n_bins-1; i++){
109  array_interpretation[i] = _buffer_interpretation[i];
110  array_mass[i] = _buffer_mass[ MapPotentialToProbabilityBin(i)]/(_buffer_interpretation[i+1]-_buffer_interpretation[i]);
111  }
112 
113  array_interpretation[n_bins-1] = _buffer_interpretation[n_bins-1];
114  array_mass[n_bins-1] = _buffer_mass[MapPotentialToProbabilityBin(n_bins-1)]/(this->_par._par_pop._theta - _buffer_interpretation[n_bins-1]);
115 }
116 
117 void AbstractOdeSystem::InitializeSingleBin(vector<MPILib::Density>* p_vec) const
118 {
119  vector<MPILib::Density>& buffer_mass = *p_vec;
120  const OdeParameter& par_ode = this->Par();
121  Number n_bins = p_vec->size();
122 
123  assert (par_ode._par_dens._mu >= this->_par._V_min);
124  assert (par_ode._par_dens._mu <= this->_par._par_pop._theta);
125 
126  MPILib::Index j = this->FindBin(par_ode._par_dens._mu);
127  if ( j == n_bins - 1 )
128  buffer_mass[j] = 1.0/(this->_par._par_pop._theta - _buffer_interpretation[n_bins -1]);
129  else
130  buffer_mass[j] = 1.0/(_buffer_interpretation[j+1] - _buffer_interpretation[j]);
131 }
132 
133 
134 void AbstractOdeSystem::InitializeGaussian(vector<MPILib::Density>* p_vec_dense) const
135 {
136  vector<MPILib::Density>& buffer_mass = *p_vec_dense;
137  const OdeParameter& par_ode = this->Par();
138  Number n_bins = p_vec_dense->size();
139  for (MPILib::Index i = 0; i < n_bins; i++)
140  {
141  double v = _buffer_interpretation[i];
142  double sqr = (v - par_ode._par_dens._mu)*(v - par_ode._par_dens._mu)/(par_ode._par_dens._sigma*par_ode._par_dens._sigma);
143  buffer_mass[i] = exp(-sqr);
144  }
145 }
146 
147 vector<MPILib::Density> AbstractOdeSystem::InitializeDensity() const
148 {
149  vector<MPILib::Density> vec_dense(_buffer_interpretation.size() + 1 ); // TODO: review, rather hacky, but do not remove without considering line 168
150  if (this->Par()._par_dens._sigma == 0.0)
151  this->InitializeSingleBin(&vec_dense);
152  else
153  this->InitializeGaussian(&vec_dense);
154 
155  this->NormaliseDensity(&vec_dense);
156  return vec_dense;
157 }
158 
160 (
161  vector<MPILib::Density>* p_vec
162 ) const
163 {
164  assert(p_vec != 0);
165 
166  vector<MPILib::Density>& buffer_mass = *p_vec;
167  double sum = 0;
168  Number n_bins = p_vec->size() - 1; // This is the compensation for adding + 1 in line 149
169 
170  assert(n_bins > 0);
171 
172  for (MPILib::Index i = 0; i < n_bins - 1; i++)
173  buffer_mass[i] *= (_buffer_interpretation[i+1] - _buffer_interpretation[i]);
174 
175  //MdK: 16-01-2017 remove index reference to _buffer_interpretation and replace by back
176  buffer_mass[n_bins-1] *= (this->_par._par_pop._theta - _buffer_interpretation.back());
177 
178  for (MPILib::Index i = 0; i < n_bins; i++)
179  sum += buffer_mass[i];
180 
181  for (MPILib::Index i = 0; i < n_bins; i++)
182  buffer_mass[i] /= sum;
183 
184 }
185 
MPILib::Index FindBin(Potential) const
Find which bin in the interpretation array contains this potential.
double Potential
A geometric grid to represent population densities.
void InitializeSingleBin(vector< MPILib::Density > *) const
MPILib::Potential _V_reset
reset potential in V
Contains the parameters necessary to configure a concrete OdeSystem instance. See AbstractOdeSystem a...
vector< MPILib::Potential > _buffer_interpretation
unsigned int Number
void InitializeGaussian(vector< MPILib::Density > *) const
unsigned int Index
The configuration of a GeomAlgorithm requires that the neural dynamics is defined somewhere...
NeuronParameter _par_pop
The neuron parameter.
void NormaliseDensity(vector< MPILib::Density > *) const
MPILib::Potential _theta
threshold potential in V
MPILib::Index InitializeResetBin() const
vector< MPILib::Index > _map_cache
const OdeParameter & Par() const
Access to the OdeParameter of the system. It is often time-critical, therefore implemented as referen...
virtual ~AbstractOdeSystem()=0
pure virtual destructor for base class
virtual AbstractNeuralDynamics * Clone() const =0
virtual construction mechanism
MPILib::Index InitializeReversalBin() const
Base class for all exceptions thrown in GeomLib.
void PrepareReport(double *, double *) const
Represents the current density profile. Both double pointers must point to contiguous memory at least...
InitialDensityParameter _par_dens
Specifies the initial density profile.
boost::shared_ptr< AbstractNeuralDynamics > _p_dyn
vector< MPILib::Density > _buffer_mass
vector< MPILib::Density > InitializeDensity() const
MPILib::Potential _V_reversal
reversal potential in V
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 which we assume to be a defining characteristic of the grid Let then the set of points the set of points which is quadrilateral in shape The quadrilateral should be but not necessarily as long as they are but it is convenient to number them in order of creation In the we will assume that strip numbers created by the integration procedure start and are so that the numbers i in each identify a unique strip Strip no is reserved for stationary points There may or more cells in strip The number of cells in strip $i denoted by with $i the strip number and $j the cell as the i
Definition: 2D.hpp:145
AbstractOdeSystem(const AbstractNeuralDynamics &)
Constructor using neural dynamics object (see AbstractNeuralDynamics and derived classes).
virtual std::vector< Potential > InterpretationArray() const =0
Generate the bin boundaries for geometric binning based on the dyn.