| 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
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
10 namespace math {
11
21 template <typename T>
22 Eigen::Matrix<T, Eigen::Dynamic, 1>
23 ordered_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) {
24 using Eigen::Matrix;
25 using Eigen::Dynamic;
26 using stan::math::index_type;
27 using std::exp;
28
29 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
30
31 size_type k = x.size();
32 Matrix<T, Dynamic, 1> y(k);
33 if (k == 0)
34 return y;
35 y[0] = x[0];
36 for (size_type i = 1; i < k; ++i)
37 y[i] = y[i-1] + exp(x[i]);
38 return y;
39 }
40
53 template <typename T>
54 inline
55 Eigen::Matrix<T, Eigen::Dynamic, 1>
56 ordered_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x, T& lp) {
57 using Eigen::Matrix;
58 using Eigen::Dynamic;
59 using stan::math::index_type;
60
61 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
62
63 for (size_type i = 1; i < x.size(); ++i)
64 lp += x(i);
65 return ordered_constrain(x);
66 }
67
68 }
69
70 }
71
72 #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:23
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:19
index_type.hpp
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
Eigen.hpp

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