1 #ifndef __STAN__IO__WRITER_HPP__
2 #define __STAN__IO__WRITER_HPP__
8 #include <boost/multi_array.hpp>
9 #include <boost/throw_exception.hpp>
35 std::vector<T> data_r_;
36 std::vector<int> data_i_;
108 data_r_.push_back(y);
124 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is negative"));
125 data_r_.push_back(
log(y));
141 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is lower than the lower bound"));
142 data_r_.push_back(
log(y - lb));
157 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is higher than the lower bound"));
158 data_r_.push_back(
log(ub - y));
174 if (y < lb || y > ub)
175 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is not between the lower and upper bounds"));
190 if (y > 1.0 || y < -1.0)
191 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is not between -1.0 and 1.0"));
192 data_r_.push_back(
atanh(y));
207 if (y > 1.0 || y < 0.0)
208 BOOST_THROW_EXCEPTION(std::runtime_error (
"y is not between 0.0 and 1.0"));
228 if (y.size() == 0)
return;
230 data_r_.push_back(y[0]);
232 data_r_.push_back(
log(y[i] - y[i-1]));
252 if (y.size() == 0)
return;
254 data_r_.push_back(
log(y[0]));
256 data_r_.push_back(
log(y[i] - y[i-1]));
268 data_r_.push_back(y[i]);
278 data_r_.push_back(y[i]);
289 data_r_.push_back(y(i,j));
293 for (
int i = 0; i < y.size(); ++i)
297 for (
int i = 0; i < y.size(); ++i)
301 for (
int i = 0; i < y.rows(); ++i)
302 for (
int j = 0; j < y.cols(); ++j)
307 for (
int i = 0; i < y.size(); ++i)
311 for (
int i = 0; i < y.size(); ++i)
315 for (
int i = 0; i < y.rows(); ++i)
316 for (
int j = 0; j < y.cols(); ++j)
322 for (
int i = 0; i < y.size(); ++i)
326 for (
int i = 0; i < y.size(); ++i)
330 for (
int i = 0; i < y.rows(); ++i)
331 for (
int j = 0; j < y.cols(); ++j)
355 double log_y_k =
log(y[k_minus_1]);
357 data_r_.push_back(
log(y[i]) - log_y_k);
379 size_t k_choose_2 = (k * (k-1)) / 2;
384 BOOST_THROW_EXCEPTION(std::runtime_error (
"y cannot be factorized by factor_cov_matrix"));
385 for (
size_t i = 0; i < k; ++i) {
388 BOOST_THROW_EXCEPTION(std::runtime_error (
"sds on log scale are unconstrained"));
390 for (
size_t i = 0; i < k_choose_2; ++i)
391 data_r_.push_back(cpcs[i]);
407 if (k == 0 || y.cols() != k)
408 BOOST_THROW_EXCEPTION(
409 std::runtime_error (
"y must have elements and y must be a square matrix"));
415 BOOST_THROW_EXCEPTION(std::runtime_error (
"factor_cov_matrix failed"));
417 data_r_.push_back(cpcs[i]);
419 data_r_.push_back(sds[i]);