Unfit  3.1.1
Data fitting and optimization software
TestFunctions.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_UNITTESTS_TESTFUNCTIONS_HPP_
23 #define UNFIT_UNITTESTS_TESTFUNCTIONS_HPP_
24 
25 #include <limits>
26 #include <vector>
27 #include "GenericCostFunction.hpp"
28 
29 namespace Unfit
30 {
31 namespace UnitTests
32 {
39 {
40  public:
48  std::vector<double> operator()(const std::vector<double> &x)
49  {
50  auto residuals = x;
51  residuals.pop_back();
52  return residuals;
53  }
54 };
55 
62 {
63  public:
71  std::vector<double> operator()(const std::vector<double> &x)
72  {
73  auto residuals = x;
74  residuals.pop_back();
75  residuals[0] = std::numeric_limits<double>::signaling_NaN();
76  return residuals;
77  }
78 };
79 
86 {
87  public:
95  std::vector<double> operator()(const std::vector<double> &x)
96  {
97  auto residuals = x;
98  residuals.pop_back();
99  residuals.back() = std::numeric_limits<double>::signaling_NaN();
100  return residuals;
101  }
102 };
103 
110 {
111  public:
119  std::vector<double> operator()(const std::vector<double> &x)
120  {
121  auto residuals = x;
122  residuals.pop_back();
123  residuals[0] = std::numeric_limits<double>::infinity();
124  return residuals;
125  }
126 };
127 
134 {
135  public:
143  std::vector<double> operator()(const std::vector<double> &x)
144  {
145  auto residuals = x;
146  residuals.pop_back();
147  residuals.back() = std::numeric_limits<double>::infinity();
148  return residuals;
149  }
150 };
151 
158 {
159  public:
167  std::vector<double> operator()(const std::vector<double> &x)
168  {
169  auto residuals = x;
170  residuals.pop_back();
171  for (auto &residual : residuals) {
172  if (residual >= 0.0 && residual <= 1.0) {
173  residual = 1.0;
174  }
175  else {
176  residual = std::numeric_limits<double>::infinity();
177  }
178  }
179  return residuals;
180  }
181 };
182 
189 {
190  public:
198  std::vector<double> operator()(const std::vector<double> &x)
199  {
200  auto residuals = x;
201  residuals.pop_back();
202  for (auto &residual : residuals) {
203  if (residual > 0.0 && residual < 1.0) {
204  residual = std::numeric_limits<double>::infinity();
205  }
206  else {
207  residual = 1.0;
208  }
209  }
210  return residuals;
211  }
212 };
213 
214 } // namespace Unittests
215 } // namespace Unfit
216 
217 #endif
218 
Definition: TestFunctions.hpp:188
std::vector< double > operator()(const std::vector< double > &x)
Definition: TestFunctions.hpp:198
Definition: TestFunctions.hpp:61
Definition: TestFunctions.hpp:133
std::vector< double > operator()(const std::vector< double > &x)
Definition: TestFunctions.hpp:167
Definition: Bounds.hpp:27
Definition: TestFunctions.hpp:157
Definition: TestFunctions.hpp:38
std::vector< double > operator()(const std::vector< double > &x)
Definition: TestFunctions.hpp:48
std::vector< double > operator()(const std::vector< double > &x)
Definition: TestFunctions.hpp:143
std::vector< double > operator()(const std::vector< double > &x)
Definition: TestFunctions.hpp:71
Definition: GenericCostFunction.hpp:36
std::vector< double > operator()(const std::vector< double > &x)
Definition: TestFunctions.hpp:119
std::vector< double > operator()(const std::vector< double > &x)
Definition: TestFunctions.hpp:95
Definition: TestFunctions.hpp:109
Definition: TestFunctions.hpp:85