| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ordered_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_ORDERED_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_ORDERED_CONSTRAIN_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/meta/index_type.hpp>
6 #include <cmath>
7
8 namespace stan {
9 namespace math {
10
20 template <typename T>
21 Eigen::Matrix<T, Eigen::Dynamic, 1>
22 ordered_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) {
23 using Eigen::Matrix;
24 using Eigen::Dynamic;
25 using std::exp;
26
27 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
28
29 size_type k = x.size();
30 Matrix<T, Dynamic, 1> y(k);
31 if (k == 0)
32 return y;
33 y[0] = x[0];
34 for (size_type i = 1; i < k; ++i)
35 y[i] = y[i-1] + exp(x[i]);
36 return y;
37 }
38
51 template <typename T>
52 inline
53 Eigen::Matrix<T, Eigen::Dynamic, 1>
54 ordered_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x, T& lp) {
55 using Eigen::Matrix;
56 using Eigen::Dynamic;
57
58 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
59
60 for (size_type i = 1; i < x.size(); ++i)
61 lp += x(i);
62 return ordered_constrain(x);
63 }
64
65 }
66
67 }
68
69 #endif
stan::math::ordered_constrain
Eigen::Matrix< T, Eigen::Dynamic, 1 > ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing ordered vector derived from the specified free vector.
Definition: ordered_constrain.hpp:22
stan
Definition: log_sum_exp.hpp:8
stan::math::size_type
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:13
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
index_type.hpp
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
Eigen.hpp

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