| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 namespace math {
10
11 template <typename T, typename F>
12 void
13 jacobian(const F& f,
14 const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
15 Eigen::Matrix<T, Eigen::Dynamic, 1>& fx,
16 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& J) {
17 using Eigen::Matrix;
18 using Eigen::Dynamic;
19 Matrix<fvar<T>, Dynamic, 1> x_fvar(x.size());
20 for (int i = 0; i < x.size(); ++i) {
21 for (int k = 0; k < x.size(); ++k)
22 x_fvar(k) = fvar<T>(x(k), i == k);
23 Matrix<fvar<T>, Dynamic, 1> fx_fvar
24 = f(x_fvar);
25 if (i == 0) {
26 J.resize(fx_fvar.size(), x.size());
27 fx.resize(fx_fvar.size());
28 for (int k = 0; k < fx_fvar.size(); ++k)
29 fx(k) = fx_fvar(k).val_;
30 }
31 for (int k = 0; k < fx_fvar.size(); ++k) {
32 J(k, i) = fx_fvar(k).d_;
33 }
34 }
35 }
36
37 }
38 }
39 #endif
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:14
stan
Definition: log_sum_exp.hpp:8
stan::math::jacobian
void jacobian(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, Eigen::Matrix< T, Eigen::Dynamic, 1 > &fx, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &J)
Definition: jacobian.hpp:13
stan::math::fvar::val_
T val_
Definition: fvar.hpp:13
Eigen.hpp
stan::math::fvar
Definition: fvar.hpp:12

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