Unfit  3.1.1
Data fitting and optimization software
ODE3DVariant.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_ODE3DVARIANT_HPP_
23 #define UNFIT_EXAMPLES_ODE3DVARIANT_HPP_
24 
25 #include <vector>
26 #include "GenericCostFunction.hpp"
27 
28 namespace Unfit
29 {
30 namespace Examples
31 {
47 {
48  public:
61  ODE3DVariant(const std::vector<double> &x, double dt)
62  : x_ {x},
63  dt_ {dt}
64  {}
65 
79  std::vector<double> operator()(const std::vector<double> &param)
80  {
81  auto residuals = x_;
82  double predicted_x = param[2]; // Initial condition
83  for (auto i = 0u; i < residuals.size(); ++i) {
84  residuals[i] -= predicted_x;
85  predicted_x += dt_ * (param[0] * predicted_x + param[1]);
86  }
87  return residuals;
88  }
89  private:
91  const std::vector<double> x_;
93  const double dt_;
94 };
95 
96 } // namespace Examples
97 } // namespace Unfit
98 
99 #endif
const double dt_
Definition: ODE3DVariant.hpp:93
const std::vector< double > x_
Definition: ODE3DVariant.hpp:91
Definition: Bounds.hpp:27
Fit a three parameter first order ordinary differential equation (ODE)
Definition: ODE3DVariant.hpp:46
Definition: GenericCostFunction.hpp:36
ODE3DVariant(const std::vector< double > &x, double dt)
Definition: ODE3DVariant.hpp:61
std::vector< double > operator()(const std::vector< double > &param)
Definition: ODE3DVariant.hpp:79