Mantid
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::Math::SLSQPMinimizer Class Reference

Minimize an objective function using the SLSQP optimization subroutine originally implemented by Dieter Kraft and ported to Python by scipy. More...

#include <SLSQPMinimizer.h>

Classes

class  FunctionWrapper
 Non-templated wrapper for objective function object to allow it to be stored without templating the class. More...
 

Public Member Functions

std::vector< double > minimize (const std::vector< double > &x0) const
 Perform the minimization. More...
 
size_t numEqualityConstraints () const
 
size_t numInequalityConstraints () const
 
size_t numParameters () const
 
SLSQPMinimizeroperator= (const SLSQPMinimizer &)=delete
 Disable assignment operator. More...
 
 SLSQPMinimizer ()=delete
 Disable default constructor. More...
 
template<typename T >
 SLSQPMinimizer (const size_t nparams, const T &objfunc)
 Constructor. More...
 
template<typename T >
 SLSQPMinimizer (const size_t nparams, const T &objfunc, const DblMatrix &equality, const DblMatrix &inequality)
 Constructor with constraints. More...
 
 SLSQPMinimizer (const SLSQPMinimizer &)=delete
 Disable copy operator. More...
 

Private Member Functions

void evaluateConstraints (std::vector< double > &constrValues, const std::vector< double > &x) const
 Compute values of constraints. More...
 
void fprime (std::vector< double > &grad, const std::vector< double > &x) const
 Compute derivative numerically. More...
 
double fvalue (const std::vector< double > &x) const
 Compute the value of the objective function. More...
 
void initializeConstraints (const DblMatrix &equality, const DblMatrix &inequality)
 Create constraint array. More...
 

Private Attributes

std::vector< double > m_constraintNorms
 Holder for constraint normals. More...
 
const size_t m_neq
 Number of equality constraints. More...
 
const size_t m_nineq
 Number of inequality constraints. More...
 
const size_t m_nparams
 Number of parameters under minimization. More...
 
FunctionWrapper m_objfunc
 User-defined function. More...
 

Detailed Description

Minimize an objective function using the SLSQP optimization subroutine originally implemented by Dieter Kraft and ported to Python by scipy.

This implementation is a port of the scipy variant using f2c to translate the Fortran code.

If the objective function is written as

\[ Cx = d \]

where \(x\) are the parameters, then the routine attempts to minimize

\[ \frac{1}{2}||Cx - d||^2 \]

where \( ||f|| \) denotes the 2nd-norm of \(f\). It possible to specify an optional set of constraints such that the function is minimized subject to

\[ Ax \geq 0 \]

and

\[ A_{eq} x = 0 \]

Definition at line 44 of file SLSQPMinimizer.h.

Constructor & Destructor Documentation

◆ SLSQPMinimizer() [1/4]

template<typename T >
Mantid::Kernel::Math::SLSQPMinimizer::SLSQPMinimizer ( const size_t  nparams,
const T &  objfunc 
)
inline

Constructor.

Parameters
nparamsThe number of parameters in the problem
objfuncAn object whose type has a member named eval with the following signature "double eval(const std::vector<double> &) const" to return the value of the objective function at a given pt

Definition at line 56 of file SLSQPMinimizer.h.

◆ SLSQPMinimizer() [2/4]

template<typename T >
Mantid::Kernel::Math::SLSQPMinimizer::SLSQPMinimizer ( const size_t  nparams,
const T &  objfunc,
const DblMatrix equality,
const DblMatrix inequality 
)
inline

Constructor with constraints.

Parameters
nparamsThe number of parameters in the problem
objfuncAn object whose type has a member named eval with the following signature "double eval(const std::vector<double> &)" to return the value of the objective function at a given pt
equalityA matrix of coefficients, \(A_{eq}\) such that in the final solution \(A_{eq} x = 0\)
inequalityA matrix of coefficients, \(A\) such that in the final solution \(A_{eq} x\geq 0\)

Definition at line 73 of file SLSQPMinimizer.h.

◆ SLSQPMinimizer() [3/4]

Mantid::Kernel::Math::SLSQPMinimizer::SLSQPMinimizer ( )
delete

Disable default constructor.

◆ SLSQPMinimizer() [4/4]

Mantid::Kernel::Math::SLSQPMinimizer::SLSQPMinimizer ( const SLSQPMinimizer )
delete

Disable copy operator.

Member Function Documentation

◆ evaluateConstraints()

void Mantid::Kernel::Math::SLSQPMinimizer::evaluateConstraints ( std::vector< double > &  constrValues,
const std::vector< double > &  x 
) const
private

Compute values of constraints.

Compute values of constraints at current x point.

Parameters
constrValuesOutput array to store values
xValues of the parameters

Definition at line 106 of file SLSQPMinimizer.cpp.

References m_constraintNorms, numEqualityConstraints(), numInequalityConstraints(), numParameters(), value, and Mantid::Geometry::x.

Referenced by minimize().

◆ fprime()

void Mantid::Kernel::Math::SLSQPMinimizer::fprime ( std::vector< double > &  grad,
const std::vector< double > &  x 
) const
private

Compute derivative numerically.

Computes the gradient w.r.t to each paramter.

Parameters
gradOutput array to store gradient
xCurrent x pt

Definition at line 85 of file SLSQPMinimizer.cpp.

References fvalue(), numParameters(), tmp, and Mantid::Geometry::x.

Referenced by minimize().

◆ fvalue()

double Mantid::Kernel::Math::SLSQPMinimizer::fvalue ( const std::vector< double > &  x) const
inlineprivate

Compute the value of the objective function.

Parameters
xThe current parameter pt
Returns
The value at the given pt

Definition at line 104 of file SLSQPMinimizer.h.

References Mantid::Geometry::x.

Referenced by fprime(), and minimize().

◆ initializeConstraints()

void Mantid::Kernel::Math::SLSQPMinimizer::initializeConstraints ( const DblMatrix equality,
const DblMatrix inequality 
)
private

Create constraint array.

Parameters
equalityA matrix of equality constraints \(A_{eq}\)(the number of columns must match number of parameters) where \(A_{eq} x = 0\)
inequalityA matrix of inequality constraints (the number of columns must match number of parameters where \(A_{eq} x \geq 0\)

Definition at line 129 of file SLSQPMinimizer.cpp.

References m_constraintNorms, ncols, Mantid::Kernel::Matrix< T >::numCols(), numEqualityConstraints(), numInequalityConstraints(), numParameters(), and Mantid::Kernel::Matrix< T >::numRows().

◆ minimize()

std::vector< double > Mantid::Kernel::Math::SLSQPMinimizer::minimize ( const std::vector< double > &  x0) const

Perform the minimization.

Perform the minimization using the SLSQP routine.

Parameters
x0The starting parameter values
Returns

Definition at line 23 of file SLSQPMinimizer.cpp.

References evaluateConstraints(), fprime(), fvalue(), Mantid::Geometry::m, m_constraintNorms, m_nparams, n, numEqualityConstraints(), numInequalityConstraints(), numParameters(), and Mantid::Geometry::x.

Referenced by Mantid::CurveFitting::Functions::ComptonScatteringCountRate::iterationStarting().

◆ numEqualityConstraints()

size_t Mantid::Kernel::Math::SLSQPMinimizer::numEqualityConstraints ( ) const
inline
Returns
The number of equality constraints

Definition at line 91 of file SLSQPMinimizer.h.

Referenced by evaluateConstraints(), initializeConstraints(), and minimize().

◆ numInequalityConstraints()

size_t Mantid::Kernel::Math::SLSQPMinimizer::numInequalityConstraints ( ) const
inline
Returns
The number of inequality constraints

Definition at line 93 of file SLSQPMinimizer.h.

Referenced by evaluateConstraints(), initializeConstraints(), and minimize().

◆ numParameters()

size_t Mantid::Kernel::Math::SLSQPMinimizer::numParameters ( ) const
inline
Returns
The number of parameters under minimization

Definition at line 89 of file SLSQPMinimizer.h.

Referenced by evaluateConstraints(), fprime(), initializeConstraints(), and minimize().

◆ operator=()

SLSQPMinimizer & Mantid::Kernel::Math::SLSQPMinimizer::operator= ( const SLSQPMinimizer )
delete

Disable assignment operator.

Member Data Documentation

◆ m_constraintNorms

std::vector<double> Mantid::Kernel::Math::SLSQPMinimizer::m_constraintNorms
mutableprivate

Holder for constraint normals.

Definition at line 154 of file SLSQPMinimizer.h.

Referenced by evaluateConstraints(), initializeConstraints(), and minimize().

◆ m_neq

const size_t Mantid::Kernel::Math::SLSQPMinimizer::m_neq
private

Number of equality constraints.

Definition at line 147 of file SLSQPMinimizer.h.

◆ m_nineq

const size_t Mantid::Kernel::Math::SLSQPMinimizer::m_nineq
private

Number of inequality constraints.

Definition at line 149 of file SLSQPMinimizer.h.

◆ m_nparams

const size_t Mantid::Kernel::Math::SLSQPMinimizer::m_nparams
private

Number of parameters under minimization.

Definition at line 145 of file SLSQPMinimizer.h.

Referenced by minimize().

◆ m_objfunc

FunctionWrapper Mantid::Kernel::Math::SLSQPMinimizer::m_objfunc
private

User-defined function.

Definition at line 152 of file SLSQPMinimizer.h.


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