1 #ifndef STAN__IO__WRITER_HPP
2 #define STAN__IO__WRITER_HPP
30 std::vector<T> data_r_;
31 std::vector<int> data_i_;
34 typedef Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>
matrix_t;
35 typedef Eigen::Matrix<T,Eigen::Dynamic,1>
vector_t;
105 data_r_.push_back(y);
121 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is negative"));
122 data_r_.push_back(
log(y));
216 if (y.size() == 0)
return;
219 data_r_.push_back(y[0]);
220 for (idx_t i = 1; i < y.size(); ++i) {
221 data_r_.push_back(
log(y[i] - y[i-1]));
245 if (y.size() == 0)
return;
247 y,
"Vector", (
double*)0);
248 data_r_.push_back(
log(y[0]));
249 for (idx_t i = 1; i < y.size(); ++i) {
250 data_r_.push_back(
log(y[i] - y[i-1]));
262 for (idx_t i = 0; i < y.size(); ++i)
263 data_r_.push_back(y[i]);
273 for (idx_t i = 0; i < y.size(); ++i)
274 data_r_.push_back(y[i]);
284 for (idx_t j = 0; j < y.cols(); ++j)
285 for (idx_t i = 0; i < y.rows(); ++i)
286 data_r_.push_back(y(i,j));
291 for (idx_t i = 0; i < y.size(); ++i)
296 for (idx_t i = 0; i < y.size(); ++i)
301 for (idx_t j = 0; j < y.cols(); ++j)
302 for (idx_t i = 0; i < y.rows(); ++i)
308 for (idx_t i = 0; i < y.size(); ++i)
313 for (idx_t i = 0; i < y.size(); ++i)
318 for (idx_t j = 0; j < y.cols(); ++j)
319 for (idx_t i = 0; i < y.rows(); ++i)
326 for (idx_t i = 0; i < y.size(); ++i)
331 for (idx_t i = 0; i < y.size(); ++i)
336 for (idx_t j = 0; j < y.cols(); ++j)
337 for (idx_t i = 0; i < y.rows(); ++i)
360 y,
"Vector", (
double*)0);
363 for (idx_t i = 0; i < uy.size(); ++i)
364 data_r_.push_back(uy[i]);
389 for (idx_t i = 0; i < uy.size(); ++i)
390 data_r_.push_back(uy[i]);
408 Eigen::Matrix<T,Eigen::Dynamic,1> y_free
410 for (idx_t i = 0; i < y_free.size(); ++i)
411 data_r_.push_back(y_free[i]);
430 Eigen::Matrix<T,Eigen::Dynamic,1> y_free
432 for (idx_t i = 0; i < y_free.size(); ++i)
433 data_r_.push_back(y_free[i]);
451 if (k == 0 || y.cols() != k)
452 BOOST_THROW_EXCEPTION(
453 std::runtime_error(
"y must have elements and"
454 " y must be a square matrix"));
455 idx_t k_choose_2 = (k * (k-1)) / 2;
460 BOOST_THROW_EXCEPTION(
461 std::runtime_error (
"factor_cov_matrix failed"));
462 for (idx_t i = 0; i < k_choose_2; ++i)
463 data_r_.push_back(cpcs[i]);
464 for (idx_t i = 0; i < k; ++i)
465 data_r_.push_back(sds[i]);
490 idx_t k_choose_2 = (k * (k-1)) / 2;
495 BOOST_THROW_EXCEPTION(
496 std::runtime_error (
"y cannot be factorized by factor_cov_matrix"));
497 for (idx_t i = 0; i < k; ++i) {
500 BOOST_THROW_EXCEPTION(
501 std::runtime_error (
"sds on log scale are unconstrained"));
503 for (idx_t i = 0; i < k_choose_2; ++i)
504 data_r_.push_back(cpcs[i]);
void corr_matrix_unconstrain(matrix_t &y)
Writes the unconstrained correlation matrix corresponding to the specified constrained correlation ma...
void row_vector_ub_unconstrain(double ub, row_vector_t &y)
fvar< T > fabs(const fvar< T > &x)
bool check_ordered(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const char *name, T_result *result)
Return true if the specified vector is sorted into increasing order.
void matrix_unconstrain(const matrix_t &y)
Write the specified unconstrained matrix.
Eigen::Matrix< T, Eigen::Dynamic, 1 > simplex_free(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an unconstrained vector that when transformed produces the specified simplex.
void integer(int n)
Write the specified integer to the sequence of integer values.
std::vector< T > & data_r()
Return a reference to the underlying vector of real values that have been written.
Eigen::Array< T, Eigen::Dynamic, 1 > array_vec_t
T prob_free(const T y)
Return the free scalar that when transformed to a probability produces the specified scalar...
boost::math::tools::promote_args< T, TU >::type ub_free(const T y, const TU ub)
Return the free scalar that corresponds to the specified upper-bounded value with respect to the spec...
bool check_simplex(const char *function, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const char *name, T_result *result)
Return true if the specified vector is simplex.
void scalar_lub_unconstrain(double lb, double ub, T &y)
Write the unconstrained value corresponding to the specified value with the specified bounds...
void cholesky_factor_unconstrain(matrix_t &y)
Writes the unconstrained Cholesky factor corresponding to the specified constrained matrix...
void positive_ordered_unconstrain(vector_t &y)
Write the unconstrained vector that corresponds to the specified postiive ascendingly ordered vector...
void unit_vector_unconstrain(vector_t &y)
Write the unconstrained vector corresponding to the specified unit_vector value.
void scalar_lb_unconstrain(double lb, T &y)
Return the unconstrained version of the specified input, which is constrained to be above the specifi...
bool check_unit_vector(const char *function, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const char *name, T_result *result)
Return true if the specified vector is unit vector.
void scalar_unconstrain(T &y)
Write the unconstrained value corresponding to the specified scalar.
void row_vector_unconstrain(const vector_t &y)
Write the specified unconstrained vector.
void simplex_unconstrain(vector_t &y)
Write the unconstrained vector corresponding to the specified simplex value.
Primary template class for the metaprogram to compute the index type of a container.
T corr_free(const T y)
Return the unconstrained scalar that when transformed to a valid correlation produces the specified v...
void row_vector_lub_unconstrain(double lb, double ub, row_vector_t &y)
void vector_ub_unconstrain(double ub, vector_t &y)
Eigen::Matrix< T, Eigen::Dynamic, 1 > unit_vector_free(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
void matrix_lub_unconstrain(double lb, double ub, matrix_t &y)
void vector_lb_unconstrain(double lb, vector_t &y)
void cholesky_corr_unconstrain(matrix_t &y)
Writes the unconstrained Cholesky factor for a correlation matrix corresponding to the specified cons...
Eigen::Matrix< T, Eigen::Dynamic, 1 > cholesky_corr_free(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x)
boost::math::tools::promote_args< T, TL, TU >::type lub_free(const T y, TL lb, TU ub)
Return the unconstrained scalar that transforms to the specified lower- and upper-bounded scalar give...
void cov_matrix_unconstrain(matrix_t &y)
Writes the unconstrained covariance matrix corresponding to the specified constrained correlation mat...
bool check_corr_matrix(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is a valid correlation matrix.
void vector_lub_unconstrain(double lb, double ub, vector_t &y)
void matrix_ub_unconstrain(double ub, matrix_t &y)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > matrix_t
Eigen::Matrix< T, Eigen::Dynamic, 1 > cholesky_factor_free(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &y)
Return the unconstrained vector of parameters correspdonding to the specified Cholesky factor...
void matrix_lb_unconstrain(double lb, matrix_t &y)
Eigen::Matrix< T, 1, Eigen::Dynamic > row_vector_t
const double E
The base of the natural logarithm, .
Eigen::Matrix< T, Eigen::Dynamic, 1 > vector_t
bool check_positive_ordered(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const char *name, T_result *result)
Return true if the specified vector contains only non-negative values and is sorted into increasing o...
bool factor_cov_matrix(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &Sigma, Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, Eigen::Array< T, Eigen::Dynamic, 1 > &sds)
This function is intended to make starting values, given a covariance matrix Sigma.
std::vector< int > & data_i()
Return a reference to the underlying vector of integer values that have been written.
void scalar_pos_unconstrain(T &y)
Write the unconstrained value corresponding to the specified positive-constrained scalar...
~writer()
Destroy this writer.
void vector_unconstrain(const vector_t &y)
Write the specified unconstrained vector.
fvar< T > log(const fvar< T > &x)
void prob_unconstrain(T &y)
Write the unconstrained value corresponding to the specified probability value.
void corr_unconstrain(T &y)
Write the unconstrained value corresponding to the specified correlation-constrained variable...
void ordered_unconstrain(vector_t &y)
Write the unconstrained vector that corresponds to the specified ascendingly ordered vector...
void row_vector_lb_unconstrain(double lb, row_vector_t &y)
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_ub_unconstrain(double ub, T &y)
Write the unconstrained value corresponding to the specified lower-bounded value. ...
A stream-based writer for integer, scalar, vector, matrix and array data types, which transforms from...
boost::math::tools::promote_args< T, TL >::type lb_free(const T y, const TL lb)
Return the unconstrained value that produces the specified lower-bound constrained value...
const double CONSTRAINT_TOLERANCE
This is the tolerance for checking arithmetic bounds in rank and in simplexes.