Unfit  3.1.1
Data fitting and optimization software
Osborne.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_OSBORNE_HPP_
23 #define UNFIT_EXAMPLES_OSBORNE_HPP_
24 
25 #include <cmath>
26 #include <vector>
27 #include "GenericCostFunction.hpp"
28 
29 namespace Unfit
30 {
31 namespace Examples
32 {
46 {
47  public:
58  Osborne(const std::vector<double> &x)
59  : x_ {x}
60  {}
61 
75  std::vector<double> operator()(const std::vector<double> &param)
76  {
77  auto residuals = x_;
78  for (auto i = 0u; i < residuals.size(); ++i) {
79  double t = 10.0 * static_cast<double>(i);
80  residuals[i] -= param[0] + param[1]*exp(-param[3]*t) +
81  param[2]*exp(-param[4]*t);
82  }
83  return residuals;
84  }
85  private:
87  const std::vector<double> x_;
88 };
89 
90 } // namespace Examples
91 } // namespace Unfit
92 
93 #endif
Osborne(const std::vector< double > &x)
Definition: Osborne.hpp:58
Definition: Bounds.hpp:27
Definition: GenericCostFunction.hpp:36
std::vector< double > operator()(const std::vector< double > &param)
Definition: Osborne.hpp:75
const std::vector< double > x_
Definition: Osborne.hpp:87
Fit a double exponential to experimental data.
Definition: Osborne.hpp:45