Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
gradient_dot_vector.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_GRADIENT_DOT_VECTOR_HPP
2 #define STAN_MATH_MIX_MAT_FUNCTOR_GRADIENT_DOT_VECTOR_HPP
3 
4 #include <stan/math/fwd/core.hpp>
6 #include <stan/math/rev/core.hpp>
7 #include <vector>
8 
9 namespace stan {
10 
11  namespace math {
12 
13  using Eigen::Dynamic;
14 
15  // aka directional derivative (not length normalized)
16  // T2 must be assignable to T1
17  template <typename T1, typename T2, typename F>
18  void
19  gradient_dot_vector(const F& f,
20  const Eigen::Matrix<T1, Dynamic, 1>& x,
21  const Eigen::Matrix<T2, Dynamic, 1>& v,
22  T1& fx,
23  T1& grad_fx_dot_v) {
24  using stan::math::fvar;
25  using stan::math::var;
26  using Eigen::Matrix;
27  Matrix<fvar<T1>, Dynamic, 1> x_fvar(x.size());
28  for (int i = 0; i < x.size(); ++i)
29  x_fvar(i) = fvar<T1>(x(i), v(i));
30  fvar<T1> fx_fvar = f(x_fvar);
31  fx = fx_fvar.val_;
32  grad_fx_dot_v = fx_fvar.d_;
33  }
34 
35  } // namespace math
36 } // namespace stan
37 #endif
void gradient_dot_vector(const F &f, const Eigen::Matrix< T1, Dynamic, 1 > &x, const Eigen::Matrix< T2, Dynamic, 1 > &v, T1 &fx, T1 &grad_fx_dot_v)
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32

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