1 #ifndef STAN_OPTIMIZATION_BFGS_UPDATE_HPP
2 #define STAN_OPTIMIZATION_BFGS_UPDATE_HPP
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
7 namespace optimization {
8 template<
typename Scalar = double,
9 int DimAtCompile = Eigen::Dynamic>
12 typedef Eigen::Matrix<Scalar, DimAtCompile, 1>
VectorT;
13 typedef Eigen::Matrix<Scalar, DimAtCompile, DimAtCompile>
HessianT;
26 inline Scalar
update(
const VectorT &yk,
const VectorT &sk,
28 Scalar rhok, skyk, B0fact;
34 Hupd.noalias() = HessianT::Identity(yk.size(), yk.size())
35 - rhok * sk * yk.transpose();
37 B0fact = yk.squaredNorm()/skyk;
38 _Hk.noalias() = ((1.0/B0fact)*Hupd)*Hupd.transpose();
41 _Hk = Hupd*_Hk*Hupd.transpose();
43 _Hk.noalias() += rhok*sk*sk.transpose();
56 pk.noalias() = -(_Hk*gk);
Probability, optimization and sampling library.
Eigen::Matrix< Scalar, DimAtCompile, DimAtCompile > HessianT
Eigen::Matrix< Scalar, DimAtCompile, 1 > VectorT
void search_direction(VectorT &pk, const VectorT &gk) const
Compute the search direction based on the current (inverse) Hessian approximation and given gradient...
Scalar update(const VectorT &yk, const VectorT &sk, bool reset=false)
Update the inverse Hessian approximation.