Stan Math Library  2.11.0
reverse mode automatic differentiation
ordered_free.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_ORDERED_FREE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_ORDERED_FREE_HPP
3 
7 #include <cmath>
8 
9 namespace stan {
10  namespace math {
24  template <typename T>
25  Eigen::Matrix<T, Eigen::Dynamic, 1>
26  ordered_free(const Eigen::Matrix<T, Eigen::Dynamic, 1>& y) {
27  stan::math::check_ordered("stan::math::ordered_free",
28  "Ordered variable", y);
29  using Eigen::Matrix;
30  using Eigen::Dynamic;
32  using std::log;
33  typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
34 
35  size_type k = y.size();
36  Matrix<T, Dynamic, 1> x(k);
37  if (k == 0)
38  return x;
39  x[0] = y[0];
40  for (size_type i = 1; i < k; ++i)
41  x[i] = log(y[i] - y[i-1]);
42  return x;
43  }
44  }
45 }
46 #endif
Eigen::Matrix< T, Eigen::Dynamic, 1 > 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_ordered(const char *function, const char *name, const std::vector< T_y > &y)
Return true if the specified vector is sorted into strictly increasing order.

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