mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-28 06:12:53 -06:00
Eigen: Added simpler nonlinear functions
git-svn-id: svn://ultimatepp.org/upp/trunk@14465 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
d6c4b051ef
commit
16cc08d07c
8 changed files with 85 additions and 20 deletions
|
|
@ -1 +1,34 @@
|
|||
// Dummy file
|
||||
#include <Core/Core.h>
|
||||
#include <Eigen.h>
|
||||
|
||||
|
||||
namespace Upp {
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
bool NonLinearOptimization(VectorXd &y, int numData, Function <int(const VectorXd &b, VectorXd &residual)> Residual) {
|
||||
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);
|
||||
int ret = lm.minimize(y);
|
||||
if (ret == Eigen::LevenbergMarquardtSpace::ImproperInputParameters ||
|
||||
ret == Eigen::LevenbergMarquardtSpace::TooManyFunctionEvaluation)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NonLinearSolver(VectorXd &y, Function <int(const VectorXd &b, VectorXd &residual)> Residual) {
|
||||
Basic_functor functor(Residual);
|
||||
HybridNonLinearSolver<Basic_functor> solver(functor);
|
||||
int ret = solver.solveNumericalDiff(y);
|
||||
if (ret == HybridNonLinearSolverSpace::ImproperInputParameters ||
|
||||
ret == HybridNonLinearSolverSpace::TooManyFunctionEvaluation ||
|
||||
ret == HybridNonLinearSolverSpace::NotMakingProgressJacobian ||
|
||||
ret == HybridNonLinearSolverSpace::NotMakingProgressIterations)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -51,20 +51,8 @@ struct Basic_functor : NonLinearOptimizationFunctor<double> {
|
|||
Function <int(const Eigen::VectorXd &b, Eigen::VectorXd &err)> function;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
bool NonLinearOptimization(T &coeff, int numData, Function <int(const T &b, T &err)>function) {
|
||||
Basic_functor functor(function);
|
||||
functor.unknowns = coeff.size();
|
||||
functor.datasetLen = numData;
|
||||
Eigen::NumericalDiff<Basic_functor> numDiff(functor);
|
||||
Eigen::LevenbergMarquardt<Eigen::NumericalDiff<Basic_functor> > lm(numDiff);
|
||||
int ret = lm.minimize(coeff);
|
||||
if (ret == Eigen::LevenbergMarquardtSpace::ImproperInputParameters ||
|
||||
ret == Eigen::LevenbergMarquardtSpace::TooManyFunctionEvaluation)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NonLinearOptimization(Eigen::VectorXd &y, int numData, Function <int(const Eigen::VectorXd &y, Eigen::VectorXd &residual)>residual);
|
||||
bool NonLinearSolver(Eigen::VectorXd &y, Function <int(const Eigen::VectorXd &b, Eigen::VectorXd &residual)> Residual);
|
||||
|
||||
template <class T>
|
||||
void Xmlize(XmlIO &xml, Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &mat) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ file
|
|||
Eigen.cpp,
|
||||
Eigen.h,
|
||||
ToStringPlugin.h,
|
||||
src.tpp,
|
||||
srcdoc.tpp,
|
||||
Copying,
|
||||
Eigen readonly separator,
|
||||
|
|
|
|||
41
uppsrc/plugin/Eigen/src.tpp/NonLinear_en-us.tpp
Normal file
41
uppsrc/plugin/Eigen/src.tpp/NonLinear_en-us.tpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
topic "";
|
||||
[H6;0 $$1,0#05600065144404261032431302351956:begin]
|
||||
[i448;a25;kKO9;2 $$2,0#37138531426314131252341829483370:codeitem]
|
||||
[l288;2 $$3,0#27521748481378242620020725143825:desc]
|
||||
[0 $$4,0#96390100711032703541132217272105:end]
|
||||
[ $$0,0#00000000000000000000000000000000:Default]
|
||||
[{_}%EN-US
|
||||
[ {{10000@(113.42.0) [s0; [*@2;4 Nonlinear functions]]}}&]
|
||||
[s0;*@3;4 &]
|
||||
[s0; [2 Some functions have been include to ease nonlinear optimization
|
||||
and equation system solving.]&]
|
||||
[s0;2 &]
|
||||
[s1;%- &]
|
||||
[s2;:Upp`:`:NonLinearOptimization`(Eigen`:`:VectorXd`&`,int`,Upp`:`:Function`<int`(const Eigen`:`:VectorXd`&`,Eigen`:`:VectorXd`&`)`>`):%- [@(0.0.255) b
|
||||
ool]_[* NonLinearOptimization]([_^Eigen`:`:VectorXd^ Eigen`::VectorXd]_`&[*@3 y],
|
||||
[@(0.0.255) int]_[*@3 numData], [_^Upp`:`:Function^ Function]_<[@(0.0.255) int]([@(0.0.255) c
|
||||
onst]_[_^Eigen`:`:VectorXd^ Eigen`::VectorXd]_`&[*@3 y], [_^Eigen`:`:VectorXd^ Eigen`::Ve
|
||||
ctorXd]_`&[*@3 residual])>[*@3 Residual])&]
|
||||
[s3; Given a number of [%-*@3 numData] records, the objective is to
|
||||
obtain in an iterative way the [%-*@3 y] unknown coefficients that
|
||||
minimizes, ideally to zero, the [%-*@3 residual] error of the [%-*@3 Residual]
|
||||
Function.&]
|
||||
[s3; To improve the success of this calculation, [%-*@3 y] has to be
|
||||
initially filled with adequate initial guess of the unknowns.&]
|
||||
[s3; [%-*@3 Residual ]Function has to fill in every call [%-*@3 residual]`[[%-*@3 numData]`]
|
||||
Vector by applying the unknowns provisionally guessed values
|
||||
in [%-*@3 y] to the model to be solved.&]
|
||||
[s4; &]
|
||||
[s1;%- &]
|
||||
[s2;:Upp`:`:NonLinearSolver`(Eigen`:`:VectorXd`&`,Upp`:`:Function`<int`(const Eigen`:`:VectorXd`&b`,Eigen`:`:VectorXd`&residual`)`>`):%- [@(0.0.255) b
|
||||
ool]_[* NonLinearSolver]([_^Eigen`:`:VectorXd^ VectorXd]_`&[*@3 y],
|
||||
[_^Upp`:`:Function^ Function]_<[@(0.0.255) int]([@(0.0.255) const]_[_^Eigen`:`:VectorXd^ E
|
||||
igen`::VectorXd]_`&[*@3 y], [_^Eigen`:`:VectorXd^ Eigen`::VectorXd]_`&[*@3 residual])>_[*@3 R
|
||||
esidual])&]
|
||||
[s3; Given a system of equations defined by Function [%-*@3 Residual],
|
||||
and a set of initial values of the unknowns set in [%-*@3 y], this
|
||||
function tries to obtain the set of [%-*@3 y] that best comply
|
||||
with [%-*@3 Residual].&]
|
||||
[s3; The dimension of [%-*@3 y] ([%-*@3 y.size()]) has to be equal to
|
||||
the number of equations ([%-*@3 residual.size()]).&]
|
||||
[s4; ]]
|
||||
0
uppsrc/plugin/Eigen/src.tpp/NonLinear_en-us.tppi
Normal file
0
uppsrc/plugin/Eigen/src.tpp/NonLinear_en-us.tppi
Normal file
4
uppsrc/plugin/Eigen/src.tpp/all.i
Normal file
4
uppsrc/plugin/Eigen/src.tpp/all.i
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
TOPIC("NonLinear_en-us")
|
||||
#include "NonLinear_en-us.tppi"
|
||||
END_TOPIC
|
||||
|
||||
|
|
@ -31,7 +31,9 @@ to ease its use for U`+`+ users. It has many samples from Eigen
|
|||
library and nonlinear equation solving and optimization like
|
||||
][^http`:`/`/www`.itl`.nist`.gov`/div898`/strd`/nls`/data`/eckerle4`.shtml^2 Eckerl
|
||||
e4][2 and ][^http`:`/`/www`.itl`.nist`.gov`/div898`/strd`/nls`/data`/thurber`.shtml^2 T
|
||||
hurber][2 (see the graphs).]&]
|
||||
hurber][2 (see the graphs). To simplify access to these features,
|
||||
][^topic`:`/`/plugin`/Eigen`/src`/NonLinear`_en`-us^2 simple functions][2
|
||||
have been added.]&]
|
||||
[s0;#2 &]
|
||||
[s0;= [2
|
||||
@@image:1272&1104
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
topic "";
|
||||
[ $$0,0#00000000000000000000000000000000:Default]
|
||||
[{_}%EN-US
|
||||
[s0; ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue