Unfit  3.1.1
Data fitting and optimization software
NelderMead.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_INCLUDE_NELDERMEAD_HPP_
23 #define UNFIT_INCLUDE_NELDERMEAD_HPP_
24 
25 #include <vector>
26 #include "GenericCostFunction.hpp"
27 #include "GenericOptimizer.hpp"
28 
29 namespace Unfit
30 {
45 {
47  friend class TestNelderMead;
48  public:
52  NelderMead();
53 
59  virtual ~NelderMead() {}
60 
96  int FindMin(GenericCostFunction &CostFunction,
97  std::vector<double> &coordinates) override;
98 
103  void Reset() override;
104 
105  private:
110  enum Operation {
111  Reflected,
112  Expanded,
113  ContractedIn,
114  ContractedOut,
115  Shrunk,
116  Restarted
117  };
118 
159  int GeneratePopulation(GenericCostFunction &CostFunction,
160  const std::vector<double> &initial_point);
161 
167  void ComputeCentroid();
168 
181  bool ContractInside(GenericCostFunction &CostFunction);
182 
195  bool ContractOutside(GenericCostFunction &CostFunction);
196 
209  bool Reflect(GenericCostFunction &CostFunction);
210 
220  bool Expand(GenericCostFunction &CostFunction);
221 
230  bool Shrink(GenericCostFunction &CostFunction);
231 
239  bool IsDegenerate();
240 
245  void InitialiseVectors();
246 
250  void UseAdaptiveParameters();
251 
258  void PrintInitialOutput(double best_cost) const override;
259 
268  void PrintIterationOutput(double best_cost) const override;
269 
282  int ProcessFindMin(GenericCostFunction &CostFunction);
283 
292  int RegeneratePopulation(GenericCostFunction &CostFunction);
293 
295  std::vector<double> contract_;
297  std::vector<double> centroid_;
299  std::vector<double> reflect_;
301  std::vector<double> expand_;
303  std::size_t dimensions_;
305  std::size_t best_vertex_;
307  std::size_t worst_vertex_;
309  std::size_t next_worst_vertex_;
311  std::size_t cost_;
316 };
317 
318 } // namespace Unfit
319 
320 #endif
virtual ~NelderMead()
Definition: NelderMead.hpp:59
void Reset() override
Definition: NelderMead.cpp:50
bool Reflect(GenericCostFunction &CostFunction)
Definition: NelderMead.cpp:127
int GeneratePopulation(GenericCostFunction &CostFunction, const std::vector< double > &initial_point)
Generate the initial simplex by accepting a vector which contains the initial guess and the CostFunct...
Definition: NelderMead.cpp:66
void ComputeCentroid()
Definition: NelderMead.cpp:112
A class to implement the NelderMead optimization method.
Definition: NelderMead.hpp:44
bool Shrink(GenericCostFunction &CostFunction)
Definition: NelderMead.cpp:178
std::vector< double > expand_
Definition: NelderMead.hpp:301
int FindMin(GenericCostFunction &CostFunction, std::vector< double > &coordinates) override
Implements the Nelder-Mead optimization method.
Definition: NelderMead.cpp:207
Definition: GenericOptimizer.hpp:41
int ProcessFindMin(GenericCostFunction &CostFunction)
Definition: NelderMead.cpp:261
Definition: Bounds.hpp:27
std::vector< double > reflect_
Definition: NelderMead.hpp:299
Access to the private member functions in the neldermead class.
Definition: TestNelderMead.cpp:42
void UseAdaptiveParameters()
Definition: NelderMead.cpp:385
NelderMead()
Definition: NelderMead.cpp:34
bool Expand(GenericCostFunction &CostFunction)
Definition: NelderMead.cpp:139
void InitialiseVectors()
Definition: NelderMead.cpp:394
Definition: GenericCostFunction.hpp:36
int RegeneratePopulation(GenericCostFunction &CostFunction)
Definition: NelderMead.cpp:254
bool IsDegenerate()
Definition: NelderMead.cpp:193
enum Operation process_
Definition: NelderMead.hpp:315
Operation
Definition: NelderMead.hpp:110
double restart_best_cost_
Definition: NelderMead.hpp:313
std::size_t best_vertex_
Definition: NelderMead.hpp:305
std::size_t worst_vertex_
Definition: NelderMead.hpp:307
bool ContractOutside(GenericCostFunction &CostFunction)
Definition: NelderMead.cpp:150
std::vector< double > centroid_
Definition: NelderMead.hpp:297
void PrintIterationOutput(double best_cost) const override
Definition: NelderMead.cpp:422
std::size_t next_worst_vertex_
Definition: NelderMead.hpp:309
std::size_t cost_
Definition: NelderMead.hpp:311
std::size_t dimensions_
Definition: NelderMead.hpp:303
std::vector< double > contract_
Definition: NelderMead.hpp:295
bool ContractInside(GenericCostFunction &CostFunction)
Definition: NelderMead.cpp:164
void PrintInitialOutput(double best_cost) const override
Definition: NelderMead.cpp:409