Stan Math Library: stan/math/prim/mat/fun/positive_ordered_constrain.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

positive_ordered_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_POSITIVE_ORDERED_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_POSITIVE_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 positive_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 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
29
30 size_type k = x.size();
31 Matrix<T, Dynamic, 1> y(k);
32 if (k == 0)
33 return y;
34 y[0] = exp(x[0]);
35 for (size_type i = 1; i < k; ++i)
36 y[i] = y[i-1] + exp(x[i]);
37 return y;
38 }
39
52 template <typename T>
53 inline
54 Eigen::Matrix<T, Eigen::Dynamic, 1>
55 positive_ordered_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
56 T& lp) {
57 using Eigen::Matrix;
58 using Eigen::Dynamic;
59 using stan::math::index_type;
60 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
61
62 for (size_type i = 0; i < x.size(); ++i)
63 lp += x(i);
64 return positive_ordered_constrain(x);
65 }
66
67 }
68
69 }
70
71 #endif
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:19
stan::math::positive_ordered_constrain
Eigen::Matrix< T, Eigen::Dynamic, 1 > positive_ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing positive ordered vector derived from the specified free vector.
Definition: positive_ordered_constrain.hpp:23
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.