Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
positive_ordered_free.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_POSITIVE_ORDERED_FREE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_POSITIVE_ORDERED_FREE_HPP
3 
7 #include <cmath>
8 
9 namespace stan {
10 
11  namespace math {
12 
26  template <typename T>
27  Eigen::Matrix<T, Eigen::Dynamic, 1>
28  positive_ordered_free(const Eigen::Matrix<T, Eigen::Dynamic, 1>& y) {
29  using Eigen::Matrix;
30  using Eigen::Dynamic;
32 
33  typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
34 
35  stan::math::check_positive_ordered("stan::math::positive_ordered_free",
36  "Positive ordered variable",
37  y);
38 
39  size_type k = y.size();
40  Matrix<T, Dynamic, 1> x(k);
41  if (k == 0)
42  return x;
43  x[0] = log(y[0]);
44  for (size_type i = 1; i < k; ++i)
45  x[i] = log(y[i] - y[i-1]);
46  return x;
47  }
48 
49 
50 
51  }
52 
53 }
54 
55 #endif
Eigen::Matrix< T, Eigen::Dynamic, 1 > positive_ordered_free(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &y)
Return the vector of unconstrained scalars that transform to the specified positive ordered vector...
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
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
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
bool check_positive_ordered(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y)
Return true if the specified vector contains non-negative values and is sorted into strictly increasi...

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