29 #ifndef LIBMV_NUMERIC_LEVENBERG_MARQUARDT_H
30 #define LIBMV_NUMERIC_LEVENBERG_MARQUARDT_H
40 template <
typename Function,
41 typename Jacobian = NumericJacobian<Function>,
42 typename Solver = Eigen::PartialPivLU<
43 Matrix<
typename Function::FMatrixType::RealScalar,
44 Function::XMatrixType::RowsAtCompileTime,
45 Function::XMatrixType::RowsAtCompileTime>>>
48 typedef typename Function::XMatrixType::RealScalar
Scalar;
49 typedef typename Function::FMatrixType
FVec;
51 typedef Matrix<
typename Function::FMatrixType::RealScalar,
52 Function::FMatrixType::RowsAtCompileTime,
53 Function::XMatrixType::RowsAtCompileTime>
55 typedef Matrix<
typename JMatrixType::RealScalar,
56 JMatrixType::ColsAtCompileTime,
57 JMatrixType::ColsAtCompileTime>
100 *
A = (*J).transpose() * (*J);
102 *
g = (*J).transpose() * *
error;
103 if (
g->array().abs().maxCoeff() <
params.gradient_threshold) {
105 }
else if (
error->norm() <
params.error_threshold) {
132 VLOG(3) <<
"iteration: " << i;
133 VLOG(3) <<
"||f(x)||: " << f_(
x).norm();
134 VLOG(3) <<
"max(g): " <<
g.array().abs().maxCoeff();
135 VLOG(3) <<
"u: " << u;
136 VLOG(3) <<
"v: " <<
v;
139 A + u * AMatrixType::Identity(J.cols(), J.cols());
140 Solver solver(A_augmented);
141 dx = solver.solve(
g);
142 bool solved = (A_augmented * dx).isApprox(
g);
144 LOG(ERROR) <<
"Failed to solve";
146 if (solved && dx.norm() <=
params.relative_step_threshold *
x.norm()) {
155 Scalar rho((
error.squaredNorm() - f_(x_new).squaredNorm()) /
162 u = u *
std::max(1 / 3., 1 - (tmp * tmp * tmp));
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
Status Update(const Parameters &x, const SolverParameters ¶ms, JMatrixType *J, AMatrixType *A, FVec *error, Parameters *g)
Function::FMatrixType FVec
Matrix< typename JMatrixType::RealScalar, JMatrixType::ColsAtCompileTime, JMatrixType::ColsAtCompileTime > AMatrixType
Function::XMatrixType::RealScalar Scalar
Function::XMatrixType Parameters
@ RELATIVE_STEP_SIZE_TOO_SMALL
LevenbergMarquardt(const Function &f)
Matrix< typename Function::FMatrixType::RealScalar, Function::FMatrixType::RowsAtCompileTime, Function::XMatrixType::RowsAtCompileTime > JMatrixType
Results minimize(const SolverParameters ¶ms, Parameters *x_and_min)
Results minimize(Parameters *x_and_min)
static void error(const char *str)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
Scalar gradient_magnitude
Scalar gradient_threshold
Scalar relative_step_threshold
Scalar initial_scale_factor