50 "The \"LMDIF\" sub-command adjusts parameters according to the "
51 "Levenberg-Marquardt method.") {
53 (
"TOLERANCE",
"The desired tolerance", 1.0
e-6);
55 (
"CALLS",
"Maximum number of calls to the matching functions", 1000.);
73 return new LMDif(name,
this);
79 static const char method[] =
"LMDIF";
129 for(
int j = 0; j < D.
size(); ++j)
if(D(j) == 0.0) D(j) = 1.0;
131 delta = dxnorm ? dxnorm : 1.0;
139 lmpar(solver, D, f, h);
152 fnorm1 = 2.0 * fnorm;
156 double actred = - 1.0;
157 if(0.1 * fnorm1 < fnorm) {
158 actred = 1.0 - (fnorm1 * fnorm1) / (fnorm * fnorm);
164 double temp1 = gnorm / fnorm;
165 double temp2 =
sqrt(
mu) * dhnorm / fnorm;
166 double prered = temp1 * temp1 + 2.0 * temp2 * temp2;
167 double dirder = - (temp1 * temp1 + temp2 * temp2);
170 ratio = prered ? actred / prered : 0.0;
174 double temp = (actred >= 0.0) ? 0.5 : dirder / (2.0 * dirder + actred);
175 if(0.1 * fnorm1 >= fnorm || temp < 0.1) temp = 0.1;
178 }
else if(
mu == 0.0 || ratio >= 0.75) {
179 delta = 2.0 * dhnorm;
185 if(ratio >= 0.0001) {
194 if((
std::abs(actred) <= tol && prered <= tol && ratio <= 2.0) ||
195 (
delta <= tol * dxnorm) ||
196 (fnorm *fnorm <= tol)) {
200 }
else if((
std::abs(actred) <= DBL_EPSILON && prered <= DBL_EPSILON &&
202 (
delta <= DBL_EPSILON * dxnorm) ||
203 (fnorm *fnorm <= DBL_EPSILON) ||
204 (gnorm <= DBL_EPSILON * fnorm)) {
207 }
while(state <
CONVERGED && ratio < 0.0001);
220 static const int limit = 10;
225 double lm = dhnorm -
delta;
228 if(lm <= 0.1 * delta) {
235 for(
int iter = 0; iter < limit; ++iter) {
236 if(
mu <= 0.0)
mu =
max(DBL_EPSILON, 0.001 * delta);
242 if(lm <= 0.1 * delta)
break;
246 for(
int i = 0; i <
n; ++i) temp[i] = D[i] * D[i] * h[i] / dhnorm;
249 double dmu = lm / (delta * (temp * temp));
269 for(
int j = 0; j <
n; ++j) {
276 for(
int i = 0; i < m; ++i) {
277 jacobian(i, j) = (temp_f(i) - f(i)) / step;
double Round(double value)
Round the double argument.
Matrix< double > jacobian
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double e
The value of .
MatchState
The possible states of a matching process.
The base class for all OPAL actions.
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
static Match * block
The block of match data.
int countFunctions() const
Return total number of functions.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
void getColNorm(Array1D< double > &) const
Return the original column norms of the matrix $A$.
void solveST(Vector< double > &V) const
Pre-multiply the vector $V$ by $S.transpose()^{-1}$.
int size() const
Get array size.
void print(const char *method, MatchState state)
Print the results of minimisation.
int countVariables() const
Get total number of variables.
Least-square solution of systems of linear equations.
void solveR(Vector< double > &X) const
Solution of $A*X = B$ in the least-squares sense.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
bool evaluate(const Vector< double > &x, Vector< double > &f)
Evaluate the matching functions.
LMDif()
Exemplar constructor.
Tps< T > sqrt(const Tps< T > &x)
Square root.
virtual void execute()
Execute the command.
virtual LMDif * clone(const std::string &name)
Make clone.
bool findJacobian(Vector< double > &X, Vector< double > &F)
T euclidean_norm(const Vector< T > &)
Euclidean norm.
T scaled_norm(const Array1D< T > D, const Vector< T > &V)
Euclidean norm of diagonal matrix D times vector V.
void lmpar(QRSolver &solver, const Array1D< double > &D, const Vector< double > &F, Vector< double > &P)
double getReal(const Attribute &attr)
Return real value.
void solveS(const Array1D< double > &D, double p, Vector< double > &X)
Solution of $A*X = B, D*X = 0$ in the least-squares sense.
void getVariables(Vector< double > &x) const
Get values of matching variables.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)