Mantid
Loading...
Searching...
No Matches
AugmentedLagrangianOptimizer.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2013 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "MantidCurveFitting/DllConfig.h"
10#include "MantidKernel/Matrix.h"
11
12#include <boost/function.hpp>
13
14namespace Mantid {
15namespace CurveFitting {
20
21//---------------------------------------------------------------------------------------------
22// Forward declaration
23//---------------------------------------------------------------------------------------------
24class UnconstrainedCostFunction;
25
53class MANTID_CURVEFITTING_DLL AugmentedLagrangianOptimizer {
54
55public:
57 using ObjFunction = boost::function<double(const size_t, const double *)>;
58
59public:
69 AugmentedLagrangianOptimizer(const size_t nparams, const ObjFunction &objfunc)
70 : m_userfunc(objfunc), m_nparams(nparams), m_neq(0), m_eq(), m_nineq(0), m_ineq(), m_maxIter(500) {}
71
85 AugmentedLagrangianOptimizer(const size_t nparams, const ObjFunction &objfunc, const Kernel::DblMatrix &equality,
86 const Kernel::DblMatrix &inequality)
87 : m_userfunc(objfunc), m_nparams(nparams), m_neq(equality.numRows()), m_eq(equality),
88 m_nineq(inequality.numRows()), m_ineq(inequality), m_maxIter(500) {
89 checkConstraints(equality, inequality);
90 }
91
94
97
100
102 inline size_t numParameters() const { return m_nparams; }
104 inline size_t numEqualityConstraints() const { return m_neq; }
106 inline size_t numInequalityConstraints() const { return m_nineq; }
107
112 inline void setMaxIterations(const int maxIter) { m_maxIter = maxIter; }
113
115 void minimize(std::vector<double> &xv) const;
116
117private:
118 friend class UnconstrainedCostFunction;
120 void unconstrainedOptimization(const std::vector<double> &lambda, const std::vector<double> &mu, const double rho,
121 std::vector<double> &xcur) const;
122
124 void checkConstraints(const Kernel::DblMatrix &equality, const Kernel::DblMatrix &inequality);
125
127 // FunctionWrapper m_userfunc;
128
131 const size_t m_nparams;
133 const size_t m_neq;
137 const size_t m_nineq;
142};
143
144} // namespace CurveFitting
145} // namespace Mantid
const std::vector< double > * lambda
Implements the Augmented Lagrangian optimization method of Birgin & Martinez.
Kernel::DblMatrix m_eq
Defines the equality constraints.
AugmentedLagrangianOptimizer()=delete
Disable default constructor.
AugmentedLagrangianOptimizer & operator=(const AugmentedLagrangianOptimizer &)=delete
Disable assignment operator.
void setMaxIterations(const int maxIter)
Override the maximum number of iterations (Default = 500)
const size_t m_neq
Number of equality constraints.
AugmentedLagrangianOptimizer(const AugmentedLagrangianOptimizer &)=delete
Disable copy operator.
AugmentedLagrangianOptimizer(const size_t nparams, const ObjFunction &objfunc, const Kernel::DblMatrix &equality, const Kernel::DblMatrix &inequality)
Constructor with constraints.
boost::function< double(const size_t, const double *)> ObjFunction
Function type.
AugmentedLagrangianOptimizer(const size_t nparams, const ObjFunction &objfunc)
Constructor.
const size_t m_nparams
Number of parameters under minimization.
Kernel::DblMatrix m_ineq
Defines the inequality constraints.
const size_t m_nineq
Number of inequality constraints.
OptimizerResult
The results of the optimization.
Helper class which provides the Collimation Length for SANS instruments.