Skip to content

Commit eaf2e44

Browse files
Merge pull request #66 from prime-slam/feature/LM-terminal
update to LM update fidelity model and terminal condition, now to be …
2 parents d2a35d3 + 05d6be9 commit eaf2e44

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

python_examples/FGraph_M3500.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def print_2d_graph(graph):
9797
print_2d_graph(graph)
9898
print('current initial chi2 = ', graph.chi2() )
9999
start = time.time()
100-
graph.solve(mrob.LM, 50)
100+
graph.solve(mrob.LM, 50, verbose=True)
101101
end = time.time()
102102
print('\nLM chi2 = ', graph.chi2() , ', total time on calculation [s] = ', 1e0*(end - start))
103103
print('solution drawn')

python_examples/FGraph_sphere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def plot_from_vertex(vertex):
161161
# uncomment for visualization
162162
#print_3d_graph(graph)
163163
start = time.time()
164-
graph.solve(mrob.LM,20)
164+
graph.solve(mrob.LM,20, verbose=True)
165165
end = time.time()
166166
print(', chi2 = ', graph.chi2() , ', time on calculation [s] = ', 1e0*(end - start))
167167
# uncomment for visualization

src/FGraph/factor_graph_solve.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ FGraphSolve::~FGraphSolve() = default;
4949

5050

5151
uint_t FGraphSolve::solve(optimMethod method, uint_t maxIters,
52-
matData_t lambda, matData_t solutionTolerance, bool verbose)
52+
matData_t lambdaParam, matData_t solutionTolerance, bool verbose)
5353
{
5454
/**
5555
* 2800 2D nodes on M3500
@@ -60,7 +60,7 @@ uint_t FGraphSolve::solve(optimMethod method, uint_t maxIters,
6060
* 1.3959 % update values,
6161
*
6262
*/
63-
lambda_ = lambda;
63+
lambda_ = lambdaParam;
6464
solutionTolerance_ = solutionTolerance;
6565
verbose_ = verbose;
6666
time_profiles_.reset();
@@ -168,7 +168,7 @@ uint_t FGraphSolve::optimize_levenberg_marquardt(uint_t maxIters)
168168
// LM trust region as described in Bertsekas (p.105)
169169

170170
// 0) parameter initialization
171-
lambda_ = 1e-5;
171+
//lambda_ = 1e-5;
172172
// sigma reference to the fidelity of the model at the proposed solution \in [0,1]
173173
matData_t sigma1(0.25), sigma2(0.8);// 0 < sigma1 < sigma2 < 1
174174
matData_t beta1(2.0), beta2(0.25); // lambda updates multiplier values, beta1 > 1 > beta2 >0
@@ -206,7 +206,7 @@ uint_t FGraphSolve::optimize_levenberg_marquardt(uint_t maxIters)
206206
}
207207

208208
// 1.3) check for convergence
209-
if (deltaChi2 < solutionTolerance_)
209+
if (deltaChi2/currentChi2 < solutionTolerance_) //in ratio
210210
{
211211
if (verbose_)
212212
std::cout << "\nFGraphSolve::optimize_levenberg_marquardt: Converged Successfully" << std::endl;
@@ -218,9 +218,14 @@ uint_t FGraphSolve::optimize_levenberg_marquardt(uint_t maxIters)
218218
// f = chi2(x_k) - chi2(x_k + dx)
219219
// chi2(x_k) - m_k(dx)
220220
// where m_k is the quadratized model = ||r||^2 - dx'*J' r + 0.5 dx'(J'J + lambda*D2)dx
221-
modelFidelity = deltaChi2 / (dx_.dot(b_) - 0.5*dx_.dot(L_* dx_));
221+
//modelFidelity = deltaChi2 / (dx_.dot(b_) - 0.5*dx_.dot(L_* dx_));
222+
// Update, according to H.B. Nielson, Damping Parameter In Marquardt’s Method, Technical Report IMM-REP-1999-05, Dept. of Mathematical Modeling, Technical University Denmark
223+
// (J'J ) dx = J'r , so this is substituted.
224+
modelFidelity = 2.0 * deltaChi2 / (dx_.dot(b_) - dx_.dot(lambda_ * diagL_* dx_));
222225
if (verbose_)
226+
{
223227
std::cout << "model fidelity = " << modelFidelity << " and m_k = " << dx_.dot(b_) << std::endl;
228+
}
224229

225230
//3) update lambda
226231
if (modelFidelity < sigma1)
@@ -613,4 +618,4 @@ std::vector<bool> FGraphSolve::get_factors_robust_mask()
613618
}
614619

615620
return results;
616-
}
621+
}

src/pybind/FGraphPy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ void init_FGraph(py::module &m)
376376
"Options:\n method = mrob.GN (Gauss Newton). It carries out a SINGLE iteration.\n"
377377
" = mrob.LM (Levenberg-Marquard), default option,it has several parameters:\n"
378378
" - marIters = 20 (by default). Only for LM\n"
379-
" - lambda = 1-6, LM paramter for the size of the update\n"
379+
" - lambda = 1-5, LM paramter for the size of the update\n"
380380
" - solutionTolerance: convergence criteria\n"
381381
" - verbose: by default false. If you want output on optim, set to true.",
382382
py::arg("method") = FGraphSolve::optimMethod::LM,
383383
py::arg("maxIters") = 20,
384-
py::arg("lambda") = 1e-6,
385-
py::arg("solutionTolerance") = 1e-2,
384+
py::arg("lambdaParam") = 1e-5,
385+
py::arg("solutionTolerance") = 1e-6,
386386
py::arg("verbose") = false)
387387
.def("chi2", &FGraphSolve::chi2,
388388
"Calculated the chi2 of the problem.\n"

0 commit comments

Comments
 (0)