Unfit  3.1.1
Data fitting and optimization software
NonStationaryMarkov.hpp
1 // Unfit: Data fitting and optimization software
2 //
3 // Copyright (C) 2012- Dr Martin Buist & Dr Alberto Corrias
4 // Contacts: martin.buist _at_ nus.edu.sg; alberto _at_ nus.edu.sg
5 //
6 // See the 'Contributors' file for a list of those who have contributed
7 // to this work.
8 //
9 // This program 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 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 #ifndef UNFIT_EXAMPLES_NONSTATIONARYMARKOV_HPP_
23 #define UNFIT_EXAMPLES_NONSTATIONARYMARKOV_HPP_
24 
25 #include <cmath>
26 #include <vector>
27 #include "GenericCostFunction.hpp"
28 
29 namespace Unfit
30 {
31 namespace Examples
32 {
47 {
48  public:
69  NonStationaryMarkov(const std::vector<std::vector<double>> &markov_data)
70  : markov_data_ {markov_data}
71  {}
72 
86  std::vector<double> operator()(const std::vector<double> &param)
87  {
88  const std::size_t num_voltages = markov_data_.size();
89  const std::size_t num_data_points = markov_data_[0].size();
90  std::vector<double> residuals(num_voltages*num_data_points);
91  double vm = -60.0;
92  // Note that the zero index is time
93  for (auto j = 1u; j < num_voltages; ++j) {
94  for (unsigned i = 0u; i < num_data_points; ++i) {
95  const auto t = markov_data_[0][i]; // time
96  residuals[j*num_data_points + i] = markov_data_[j][i] // experiment
97  - param[0] * exp(vm / param[1]) * exp(-(t - param[2]) *
98  (t - param[2]) / (2.0 * param[3] * param[3])); // - model
99  }
100  vm += 10.0;
101  }
102  return residuals;
103  }
104  private:
106  const std::vector<std::vector<double>> markov_data_;
107 };
108 
109 } // namespace Examples
110 } // namespace Unfit
111 
112 #endif
Definition: Bounds.hpp:27
Definition: GenericCostFunction.hpp:36
NonStationaryMarkov(const std::vector< std::vector< double >> &markov_data)
Definition: NonStationaryMarkov.hpp:69
std::vector< double > operator()(const std::vector< double > &param)
Definition: NonStationaryMarkov.hpp:86
An example data fitting problem with four parameters.
Definition: NonStationaryMarkov.hpp:46
const std::vector< std::vector< double > > markov_data_
Definition: NonStationaryMarkov.hpp:106