Unfit  3.1.1
Data fitting and optimization software
Parabolic.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_PARABOLIC_HPP_
23 #define UNFIT_EXAMPLES_PARABOLIC_HPP_
24 
25 #include <vector>
26 #include "GenericCostFunction.hpp"
27 
28 namespace Unfit
29 {
30 namespace Examples
31 {
44 {
45  public:
57  Parabolic(const std::vector<double> &data_x,
58  const std::vector<double> &data_y)
59  : data_x_ {data_x},
60  data_y_ {data_y}
61  {}
62 
78  std::vector<double> operator()(const std::vector<double> &param)
79  {
80  // First set the residuals to be the observed values
81  auto residuals = data_y_;
82  // Next, subtract the model evaluated at each point to give the residuals
83  // as r[i] = y[i] - (A*x[i]*x[i] + B*x[i] + C)
84  for (auto i = 0u; i < residuals.size(); ++i) {
85  residuals[i] -= (param[0]*data_x_[i]*data_x_[i] + param[1]*data_x_[i]
86  + param[2]);
87  }
88  return residuals;
89  }
90  private:
92  const std::vector<double> data_x_;
94  const std::vector<double> data_y_;
95 };
96 
97 } // namespace Examples
98 } // namespace Unfit
99 
100 #endif
std::vector< double > operator()(const std::vector< double > &param)
Definition: Parabolic.hpp:78
const std::vector< double > data_y_
Definition: Parabolic.hpp:94
const std::vector< double > data_x_
Definition: Parabolic.hpp:92
Definition: Bounds.hpp:27
Parabolic(const std::vector< double > &data_x, const std::vector< double > &data_y)
Definition: Parabolic.hpp:57
Definition: GenericCostFunction.hpp:36
Fit a three parameter parabola to some data.
Definition: Parabolic.hpp:43