Skip to content

Commit

Permalink
return approximate Hessian and inverse Hessian
Browse files Browse the repository at this point in the history
  • Loading branch information
yixuan committed Dec 28, 2024
1 parent ca3efce commit f800f18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/example-rosenbrock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ int main()
std::cout << "f(x) = " << fx << std::endl;
std::cout << "grad = " << solver.final_grad().transpose() << std::endl;
std::cout << "||grad|| = " << solver.final_grad_norm() << std::endl;
std::cout << "approx_hess = \n" << solver.final_approx_hessian() << std::endl;
std::cout << "approx_inv_hess = \n" << solver.final_approx_inverse_hessian() << std::endl;

return 0;
}
12 changes: 11 additions & 1 deletion include/LBFGS.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2023 Yixuan Qiu <[email protected]>
// Copyright (C) 2016-2024 Yixuan Qiu <[email protected]>
// Under MIT license

#ifndef LBFGSPP_LBFGS_H
Expand Down Expand Up @@ -185,6 +185,16 @@ class LBFGSSolver
/// Returning the Euclidean norm of the final gradient.
///
Scalar final_grad_norm() const { return m_gnorm; }

///
/// Returning the approximate Hessian matrix on the last iterate.
///
Matrix final_approx_hessian() const { return m_bfgs.get_Bmat(); }

///
/// Returning the approximate inverse Hessian matrix on the last iterate.
///
Matrix final_approx_inverse_hessian() const { return m_bfgs.get_Hmat(); }
};

} // namespace LBFGSpp
Expand Down

0 comments on commit f800f18

Please sign in to comment.