TR-mbed 1.0
Loading...
Searching...
No Matches
dogleg.h
Go to the documentation of this file.
1namespace Eigen {
2
3namespace internal {
4
5template <typename Scalar>
6void dogleg(
10 Scalar delta,
12{
13 using std::abs;
14 using std::sqrt;
15
16 typedef DenseIndex Index;
17
18 /* Local variables */
19 Index i, j;
20 Scalar sum, temp, alpha, bnorm;
21 Scalar gnorm, qnorm;
23
24 /* Function Body */
26 const Index n = qrfac.cols();
27 eigen_assert(n==qtb.size());
28 eigen_assert(n==x.size());
29 eigen_assert(n==diag.size());
31
32 /* first, calculate the gauss-newton direction. */
33 for (j = n-1; j >=0; --j) {
34 temp = qrfac(j,j);
35 if (temp == 0.) {
36 temp = epsmch * qrfac.col(j).head(j+1).maxCoeff();
37 if (temp == 0.)
38 temp = epsmch;
39 }
40 if (j==n-1)
41 x[j] = qtb[j] / temp;
42 else
43 x[j] = (qtb[j] - qrfac.row(j).tail(n-j-1).dot(x.tail(n-j-1))) / temp;
44 }
45
46 /* test whether the gauss-newton direction is acceptable. */
47 qnorm = diag.cwiseProduct(x).stableNorm();
48 if (qnorm <= delta)
49 return;
50
51 // TODO : this path is not tested by Eigen unit tests
52
53 /* the gauss-newton direction is not acceptable. */
54 /* next, calculate the scaled gradient direction. */
55
56 wa1.fill(0.);
57 for (j = 0; j < n; ++j) {
58 wa1.tail(n-j) += qrfac.row(j).tail(n-j) * qtb[j];
59 wa1[j] /= diag[j];
60 }
61
62 /* calculate the norm of the scaled gradient and test for */
63 /* the special case in which the scaled gradient is zero. */
64 gnorm = wa1.stableNorm();
65 sgnorm = 0.;
66 alpha = delta / qnorm;
67 if (gnorm == 0.)
68 goto algo_end;
69
70 /* calculate the point along the scaled gradient */
71 /* at which the quadratic is minimized. */
72 wa1.array() /= (diag*gnorm).array();
73 // TODO : once unit tests cover this part,:
74 // wa2 = qrfac.template triangularView<Upper>() * wa1;
75 for (j = 0; j < n; ++j) {
76 sum = 0.;
77 for (i = j; i < n; ++i) {
78 sum += qrfac(j,i) * wa1[i];
79 }
80 wa2[j] = sum;
81 }
82 temp = wa2.stableNorm();
83 sgnorm = gnorm / temp / temp;
84
85 /* test whether the scaled gradient direction is acceptable. */
86 alpha = 0.;
87 if (sgnorm >= delta)
88 goto algo_end;
89
90 /* the scaled gradient direction is not acceptable. */
91 /* finally, calculate the point along the dogleg */
92 /* at which the quadratic is minimized. */
93 bnorm = qtb.stableNorm();
94 temp = bnorm / gnorm * (bnorm / qnorm) * (sgnorm / delta);
95 temp = temp - delta / qnorm * numext::abs2(sgnorm / delta) + sqrt(numext::abs2(temp - delta / qnorm) + (1.-numext::abs2(delta / qnorm)) * (1.-numext::abs2(sgnorm / delta)));
96 alpha = delta / qnorm * (1. - numext::abs2(sgnorm / delta)) / temp;
98
99 /* form appropriate convex combination of the gauss-newton */
100 /* direction and the scaled gradient direction. */
101 temp = (1.-alpha) * (std::min)(sgnorm,delta);
102 x = temp * wa1 + alpha * x;
103}
104
105} // end namespace internal
106
107} // end namespace Eigen
int n
Definition BiCGSTAB_simple.cpp:1
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition Macros.h:1037
SCALAR Scalar
Definition bench_gemm.cpp:46
Definition EmulateArray.h:21
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition gnuplot_common_settings.hh:12
RealScalar alpha
Definition level1_cplx_impl.h:147
void dogleg(const Matrix< Scalar, Dynamic, Dynamic > &qrfac, const Matrix< Scalar, Dynamic, 1 > &diag, const Matrix< Scalar, Dynamic, 1 > &qtb, Scalar delta, Matrix< Scalar, Dynamic, 1 > &x)
Definition dogleg.h:6
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition MathFunctions.h:1292
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition Meta.h:66
Definition BandTriangularSolver.h:13
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233
Definition ForwardDeclarations.h:17
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2