queso-0.56.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
QUESO::GslOptimizer Class Reference

A base class for handling optimisation of scalar functions. More...

#include <GslOptimizer.h>

Inheritance diagram for QUESO::GslOptimizer:
Inheritance graph
[legend]
Collaboration diagram for QUESO::GslOptimizer:
Collaboration graph
[legend]

Public Types

enum  SolverType {
  FLETCHER_REEVES_CG, POLAK_RIBIERE_CG, BFGS, BFGS2,
  STEEPEST_DESCENT, NELDER_MEAD, NELDER_MEAD2, NELDER_MEAD2_RAND
}
 

Public Member Functions

 GslOptimizer (const BaseScalarFunction< GslVector, GslMatrix > &objectiveFunction)
 Constructs an object that will maximize a scalar function. More...
 
 GslOptimizer (OptimizerOptions options, const BaseScalarFunction< GslVector, GslMatrix > &objectiveFunction)
 Constructs an object that will maximize a scalar function. More...
 
virtual ~GslOptimizer ()
 Destructor. More...
 
virtual void minimize (OptimizerMonitor *monitor=NULL)
 Minimize the objective function, starting at m_initialPoint. More...
 
const BaseScalarFunction
< GslVector, GslMatrix > & 
objectiveFunction () const
 Returns the objective function. More...
 
void setInitialPoint (const GslVector &intialPoint)
 Set the point at which the optimization starts. More...
 
const GslVectorminimizer () const
 Return the point that minimizes the objective function. More...
 
void set_solver_type (SolverType solver)
 
void set_solver_type (std::string &solver)
 
SolverType string_to_enum (std::string &solver)
 
void set_step_size (const GslVector &step_size)
 Sets step size used in gradient-free solvers. More...
 
void set_step_size (double step_size)
 Sets step size used in gradient-based solvers. More...
 
void set_line_tol (double tol)
 Set GSL line minimization tolerance. More...
 
virtual std::string getSolverType () const
 Gets the algorithm to use for minimisation. More...
 
virtual double getFstepSize () const
 Gets the step size to use in gradient-free solvers. More...
 
virtual double getFdfstepSize () const
 Gets the step to use in gradient-based solvers. More...
 
virtual double getLineTolerance () const
 Gets the tolerance to use for line minimisation. More...
 
virtual void setSolverType (std::string solverType)
 Sets the algorithm to use for minimisation. More...
 
virtual void setFstepSize (double fstepSize)
 Sets the step size to use in gradient-free solvers. More...
 
virtual void setFdfstepSize (double fdfstepSize)
 Sets the step to use in gradient-based solvers. More...
 
virtual void setLineTolerance (double lineTolerance)
 Sets the tolerance to use for line minimisation. More...
 
- Public Member Functions inherited from QUESO::BaseOptimizer
 BaseOptimizer ()
 Default constructor. More...
 
 BaseOptimizer (OptimizerOptions options)
 Constructor that takes an options object. More...
 
virtual ~BaseOptimizer ()
 Destructor. More...
 
unsigned int getMaxIterations () const
 Returns the maximum number of iterations the optimizer will do. More...
 
double getTolerance () const
 Returns the tolerance used to test for an extremum in the optimizer. More...
 
double getFiniteDifferenceStepSize () const
 Returns the step size used in the finite difference formula. More...
 
void setMaxIterations (unsigned int maxIterations)
 Sets the maximum number of iterations to be used by the optimizer. More...
 
void setTolerance (double tolerance)
 Sets the tolerance the optimizer will use to test for an extremum. More...
 
void setFiniteDifferenceStepSize (double h)
 Sets the step to use in the finite difference derivative. More...
 

Private Member Functions

bool solver_needs_gradient (SolverType solver)
 Helper function. More...
 
void minimize_with_gradient (unsigned int dim, OptimizerMonitor *monitor)
 
void minimize_no_gradient (unsigned int dim, OptimizerMonitor *monitor)
 

Private Attributes

const BaseScalarFunction
< GslVector, GslMatrix > & 
m_objectiveFunction
 
GslVectorm_initialPoint
 
GslVectorm_minimizer
 
SolverType m_solver_type
 
GslVector m_fstep_size
 For use in gradient-free algorithms. More...
 
double m_fdfstep_size
 For use in gradient-based algorithms. More...
 
double m_line_tol
 Line minimization tolerance in gradient-based algorithms. More...
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::BaseOptimizer
unsigned int m_maxIterations
 
double m_tolerance
 
double m_finiteDifferenceStepSize
 
std::string m_solverType
 
double m_fstepSize
 
double m_fdfstepSize
 
double m_lineTolerance
 
ScopedPtr< OptimizerOptions >::Type m_optionsObj
 

Detailed Description

A base class for handling optimisation of scalar functions.

WRITE DOCS HERE

Definition at line 50 of file GslOptimizer.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

QUESO::GslOptimizer::GslOptimizer ( const BaseScalarFunction< GslVector, GslMatrix > &  objectiveFunction)

Constructs an object that will maximize a scalar function.

The function objectiveFunction is the function that will be maximized.

Definition at line 159 of file GslOptimizer.C.

References QUESO::GslVector::cwSet(), getFstepSize(), getSolverType(), m_fstep_size, m_minimizer, and setSolverType().

161  : BaseOptimizer(),
163  m_initialPoint(new GslVector(objectiveFunction.domainSet().
164  vectorSpace().zeroVector())),
165  m_minimizer(new GslVector(this->m_objectiveFunction.domainSet().
166  vectorSpace().zeroVector())),
168  m_fstep_size(this->m_objectiveFunction.domainSet().vectorSpace().zeroVector()),
171 {
172  // We initialize the minimizer to GSL_NAN just in case the optimization fails
173  m_minimizer->cwSet(GSL_NAN);
174 
175  // Set to documented default value.
177 
178  // Set solver type to the one set in the options object
180 }
BaseOptimizer()
Default constructor.
Definition: Optimizer.C:29
void cwSet(double value)
Component-wise sets all values to this with value.
Definition: GslVector.C:326
virtual double getLineTolerance() const
Gets the tolerance to use for line minimisation.
Definition: GslOptimizer.C:610
const BaseScalarFunction< GslVector, GslMatrix > & m_objectiveFunction
Definition: GslOptimizer.h:155
SolverType m_solver_type
Definition: GslOptimizer.h:160
GslVector m_fstep_size
For use in gradient-free algorithms.
Definition: GslOptimizer.h:163
double m_fdfstep_size
For use in gradient-based algorithms.
Definition: GslOptimizer.h:166
virtual double getFdfstepSize() const
Gets the step to use in gradient-based solvers.
Definition: GslOptimizer.C:604
GslVector * m_minimizer
Definition: GslOptimizer.h:158
virtual std::string getSolverType() const
Gets the algorithm to use for minimisation.
Definition: GslOptimizer.C:592
virtual void setSolverType(std::string solverType)
Sets the algorithm to use for minimisation.
Definition: GslOptimizer.C:560
const BaseScalarFunction< GslVector, GslMatrix > & objectiveFunction() const
Returns the objective function.
Definition: GslOptimizer.C:241
double m_line_tol
Line minimization tolerance in gradient-based algorithms.
Definition: GslOptimizer.h:169
virtual double getFstepSize() const
Gets the step size to use in gradient-free solvers.
Definition: GslOptimizer.C:598
GslVector * m_initialPoint
Definition: GslOptimizer.h:157
QUESO::GslOptimizer::GslOptimizer ( OptimizerOptions  options,
const BaseScalarFunction< GslVector, GslMatrix > &  objectiveFunction 
)

Constructs an object that will maximize a scalar function.

The function objectiveFunction is the function that will be maximized. This constructor allows the passing of custom options to optimizer to modify things like tolerance, maximum number of iterations, and finite difference step size.

Definition at line 182 of file GslOptimizer.C.

References QUESO::GslVector::cwSet(), getFstepSize(), getSolverType(), m_fstep_size, m_minimizer, and setSolverType().

185  : BaseOptimizer(options),
187  m_initialPoint(new GslVector(objectiveFunction.domainSet().
188  vectorSpace().zeroVector())),
189  m_minimizer(new GslVector(this->m_objectiveFunction.domainSet().
190  vectorSpace().zeroVector())),
192  m_fstep_size(this->m_objectiveFunction.domainSet().vectorSpace().zeroVector()),
195 {
196  // We initialize the minimizer to GSL_NAN just in case the optimization fails
197  m_minimizer->cwSet(GSL_NAN);
198 
199  // Set to documented default value.
201 
202  // Set solver type to the one set in the options object
204 }
BaseOptimizer()
Default constructor.
Definition: Optimizer.C:29
void cwSet(double value)
Component-wise sets all values to this with value.
Definition: GslVector.C:326
virtual double getLineTolerance() const
Gets the tolerance to use for line minimisation.
Definition: GslOptimizer.C:610
const BaseScalarFunction< GslVector, GslMatrix > & m_objectiveFunction
Definition: GslOptimizer.h:155
SolverType m_solver_type
Definition: GslOptimizer.h:160
GslVector m_fstep_size
For use in gradient-free algorithms.
Definition: GslOptimizer.h:163
double m_fdfstep_size
For use in gradient-based algorithms.
Definition: GslOptimizer.h:166
virtual double getFdfstepSize() const
Gets the step to use in gradient-based solvers.
Definition: GslOptimizer.C:604
GslVector * m_minimizer
Definition: GslOptimizer.h:158
virtual std::string getSolverType() const
Gets the algorithm to use for minimisation.
Definition: GslOptimizer.C:592
virtual void setSolverType(std::string solverType)
Sets the algorithm to use for minimisation.
Definition: GslOptimizer.C:560
const BaseScalarFunction< GslVector, GslMatrix > & objectiveFunction() const
Returns the objective function.
Definition: GslOptimizer.C:241
double m_line_tol
Line minimization tolerance in gradient-based algorithms.
Definition: GslOptimizer.h:169
virtual double getFstepSize() const
Gets the step size to use in gradient-free solvers.
Definition: GslOptimizer.C:598
GslVector * m_initialPoint
Definition: GslOptimizer.h:157
QUESO::GslOptimizer::~GslOptimizer ( )
virtual

Destructor.

Definition at line 206 of file GslOptimizer.C.

References m_initialPoint.

207 {
208  delete this->m_initialPoint;
209 }
GslVector * m_initialPoint
Definition: GslOptimizer.h:157

Member Function Documentation

double QUESO::GslOptimizer::getFdfstepSize ( ) const
virtual

Gets the step to use in gradient-based solvers.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 604 of file GslOptimizer.C.

References QUESO::BaseOptimizer::m_optionsObj.

Referenced by minimize_with_gradient().

605 {
606  return this->m_optionsObj->m_fdfstepSize;
607 }
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
double QUESO::GslOptimizer::getFstepSize ( ) const
virtual

Gets the step size to use in gradient-free solvers.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 598 of file GslOptimizer.C.

References QUESO::BaseOptimizer::m_optionsObj.

Referenced by GslOptimizer().

599 {
600  return this->m_optionsObj->m_fstepSize;
601 }
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
double QUESO::GslOptimizer::getLineTolerance ( ) const
virtual

Gets the tolerance to use for line minimisation.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 610 of file GslOptimizer.C.

References QUESO::BaseOptimizer::m_optionsObj.

Referenced by minimize_with_gradient().

611 {
612  return this->m_optionsObj->m_lineTolerance;
613 }
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
std::string QUESO::GslOptimizer::getSolverType ( ) const
virtual

Gets the algorithm to use for minimisation.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 592 of file GslOptimizer.C.

References QUESO::BaseOptimizer::m_optionsObj.

Referenced by GslOptimizer().

593 {
594  return this->m_optionsObj->m_solverType;
595 }
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
void QUESO::GslOptimizer::minimize ( OptimizerMonitor monitor = NULL)
virtual

Minimize the objective function, starting at m_initialPoint.

m_initialPoint is handled in the derived class

Implements QUESO::BaseOptimizer.

Definition at line 211 of file GslOptimizer.C.

References dim, m_initialPoint, m_objectiveFunction, m_solver_type, minimize_no_gradient(), minimize_with_gradient(), queso_error, and solver_needs_gradient().

Referenced by QUESO::StatisticalInverseProblem< P_V, P_M >::solveWithBayesMetropolisHastings().

211  {
212 
213  // First check that initial guess is reasonable
214  if (!this->m_objectiveFunction.domainSet().contains(*(this->m_initialPoint)))
215  {
216  if( m_objectiveFunction.domainSet().env().fullRank() == 0 )
217  {
218  std::cerr << "Minimization was given initial point outside of domain"
219  << std::endl;
220  }
221  queso_error();
222  }
223 
224  unsigned int dim = this->m_objectiveFunction.domainSet().vectorSpace().
225  zeroVector().sizeLocal();
226 
227  // We use m_solver_type here because we need the enum
229  {
230  this->minimize_with_gradient( dim, monitor );
231  }
232  else
233  {
234  this->minimize_no_gradient( dim, monitor );
235  }
236 
237  return;
238 }
int dim
Definition: ann2fig.cpp:81
#define queso_error()
Definition: asserts.h:53
void minimize_with_gradient(unsigned int dim, OptimizerMonitor *monitor)
Definition: GslOptimizer.C:297
bool solver_needs_gradient(SolverType solver)
Helper function.
Definition: GslOptimizer.C:266
const BaseScalarFunction< GslVector, GslMatrix > & m_objectiveFunction
Definition: GslOptimizer.h:155
SolverType m_solver_type
Definition: GslOptimizer.h:160
void minimize_no_gradient(unsigned int dim, OptimizerMonitor *monitor)
Definition: GslOptimizer.C:395
GslVector * m_initialPoint
Definition: GslOptimizer.h:157
void QUESO::GslOptimizer::minimize_no_gradient ( unsigned int  dim,
OptimizerMonitor monitor 
)
private

Definition at line 395 of file GslOptimizer.C.

References QUESO::OptimizerMonitor::append(), BFGS, BFGS2, QUESO::c_evaluate(), dim, FLETCHER_REEVES_CG, QUESO::BaseOptimizer::getMaxIterations(), QUESO::BaseOptimizer::getTolerance(), m_fstep_size, m_initialPoint, m_objectiveFunction, m_solver_type, NELDER_MEAD, NELDER_MEAD2, NELDER_MEAD2_RAND, POLAK_RIBIERE_CG, queso_error, and STEEPEST_DESCENT.

Referenced by minimize().

396 {
397  // Set initial point
398  gsl_vector* x = gsl_vector_alloc(dim);
399  for (unsigned int i = 0; i < dim; i++) {
400  gsl_vector_set(x, i, (*m_initialPoint)[i]);
401  }
402 
403  // Tell GSL which solver we're using
404  const gsl_multimin_fminimizer_type* type = NULL;
405 
406  switch(m_solver_type)
407  {
408  case(NELDER_MEAD):
409  type = gsl_multimin_fminimizer_nmsimplex;
410  break;
411  case(NELDER_MEAD2):
412  type = gsl_multimin_fminimizer_nmsimplex2;
413  break;
414  case(NELDER_MEAD2_RAND):
415  type = gsl_multimin_fminimizer_nmsimplex2rand;
416  break;
417  case(FLETCHER_REEVES_CG):
418  case(POLAK_RIBIERE_CG):
419  case(BFGS):
420  case(BFGS2):
421  case(STEEPEST_DESCENT):
422  default:
423  // Wat?!
424  queso_error();
425  }
426 
427  // Init solver
428  gsl_multimin_fminimizer* solver =
429  gsl_multimin_fminimizer_alloc(type, dim);
430 
431  // Point GSL at the right functions
432  gsl_multimin_function minusLogPosterior;
433  minusLogPosterior.n = dim;
434  minusLogPosterior.f = &c_evaluate;
435  minusLogPosterior.params = (void *)(this);
436 
437  // Needed for these gradient free algorithms.
438  gsl_vector* step_size = gsl_vector_alloc(dim);
439 
440  for(unsigned int i = 0; i < dim; i++) {
441  gsl_vector_set(step_size, i, m_fstep_size[i]);
442  }
443 
444  gsl_multimin_fminimizer_set(solver, &minusLogPosterior, x, step_size);
445 
446  int status;
447  size_t iter = 0;
448  double size = 0.0;
449 
450  do
451  {
452  iter++;
453  status = gsl_multimin_fminimizer_iterate(solver);
454 
455  if (status) {
456  if( m_objectiveFunction.domainSet().env().fullRank() == 0 )
457  {
458  std::cerr << "Error while GSL does optimisation. "
459  << "See below for GSL error type." << std::endl;
460  std::cerr << "Gsl error: " << gsl_strerror(status) << std::endl;
461  }
462  break;
463  }
464 
465  size = gsl_multimin_fminimizer_size(solver);
466 
467  status = gsl_multimin_test_size (size, this->getTolerance());
468 
469  if(monitor)
470  {
471  gsl_vector* x = gsl_multimin_fminimizer_x(solver);
472  std::vector<double> x_min(dim);
473  for( unsigned int i = 0; i < dim; i++)
474  x_min[i] = gsl_vector_get(x,i);
475 
476  double f = gsl_multimin_fminimizer_minimum(solver);
477 
478  monitor->append( x_min, f, size );
479  }
480 
481  }
482 
483  while ((status == GSL_CONTINUE) && (iter < this->getMaxIterations()));
484 
485  for (unsigned int i = 0; i < dim; i++) {
486  (*m_minimizer)[i] = gsl_vector_get(solver->x, i);
487  }
488 
489  // We're being good human beings and cleaning up the memory we allocated
490  gsl_vector_free(step_size);
491  gsl_multimin_fminimizer_free(solver);
492  gsl_vector_free(x);
493 
494  return;
495 }
int dim
Definition: ann2fig.cpp:81
#define queso_error()
Definition: asserts.h:53
double getTolerance() const
Returns the tolerance used to test for an extremum in the optimizer.
Definition: Optimizer.C:57
const BaseScalarFunction< GslVector, GslMatrix > & m_objectiveFunction
Definition: GslOptimizer.h:155
SolverType m_solver_type
Definition: GslOptimizer.h:160
GslVector m_fstep_size
For use in gradient-free algorithms.
Definition: GslOptimizer.h:163
double c_evaluate(const gsl_vector *x, void *context)
Definition: GslOptimizer.C:43
unsigned int getMaxIterations() const
Returns the maximum number of iterations the optimizer will do.
Definition: Optimizer.C:51
GslVector * m_initialPoint
Definition: GslOptimizer.h:157
void QUESO::GslOptimizer::minimize_with_gradient ( unsigned int  dim,
OptimizerMonitor monitor 
)
private

Definition at line 297 of file GslOptimizer.C.

References QUESO::OptimizerMonitor::append(), BFGS, BFGS2, QUESO::c_evaluate(), QUESO::c_evaluate_derivative(), QUESO::c_evaluate_with_derivative(), dim, FLETCHER_REEVES_CG, getFdfstepSize(), getLineTolerance(), QUESO::BaseOptimizer::getMaxIterations(), m_initialPoint, m_objectiveFunction, m_solver_type, NELDER_MEAD, NELDER_MEAD2, NELDER_MEAD2_RAND, POLAK_RIBIERE_CG, queso_error, and STEEPEST_DESCENT.

Referenced by minimize().

298 {
299  // Set initial point
300  gsl_vector * x = gsl_vector_alloc(dim);
301  for (unsigned int i = 0; i < dim; i++) {
302  gsl_vector_set(x, i, (*m_initialPoint)[i]);
303  }
304 
305  // Tell GSL which solver we're using
306  const gsl_multimin_fdfminimizer_type* type = NULL;
307 
308  // We use m_solver_type here because we need the enum
309  switch(m_solver_type)
310  {
311  case(FLETCHER_REEVES_CG):
312  type = gsl_multimin_fdfminimizer_conjugate_fr;
313  break;
314  case(POLAK_RIBIERE_CG):
315  type = gsl_multimin_fdfminimizer_conjugate_pr;
316  break;
317  case(BFGS):
318  type = gsl_multimin_fdfminimizer_vector_bfgs;
319  break;
320  case(BFGS2):
321  type = gsl_multimin_fdfminimizer_vector_bfgs2;
322  break;
323  case(STEEPEST_DESCENT):
324  type = gsl_multimin_fdfminimizer_steepest_descent;
325  break;
326  case(NELDER_MEAD):
327  case(NELDER_MEAD2):
328  case(NELDER_MEAD2_RAND):
329  default:
330  // Wat?!
331  queso_error();
332  }
333 
334  // Init solver
335  gsl_multimin_fdfminimizer * solver =
336  gsl_multimin_fdfminimizer_alloc(type, dim);
337 
338  // Point GSL to the right functions
339  gsl_multimin_function_fdf minusLogPosterior;
340  minusLogPosterior.n = dim;
341  minusLogPosterior.f = &c_evaluate;
342  minusLogPosterior.df = &c_evaluate_derivative;
343  minusLogPosterior.fdf = &c_evaluate_with_derivative;
344  minusLogPosterior.params = (void *)(this);
345 
346  gsl_multimin_fdfminimizer_set(solver, &minusLogPosterior, x, getFdfstepSize(), getLineTolerance());
347 
348  int status;
349  size_t iter = 0;
350 
351  do {
352  iter++;
353  status = gsl_multimin_fdfminimizer_iterate(solver);
354 
355  if (status) {
356  if( m_objectiveFunction.domainSet().env().fullRank() == 0 )
357  {
358  std::cerr << "Error while GSL does optimisation. "
359  << "See below for GSL error type." << std::endl;
360  std::cerr << "Gsl error: " << gsl_strerror(status) << std::endl;
361  }
362  break;
363  }
364 
365  status = gsl_multimin_test_gradient(solver->gradient, this->getTolerance());
366 
367  if(monitor)
368  {
369  gsl_vector* x = gsl_multimin_fdfminimizer_x(solver);
370  std::vector<double> x_min(dim);
371  for( unsigned int i = 0; i < dim; i++)
372  x_min[i] = gsl_vector_get(x,i);
373 
374  double f = gsl_multimin_fdfminimizer_minimum(solver);
375 
376  gsl_vector* grad = gsl_multimin_fdfminimizer_gradient(solver);
377  double grad_norm = gsl_blas_dnrm2(grad);
378 
379  monitor->append( x_min, f, grad_norm );
380  }
381 
382  } while ((status == GSL_CONTINUE) && (iter < this->getMaxIterations()));
383 
384  for (unsigned int i = 0; i < dim; i++) {
385  (*m_minimizer)[i] = gsl_vector_get(solver->x, i);
386  }
387 
388  // We're being good human beings and cleaning up the memory we allocated
389  gsl_multimin_fdfminimizer_free(solver);
390  gsl_vector_free(x);
391 
392  return;
393 }
int dim
Definition: ann2fig.cpp:81
#define queso_error()
Definition: asserts.h:53
virtual double getLineTolerance() const
Gets the tolerance to use for line minimisation.
Definition: GslOptimizer.C:610
const BaseScalarFunction< GslVector, GslMatrix > & m_objectiveFunction
Definition: GslOptimizer.h:155
SolverType m_solver_type
Definition: GslOptimizer.h:160
void c_evaluate_derivative(const gsl_vector *x, void *context, gsl_vector *derivative)
Definition: GslOptimizer.C:69
double c_evaluate(const gsl_vector *x, void *context)
Definition: GslOptimizer.C:43
void c_evaluate_with_derivative(const gsl_vector *x, void *context, double *f, gsl_vector *derivative)
Definition: GslOptimizer.C:151
virtual double getFdfstepSize() const
Gets the step to use in gradient-based solvers.
Definition: GslOptimizer.C:604
unsigned int getMaxIterations() const
Returns the maximum number of iterations the optimizer will do.
Definition: Optimizer.C:51
GslVector * m_initialPoint
Definition: GslOptimizer.h:157
const GslVector & QUESO::GslOptimizer::minimizer ( ) const

Return the point that minimizes the objective function.

This state will be filled with GSL_NAN if, for some reason, the optimization failed

Definition at line 255 of file GslOptimizer.C.

References m_minimizer.

Referenced by QUESO::StatisticalInverseProblem< P_V, P_M >::solveWithBayesMetropolisHastings().

256 {
257  return *(this->m_minimizer);
258 }
GslVector * m_minimizer
Definition: GslOptimizer.h:158
const BaseScalarFunction< GslVector, GslMatrix > & QUESO::GslOptimizer::objectiveFunction ( ) const

Returns the objective function.

Definition at line 241 of file GslOptimizer.C.

References m_objectiveFunction.

Referenced by QUESO::c_evaluate(), QUESO::c_evaluate_derivative(), and setFstepSize().

242 {
243  return this->m_objectiveFunction;
244 }
const BaseScalarFunction< GslVector, GslMatrix > & m_objectiveFunction
Definition: GslOptimizer.h:155
void QUESO::GslOptimizer::set_line_tol ( double  tol)

Set GSL line minimization tolerance.

Applicable only to gradient-based solvers. Default is 0.1, as recommended by GSL documentation. See GSL documentation for more details.

void QUESO::GslOptimizer::set_solver_type ( SolverType  solver)

Definition at line 260 of file GslOptimizer.C.

References m_solver_type, and queso_deprecated.

Referenced by set_solver_type(), and setSolverType().

261 {
263  m_solver_type = solver;
264 }
#define queso_deprecated()
Definition: Defines.h:134
SolverType m_solver_type
Definition: GslOptimizer.h:160
void QUESO::GslOptimizer::set_solver_type ( std::string &  solver)

Definition at line 553 of file GslOptimizer.C.

References queso_deprecated, set_solver_type(), and string_to_enum().

554 {
556  this->set_solver_type( this->string_to_enum(solver) );
557 }
void set_solver_type(SolverType solver)
Definition: GslOptimizer.C:260
SolverType string_to_enum(std::string &solver)
Definition: GslOptimizer.C:509
#define queso_deprecated()
Definition: Defines.h:134
void QUESO::GslOptimizer::set_step_size ( const GslVector step_size)

Sets step size used in gradient-free solvers.

By default, the step size used will be a vector of 0.1. Use this method to reset the step_size to the desired values.

Definition at line 497 of file GslOptimizer.C.

References m_fstep_size, and queso_deprecated.

Referenced by setFdfstepSize(), and setFstepSize().

498 {
500  m_fstep_size = step_size;
501 }
#define queso_deprecated()
Definition: Defines.h:134
GslVector m_fstep_size
For use in gradient-free algorithms.
Definition: GslOptimizer.h:163
void QUESO::GslOptimizer::set_step_size ( double  step_size)

Sets step size used in gradient-based solvers.

GSL doesn't document this parameter well, but it seems to be related to the line search, so we default to 1.0 for full step.

Definition at line 503 of file GslOptimizer.C.

References m_fdfstep_size, and queso_deprecated.

504 {
506  m_fdfstep_size = step_size;
507 }
#define queso_deprecated()
Definition: Defines.h:134
double m_fdfstep_size
For use in gradient-based algorithms.
Definition: GslOptimizer.h:166
void QUESO::GslOptimizer::setFdfstepSize ( double  fdfstepSize)
virtual

Sets the step to use in gradient-based solvers.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 579 of file GslOptimizer.C.

References QUESO::BaseOptimizer::m_optionsObj, and set_step_size().

580 {
581  this->m_optionsObj->m_fdfstepSize = fdfstepSize;
582  this->set_step_size(fdfstepSize);
583 }
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
void set_step_size(const GslVector &step_size)
Sets step size used in gradient-free solvers.
Definition: GslOptimizer.C:497
void QUESO::GslOptimizer::setFstepSize ( double  fstepSize)
virtual

Sets the step size to use in gradient-free solvers.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 567 of file GslOptimizer.C.

References QUESO::GslVector::cwSet(), QUESO::BaseOptimizer::m_optionsObj, objectiveFunction(), and set_step_size().

568 {
569  this->m_optionsObj->m_fstepSize = fstepSize;
570 
571  GslVector fstepSizeVector(
572  objectiveFunction().domainSet().vectorSpace().zeroVector());
573  fstepSizeVector.cwSet(fstepSize);
574 
575  this->set_step_size(fstepSizeVector);
576 }
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
void set_step_size(const GslVector &step_size)
Sets step size used in gradient-free solvers.
Definition: GslOptimizer.C:497
const BaseScalarFunction< GslVector, GslMatrix > & objectiveFunction() const
Returns the objective function.
Definition: GslOptimizer.C:241
void QUESO::GslOptimizer::setInitialPoint ( const GslVector intialPoint)

Set the point at which the optimization starts.

Definition at line 247 of file GslOptimizer.C.

References m_initialPoint, and QUESO::GslVector::sizeLocal().

Referenced by QUESO::StatisticalInverseProblem< P_V, P_M >::solveWithBayesMetropolisHastings().

248 {
249  for (unsigned int i = 0; i < initialPoint.sizeLocal(); i++) {
250  (*(this->m_initialPoint))[i] = initialPoint[i];
251  }
252 }
GslVector * m_initialPoint
Definition: GslOptimizer.h:157
void QUESO::GslOptimizer::setLineTolerance ( double  lineTolerance)
virtual

Sets the tolerance to use for line minimisation.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 586 of file GslOptimizer.C.

References QUESO::BaseOptimizer::m_optionsObj.

587 {
588  this->m_optionsObj->m_lineTolerance = lineTolerance;
589 }
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
void QUESO::GslOptimizer::setSolverType ( std::string  solverType)
virtual

Sets the algorithm to use for minimisation.

Reimplemented from QUESO::BaseOptimizer.

Definition at line 560 of file GslOptimizer.C.

References QUESO::BaseOptimizer::m_optionsObj, and set_solver_type().

Referenced by GslOptimizer().

561 {
562  this->m_optionsObj->m_solverType = solverType;
563  this->set_solver_type(solverType);
564 }
void set_solver_type(SolverType solver)
Definition: GslOptimizer.C:260
ScopedPtr< OptimizerOptions >::Type m_optionsObj
Definition: Optimizer.h:126
bool QUESO::GslOptimizer::solver_needs_gradient ( SolverType  solver)
private

Helper function.

Definition at line 266 of file GslOptimizer.C.

References BFGS, BFGS2, FLETCHER_REEVES_CG, NELDER_MEAD, NELDER_MEAD2, NELDER_MEAD2_RAND, POLAK_RIBIERE_CG, queso_error, and STEEPEST_DESCENT.

Referenced by minimize().

267 {
268  bool gradient_needed = false;
269 
270  switch(solver)
271  {
272  case(FLETCHER_REEVES_CG):
273  case(POLAK_RIBIERE_CG):
274  case(BFGS):
275  case(BFGS2):
276  case(STEEPEST_DESCENT):
277  {
278  gradient_needed = true;
279  break;
280  }
281  case(NELDER_MEAD):
282  case(NELDER_MEAD2):
283  case(NELDER_MEAD2_RAND):
284  {
285  break;
286  }
287  default:
288  {
289  // Wat?!
290  queso_error();
291  }
292  } // switch(solver)
293 
294  return gradient_needed;
295 }
#define queso_error()
Definition: asserts.h:53
GslOptimizer::SolverType QUESO::GslOptimizer::string_to_enum ( std::string &  solver)

Definition at line 509 of file GslOptimizer.C.

References BFGS, BFGS2, FLETCHER_REEVES_CG, m_objectiveFunction, NELDER_MEAD, NELDER_MEAD2, NELDER_MEAD2_RAND, POLAK_RIBIERE_CG, queso_deprecated, queso_error, and STEEPEST_DESCENT.

Referenced by set_solver_type().

510 {
511  SolverType solver_type;
512 
513  if( solver == std::string("fletcher_reeves_cg") )
514  solver_type = FLETCHER_REEVES_CG;
515  else if( solver == std::string("polak_ribiere_cg") )
516  solver_type = POLAK_RIBIERE_CG;
517  else if( solver == std::string("bfgs") )
518  solver_type = BFGS;
519  else if( solver == std::string("bfgs2") )
520  solver_type = BFGS2;
521  else if( solver == std::string("steepest_decent") ) {
523  solver_type = STEEPEST_DESCENT;
524  }
525  else if( solver == std::string("steepest_descent") )
526  solver_type = STEEPEST_DESCENT;
527  else if( solver == std::string("nelder_mead") )
528  solver_type = NELDER_MEAD;
529  else if( solver == std::string("nelder_mead2") )
530  solver_type = NELDER_MEAD2;
531  else if( solver == std::string("nelder_mead2_rand") )
532  solver_type = NELDER_MEAD2_RAND;
533  else
534  {
535  if( m_objectiveFunction.domainSet().env().fullRank() == 0 )
536  {
537  std::cerr << "Error: Invalid GslOptimizer solver name: " << solver << std::endl
538  << " Valids choices are: fletcher_reeves_cg" << std::endl
539  << " polak_ribiere_cg" << std::endl
540  << " bfgs" << std::endl
541  << " bfgs2" << std::endl
542  << " steepest_descent" << std::endl
543  << " nelder_mead" << std::endl
544  << " nelder_mead2" << std::endl
545  << " nelder_mead2_rand" << std::endl;
546  }
547  queso_error();
548  }
549 
550  return solver_type;
551 }
#define queso_error()
Definition: asserts.h:53
#define queso_deprecated()
Definition: Defines.h:134
const BaseScalarFunction< GslVector, GslMatrix > & m_objectiveFunction
Definition: GslOptimizer.h:155

Member Data Documentation

double QUESO::GslOptimizer::m_fdfstep_size
private

For use in gradient-based algorithms.

Definition at line 166 of file GslOptimizer.h.

Referenced by set_step_size().

GslVector QUESO::GslOptimizer::m_fstep_size
private

For use in gradient-free algorithms.

Definition at line 163 of file GslOptimizer.h.

Referenced by GslOptimizer(), minimize_no_gradient(), and set_step_size().

GslVector* QUESO::GslOptimizer::m_initialPoint
private
double QUESO::GslOptimizer::m_line_tol
private

Line minimization tolerance in gradient-based algorithms.

Definition at line 169 of file GslOptimizer.h.

GslVector* QUESO::GslOptimizer::m_minimizer
private

Definition at line 158 of file GslOptimizer.h.

Referenced by GslOptimizer(), and minimizer().

const BaseScalarFunction<GslVector, GslMatrix>& QUESO::GslOptimizer::m_objectiveFunction
private
SolverType QUESO::GslOptimizer::m_solver_type
private

The documentation for this class was generated from the following files:

Generated on Tue Nov 29 2016 10:53:13 for queso-0.56.0 by  doxygen 1.8.5