Stan Math Library  2.20.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> positive_ordered_free(
26  const Eigen::Matrix<T, Eigen::Dynamic, 1>& y) {
27  using Eigen::Dynamic;
28  using Eigen::Matrix;
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", y);
34  size_type k = y.size();
35  Matrix<T, Dynamic, 1> x(k);
36  if (k == 0)
37  return x;
38  x[0] = log(y[0]);
39  for (size_type i = 1; i < k; ++i)
40  x[i] = log(y[i] - y[i - 1]);
41  return x;
42 }
43 } // namespace math
44 } // namespace stan
45 #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:12
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:11
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18

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