1 #ifndef __STAN__IO__WRITER_HPP__
2 #define __STAN__IO__WRITER_HPP__
25 std::vector<T> data_r_;
26 std::vector<int> data_i_;
29 typedef Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>
matrix_t;
30 typedef Eigen::Matrix<T,Eigen::Dynamic,1>
vector_t;
114 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is negative"));
115 data_r_.push_back(
log(y));
131 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is lower than the lower bound"));
132 data_r_.push_back(
log(y - lb));
147 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is higher than the lower bound"));
148 data_r_.push_back(
log(ub - y));
164 if (y < lb || y > ub)
165 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is not between the lower and upper bounds"));
180 if (y > 1.0 || y < -1.0)
181 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is not between -1.0 and 1.0"));
182 data_r_.push_back(
atanh(y));
197 if (y > 1.0 || y < 0.0)
198 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is not between 0.0 and 1.0"));
218 if (y.size() == 0)
return;
220 data_r_.push_back(y[0]);
222 data_r_.push_back(
log(y[i] - y[i-1]));
242 if (y.size() == 0)
return;
244 data_r_.push_back(
log(y[0]));
246 data_r_.push_back(
log(y[i] - y[i-1]));
258 data_r_.push_back(y[i]);
268 data_r_.push_back(y[i]);
279 data_r_.push_back(y(i,j));
283 for (
int i = 0; i < y.size(); ++i)
287 for (
int i = 0; i < y.size(); ++i)
291 for (
int i = 0; i < y.rows(); ++i)
292 for (
int j = 0; j < y.cols(); ++j)
297 for (
int i = 0; i < y.size(); ++i)
301 for (
int i = 0; i < y.size(); ++i)
305 for (
int i = 0; i < y.rows(); ++i)
306 for (
int j = 0; j < y.cols(); ++j)
312 for (
int i = 0; i < y.size(); ++i)
316 for (
int i = 0; i < y.size(); ++i)
320 for (
int i = 0; i < y.rows(); ++i)
321 for (
int j = 0; j < y.cols(); ++j)
345 double log_y_k =
log(y[k_minus_1]);
347 data_r_.push_back(
log(y[i]) - log_y_k);
369 size_t k_choose_2 = (k * (k-1)) / 2;
374 BOOST_THROW_EXCEPTION(std::runtime_error (
"y cannot be factorized by factor_cov_matrix"));
375 for (
size_t i = 0; i < k; ++i) {
378 BOOST_THROW_EXCEPTION(std::runtime_error (
"sds on log scale are unconstrained"));
380 for (
size_t i = 0; i < k_choose_2; ++i)
381 data_r_.push_back(cpcs[i]);
397 if (k == 0 || y.cols() != k)
398 BOOST_THROW_EXCEPTION(
399 std::runtime_error (
"y must have elements and y must be a square matrix"));
405 BOOST_THROW_EXCEPTION(std::runtime_error (
"factor_cov_matrix failed"));
407 data_r_.push_back(cpcs[i]);
409 data_r_.push_back(sds[i]);
internal::traits< Derived >::Index size_type
A stream-based writer for integer, scalar, vector, matrix and array data types, which transforms from...
void corr_unconstrain(T &y)
Write the unconstrained value corresponding to the specified correlation-constrained variable.
const double CONSTRAINT_TOLERANCE
This is the tolerance for checking arithmetic bounds in rank and in simplexes.
void row_vector_lub_unconstrain(double lb, double ub, row_vector_t &y)
void scalar_pos_unconstrain(T &y)
Write the unconstrained value corresponding to the specified positive-constrained scalar.
void matrix_ub_unconstrain(double ub, matrix_t &y)
void matrix_lub_unconstrain(double lb, double ub, matrix_t &y)
void matrix_unconstrain(const matrix_t &y)
Write the specified unconstrained matrix.
void scalar_unconstrain(T &y)
Write the unconstrained value corresponding to the specified scalar.
void row_vector_lb_unconstrain(double lb, row_vector_t &y)
void vector_lub_unconstrain(double lb, double ub, vector_t &y)
void cov_matrix_unconstrain(matrix_t &y)
Writes the unconstrained covariance matrix corresponding to the specified constrained correlation mat...
void prob_unconstrain(T &y)
Write the unconstrained value corresponding to the specified probability value.
void vector_ub_unconstrain(double ub, vector_t &y)
Eigen::Matrix< T, Eigen::Dynamic, 1 > vector_t
Eigen::Matrix< T, 1, Eigen::Dynamic > row_vector_t
void integer(int n)
Write the specified integer to the sequence of integer values.
void vector_unconstrain(const vector_t &y)
Write the specified unconstrained vector.
std::vector< int > & data_i()
Return a reference to the underlying vector of integer values that have been written.
void matrix_lb_unconstrain(double lb, matrix_t &y)
void scalar_ub_unconstrain(double ub, T &y)
Write the unconstrained value corresponding to the specified lower-bounded value.
writer(std::vector< T > &data_r, std::vector< int > &data_i)
Construct a writer that writes to the specified scalar and integer vectors.
void scalar_lb_unconstrain(double lb, T &y)
Return the unconstrained version of the specified input, which is constrained to be above the specifi...
void scalar_lub_unconstrain(double lb, double ub, T &y)
Write the unconstrained value corresponding to the specified value with the specified bounds.
Eigen::Array< T, Eigen::Dynamic, 1 > array_vec_t
~writer()
Destroy this writer.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > matrix_t
void row_vector_unconstrain(const vector_t &y)
Write the specified unconstrained vector.
void vector_lb_unconstrain(double lb, vector_t &y)
void positive_ordered_unconstrain(vector_t &y)
Write the unconstrained vector that corresponds to the specified postiive ascendingly ordered vector.
void simplex_unconstrain(vector_t &y)
Write the unconstrained vector corresponding to the specified simplex value.
void corr_matrix_unconstrain(matrix_t &y)
Writes the unconstrained correlation matrix corresponding to the specified constrained correlation ma...
void ordered_unconstrain(vector_t &y)
Write the unconstrained vector that corresponds to the specified ascendingly ordered vector.
std::vector< T > & data_r()
Return a reference to the underlying vector of real values that have been written.
void row_vector_ub_unconstrain(double ub, row_vector_t &y)
var fabs(const var &a)
Return the absolute value of the variable (cmath).
var log(const var &a)
Return the natural log of the specified variable (cmath).
var atanh(const stan::agrad::var &a)
The inverse hyperbolic tangent function for variables (C99).
bool check_corr_matrix(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result, const Policy &)
Return true if the specified matrix is a valid correlation matrix.
bool check_simplex(const char *function, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const char *name, T_result *result, const Policy &)
Return true if the specified vector is simplex.
boost::math::tools::promote_args< T >::type logit(T a)
Returns the logit function applied to the argument.
bool check_ordered(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const char *name, T_result *result, const Policy &)
Return true if the specified vector is sorted into increasing order.
bool check_positive_ordered(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const char *name, T_result *result, const Policy &)
Return true if the specified vector contains only non-negative values and is sorted into increasing o...
const double E
The base of the natural logarithm, .
bool factor_cov_matrix(Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, Eigen::Array< T, Eigen::Dynamic, 1 > &sds, const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &Sigma)
This function is intended to make starting values, given a covariance matrix Sigma.
Probability, optimization and sampling library.