DoglegOptimizerImpl.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
18 #include <cmath>
19 #include <cassert>
21 
22 using namespace std;
23 
24 namespace gtsam {
25 /* ************************************************************************* */
26 VectorValues DoglegOptimizerImpl::ComputeDoglegPoint(
27  double delta, const VectorValues& dx_u, const VectorValues& dx_n, const bool verbose) {
28 
29  // Get magnitude of each update and find out which segment delta falls in
30  assert(delta >= 0.0);
31  double deltaSq = delta*delta;
32  double x_u_norm_sq = dx_u.squaredNorm();
33  double x_n_norm_sq = dx_n.squaredNorm();
34  if(verbose) cout << "Steepest descent magnitude " << std::sqrt(x_u_norm_sq) << ", Newton's method magnitude " << std::sqrt(x_n_norm_sq) << endl;
35  if(deltaSq < x_u_norm_sq) {
36  // Trust region is smaller than steepest descent update
37  VectorValues x_d = std::sqrt(deltaSq / x_u_norm_sq) * dx_u;
38  if(verbose) cout << "In steepest descent region with fraction " << std::sqrt(deltaSq / x_u_norm_sq) << " of steepest descent magnitude" << endl;
39  return x_d;
40  } else if(deltaSq < x_n_norm_sq) {
41  // Trust region boundary is between steepest descent point and Newton's method point
42  return ComputeBlend(delta, dx_u, dx_n, verbose);
43  } else {
44  assert(deltaSq >= x_n_norm_sq);
45  if(verbose) cout << "In pure Newton's method region" << endl;
46  // Trust region is larger than Newton's method point
47  return dx_n;
48  }
49 }
50 
51 /* ************************************************************************* */
52 VectorValues DoglegOptimizerImpl::ComputeBlend(double delta, const VectorValues& x_u, const VectorValues& x_n, const bool verbose) {
53 
54  // See doc/trustregion.lyx or doc/trustregion.pdf
55 
56  // Compute inner products
57  const double un = dot(x_u, x_n);
58  const double uu = dot(x_u, x_u);
59  const double nn = dot(x_n, x_n);
60 
61  // Compute quadratic formula terms
62  const double a = uu - 2.*un + nn;
63  const double b = 2. * (un - uu);
64  const double c = uu - delta*delta;
65  double sqrt_b_m4ac = std::sqrt(b*b - 4*a*c);
66 
67  // Compute blending parameter
68  double tau1 = (-b + sqrt_b_m4ac) / (2.*a);
69  double tau2 = (-b - sqrt_b_m4ac) / (2.*a);
70 
71  // Determine correct solution accounting for machine precision
72  double tau;
73  const double eps = std::numeric_limits<double>::epsilon();
74  if(-eps <= tau1 && tau1 <= 1.0 + eps) {
75  assert(!(-eps <= tau2 && tau2 <= 1.0 + eps));
76  tau = tau1;
77  } else {
78  assert(-eps <= tau2 && tau2 <= 1.0 + eps);
79  tau = tau2;
80  }
81 
82  // Compute blended point
83  if(verbose) cout << "In blend region with fraction " << tau << " of Newton's method point" << endl;
84  VectorValues blend = (1. - tau) * x_u;
85  blend += tau * x_n;
86  return blend;
87 }
88 
89 }
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
b
Scalar * b
Definition: benchVecAdd.cpp:17
dot
Scalar EIGEN_BLAS_FUNC() dot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_real_impl.h:49
epsilon
static double epsilon
Definition: testRot3.cpp:37
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::VectorValues::squaredNorm
double squaredNorm() const
Definition: VectorValues.cpp:260
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition: SFMdata.h:40
std
Definition: BFloat16.h:88
DoglegOptimizerImpl.h
Nonlinear factor graph optimizer using Powell's Dogleg algorithm (detail implementation)
nn
idx_t * nn
Definition: include/metis.h:207
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:29