Stan  2.14.0
probability, sampling & optimization
reader.hpp
Go to the documentation of this file.
1 #ifndef STAN_IO_READER_HPP
2 #define STAN_IO_READER_HPP
3 
4 #include <boost/throw_exception.hpp>
5 #include <stan/math/prim/mat.hpp>
6 #include <vector>
7 
8 namespace stan {
9 
10  namespace io {
11 
12 
34  template <typename T>
35  class reader {
36  private:
37  std::vector<T>& data_r_;
38  std::vector<int>& data_i_;
39  size_t pos_;
40  size_t int_pos_;
41 
42  inline T& scalar_ptr() {
43  return data_r_.at(pos_);
44  }
45 
46  inline T& scalar_ptr_increment(size_t m) {
47  pos_ += m;
48  return data_r_.at(pos_ - m);
49  }
50 
51  inline int& int_ptr() {
52  return data_i_.at(int_pos_);
53  }
54 
55  inline int& int_ptr_increment(size_t m) {
56  int_pos_ += m;
57  return data_i_.at(int_pos_ - m);
58  }
59 
60  public:
61  typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> matrix_t;
62  typedef Eigen::Matrix<T, Eigen::Dynamic, 1> vector_t;
63  typedef Eigen::Matrix<T, 1, Eigen::Dynamic> row_vector_t;
64 
65  typedef Eigen::Map<matrix_t> map_matrix_t;
66  typedef Eigen::Map<vector_t> map_vector_t;
67  typedef Eigen::Map<row_vector_t> map_row_vector_t;
68 
69 
81  reader(std::vector<T>& data_r,
82  std::vector<int>& data_i)
83  : data_r_(data_r),
84  data_i_(data_i),
85  pos_(0),
86  int_pos_(0) {
87  }
88 
92  ~reader() { }
93 
99  inline size_t available() {
100  return data_r_.size() - pos_;
101  }
102 
108  inline size_t available_i() {
109  return data_i_.size() - int_pos_;
110  }
111 
117  inline int integer() {
118  if (int_pos_ >= data_i_.size())
119  BOOST_THROW_EXCEPTION(
120  std::runtime_error("no more integers to read."));
121  return data_i_[int_pos_++];
122  }
123 
131  inline int integer_constrain() {
132  return integer();
133  }
134 
142  inline int integer_constrain(T& /*log_prob*/) {
143  return integer();
144  }
145 
146 
147 
153  inline T scalar() {
154  if (pos_ >= data_r_.size())
155  BOOST_THROW_EXCEPTION(std::runtime_error("no more scalars to read"));
156  return data_r_[pos_++];
157  }
158 
165  inline T scalar_constrain() {
166  return scalar();
167  }
168 
180  T scalar_constrain(T& /*log_prob*/) {
181  return scalar();
182  }
183 
184 
192  inline std::vector<T> std_vector(size_t m) {
193  if (m == 0) return std::vector<T>();
194  std::vector<T> vec;
195  T& start = scalar_ptr_increment(m);
196  vec.insert(vec.begin(), &start, &scalar_ptr());
197  return vec;
198  }
199 
207  inline vector_t vector(size_t m) {
208  if (m == 0) return vector_t();
209  return map_vector_t(&scalar_ptr_increment(m), m);
210  }
218  inline vector_t vector_constrain(size_t m) {
219  if (m == 0) return vector_t();
220  return map_vector_t(&scalar_ptr_increment(m), m);
221  }
230  inline vector_t vector_constrain(size_t m, T& /*lp*/) {
231  if (m == 0) return vector_t();
232  return map_vector_t(&scalar_ptr_increment(m), m);
233  }
234 
235 
236 
244  inline row_vector_t row_vector(size_t m) {
245  if (m == 0) return row_vector_t();
246  return map_row_vector_t(&scalar_ptr_increment(m), m);
247  }
248 
256  inline row_vector_t row_vector_constrain(size_t m) {
257  if (m == 0) return row_vector_t();
258  return map_row_vector_t(&scalar_ptr_increment(m), m);
259  }
260 
270  inline row_vector_t row_vector_constrain(size_t m, T& /*lp*/) {
271  if (m == 0) return row_vector_t();
272  return map_row_vector_t(&scalar_ptr_increment(m), m);
273  }
274 
292  inline matrix_t matrix(size_t m, size_t n) {
293  if (m == 0 || n == 0)
294  return matrix_t(m, n);
295  return map_matrix_t(&scalar_ptr_increment(m*n), m, n);
296  }
297 
308  inline matrix_t matrix_constrain(size_t m, size_t n) {
309  if (m == 0 || n == 0)
310  return matrix_t(m, n);
311  return map_matrix_t(&scalar_ptr_increment(m*n), m, n);
312  }
313 
326  inline matrix_t matrix_constrain(size_t m, size_t n, T& /*lp*/) {
327  if (m == 0 || n == 0)
328  return matrix_t(m, n);
329  return map_matrix_t(&scalar_ptr_increment(m*n), m, n);
330  }
331 
332 
342  inline int integer_lb(int lb) {
343  int i = integer();
344  if (!(i >= lb))
345  BOOST_THROW_EXCEPTION(
346  std::runtime_error("required value greater than or equal to lb"));
347  return i;
348  }
358  inline int integer_lb_constrain(int lb) {
359  return integer_lb(lb);
360  }
371  inline int integer_lb_constrain(int lb, T& /*lp*/) {
372  return integer_lb(lb);
373  }
374 
375 
385  inline int integer_ub(int ub) {
386  int i = integer();
387  if (!(i <= ub))
388  BOOST_THROW_EXCEPTION(
389  std::runtime_error("required value less than or equal to ub"));
390  return i;
391  }
401  inline int integer_ub_constrain(int ub) {
402  return integer_ub(ub);
403  }
414  int integer_ub_constrain(int ub, T& /*lp*/) {
415  return integer_ub(ub);
416  }
417 
430  inline int integer_lub(int lb, int ub) {
431  // read first to make position deterministic [arbitrary choice]
432  int i = integer();
433  if (lb > ub)
434  BOOST_THROW_EXCEPTION(
435  std::runtime_error("lower bound must be less than or equal to ub"));
436  if (!(i >= lb))
437  BOOST_THROW_EXCEPTION(
438  std::runtime_error("required value greater than or equal to lb"));
439  if (!(i <= ub))
440  BOOST_THROW_EXCEPTION(
441  std::runtime_error("required value less than or equal to ub"));
442  return i;
443  }
454  inline int integer_lub_constrain(int lb, int ub) {
455  return integer_lub(lb, ub);
456  }
468  inline int integer_lub_constrain(int lb, int ub, T& /*lp*/) {
469  return integer_lub(lb, ub);
470  }
471 
472 
473 
483  inline T scalar_pos() {
484  T x(scalar());
485  stan::math::check_positive("stan::io::scalar_pos",
486  "Constrained scalar", x);
487  return x;
488  }
489 
497  inline T scalar_pos_constrain() {
498  return stan::math::positive_constrain(scalar());
499  }
500 
511  inline T scalar_pos_constrain(T& lp) {
512  return stan::math::positive_constrain(scalar(), lp);
513  }
514 
527  template <typename TL>
528  inline T scalar_lb(const TL lb) {
529  T x(scalar());
530  stan::math::check_greater_or_equal("stan::io::scalar_lb",
531  "Constrained scalar", x, lb);
532  return x;
533  }
534 
546  template <typename TL>
547  inline T scalar_lb_constrain(const TL lb) {
548  return stan::math::lb_constrain(scalar(), lb);
549  }
550 
562  template <typename TL>
563  inline T scalar_lb_constrain(const TL lb, T& lp) {
564  return stan::math::lb_constrain(scalar(), lb, lp);
565  }
566 
567 
568 
581  template <typename TU>
582  inline T scalar_ub(TU ub) {
583  T x(scalar());
584  stan::math::check_less_or_equal("stan::io::scalar_ub",
585  "Constrained scalar", x, ub);
586  return x;
587  }
588 
600  template <typename TU>
601  inline T scalar_ub_constrain(const TU ub) {
602  return stan::math::ub_constrain(scalar(), ub);
603  }
604 
616  template <typename TU>
617  inline T scalar_ub_constrain(const TU ub, T& lp) {
618  return stan::math::ub_constrain(scalar(), ub, lp);
619  }
620 
635  template <typename TL, typename TU>
636  inline T scalar_lub(const TL lb, const TU ub) {
637  T x(scalar());
638  stan::math::check_bounded<T, TL, TU>
639  ("stan::io::scalar_lub", "Constrained scalar", x, lb, ub);
640  return x;
641  }
642 
656  template <typename TL, typename TU>
657  inline T scalar_lub_constrain(const TL lb, const TU ub) {
658  return stan::math::lub_constrain(scalar(), lb, ub);
659  }
660 
674  template <typename TL, typename TU>
675  inline T scalar_lub_constrain(TL lb, TU ub, T& lp) {
676  return stan::math::lub_constrain(scalar(), lb, ub, lp);
677  }
678 
687  inline T prob() {
688  T x(scalar());
689  stan::math::check_bounded<T, double, double>
690  ("stan::io::prob", "Constrained probability", x, 0, 1);
691  return x;
692  }
693 
702  inline T prob_constrain() {
703  return stan::math::prob_constrain(scalar());
704  }
705 
716  inline T prob_constrain(T& lp) {
717  return stan::math::prob_constrain(scalar(), lp);
718  }
719 
720 
721 
722 
734  inline T corr() {
735  T x(scalar());
736  stan::math::check_bounded<T, double, double>
737  ("stan::io::corr", "Correlation value", x, -1, 1);
738  return x;
739  }
740 
749  inline T corr_constrain() {
750  return stan::math::corr_constrain(scalar());
751  }
752 
764  inline T corr_constrain(T& lp) {
765  return stan::math::corr_constrain(scalar(), lp);
766  }
767 
778  inline vector_t unit_vector(size_t k) {
779  vector_t theta(vector(k));
780  stan::math::check_unit_vector("stan::io::unit_vector",
781  "Constrained vector", theta);
782  return theta;
783  }
784 
795  inline
796  Eigen::Matrix<T, Eigen::Dynamic, 1> unit_vector_constrain(size_t k) {
797  return stan::math::unit_vector_constrain(vector(k));
798  }
799 
812  inline vector_t unit_vector_constrain(size_t k, T& lp) {
813  return stan::math::unit_vector_constrain(vector(k), lp);
814  }
815 
826  inline vector_t simplex(size_t k) {
827  vector_t theta(vector(k));
828  stan::math::check_simplex("stan::io::simplex",
829  "Constrained vector", theta);
830  return theta;
831  }
832 
843  inline
844  Eigen::Matrix<T, Eigen::Dynamic, 1> simplex_constrain(size_t k) {
845  return stan::math::simplex_constrain(vector(k-1));
846  }
847 
860  inline vector_t simplex_constrain(size_t k, T& lp) {
861  return stan::math::simplex_constrain(vector(k-1), lp);
862  }
863 
874  inline vector_t ordered(size_t k) {
875  vector_t x(vector(k));
876  stan::math::check_ordered("stan::io::ordered", "Constrained vector", x);
877  return x;
878  }
879 
889  inline vector_t ordered_constrain(size_t k) {
890  return stan::math::ordered_constrain(vector(k));
891  }
892 
904  inline vector_t ordered_constrain(size_t k, T& lp) {
905  return stan::math::ordered_constrain(vector(k), lp);
906  }
907 
918  inline vector_t positive_ordered(size_t k) {
919  vector_t x(vector(k));
920  stan::math::check_positive_ordered("stan::io::positive_ordered",
921  "Constrained vector", x);
922  return x;
923  }
924 
934  inline vector_t positive_ordered_constrain(size_t k) {
935  return stan::math::positive_ordered_constrain(vector(k));
936  }
937 
949  inline vector_t positive_ordered_constrain(size_t k, T& lp) {
950  return stan::math::positive_ordered_constrain(vector(k), lp);
951  }
952 
953 
954 
965  inline matrix_t cholesky_factor(size_t M, size_t N) {
966  matrix_t y(matrix(M, N));
967  stan::math::check_cholesky_factor("stan::io::cholesky_factor",
968  "Constrained matrix", y);
969  return y;
970  }
971 
983  inline matrix_t cholesky_factor_constrain(size_t M, size_t N) {
984  return stan::math::cholesky_factor_constrain
985  (vector((N * (N + 1)) / 2 + (M - N) * N), M, N);
986  }
987 
1001  inline matrix_t cholesky_factor_constrain(size_t M, size_t N, T& lp) {
1002  return stan::math::cholesky_factor_constrain
1003  (vector((N * (N + 1)) / 2 + (M - N) * N), M, N, lp);
1004  }
1005 
1006 
1007 
1018  inline matrix_t cholesky_corr(size_t K) {
1019  using stan::math::check_cholesky_factor_corr;
1020  matrix_t y(matrix(K, K));
1021  check_cholesky_factor_corr("stan::io::cholesky_factor_corr",
1022  "Constrained matrix", y);
1023  return y;
1024  }
1025 
1036  inline matrix_t cholesky_corr_constrain(size_t K) {
1037  return stan::math::cholesky_corr_constrain(vector((K * (K - 1)) / 2),
1038  K);
1039  }
1040 
1054  inline matrix_t cholesky_corr_constrain(size_t K, T& lp) {
1055  return stan::math::cholesky_corr_constrain(vector((K * (K - 1)) / 2),
1056  K, lp);
1057  }
1058 
1059 
1060 
1072  inline matrix_t cov_matrix(size_t k) {
1073  matrix_t y(matrix(k, k));
1074  stan::math::check_cov_matrix("stan::io::cov_matrix",
1075  "Constrained matrix", y);
1076  return y;
1077  }
1078 
1087  inline matrix_t cov_matrix_constrain(size_t k) {
1088  return stan::math::cov_matrix_constrain(vector(k + (k * (k - 1)) / 2),
1089  k);
1090  }
1091 
1103  inline matrix_t cov_matrix_constrain(size_t k, T& lp) {
1104  return stan::math::cov_matrix_constrain(vector(k + (k * (k - 1)) / 2),
1105  k, lp);
1106  }
1107 
1108 
1118  inline matrix_t corr_matrix(size_t k) {
1119  matrix_t x(matrix(k, k));
1120  stan::math::check_corr_matrix("stan::math::corr_matrix",
1121  "Constrained matrix", x);
1122  return x;
1123  }
1124 
1133  inline matrix_t corr_matrix_constrain(size_t k) {
1134  return stan::math::corr_matrix_constrain(vector((k * (k - 1)) / 2), k);
1135  }
1136 
1148  inline matrix_t corr_matrix_constrain(size_t k, T& lp) {
1149  return stan::math::corr_matrix_constrain(vector((k * (k - 1)) / 2),
1150  k, lp);
1151  }
1152 
1153  template <typename TL>
1154  inline vector_t vector_lb(const TL lb, size_t m) {
1155  vector_t v(m);
1156  for (size_t i = 0; i < m; ++i)
1157  v(i) = scalar_lb(lb);
1158  return v;
1159  }
1160 
1161  template <typename TL>
1162  inline vector_t vector_lb_constrain(const TL lb, size_t m) {
1163  vector_t v(m);
1164  for (size_t i = 0; i < m; ++i)
1165  v(i) = scalar_lb_constrain(lb);
1166  return v;
1167  }
1168 
1169  template <typename TL>
1170  inline vector_t vector_lb_constrain(const TL lb, size_t m, T& lp) {
1171  vector_t v(m);
1172  for (size_t i = 0; i < m; ++i)
1173  v(i) = scalar_lb_constrain(lb, lp);
1174  return v;
1175  }
1176 
1177  template <typename TL>
1178  inline row_vector_t row_vector_lb(const TL lb, size_t m) {
1179  row_vector_t v(m);
1180  for (size_t i = 0; i < m; ++i)
1181  v(i) = scalar_lb(lb);
1182  return v;
1183  }
1184 
1185  template <typename TL>
1186  inline row_vector_t row_vector_lb_constrain(const TL lb, size_t m) {
1187  row_vector_t v(m);
1188  for (size_t i = 0; i < m; ++i)
1189  v(i) = scalar_lb_constrain(lb);
1190  return v;
1191  }
1192 
1193  template <typename TL>
1194  inline row_vector_t
1195  row_vector_lb_constrain(const TL lb, size_t m, T& lp) {
1196  row_vector_t v(m);
1197  for (size_t i = 0; i < m; ++i)
1198  v(i) = scalar_lb_constrain(lb, lp);
1199  return v;
1200  }
1201 
1202  template <typename TL>
1203  inline matrix_t matrix_lb(const TL lb, size_t m, size_t n) {
1204  matrix_t v(m, n);
1205  for (size_t j = 0; j < n; ++j)
1206  for (size_t i = 0; i < m; ++i)
1207  v(i, j) = scalar_lb(lb);
1208  return v;
1209  }
1210 
1211  template <typename TL>
1212  inline matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n) {
1213  matrix_t v(m, n);
1214  for (size_t j = 0; j < n; ++j)
1215  for (size_t i = 0; i < m; ++i)
1216  v(i, j) = scalar_lb_constrain(lb);
1217  return v;
1218  }
1219 
1220  template <typename TL>
1221  inline matrix_t
1222  matrix_lb_constrain(const TL lb, size_t m, size_t n, T& lp) {
1223  matrix_t v(m, n);
1224  for (size_t j = 0; j < n; ++j)
1225  for (size_t i = 0; i < m; ++i)
1226  v(i, j) = scalar_lb_constrain(lb, lp);
1227  return v;
1228  }
1229 
1230  template <typename TU>
1231  inline vector_t vector_ub(const TU ub, size_t m) {
1232  vector_t v(m);
1233  for (size_t i = 0; i < m; ++i)
1234  v(i) = scalar_ub(ub);
1235  return v;
1236  }
1237 
1238  template <typename TU>
1239  inline vector_t vector_ub_constrain(const TU ub, size_t m) {
1240  vector_t v(m);
1241  for (size_t i = 0; i < m; ++i)
1242  v(i) = scalar_ub_constrain(ub);
1243  return v;
1244  }
1245 
1246  template <typename TU>
1247  inline vector_t vector_ub_constrain(const TU ub, size_t m, T& lp) {
1248  vector_t v(m);
1249  for (size_t i = 0; i < m; ++i)
1250  v(i) = scalar_ub_constrain(ub, lp);
1251  return v;
1252  }
1253 
1254  template <typename TU>
1255  inline row_vector_t row_vector_ub(const TU ub, size_t m) {
1256  row_vector_t v(m);
1257  for (size_t i = 0; i < m; ++i)
1258  v(i) = scalar_ub(ub);
1259  return v;
1260  }
1261 
1262  template <typename TU>
1263  inline row_vector_t row_vector_ub_constrain(const TU ub, size_t m) {
1264  row_vector_t v(m);
1265  for (size_t i = 0; i < m; ++i)
1266  v(i) = scalar_ub_constrain(ub);
1267  return v;
1268  }
1269 
1270  template <typename TU>
1271  inline row_vector_t
1272  row_vector_ub_constrain(const TU ub, size_t m, T& lp) {
1273  row_vector_t v(m);
1274  for (size_t i = 0; i < m; ++i)
1275  v(i) = scalar_ub_constrain(ub, lp);
1276  return v;
1277  }
1278 
1279  template <typename TU>
1280  inline matrix_t matrix_ub(const TU ub, size_t m, size_t n) {
1281  matrix_t v(m, n);
1282  for (size_t j = 0; j < n; ++j)
1283  for (size_t i = 0; i < m; ++i)
1284  v(i, j) = scalar_ub(ub);
1285  return v;
1286  }
1287 
1288  template <typename TU>
1289  inline matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n) {
1290  matrix_t v(m, n);
1291  for (size_t j = 0; j < n; ++j)
1292  for (size_t i = 0; i < m; ++i)
1293  v(i, j) = scalar_ub_constrain(ub);
1294  return v;
1295  }
1296 
1297  template <typename TU>
1298  inline matrix_t
1299  matrix_ub_constrain(const TU ub, size_t m, size_t n, T& lp) {
1300  matrix_t v(m, n);
1301  for (size_t j = 0; j < n; ++j)
1302  for (size_t i = 0; i < m; ++i)
1303  v(i, j) = scalar_ub_constrain(ub, lp);
1304  return v;
1305  }
1306 
1307  template <typename TL, typename TU>
1308  inline vector_t vector_lub(const TL lb, const TU ub, size_t m) {
1309  vector_t v(m);
1310  for (size_t i = 0; i < m; ++i)
1311  v(i) = scalar_lub(lb, ub);
1312  return v;
1313  }
1314 
1315  template <typename TL, typename TU>
1316  inline vector_t
1317  vector_lub_constrain(const TL lb, const TU ub, size_t m) {
1318  vector_t v(m);
1319  for (size_t i = 0; i < m; ++i)
1320  v(i) = scalar_lub_constrain(lb, ub);
1321  return v;
1322  }
1323 
1324  template <typename TL, typename TU>
1325  inline vector_t
1326  vector_lub_constrain(const TL lb, const TU ub, size_t m, T& lp) {
1327  vector_t v(m);
1328  for (size_t i = 0; i < m; ++i)
1329  v(i) = scalar_lub_constrain(lb, ub, lp);
1330  return v;
1331  }
1332 
1333  template <typename TL, typename TU>
1334  inline row_vector_t row_vector_lub(const TL lb, const TU ub, size_t m) {
1335  row_vector_t v(m);
1336  for (size_t i = 0; i < m; ++i)
1337  v(i) = scalar_lub(lb, ub);
1338  return v;
1339  }
1340  template <typename TL, typename TU>
1341  inline row_vector_t
1342  row_vector_lub_constrain(const TL lb, const TU ub, size_t m) {
1343  row_vector_t v(m);
1344  for (size_t i = 0; i < m; ++i)
1345  v(i) = scalar_lub_constrain(lb, ub);
1346  return v;
1347  }
1348 
1349  template <typename TL, typename TU>
1350  inline row_vector_t
1351  row_vector_lub_constrain(const TL lb, const TU ub, size_t m, T& lp) {
1352  row_vector_t v(m);
1353  for (size_t i = 0; i < m; ++i)
1354  v(i) = scalar_lub_constrain(lb, ub, lp);
1355  return v;
1356  }
1357 
1358  template <typename TL, typename TU>
1359  inline matrix_t matrix_lub(const TL lb, const TU ub, size_t m, size_t n) {
1360  matrix_t v(m, n);
1361  for (size_t j = 0; j < n; ++j)
1362  for (size_t i = 0; i < m; ++i)
1363  v(i, j) = scalar_lub(lb, ub);
1364  return v;
1365  }
1366 
1367  template <typename TL, typename TU>
1368  inline matrix_t
1369  matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n) {
1370  matrix_t v(m, n);
1371  for (size_t j = 0; j < n; ++j)
1372  for (size_t i = 0; i < m; ++i)
1373  v(i, j) = scalar_lub_constrain(lb, ub);
1374  return v;
1375  }
1376 
1377  template <typename TL, typename TU>
1378  inline matrix_t
1379  matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n,
1380  T& lp) {
1381  matrix_t v(m, n);
1382  for (size_t j = 0; j < n; ++j)
1383  for (size_t i = 0; i < m; ++i)
1384  v(i, j) = scalar_lub_constrain(lb, ub, lp);
1385  return v;
1386  }
1387  };
1388 
1389  }
1390 
1391 }
1392 
1393 #endif
matrix_t cholesky_corr_constrain(size_t K, T &lp)
Return the next Cholesky factor for a correlation matrix with the specified dimensionality, reading from an unconstrained vector of the appropriate size, and increment the log probability reference with the log Jacobian adjustment for the transform.
Definition: reader.hpp:1054
vector_t positive_ordered_constrain(size_t k)
Return the next positive ordered vector of the specified length.
Definition: reader.hpp:934
row_vector_t row_vector_ub_constrain(const TU ub, size_t m)
Definition: reader.hpp:1263
vector_t simplex_constrain(size_t k, T &lp)
Return the next simplex of the specified size (using one fewer unconstrained scalars), incrementing the specified reference with the log absolute Jacobian determinant.
Definition: reader.hpp:860
T scalar_lub_constrain(const TL lb, const TU ub)
Return the next scalar transformed to be between the specified lower and upper bounds.
Definition: reader.hpp:657
matrix_t matrix_lub(const TL lb, const TU ub, size_t m, size_t n)
Definition: reader.hpp:1359
T scalar_ub(TU ub)
Return the next scalar, checking that it is less than or equal to the specified upper bound...
Definition: reader.hpp:582
T scalar_pos()
Return the next scalar, checking that it is positive.
Definition: reader.hpp:483
vector_t unit_vector_constrain(size_t k, T &lp)
Return the next unit_vector of the specified size (using one fewer unconstrained scalars), incrementing the specified reference with the log absolute Jacobian determinant.
Definition: reader.hpp:812
int integer_ub_constrain(int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound...
Definition: reader.hpp:401
matrix_t matrix_ub(const TU ub, size_t m, size_t n)
Definition: reader.hpp:1280
matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n)
Definition: reader.hpp:1369
std::vector< T > std_vector(size_t m)
Return a standard library vector of the specified dimensionality made up of the next scalars...
Definition: reader.hpp:192
T scalar_lb(const TL lb)
Return the next scalar, checking that it is greater than or equal to the specified lower bound...
Definition: reader.hpp:528
Eigen::Matrix< T, Eigen::Dynamic, 1 > vector_t
Definition: reader.hpp:62
row_vector_t row_vector_constrain(size_t m)
Return a row vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:256
int integer_ub_constrain(int ub, T &)
Return the next integer, checking that it is less than or equal to the specified upper bound...
Definition: reader.hpp:414
T scalar_constrain()
Return the next scalar.
Definition: reader.hpp:165
vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m, T &lp)
Definition: reader.hpp:1326
Probability, optimization and sampling library.
Eigen::Map< row_vector_t > map_row_vector_t
Definition: reader.hpp:67
int integer_lb_constrain(int lb, T &)
Return the next integer, checking that it is greater than or equal to the specified lower bound...
Definition: reader.hpp:371
vector_t vector_constrain(size_t m)
Return a column vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:218
row_vector_t row_vector_ub(const TU ub, size_t m)
Definition: reader.hpp:1255
matrix_t cov_matrix(size_t k)
Return the next covariance matrix with the specified dimensionality.
Definition: reader.hpp:1072
matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n, T &lp)
Definition: reader.hpp:1222
T corr_constrain()
Return the next scalar transformed to be a correlation between -1 and 1.
Definition: reader.hpp:749
T scalar_constrain(T &)
Return the next scalar in the sequence, incrementing the specified reference with the log absolute Ja...
Definition: reader.hpp:180
matrix_t cov_matrix_constrain(size_t k)
Return the next covariance matrix of the specified dimensionality.
Definition: reader.hpp:1087
T prob_constrain(T &lp)
Return the next scalar transformed to be a probability between 0 and 1, incrementing the specified re...
Definition: reader.hpp:716
matrix_t corr_matrix_constrain(size_t k, T &lp)
Return the next correlation matrix of the specified dimensionality, incrementing the specified refere...
Definition: reader.hpp:1148
int integer_constrain(T &)
Return the next integer in the integer sequence.
Definition: reader.hpp:142
T corr()
Return the next scalar, checking that it is a valid value for a correlation, between -1 (inclusive) a...
Definition: reader.hpp:734
int integer_ub(int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound...
Definition: reader.hpp:385
int integer_lb_constrain(int lb)
Return the next integer, checking that it is greater than or equal to the specified lower bound...
Definition: reader.hpp:358
T scalar_lb_constrain(const TL lb)
Return the next scalar transformed to have the specified lower bound.
Definition: reader.hpp:547
matrix_t cholesky_corr(size_t K)
Return the next Cholesky factor for a correlation matrix with the specified dimensionality, reading it directly without transforms.
Definition: reader.hpp:1018
T scalar_pos_constrain()
Return the next scalar, transformed to be positive.
Definition: reader.hpp:497
Eigen::Matrix< T, 1, Eigen::Dynamic > row_vector_t
Definition: reader.hpp:63
vector_t vector_ub(const TU ub, size_t m)
Definition: reader.hpp:1231
row_vector_t row_vector(size_t m)
Return a row vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:244
vector_t vector(size_t m)
Return a column vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:207
vector_t vector_lub(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1308
row_vector_t row_vector_constrain(size_t m, T &)
Return a row vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:270
matrix_t matrix_constrain(size_t m, size_t n)
Return a matrix of the specified dimensionality made up of the next scalars arranged in column-major ...
Definition: reader.hpp:308
vector_t unit_vector(size_t k)
Return a unit_vector of the specified size made up of the next scalars.
Definition: reader.hpp:778
row_vector_t row_vector_lb_constrain(const TL lb, size_t m)
Definition: reader.hpp:1186
vector_t vector_ub_constrain(const TU ub, size_t m, T &lp)
Definition: reader.hpp:1247
Eigen::Map< vector_t > map_vector_t
Definition: reader.hpp:66
matrix_t cholesky_factor(size_t M, size_t N)
Return the next Cholesky factor with the specified dimensionality, reading it directly without transf...
Definition: reader.hpp:965
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > matrix_t
Definition: reader.hpp:61
vector_t ordered(size_t k)
Return the next vector of specified size containing values in ascending order.
Definition: reader.hpp:874
A stream-based reader for integer, scalar, vector, matrix and array data types, with Jacobian calcula...
Definition: reader.hpp:35
reader(std::vector< T > &data_r, std::vector< int > &data_i)
Construct a variable reader using the specified vectors as the source of scalar and integer values fo...
Definition: reader.hpp:81
T scalar_ub_constrain(const TU ub)
Return the next scalar transformed to have the specified upper bound.
Definition: reader.hpp:601
matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n, T &lp)
Definition: reader.hpp:1379
int integer_lub(int lb, int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound...
Definition: reader.hpp:430
matrix_t matrix(size_t m, size_t n)
Return a matrix of the specified dimensionality made up of the next scalars arranged in column-major ...
Definition: reader.hpp:292
T corr_constrain(T &lp)
Return the next scalar transformed to be a (partial) correlation between -1 and 1, incrementing the specified reference with the log of the absolute Jacobian determinant.
Definition: reader.hpp:764
row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m, T &lp)
Definition: reader.hpp:1351
T scalar()
Return the next scalar in the sequence.
Definition: reader.hpp:153
T scalar_pos_constrain(T &lp)
Return the next scalar transformed to be positive, incrementing the specified reference with the log ...
Definition: reader.hpp:511
vector_t ordered_constrain(size_t k)
Return the next ordered vector of the specified length.
Definition: reader.hpp:889
matrix_t matrix_lb(const TL lb, size_t m, size_t n)
Definition: reader.hpp:1203
int integer_lub_constrain(int lb, int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound...
Definition: reader.hpp:454
matrix_t cholesky_factor_constrain(size_t M, size_t N, T &lp)
Return the next Cholesky factor with the specified dimensionality, reading from an unconstrained vect...
Definition: reader.hpp:1001
T prob_constrain()
Return the next scalar transformed to be a probability between 0 and 1.
Definition: reader.hpp:702
vector_t simplex(size_t k)
Return a simplex of the specified size made up of the next scalars.
Definition: reader.hpp:826
Eigen::Matrix< T, Eigen::Dynamic, 1 > unit_vector_constrain(size_t k)
Return the next unit_vector transformed vector of the specified length.
Definition: reader.hpp:796
matrix_t corr_matrix(size_t k)
Returns the next correlation matrix of the specified dimensionality.
Definition: reader.hpp:1118
vector_t vector_lb(const TL lb, size_t m)
Definition: reader.hpp:1154
T scalar_lb_constrain(const TL lb, T &lp)
Return the next scalar transformed to have the specified lower bound, incrementing the specified refe...
Definition: reader.hpp:563
vector_t vector_lb_constrain(const TL lb, size_t m)
Definition: reader.hpp:1162
vector_t positive_ordered(size_t k)
Return the next vector of specified size containing positive values in ascending order.
Definition: reader.hpp:918
size_t available()
Return the number of scalars remaining to be read.
Definition: reader.hpp:99
matrix_t cov_matrix_constrain(size_t k, T &lp)
Return the next covariance matrix of the specified dimensionality, incrementing the specified referen...
Definition: reader.hpp:1103
row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1342
Eigen::Matrix< T, Eigen::Dynamic, 1 > simplex_constrain(size_t k)
Return the next simplex transformed vector of the specified length.
Definition: reader.hpp:844
~reader()
Destroy this variable reader.
Definition: reader.hpp:92
row_vector_t row_vector_lub(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1334
int integer()
Return the next integer in the integer sequence.
Definition: reader.hpp:117
matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n, T &lp)
Definition: reader.hpp:1299
matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n)
Definition: reader.hpp:1289
matrix_t cholesky_factor_constrain(size_t M, size_t N)
Return the next Cholesky factor with the specified dimensionality, reading from an unconstrained vect...
Definition: reader.hpp:983
int integer_constrain()
Return the next integer in the integer sequence.
Definition: reader.hpp:131
size_t available_i()
Return the number of integers remaining to be read.
Definition: reader.hpp:108
row_vector_t row_vector_lb(const TL lb, size_t m)
Definition: reader.hpp:1178
vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1317
Eigen::Map< matrix_t > map_matrix_t
Definition: reader.hpp:65
int integer_lb(int lb)
Return the next integer, checking that it is greater than or equal to the specified lower bound...
Definition: reader.hpp:342
int integer_lub_constrain(int lb, int ub, T &)
Return the next integer, checking that it is less than or equal to the specified upper bound...
Definition: reader.hpp:468
T scalar_ub_constrain(const TU ub, T &lp)
Return the next scalar transformed to have the specified upper bound, incrementing the specified refe...
Definition: reader.hpp:617
T scalar_lub_constrain(TL lb, TU ub, T &lp)
Return the next scalar transformed to be between the the specified lower and upper bounds...
Definition: reader.hpp:675
matrix_t corr_matrix_constrain(size_t k)
Return the next correlation matrix of the specified dimensionality.
Definition: reader.hpp:1133
matrix_t matrix_constrain(size_t m, size_t n, T &)
Return a matrix of the specified dimensionality made up of the next scalars arranged in column-major ...
Definition: reader.hpp:326
vector_t vector_lb_constrain(const TL lb, size_t m, T &lp)
Definition: reader.hpp:1170
vector_t ordered_constrain(size_t k, T &lp)
Return the next ordered vector of the specified size, incrementing the specified reference with the l...
Definition: reader.hpp:904
matrix_t cholesky_corr_constrain(size_t K)
Return the next Cholesky factor for a correlation matrix with the specified dimensionality, reading from an unconstrained vector of the appropriate size.
Definition: reader.hpp:1036
T prob()
Return the next scalar, checking that it is a valid value for a probability, between 0 (inclusive) an...
Definition: reader.hpp:687
vector_t positive_ordered_constrain(size_t k, T &lp)
Return the next positive_ordered vector of the specified size, incrementing the specified reference w...
Definition: reader.hpp:949
row_vector_t row_vector_ub_constrain(const TU ub, size_t m, T &lp)
Definition: reader.hpp:1272
T scalar_lub(const TL lb, const TU ub)
Return the next scalar, checking that it is between the specified lower and upper bound...
Definition: reader.hpp:636
row_vector_t row_vector_lb_constrain(const TL lb, size_t m, T &lp)
Definition: reader.hpp:1195
matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n)
Definition: reader.hpp:1212
vector_t vector_ub_constrain(const TU ub, size_t m)
Definition: reader.hpp:1239
vector_t vector_constrain(size_t m, T &)
Return a column vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:230

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