-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMathGenMin.h
163 lines (120 loc) · 4 KB
/
MathGenMin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef __MATHPOWELL_H__
#define __MATHPOWELL_H__
#include "MathGold.h"
#include "MathVector.h"
#include "MathMatrix.h"
#include "Random.h"
// Multidimensional minimization of a continuous function
// starting with a user supplied starting point and
// direction vector
//
class GeneralMinimizer
{
public:
VectorFunc * func; // Function to be minimized
Matrix directions;
Vector point;
double fmin;
// Setup matrices assuming ndim point
virtual void Reset(int ndim, double scale = 1.0);
// Find a minimum using direction set and starting point
virtual double Minimize(double ftol = TOL) = 0;
GeneralMinimizer();
virtual ~GeneralMinimizer() { }
double f(Vector & v)
{ return func->Evaluate(v); }
void df(Vector & v, Vector & d, double scale = 1.0)
{ func->Derivative(v, d, scale); }
};
// Powell's conjugate direction method
// After each round, the direction of largest decrease is replaces
// its biggest component among the original directions
//
class PowellMinimizer : public GeneralMinimizer
{
public:
int iter;
virtual ~PowellMinimizer() { }
virtual double Minimize(double ftol = TOL);
};
// Simulated annealing using simplex method of Nelder and Mead
//
class SAMinimizer : public GeneralMinimizer
{
public:
int iter;
bool freeRand;
Random * rand;
Vector y; // evaluation of entropy at y
Matrix simplex; // volume in n dimensions (n+1) points
SAMinimizer();
SAMinimizer(Random & rand);
virtual ~SAMinimizer();
virtual void Reset(int ndim, double scale = 1.0);
// Lowers temperature T from maxT to minT in Tcycles linear decay cycles
// Titer iterations at each temperature
virtual double Minimize(double ftol = TOL);
double MinimizeLoop(double ftol = TOL);
double T, maxT, minT; // Temperature
int Tcycles, Titer; // Cycling parameters
private:
Vector psum;
Vector ptry;
double yhi;
void Constructor();
double Amoeba(int ihi, double factor);
};
// Multidimensional minimization of a continuous function by
// the down-hill simplex method of Nelder and Mead
// (Computer Journal 1965)
//
class AmoebaMinimizer : public GeneralMinimizer
{
public:
Matrix simplex;
long cycleCount, cycleMax; // number of function evaluations
AmoebaMinimizer();
virtual ~AmoebaMinimizer() { }
virtual void Reset(int dimensions, double scale = 1.0);
virtual double Minimize(double ftol = TOL);
private:
Vector psum, ptry, y;
double Amoeba(int ihi, double factor);
};
// Differential Evolution minimizer
// A stochastic minimizer based on the algorithm of Storn and Price, 1996
class EvolutionaryMinimizer : public GeneralMinimizer
{
public:
Matrix points;
Vector y;
double crossover; // This is the CR parameter of Storn and Price
double step_size; // This is the L parameter of Storn and Price
int multiples; // The NP paraemter of Storn and Price will be dimensions * multiple
Random * rand;
bool generate_random_points;
int generations;
int max_generations;
EvolutionaryMinimizer();
EvolutionaryMinimizer(Random & randomSeries);
~EvolutionaryMinimizer() { }
virtual void Reset(int dimensions, double scale = 1.0);
virtual double Minimize(double ftol = TOL);
private:
void Init(Random & randomSeries);
};
// Conjugate gradient minimizer
// Polak-Ribiere improvement on Fletcher-Reeves algorithm for
// multidimensional minimization.
//
class FletcherMinimizer : public GeneralMinimizer
{
public:
int iter;
FletcherMinimizer() { }
virtual void Reset(int dimensions, double scale = 1.0);
virtual double Minimize(double ftol = TOL);
private:
Vector g, h;
};
#endif