Miind
CNZLCache.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 
21 #include "CNZLCache.hpp"
22 
23 using namespace GeomLib;
24 using namespace MPILib;
25 
27 _old_set(0),
28 _vec_coverpair(0)
29 {
30 }
31 
33 {
34  // create the vectors if necessary
35  while (_vec_coverpair.size() < _p_vec_set->size()){
36  input_pair_list pair_list;
37  pair_list.first = vector<BinEstimator::CoverPair>(_n_bins);
38  pair_list.second = vector<BinEstimator::CoverPair>(_n_bins);
39  _vec_coverpair.push_back(pair_list);
40  }
41 
42  // vectors are there
43  for (Index i = 0; i < _p_vec_set->size(); i++){
44 
45  // initially this was only done when rate_e != 0; this is an error, as input steps may change at point in time when the rate happens to 0 incidently
46  MPILib::Efficacy h_e = (*_p_vec_set)[i]._h_exc;
47  for(Index j = 0; j < _n_bins; j++)
48  _vec_coverpair[i].first[j] = _p_estimator->CalculateBinCover(j,-h_e);
49 
50  MPILib::Efficacy h_i = (*_p_vec_set)[i]._h_inh;
51  for (Index j = 0; j < _n_bins; j++)
52  _vec_coverpair[i].second[j] = _p_estimator->CalculateBinCover(j,-h_i);
53 
54  }
55 }
56 
58 {
59  const vector<InputParameterSet> vec_set = *_p_vec_set;
60 
61  if (_old_set.size() != _p_vec_set->size() )
62  return true;
63 
64  Number n_size = _old_set.size();
65  for (Index i = 0; i < n_size; i++)
66  {
67  if (vec_set[i]._h_exc != _old_set[i]._h_exc || vec_set[i]._h_inh != _old_set[i]._h_inh)
68  return true;
69  }
70 
71  return false;
72 }
73 
75 (
76  const AbstractOdeSystem& sys,
77  const vector<InputParameterSet>& vec_set,
78  const BinEstimator& estimator
79 )
80 {
81  _n_bins = sys.NumberOfBins();
82 
83  _p_estimator = &estimator;
84  _p_vec_set = &vec_set;
85  _p_sys = &sys;
86 
87  if (InputStepsHaveChanged() ){
88  InitializeCoverPairs();
89  _old_set = *_p_vec_set;
90  }
91  // else
92  // keep the old values
93 }
A geometric grid to represent population densities.
vector< input_pair_list > _vec_coverpair
Definition: CNZLCache.hpp:66
const Estimator * _p_estimator
Definition: CNZLCache.hpp:63
unsigned int Number
double Efficacy
unsigned int Index
pair< vector< typename Estimator::CoverPair >, vector< typename Estimator::CoverPair > > input_pair_list
Definition: CNZLCache.hpp:52
vector< InputParameterSet > _old_set
Definition: CNZLCache.hpp:62
CNZLCache()
No default arguments for constructor.
Definition: CNZLCache.cpp:26
void Initialize(const AbstractOdeSystem &, const vector< InputParameterSet > &set, const Estimator &)
Initialize the cache. Must be called before first use.
Definition: CNZLCache.cpp:75
const vector< InputParameterSet > * _p_vec_set
Definition: CNZLCache.hpp:61
Number NumberOfBins() const
Number of bins used in the grid representation.
void InitializeCoverPairs()
Definition: CNZLCache.cpp:32
Calculates the coverage corresponding a given bin and a potential difference.
bool InputStepsHaveChanged() const
Definition: CNZLCache.cpp:57