Stan Math Library  2.14.0
reverse mode automatic differentiation
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  namespace math {
24  template <typename T>
25  Eigen::Matrix<T, Eigen::Dynamic, 1>
26  positive_ordered_free(const Eigen::Matrix<T, Eigen::Dynamic, 1>& y) {
27  using Eigen::Matrix;
28  using Eigen::Dynamic;
29  using std::log;
30  typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
31 
32  check_positive_ordered("stan::math::positive_ordered_free",
33  "Positive ordered variable",
34  y);
35  size_type k = y.size();
36  Matrix<T, Dynamic, 1> x(k);
37  if (k == 0)
38  return x;
39  x[0] = log(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 > 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:14
void check_positive_ordered(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y)
Check if the specified vector contains non-negative values and is sorted into strictly increasing ord...
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:18

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