3 #include "DefineOutputMacros.hpp" 9 namespace Implementation {
31 template<
typename Scalar,
typename OutputFunction>
209 template<
typename Scalar,
typename OutputFunction>
219 , output_function(output_function)
224 template<
typename Scalar,
typename OutputFunction>
248 template<
typename Scalar,
typename OutputFunction>
274 template<
typename Scalar,
typename OutputFunction>
280 template<
typename Scalar,
typename OutputFunction>
286 template<
typename Scalar,
typename OutputFunction>
294 p << YTv.head(
b), Scalar{1} /
gamma * STv.head(
b);
300 p = solve_triangular_system_and_check(
309 template<
typename Scalar,
typename OutputFunction>
315 template<
typename Scalar,
typename OutputFunction>
321 template<
typename Scalar,
typename OutputFunction>
327 template<
typename Scalar,
typename OutputFunction>
334 b = std::min(
m,
b + 1);
346 R.row(
b-1).head(
b-1).setZero();
347 R.col(
b-1).noalias() =
S.transpose() *
Y.col(
b-1);
353 L.row(
b-1).head(
b-1).noalias() =
Y.transpose().topLeftCorner(
b-1,
n) *
S.col(
b-1);
354 L.col(
b-1).setZero();
357 YTY.col(
b-1).noalias() =
Y.transpose() *
Y.col(
b-1);
358 YTY.row(
b-1).head(
b-1) =
YTY.col(
b-1).head(
b-1).eval();
361 D.col(
b-1).setZero();
362 D.row(
b-1).setZero();
363 D(
b - 1,
b - 1) =
R(
b - 1,
b - 1);
366 STS.col(
b-1).noalias() =
S.transpose() *
S.col(
b-1);
367 STS.row(
b-1).head(
b-1) =
STS.col(
b-1).head(
b-1).eval();
380 dD_sq.diagonal().array() = dD.diagonal().array().sqrt();
387 Eigen::LLT<Matrix<Scalar>> llt (to_factorize);
402 if (to_factorize.norm() != Scalar{0}) {
403 re = (to_factorize - JJT).norm() / to_factorize.norm();
405 else if (JJT.norm() != Scalar{0}) {
406 re = (to_factorize - JJT).norm() / JJT.norm();
412 "Relative error of Cholesky decomposition is " << re
413 <<
" and larger than " <<
epsilon);
419 "Relative error of Cholesky decomposition is " << re
420 <<
" and smaller or equal than " <<
epsilon);
433 LOW.topLeftCorner(
b,
b).diagonal() = dD_sq.diagonal();
434 LOW.bottomLeftCorner(
b,
b) = -LD_sqI;
435 LOW.bottomRightCorner(
b,
b) = J;
439 UPP.topLeftCorner(
b,
b).diagonal() = -dD_sq.diagonal();
440 UPP.topRightCorner(
b,
b) = D_sqILT;
441 UPP.bottomRightCorner(
b,
b) = JT;
445 W.topLeftCorner(
n,
b) =
Y;
446 W.topRightCorner(
n,
b) = 1.0 /
gamma *
S;
450 M_.topLeftCorner(
b,
b) = -
D;
451 M_.topRightCorner(
b,
b) =
L.transpose();
452 M_.bottomLeftCorner(
b,
b) =
L;
453 M_.bottomRightCorner(
b,
b) = 1.0 /
gamma *
STS;
463 M = Eigen::FullPivLU<Matrix<Scalar>>(M_).inverse();
468 re = (identity - should_be_identity).norm() / identity.norm();
473 "Relative error of matrix inversion is " << re
474 <<
" and larger than " <<
epsilon);
480 "Relative error of matrix inversion is " << re
481 <<
" and smaller or equal than " <<
epsilon);
487 template<
typename Scalar,
typename OutputFunction>
493 S.conservativeResize(Eigen::NoChange, b);
495 Y.conservativeResize(Eigen::NoChange, b);
497 R.conservativeResize(b, b);
499 L.conservativeResize(b, b);
501 D.conservativeResize(b, b);
503 YTY.conservativeResize(b, b);
505 STS.conservativeResize(b, b);
508 S.topLeftCorner(
n, b-1) =
S.topRightCorner(
n, b-1);
509 Y.topLeftCorner(
n, b-1) =
Y.topRightCorner(
n, b-1);
511 R.topLeftCorner(b-1, b-1) =
R.bottomRightCorner(b-1, b-1);
512 L.topLeftCorner(b-1, b-1) =
L.bottomRightCorner(b-1, b-1);
513 D.topLeftCorner(b-1, b-1) =
D.bottomRightCorner(b-1, b-1);
514 YTY.topLeftCorner(b-1, b-1) =
YTY.bottomRightCorner(b-1, b-1);
515 STS.topLeftCorner(b-1, b-1) =
STS.bottomRightCorner(b-1, b-1);
Matrix< Scalar > YTY
matrix storing
Definition: LBFGSStorage.hpp:190
Scalar gamma
current scaling of the inverse Hessian
Definition: LBFGSStorage.hpp:200
Matrix< Scalar > L
helper matrix
Definition: LBFGSStorage.hpp:186
OutputFunction & output_function
output function for status messages.
Definition: LBFGSStorage.hpp:206
Eigen::Index b
Current number of stored update pairs.
Definition: LBFGSStorage.hpp:172
Matrix< Scalar > S
matrix storing the last vectors
Definition: LBFGSStorage.hpp:180
Matrix< Scalar > R
helper matrix
Definition: LBFGSStorage.hpp:184
Matrix< Scalar > UPP
working matrix
Definition: LBFGSStorage.hpp:197
LBFGSStorage(Eigen::Index n, Eigen::Index m, Scalar epsilon, OutputFunction &output_function)
Construct a BFGS storage.
Definition: LBFGSStorage.hpp:210
void resize(Eigen::Index b)
Function that resizes the storage to b.
Definition: LBFGSStorage.hpp:488
Matrix< Scalar > LOW
working matrix
Definition: LBFGSStorage.hpp:195
Eigen::Index m
Maximal number of update pairs to store.
Definition: LBFGSStorage.hpp:170
Eigen::DiagonalMatrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > DiagonalMatrix
Diagonal matrix type used.
Definition: Types.hpp:33
Eigen::Index n
Dimensionality of the problem.
Definition: LBFGSStorage.hpp:168
Matrix< Scalar > STS
matrix storing
Definition: LBFGSStorage.hpp:192
Matrix< Scalar > calculate_B()
Calculate the Hessian matrix approximation .
Definition: LBFGSStorage.hpp:322
bool update(const Vector< Scalar > &s, const Vector< Scalar > &y, const Vector< Scalar > &g)
Update the (inverse) Hessian approximation.
Definition: LBFGSStorage.hpp:328
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Vector type used.
Definition: Types.hpp:15
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Matrix type used.
Definition: Types.hpp:24
Matrix< Scalar > W
working matrix
Definition: LBFGSStorage.hpp:175
Scalar calculate_vHv(const Vector< Scalar > &v)
Calculate normalized scalar product of vector with inverse Hessian approximation ...
Definition: LBFGSStorage.hpp:281
Scalar epsilon
numerical stability check epsilon
Definition: LBFGSStorage.hpp:203
Matrix< Scalar > Y
matrix storing the last vectors
Definition: LBFGSStorage.hpp:182
BFGS optimizations.
Definition: BFGS.hpp:24
Matrix< Scalar > M
working matrix
Definition: LBFGSStorage.hpp:177
L-BFGS storage.
Definition: LBFGSStorage.hpp:32
void reset()
Reset the (inverse) Hessian approximation to identity matrix.
Definition: LBFGSStorage.hpp:225
Vector< Scalar > calculate_Bv(const Vector< Scalar > &v, const Vector< Scalar > &STv, const Vector< Scalar > &YTv)
Calculate product of Hessian approximation with vector .
Definition: LBFGSStorage.hpp:287
Vector< Scalar > calculate_Hv(const Vector< Scalar > &v, const Vector< Scalar > &STv, const Vector< Scalar > &YTv)
Calculate product of inverse Hessian approximation with vector .
Definition: LBFGSStorage.hpp:249
Scalar calculate_vBv(const Vector< Scalar > &v)
Calculate normalized scalar product of vector with Hessian approximation .
Definition: LBFGSStorage.hpp:316
Matrix< Scalar > D
helper matrix
Definition: LBFGSStorage.hpp:188