mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-21 22:04:56 -06:00
Eigen: Improvements in NonLinearOptimization()
git-svn-id: svn://ultimatepp.org/upp/trunk@14682 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
0de514b9f2
commit
74f660ecdf
2 changed files with 13 additions and 3 deletions
|
|
@ -5,15 +5,23 @@ namespace Upp {
|
|||
|
||||
using namespace Eigen;
|
||||
|
||||
bool NonLinearOptimization(VectorXd &y, Eigen::Index numData, Function <int(const VectorXd &b, VectorXd &residual)> Residual) {
|
||||
bool NonLinearOptimization(VectorXd &y, Eigen::Index numData,
|
||||
Function <int(const VectorXd &b, VectorXd &residual)> Residual,
|
||||
double xtol, double ftol, int maxfev) {
|
||||
Basic_functor functor(Residual);
|
||||
functor.unknowns = y.size();
|
||||
functor.datasetLen = numData;
|
||||
Eigen::NumericalDiff<Basic_functor> numDiff(functor);
|
||||
Eigen::LevenbergMarquardt<Eigen::NumericalDiff<Basic_functor> > lm(numDiff);
|
||||
if (!IsNull(xtol))
|
||||
lm.parameters.xtol *= xtol;
|
||||
if (!IsNull(ftol))
|
||||
lm.parameters.ftol *= ftol;
|
||||
if (!IsNull(maxfev))
|
||||
lm.parameters.maxfev = maxfev;
|
||||
int ret = lm.minimize(y);
|
||||
if (ret == Eigen::LevenbergMarquardtSpace::ImproperInputParameters ||
|
||||
ret == Eigen::LevenbergMarquardtSpace::TooManyFunctionEvaluation)
|
||||
ret == Eigen::LevenbergMarquardtSpace::TooManyFunctionEvaluation)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,9 @@ struct Basic_functor : NonLinearOptimizationFunctor<double> {
|
|||
Function <int(const Eigen::VectorXd &b, Eigen::VectorXd &err)> function;
|
||||
};
|
||||
|
||||
bool NonLinearOptimization(Eigen::VectorXd &y, Eigen::Index numData, Function <int(const Eigen::VectorXd &y, Eigen::VectorXd &residual)>residual);
|
||||
bool NonLinearOptimization(Eigen::VectorXd &y, Eigen::Index numData,
|
||||
Function <int(const Eigen::VectorXd &y, Eigen::VectorXd &residual)>residual,
|
||||
double xtol = Null, double ftol = Null, int maxfev = Null);
|
||||
bool SolveNonLinearEquations(Eigen::VectorXd &y, Function <int(const Eigen::VectorXd &b, Eigen::VectorXd &residual)> Residual);
|
||||
|
||||
template <class T>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue