Mantid
|
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 |
SLSQPMinimizer & | operator= (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... | |
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.
|
inline |
Constructor.
nparams | The number of parameters in the problem |
objfunc | An 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.
|
inline |
Constructor with constraints.
nparams | The number of parameters in the problem |
objfunc | An 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 |
equality | A matrix of coefficients, \(A_{eq}\) such that in the final solution \(A_{eq} x = 0\) |
inequality | A matrix of coefficients, \(A\) such that in the final solution \(A_{eq} x\geq 0\) |
Definition at line 73 of file SLSQPMinimizer.h.
|
delete |
Disable default constructor.
|
delete |
Disable copy operator.
|
private |
Compute values of constraints.
Compute values of constraints at current x point.
constrValues | Output array to store values |
x | Values 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().
|
private |
Compute derivative numerically.
Computes the gradient w.r.t to each paramter.
grad | Output array to store gradient |
x | Current x pt |
Definition at line 85 of file SLSQPMinimizer.cpp.
References fvalue(), numParameters(), tmp, and Mantid::Geometry::x.
Referenced by minimize().
|
inlineprivate |
Compute the value of the objective function.
x | The current parameter pt |
Definition at line 104 of file SLSQPMinimizer.h.
References Mantid::Geometry::x.
Referenced by fprime(), and minimize().
|
private |
Create constraint array.
equality | A matrix of equality constraints \(A_{eq}\)(the number of columns must match number of parameters) where \(A_{eq} x = 0\) |
inequality | A 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().
std::vector< double > Mantid::Kernel::Math::SLSQPMinimizer::minimize | ( | const std::vector< double > & | x0 | ) | const |
Perform the minimization.
Perform the minimization using the SLSQP routine.
x0 | The starting parameter values |
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().
|
inline |
Definition at line 91 of file SLSQPMinimizer.h.
Referenced by evaluateConstraints(), initializeConstraints(), and minimize().
|
inline |
Definition at line 93 of file SLSQPMinimizer.h.
Referenced by evaluateConstraints(), initializeConstraints(), and minimize().
|
inline |
Definition at line 89 of file SLSQPMinimizer.h.
Referenced by evaluateConstraints(), fprime(), initializeConstraints(), and minimize().
|
delete |
Disable assignment operator.
|
mutableprivate |
Holder for constraint normals.
Definition at line 154 of file SLSQPMinimizer.h.
Referenced by evaluateConstraints(), initializeConstraints(), and minimize().
|
private |
Number of equality constraints.
Definition at line 147 of file SLSQPMinimizer.h.
|
private |
Number of inequality constraints.
Definition at line 149 of file SLSQPMinimizer.h.
|
private |
Number of parameters under minimization.
Definition at line 145 of file SLSQPMinimizer.h.
Referenced by minimize().
|
private |
User-defined function.
Definition at line 152 of file SLSQPMinimizer.h.