All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
ordered_constrain.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_ORDERED_CONSTRAIN_HPP
#define STAN_MATH_PRIM_MAT_FUN_ORDERED_CONSTRAIN_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/index_type.hpp>
#include <cmath>
namespace stan {
namespace math {
template <typename T>
Eigen::Matrix<T, Eigen::Dynamic, 1>
ordered_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) {
using Eigen::Matrix;
using Eigen::Dynamic;
using stan::math::index_type;
using std::exp;
typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
size_type k = x.size();
Matrix<T, Dynamic, 1> y(k);
if (k == 0)
return y;
y[0] = x[0];
for (size_type i = 1; i < k; ++i)
y[i] = y[i-1] + exp(x[i]);
return y;
}
template <typename T>
inline
Eigen::Matrix<T, Eigen::Dynamic, 1>
ordered_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x, T& lp) {
using Eigen::Matrix;
using Eigen::Dynamic;
using stan::math::index_type;
typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
for (size_type i = 1; i < x.size(); ++i)
lp += x(i);
return ordered_constrain(x);
}
}
}
#endif
stan::math::ordered_constrain
Eigen::Matrix< T, Eigen::Dynamic, 1 > ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing ordered vector derived from the specified free vector.
Definition: ordered_constrain.hpp:23
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
index_type.hpp
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
Eigen.hpp

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