| 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
jacobian.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUNCTOR_JACOBIAN_HPP
2 #define STAN_MATH_FWD_MAT_FUNCTOR_JACOBIAN_HPP
3
4 #include <stan/math/fwd/core.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <vector>
7
8 namespace stan {
9
10 namespace math {
11
12 using Eigen::Dynamic;
13
14 template <typename T, typename F>
15 void
16 jacobian(const F& f,
17 const Eigen::Matrix<T, Dynamic, 1>& x,
18 Eigen::Matrix<T, Dynamic, 1>& fx,
19 Eigen::Matrix<T, Dynamic, Dynamic>& J) {
20 using Eigen::Matrix;
21 using stan::math::fvar;
22 Matrix<fvar<T>, Dynamic, 1> x_fvar(x.size());
23 for (int i = 0; i < x.size(); ++i) {
24 for (int k = 0; k < x.size(); ++k)
25 x_fvar(k) = fvar<T>(x(k), i == k);
26 Matrix<fvar<T>, Dynamic, 1> fx_fvar
27 = f(x_fvar);
28 if (i == 0) {
29 J.resize(x.size(), fx_fvar.size());
30 fx.resize(fx_fvar.size());
31 for (int k = 0; k < fx_fvar.size(); ++k)
32 fx(k) = fx_fvar(k).val_;
33 }
34 for (int k = 0; k < fx_fvar.size(); ++k) {
35 J(i, k) = fx_fvar(k).d_;
36 }
37 }
38 }
39
40 } // namespace math
41 } // namespace stan
42 #endif
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan::math::fvar::val_
T val_
Definition: fvar.hpp:14
Eigen.hpp
stan::math::jacobian
void jacobian(const F &f, const Eigen::Matrix< T, Dynamic, 1 > &x, Eigen::Matrix< T, Dynamic, 1 > &fx, Eigen::Matrix< T, Dynamic, Dynamic > &J)
Definition: jacobian.hpp:16
stan::math::fvar
Definition: fvar.hpp:13

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