Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
hessian.hpp
Go to the documentation of this file.
1 #ifndef __STAN__AGRAD__HESSIAN_HPP__
2 #define __STAN__AGRAD__HESSIAN_HPP__
3 
4 #include <vector>
5 
6 #include <stan/agrad/agrad.hpp>
7 #include <stan/agrad/fvar.hpp>
8 
10 
11 namespace stan {
12 
13  namespace agrad {
14 
15  // f: vector<T> -> T
16  // Hv = H(f(x)) * v; return f(x)
17 
18  template <class F>
19  double
20  hessian(const F& f,
21  const std::vector<double>& x,
22  const std::vector<double>& v,
23  std::vector<double>& Hv) {
24 
25  using stan::agrad::var;
26  using stan::agrad::fvar;
27 
28  std::vector<var> x_var(x.size());
29  for (int i = 0; i < x_var.size(); ++i)
30  x_var[i] = x[i];
31 
32  std::vector<fvar<var> > x_fvar(x.size());
33  for (int i = 0; i < x_fvar.size(); ++i)
34  x_fvar[i] = fvar<var>(x_var[i], v[i]);
35  fvar<var> y = f(x_fvar);
36  y.d_.grad(x_var,Hv);
37  return y.val_.val();
38  }
39 
40  }
41 }
42 
43 
44 #endif

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