HackAnalysis  2
neldermead.h
1 #pragma once
2 # include <cstdlib>
3 # include <iostream>
4 # include <iomanip>
5 # include <cmath>
6 //#include<array> // for begin and end etc
7 
8 #include <vector>
9 #include <functional>
10 /*
11 void nelmin ( double fn ( double x[] ), int n, double start[], double xmin[],
12  double *ynewlo, double reqmin, double step[], int konvge, int kcount,
13  int *icount, int *numres, int *ifault );
14 */
15 /*
16 void nelmin (std::function<double(double x[])> &fn, int n, std::vector<double> &start, std::vector<double> &xmin,
17  double *ynewlo, double reqmin, std::vector<double> &step, int konvge, int kcount,
18  int *icount, int *numres, int *ifault );
19 */
20 
21 /*
22 void nelmin (auto &fn, int n, std::vector<double> &start, std::vector<double> &xmin,
23  double *ynewlo, double reqmin, std::vector<double> &step, int konvge, int kcount,
24  int *icount, int *numres, int *ifault );
25 */
26 
27 template<typename FUNC> void nelmin (FUNC &fn, int n, double start[], double xmin[],
28  double *ynewlo, double reqmin, std::vector<double> &step, int konvge, int kcount,
29  int *icount, int *numres, int *ifault );
30 
32 {
33  private:
34  //int nvars=0; // number of variables
35  std::vector<double> vals;
36  std::vector<double> steps;
37  //std::vector<double> xmin;
38  std::vector<bool> fixed;
39  double _eps=0.001;
40  int _maxit=1000;
41  int _printlevel=0;
42  int kcount = 0;
43  int icound = 0;
44  int _status = 0;
45 
46 
47  public:
48  NELDERMEAD() {};
49  void Minimize(std::function<double(const double*)> infn);
50  //void Minimize(double (*infn) ( const double*));
51  void SetVariable(int index, const char* name, double initialval, double step);
52  void SetVariableValue( int index, double value);
53  void FixVariable(int n);
54  void ReleaseVariable(int n);
55  void SetMaxFunctionCalls(int ncalls);
56  void SetMaxIterations(int nits);
57  void SetTolerance(double tol);
58  void SetPrintLevel(int level);
59 
60  int Status();
61 
62  const double* X();
63 
64  ~NELDERMEAD();
65 };
66 
67 
68 /*
69 double ccoeff = 0.5;
70  double del;
71  double dn;
72  double dnn;
73  double ecoeff = 2.0;
74  double eps = 0.001;
75  int i;
76  int ihi;
77  int ilo;
78  int j;
79  int jcount;
80  int l;
81  int nn;
82  double *p;
83  double *p2star;
84  double *pbar;
85  double *pstar;
86  double rcoeff = 1.0;
87  double rq;
88  double x;
89  double *y;
90  double y2star;
91  double ylo;
92  double ystar;
93  double z;
94 
95 
96 */
Definition: neldermead.h:32