|
| OptimizerLineSearch (int dimCtrl, S eps, int maxIt, S lambda, int maxStepAttempts, std::string stepCondition, bool verboseOn=true, const std::string fname="", const std::string logFileName="", bool withUpperBound=false, S upperBound=S(), bool withLowerBound=false, S lowerBound=S(), bool vectorBounds=false, S controlEps=S(std::numeric_limits< double >::epsilon()), bool failOnMaxIter=true, std::vector< OptimizerLogType > gplotAnalysis={}) |
| Construction of an OptimizerLineSearch.
|
|
virtual | ~OptimizerLineSearch () |
|
virtual void | computeDirection ()=0 |
|
void | checkBound () |
|
void | boundControl () |
|
bool | smallerValue (const S &tempValue) |
|
bool | noCondition (const S &tempValue) |
|
bool | armijoWolfeConditions (const S &tempValue) |
|
void | quadraticInterpolationStep (const S &tempValue) |
|
void | backtrackingLineSearch (S &tempValue, S lambda, bool(OptimizerLineSearch::*condition)(const S &)) |
|
virtual void | optimizationStep () |
| Optimization step: line search.
|
|
| Optimizer (int dimCtrl, S eps, int maxIt, bool verboseOn=true, const std::string fname="", const std::string logFileName="", bool withUpperBound=false, S upperBound=S(), bool withLowerBound=false, S lowerBound=S(), bool vectorBounds=false, S controlEps=S(std::numeric_limits< double >::epsilon()), bool failOnMaxIter=true, std::vector< OptimizerLogType > gplotAnalysis={}) |
|
virtual | ~Optimizer () |
|
void | maxIterationReached () |
|
virtual void | optimize () |
|
virtual void | optimize (OptiCase< S, C > &optiCase) |
|
void | simulate () |
|
void | simulate (OptiCase< S, C > &optiCase) |
|
void | evaluateObjective (const C &control, S &result) |
|
void | computeDerivatives (const C &control, C &derivatives) |
|
void | print (int it) |
| Prints information of the current optimization step it.
|
|
void | setControl (C &control) |
|
const C & | getControl () const |
|
const C & | getDerivative () const |
|
const S & | getObjective () const |
|
int | getIteration () const |
|
void | writeControlToFile (const std::string fname="control.dat") |
| Writes the current control variables linewise into file fname.
|
|
void | readControlFromFile (const std::string fname="control.dat") |
| Reads the latest control variables from file fname.
|
|
void | setStartValue (S startValue) |
|
OptiCase< S, C > * | getOptiCase () |
|
void | setOptiCase (OptiCase< S, C > *optiCase) |
|
void | setGnuplotData () |
|
void | setReferenceControl (C result) |
| set the reference value for the control vector (exact solution)
|
|
template<typename S, typename C>
class olb::opti::OptimizerLineSearch< S, C >
Optimization algorithm: LineSearch.
OptimizerLineSearch optimizes an optimization problem which is given in OptiCase. OptiCase provides therefore methods to evaluate an object functional and compute derivatives. LineSearch searches along a particular direction to find a lower value of the evaluated object functional.
This class is intended to be derived from.
Definition at line 51 of file optimizerLineSearch.h.
template<typename S , typename C >
Definition at line 203 of file optimizerLineSearch.h.
204 {
205 S c1 = 1e-4;
206 S c2 = 0.9;
207 S dir = 0.;
208 S dirNext = 0.;
209
210
211 for (
int i=0; i<this->
_dimCtrl; i++) {
213 }
214
215
218 clout << "Armijo failed!" << std::endl;
219 }
220
222
223 return false;
224 }
225
227
228
231
232 for (
int i=0; i<this->
_dimCtrl; i++) {
234 }
235 bool curvature = ( dirNext <= c2*dir );
238 }
239
240 if (!curvature) {
242 clout << "Curvature failed!" << std::endl;
243 }
244
246 return false;
247 }
248 }
249 return true;
250 }
C _derivative
Vector of derivatives of the object functional with respect to the controlled variables.
int _dimCtrl
Number of controlled variables.
C _control
Vector of controlled variables (size _dimCtrl)
S _value
Value of the objective functional evaluated for controlled variables saved in _control.
void computeDerivatives(const C &control, C &derivatives)
ADf< T, DIM > abs(const ADf< T, DIM > &a)
References olb::opti::Optimizer< S, C >::_control, olb::opti::Optimizer< S, C >::_derivative, olb::opti::Optimizer< S, C >::_dimCtrl, olb::opti::OptimizerLineSearch< S, C >::_nextDerivative, olb::opti::OptimizerLineSearch< S, C >::_nextDerivFlag, olb::opti::OptimizerLineSearch< S, C >::_stepCondition, olb::opti::OptimizerLineSearch< S, C >::_stepLengthFunction, olb::opti::Optimizer< S, C >::_value, olb::opti::Optimizer< S, C >::_verboseOn, olb::util::abs(), and olb::opti::Optimizer< S, C >::computeDerivatives().
template<typename S , typename C >
Definition at line 276 of file optimizerLineSearch.h.
277 {
278
279
281 int refinementStep = 0;
282
283
284 while ( !(this->*condition)(tempValue) ) {
285 if (
util::abs(lambda/this->
_value) < std::numeric_limits<double>::epsilon() ) {
286 clout << "Excessive refinement steps (too small step size).\nProgram terminated." <<std::endl;
288 }
289 refinementStep++;
290
291
293 clout << "Excessive refinement steps (maxStepAttempts exeeded).\nProgram terminated." <<std::endl;
295 }
296
298 bool notSensible = true;
299 for (
int iDim=0; iDim<this->
_dimCtrl; iDim++) {
300
301
302 S tmp = (newLambda-lambda)*this->
_direction[iDim];
304
307 }
308 }
309
310 if (notSensible) {
311 clout << "Excessive refinement steps (not sensible).\nProgram terminated." <<std::endl;
313 }
314
317 }
318
320 clout <<
"[Step " << this->
_it <<
"][Ref " << refinementStep <<
"] <<<<<<<<<< lambda=" << newLambda <<
" <<<<<<<<<<" << std::endl;
321 }
322
325 }
326 else {
328 }
329 lambda = newLambda;
330 }
332 };
bool _withUpperBound
Bounded versions.
int _it
Current iteration no.
void evaluateObjective(const C &control, S &result)
bool nearZero(const ADf< T, DIM > &a)
References olb::opti::Optimizer< S, C >::_boundedControl, olb::opti::Optimizer< S, C >::_control, olb::opti::Optimizer< S, C >::_dimCtrl, olb::opti::Optimizer< S, C >::_it, olb::opti::OptimizerLineSearch< S, C >::_lambda, olb::opti::OptimizerLineSearch< S, C >::_maxStepAttempts, olb::opti::Optimizer< S, C >::_value, olb::opti::Optimizer< S, C >::_verboseOn, olb::opti::Optimizer< S, C >::_withLowerBound, olb::opti::Optimizer< S, C >::_withUpperBound, olb::util::abs(), olb::opti::OptimizerLineSearch< S, C >::boundControl(), olb::opti::Optimizer< S, C >::evaluateObjective(), and olb::util::nearZero().
template<typename S , typename C >
Definition at line 123 of file optimizerLineSearch.h.
124 {
126 bool atUpper = true;
127 for (
int iDim=0; iDim<this->
_dimCtrl; ++iDim) {
130 }
131 if (atUpper) {
133 clout <<
"Control stuck at upper bound: " << std::string(this->
_upperBound.begin(), this->_upperBound.end()) << std::endl;
135 }
137 }
138 else {
140 }
141 }
143 bool atLower = true;
144 for (
int iDim=0; iDim<this->
_dimCtrl; ++iDim) {
147 }
148 if (atLower) {
150 clout <<
"Control stuck at lower bound: " << std::string(this->
_lowerBound.begin(), this->_lowerBound.end()) << std::endl;
152 }
154 }
155 else {
157 }
158 }
159 };
References olb::opti::Optimizer< S, C >::_boundedControl, olb::opti::Optimizer< S, C >::_dimCtrl, olb::opti::Optimizer< S, C >::_lowerBound, olb::opti::OptimizerLineSearch< S, C >::_lowerBoundFlag, olb::opti::Optimizer< S, C >::_upperBound, olb::opti::OptimizerLineSearch< S, C >::_upperBoundFlag, olb::opti::Optimizer< S, C >::_vectorBounds, olb::opti::Optimizer< S, C >::_withLowerBound, olb::opti::Optimizer< S, C >::_withUpperBound, and olb::util::nearZero().
template<typename S , typename C >
Optimization step: line search.
Implements olb::opti::Optimizer< S, C >.
Definition at line 336 of file optimizerLineSearch.h.
337 {
338
340 clout << "Computing directions..." << std::endl;
341 }
342
343
344
346
350
351
352 const C initialControl = this->
_control;
353
354
355 for (
int iDim=0; iDim<this->
_dimCtrl; iDim++) {
357 }
358
362 }
363
365 clout <<
"[Step " << this->
_it <<
"] <<<<<<<<<< lambda=" << this->
_lambda <<
" <<<<<<<<<<" << std::endl;
366 }
367
368 S tempValue = S();
371 }
372 else {
374 }
375
376
378
381 clout << "Bounding control" << std::endl;
382 }
383 for (
int iDim=0; iDim<this->
_dimCtrl; iDim++) {
385 }
386 }
387
388
390
392
393
395 for (
int iDim=0; iDim<this->
_dimCtrl; ++iDim) {
396 S ave = 0.5 * (initialControl[iDim] + this->
_control[iDim]);
400 break;
401 }
402 }
403 }
406 }
407 };
virtual void computeDirection()=0
void backtrackingLineSearch(S &tempValue, S lambda, bool(OptimizerLineSearch::*condition)(const S &))
bool _controlsConverged
For setting tolerance of controls.
References olb::opti::Optimizer< S, C >::_boundedControl, olb::opti::Optimizer< S, C >::_control, olb::opti::Optimizer< S, C >::_controlEps, olb::opti::Optimizer< S, C >::_controlsConverged, olb::opti::Optimizer< S, C >::_dimCtrl, olb::opti::OptimizerLineSearch< S, C >::_direction, olb::opti::Optimizer< S, C >::_it, olb::opti::OptimizerLineSearch< S, C >::_lowerBoundFlag, olb::opti::OptimizerLineSearch< S, C >::_stepConditionFunction, olb::opti::OptimizerLineSearch< S, C >::_upperBoundFlag, olb::opti::Optimizer< S, C >::_value, olb::opti::Optimizer< S, C >::_verboseOn, olb::opti::Optimizer< S, C >::_withLowerBound, olb::opti::Optimizer< S, C >::_withUpperBound, olb::util::abs(), olb::opti::OptimizerLineSearch< S, C >::backtrackingLineSearch(), olb::opti::OptimizerLineSearch< S, C >::boundControl(), olb::opti::OptimizerLineSearch< S, C >::checkBound(), olb::opti::OptimizerLineSearch< S, C >::computeDirection(), and olb::opti::Optimizer< S, C >::evaluateObjective().