Stan  2.10.0
probability, sampling & optimization
bfgs_update.hpp
Go to the documentation of this file.
1 #ifndef STAN_OPTIMIZATION_BFGS_UPDATE_HPP
2 #define STAN_OPTIMIZATION_BFGS_UPDATE_HPP
3 
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 
6 namespace stan {
7  namespace optimization {
8  template<typename Scalar = double,
9  int DimAtCompile = Eigen::Dynamic>
11  public:
12  typedef Eigen::Matrix<Scalar, DimAtCompile, 1> VectorT;
13  typedef Eigen::Matrix<Scalar, DimAtCompile, DimAtCompile> HessianT;
14 
26  inline Scalar update(const VectorT &yk, const VectorT &sk,
27  bool reset = false) {
28  Scalar rhok, skyk, B0fact;
29  HessianT Hupd;
30 
31  skyk = yk.dot(sk);
32  rhok = 1.0/skyk;
33 
34  Hupd.noalias() = HessianT::Identity(yk.size(), yk.size())
35  - rhok * sk * yk.transpose();
36  if (reset) {
37  B0fact = yk.squaredNorm()/skyk;
38  _Hk.noalias() = ((1.0/B0fact)*Hupd)*Hupd.transpose();
39  } else {
40  B0fact = 1.0;
41  _Hk = Hupd*_Hk*Hupd.transpose();
42  }
43  _Hk.noalias() += rhok*sk*sk.transpose();
44  return B0fact;
45  }
46 
55  inline void search_direction(VectorT &pk, const VectorT &gk) const {
56  pk.noalias() = -(_Hk*gk);
57  }
58 
59  private:
60  HessianT _Hk;
61  };
62  }
63 }
64 
65 #endif
Probability, optimization and sampling library.
Eigen::Matrix< Scalar, DimAtCompile, DimAtCompile > HessianT
Definition: bfgs_update.hpp:13
Eigen::Matrix< Scalar, DimAtCompile, 1 > VectorT
Definition: bfgs_update.hpp:12
void search_direction(VectorT &pk, const VectorT &gk) const
Compute the search direction based on the current (inverse) Hessian approximation and given gradient...
Definition: bfgs_update.hpp:55
Scalar update(const VectorT &yk, const VectorT &sk, bool reset=false)
Update the inverse Hessian approximation.
Definition: bfgs_update.hpp:26

     [ Stan Home Page ] © 2011–2016, Stan Development Team.