Stan Math Library: stan/math/mix/mat/functor/gradient_dot_vector.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <stan/math/rev/core.hpp>
7 #include <vector>
8
9 namespace stan {
10
11 namespace math {
12
13 // aka directional derivative (not length normalized)
14 // T2 must be assignable to T1
15 template <typename T1, typename T2, typename F>
16 void
17 gradient_dot_vector(const F& f,
18 const Eigen::Matrix<T1, Eigen::Dynamic, 1>& x,
19 const Eigen::Matrix<T2, Eigen::Dynamic, 1>& v,
20 T1& fx,
21 T1& grad_fx_dot_v) {
22 using stan::math::fvar;
23 using stan::math::var;
24 using Eigen::Matrix;
25 Matrix<fvar<T1>, Eigen::Dynamic, 1> x_fvar(x.size());
26 for (int i = 0; i < x.size(); ++i)
27 x_fvar(i) = fvar<T1>(x(i), v(i));
28 fvar<T1> fx_fvar = f(x_fvar);
29 fx = fx_fvar.val_;
30 grad_fx_dot_v = fx_fvar.d_;
31 }
32
33 } // namespace math
34 } // namespace stan
35 #endif
core.hpp
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan
Definition: log_sum_exp.hpp:8
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
stan::math::fvar::val_
T val_
Definition: fvar.hpp:14
Eigen.hpp
stan::math::gradient_dot_vector
void gradient_dot_vector(const F &f, const Eigen::Matrix< T1, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< T2, Eigen::Dynamic, 1 > &v, T1 &fx, T1 &grad_fx_dot_v)
Definition: gradient_dot_vector.hpp:17
stan::math::fvar
Definition: fvar.hpp:13

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