| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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 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
core.hpp
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan::math::gradient_dot_vector
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)
Definition: gradient_dot_vector.hpp:19
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::fvar::val_
T val_
Definition: fvar.hpp:14
Eigen.hpp
stan::math::fvar
Definition: fvar.hpp:13

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