Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/opti/opti.hpp
3206 views
1
#ifndef FILE_OPTI
2
#define FILE_OPTI
3
4
/**************************************************************************/
5
/* File: opti.hpp */
6
/* Author: Joachim Schoeberl */
7
/* Date: 01. Jun. 95 */
8
/**************************************************************************/
9
10
11
12
namespace netgen
13
{
14
15
/**
16
Function to be minimized.
17
*/
18
class MinFunction
19
{
20
public:
21
///
22
virtual double Func (const Vector & x) const;
23
///
24
virtual void Grad (const Vector & x, Vector & g) const;
25
/// function and gradient
26
virtual double FuncGrad (const Vector & x, Vector & g) const;
27
/// directional derivative
28
virtual double FuncDeriv (const Vector & x, const Vector & dir, double & deriv) const;
29
/// if |g| < gradaccuray, then stop bfgs
30
virtual double GradStopping (const Vector & /* x */) const { return 0; }
31
32
///
33
virtual void ApproximateHesse (const Vector & /* x */,
34
DenseMatrix & /* hesse */) const;
35
};
36
37
38
class OptiParameters
39
{
40
public:
41
int maxit_linsearch;
42
int maxit_bfgs;
43
double typf;
44
double typx;
45
46
OptiParameters ()
47
{
48
maxit_linsearch = 100;
49
maxit_bfgs = 100;
50
typf = 1;
51
typx = 1;
52
}
53
};
54
55
56
/** Implementation of BFGS method.
57
Efficient method for non-linear minimiztion problems.
58
@param x initial value and solution
59
@param fun function to be minimized
60
*/
61
extern double BFGS (Vector & x, const MinFunction & fun,
62
const OptiParameters & par,
63
double eps = 1e-8);
64
65
/** Steepest descent method.
66
Simple method for non-linear minimization problems.
67
@param x initial value and solution
68
@param fun function to be minimized
69
*/
70
void SteepestDescent (Vector & x, const MinFunction & fun,
71
const OptiParameters & par);
72
73
74
extern void lines (
75
Vector & x, // i: Ausgangspunkt der Liniensuche
76
Vector & xneu, // o: Loesung der Liniensuche bei Erfolg
77
Vector & p, // i: Suchrichtung
78
double & f, // i: Funktionswert an der Stelle x
79
// o: Funktionswert an der Stelle xneu, falls ifail = 0
80
Vector & g, // i: Gradient an der Stelle x
81
// o: Gradient an der Stelle xneu, falls ifail = 0
82
83
const MinFunction & fun, // function to minmize
84
const OptiParameters & par, // parameters
85
double & alphahat, // i: Startwert f�r alpha_hat
86
// o: Loesung falls ifail = 0
87
double fmin, // i: untere Schranke f�r f
88
double mu1, // i: Parameter mu_1 aus Alg.2.1
89
double sigma, // i: Parameter sigma aus Alg.2.1
90
double xi1, // i: Parameter xi_1 aus Alg.2.1
91
double xi2, // i: Parameter xi_1 aus Alg.2.1
92
double tau, // i: Parameter tau aus Alg.2.1
93
double tau1, // i: Parameter tau_1 aus Alg.2.1
94
double tau2, // i: Parameter tau_2 aus Alg.2.1
95
int & ifail); // o: 0 bei erfolgreicher Liniensuche
96
// -1 bei Abbruch wegen Unterschreiten von fmin
97
// 1 bei Abbruch, aus sonstigen Gr�nden
98
99
100
101
102
/**
103
Solver for linear programming problem.
104
105
\begin{verbatim}
106
min c^t x
107
A x <= b
108
\end{verbatim}
109
*/
110
extern void LinearOptimize (const DenseMatrix & a, const Vector & b,
111
const Vector & c, Vector & x);
112
113
114
#ifdef NONE
115
116
/**
117
Simple projection iteration.
118
119
find $u = argmin_{v >= 0} 0.5 u A u - f u$
120
*/
121
extern void ApproxProject (const BaseMatrix & a, Vector & u,
122
const Vector & f,
123
double tau, int its);
124
125
126
/**
127
CG Algorithm for quadratic programming problem.
128
See: Dostal ...
129
130
d ... diag(A) ^{-1}
131
*/
132
extern void ApproxProjectCG (const BaseMatrix & a, Vector & x,
133
const Vector & b, const class DiagMatrix & d,
134
double gamma, int & steps, int & changes);
135
136
#endif
137
138
139
}
140
141
#endif
142
143
144