Stan  1.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>
6 
7 namespace stan {
8 
9  namespace io {
10 
11 
33  template <typename T>
34  class reader {
35 
36  private:
37 
38  std::vector<T>& data_r_;
39  std::vector<int>& data_i_;
40  size_t pos_;
41  size_t int_pos_;
42 
43  inline T& scalar_ptr() {
44  return data_r_.at(pos_);
45  }
46 
47  inline T& scalar_ptr_increment(size_t m) {
48  pos_ += m;
49  return data_r_.at(pos_ - m);
50  }
51 
52  inline int& int_ptr() {
53  return data_i_.at(int_pos_);
54  }
55 
56  inline int& int_ptr_increment(size_t m) {
57  int_pos_ += m;
58  return data_i_.at(int_pos_ - m);
59  }
60 
61  public:
62 
63  typedef Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> matrix_t;
64  typedef Eigen::Matrix<T,Eigen::Dynamic,1> vector_t;
65  typedef Eigen::Matrix<T,1,Eigen::Dynamic> row_vector_t;
66 
67  typedef Eigen::Map<matrix_t> map_matrix_t;
68  typedef Eigen::Map<vector_t> map_vector_t;
69  typedef Eigen::Map<row_vector_t> map_row_vector_t;
70 
71 
83  reader(std::vector<T>& data_r,
84  std::vector<int>& data_i)
85  : data_r_(data_r),
86  data_i_(data_i),
87  pos_(0),
88  int_pos_(0) {
89  }
90 
94  ~reader() { }
95 
101  inline size_t available() {
102  return data_r_.size() - pos_;
103  }
104 
110  inline size_t available_i() {
111  return data_i_.size() - int_pos_;
112  }
113 
119  inline int integer() {
120  if (int_pos_ >= data_i_.size())
121  BOOST_THROW_EXCEPTION(
122  std::runtime_error("no more integers to read."));
123  return data_i_[int_pos_++];
124  }
125 
133  inline int integer_constrain() {
134  return integer();
135  }
136 
144  inline int integer_constrain(T& log_prob) {
145  return integer();
146  }
147 
148 
149 
155  inline T scalar() {
156  if (pos_ >= data_r_.size())
157  BOOST_THROW_EXCEPTION(std::runtime_error("no more scalars to read"));
158  return data_r_[pos_++];
159  }
160 
167  inline T scalar_constrain() {
168  return scalar();
169  }
170 
182  T scalar_constrain(T& log_prob) {
183  return scalar();
184  }
185 
186 
194  inline std::vector<T> std_vector(size_t m) {
195  std::vector<T> vec;
196  T& start = scalar_ptr_increment(m);
197  vec.insert(vec.begin(), &start, &scalar_ptr());
198  return vec;
199  }
200 
208  inline vector_t vector(size_t m) {
209  return map_vector_t(&scalar_ptr_increment(m),m);
210  }
218  inline vector_t vector_constrain(size_t m) {
219  return map_vector_t(&scalar_ptr_increment(m),m);
220  }
229  inline vector_t vector_constrain(size_t m, T& lp) {
230  return map_vector_t(&scalar_ptr_increment(m),m);
231  }
232 
233 
234 
242  inline row_vector_t row_vector(size_t m) {
243  return map_row_vector_t(&scalar_ptr_increment(m),m);
244  }
245 
254  return map_row_vector_t(&scalar_ptr_increment(m),m);
255  }
256 
266  inline row_vector_t row_vector_constrain(size_t m, T& lp) {
267  return map_row_vector_t(&scalar_ptr_increment(m),m);
268  }
269 
287  inline matrix_t matrix(size_t m, size_t n) {
288  return map_matrix_t(&scalar_ptr_increment(m*n),m,n);
289  }
290 
301  inline matrix_t matrix_constrain(size_t m, size_t n) {
302  return map_matrix_t(&scalar_ptr_increment(m*n),m,n);
303  }
304 
317  inline matrix_t matrix_constrain(size_t m, size_t n, T& lp) {
318  return map_matrix_t(&scalar_ptr_increment(m*n),m,n);
319  }
320 
321 
331  inline int integer_lb(int lb) {
332  int i = integer();
333  if (!(i >= lb))
334  BOOST_THROW_EXCEPTION(
335  std::runtime_error("required value greater than or equal to lb"));
336  return i;
337  }
347  inline int integer_lb_constrain(int lb) {
348  return integer_lb(lb);
349  }
360  inline int integer_lb_constrain(int lb, T& lp) {
361  return integer_lb(lb);
362  }
363 
364 
374  inline int integer_ub(int ub) {
375  int i = integer();
376  if (!(i <= ub))
377  BOOST_THROW_EXCEPTION(
378  std::runtime_error("required value less than or equal to ub"));
379  return i;
380  }
390  inline int integer_ub_constrain(int ub) {
391  return integer_ub(ub);
392  }
403  int integer_ub_constrain(int ub, T& lp) {
404  return integer_ub(ub);
405  }
406 
419  inline int integer_lub(int lb, int ub) {
420  // read first to make position deterministic [arbitrary choice]
421  int i = integer();
422  if (lb > ub)
423  BOOST_THROW_EXCEPTION(
424  std::runtime_error("lower bound must be less than or equal to ub"));
425  if (!(i >= lb))
426  BOOST_THROW_EXCEPTION(
427  std::runtime_error("required value greater than or equal to lb"));
428  if (!(i <= ub))
429  BOOST_THROW_EXCEPTION(
430  std::runtime_error("required value less than or equal to ub"));
431  return i;
432  }
443  inline int integer_lub_constrain(int lb, int ub) {
444  return integer_lub(lb,ub);
445  }
457  inline int integer_lub_constrain(int lb, int ub, T& lp) {
458  return integer_lub(lb,ub);
459  }
460 
461 
462 
472  inline T scalar_pos() {
473  T x(scalar());
474  stan::math::check_positive("stan::io::scalar_pos(%1%)", x,
475  "Constrained scalar");
476  return x;
477  }
478 
486  inline T scalar_pos_constrain() {
488  }
489 
500  inline T scalar_pos_constrain(T& lp) {
502  }
503 
516  template <typename TL>
517  inline T scalar_lb(const TL lb) {
518  T x(scalar());
519  stan::math::check_greater_or_equal("stan::io::scalar_lb(%1%)",
520  x, lb, "Constrained scalar");
521  return x;
522  }
523 
535  template <typename TL>
536  inline T scalar_lb_constrain(const TL lb) {
537  return stan::prob::lb_constrain(scalar(),lb);
538  }
539 
551  template <typename TL>
552  inline T scalar_lb_constrain(const TL lb, T& lp) {
553  return stan::prob::lb_constrain(scalar(),lb,lp);
554  }
555 
556 
557 
570  template <typename TU>
571  inline T scalar_ub(TU ub) {
572  T x(scalar());
573  stan::math::check_less_or_equal("stan::io::scalar_ub(%1%)", x, ub, "Constrained scalar");
574  return x;
575  }
576 
588  template <typename TU>
589  inline T scalar_ub_constrain(const TU ub) {
590  return stan::prob::ub_constrain(scalar(),ub);
591  }
592 
604  template <typename TU>
605  inline T scalar_ub_constrain(const TU ub, T& lp) {
606  return stan::prob::ub_constrain(scalar(),ub,lp);
607  }
608 
623  template <typename TL, typename TU>
624  inline T scalar_lub(const TL lb, const TU ub) {
625  T x(scalar());
626  stan::math::check_bounded("stan::io::scalar_lub(%1%)", x, lb, ub, "Constrained scalar");
627  return x;
628  }
629 
643  template <typename TL, typename TU>
644  inline T scalar_lub_constrain(const TL lb, const TU ub) {
645  return stan::prob::lub_constrain(scalar(),lb,ub);
646  }
647 
661  template <typename TL, typename TU>
662  inline T scalar_lub_constrain(TL lb, TU ub, T& lp) {
663  return stan::prob::lub_constrain(scalar(),lb,ub,lp);
664  }
665 
674  inline T prob() {
675  T x(scalar());
676  stan::math::check_bounded("stan::io::prob(%1%)", x, 0, 1, "Constrained probability");
677  return x;
678  }
679 
688  inline T prob_constrain() {
690  }
691 
702  inline T prob_constrain(T& lp) {
703  return stan::prob::prob_constrain(scalar(),lp);
704  }
705 
706 
707 
708 
720  inline T corr() {
721  T x(scalar());
722  stan::math::check_bounded("stan::io::corr(%1%)", x, -1, 1, "Correlation value");
723  return x;
724  }
725 
734  inline T corr_constrain() {
736  }
737 
749  inline T corr_constrain(T& lp) {
750  return stan::prob::corr_constrain(scalar(),lp);
751  }
752 
763  inline vector_t simplex(size_t k) {
764  vector_t theta(vector(k));
765  stan::math::check_simplex("stan::io::simplex(%1%)", theta, "Constrained vector");
766  return theta;
767  }
768 
779  inline
780  Eigen::Matrix<T,Eigen::Dynamic,1> simplex_constrain(size_t k) {
782  }
783 
796  inline vector_t simplex_constrain(size_t k, T& lp) {
797  return stan::prob::simplex_constrain(vector(k-1),lp);
798  }
799 
810  inline vector_t ordered(size_t k) {
811  vector_t x(vector(k));
812  stan::math::check_ordered("stan::io::ordered(%1%)", x, "Constrained vector");
813  return x;
814  }
815 
825  inline vector_t ordered_constrain(size_t k) {
827  }
828 
840  inline vector_t ordered_constrain(size_t k, T& lp) {
842  }
843 
854  inline vector_t positive_ordered(size_t k) {
855  vector_t x(vector(k));
856  stan::math::check_positive_ordered("stan::io::positive_ordered(%1%)", x, "Constrained vector");
857  return x;
858  }
859 
871  }
872 
884  inline vector_t positive_ordered_constrain(size_t k, T& lp) {
886  }
887 
897  inline matrix_t corr_matrix(size_t k) {
898  matrix_t x(matrix(k,k));
899  stan::math::check_corr_matrix("stan::math::corr_matrix(%1%)", x, "Constrained matrix");
900  return x;
901  }
902 
911  inline matrix_t corr_matrix_constrain(size_t k) {
912  return stan::prob::corr_matrix_constrain(vector((k * (k - 1)) / 2),k);
913  }
914 
926  inline matrix_t corr_matrix_constrain(size_t k, T& lp) {
927  return stan::prob::corr_matrix_constrain(vector((k * (k - 1)) / 2),
928  k,lp);
929  }
930 
931 
943  inline matrix_t cov_matrix(size_t k) {
944  matrix_t y(matrix(k,k));
945  stan::math::check_cov_matrix("stan::io::cov_matrix(%1%)", y, "Constrained matrix");
946  return y;
947  }
948 
957  inline matrix_t cov_matrix_constrain(size_t k) {
958  return stan::prob::cov_matrix_constrain(vector(k + (k * (k - 1)) / 2),
959  k);
960  }
961 
973  inline matrix_t cov_matrix_constrain(size_t k, T& lp) {
974  return stan::prob::cov_matrix_constrain(vector(k + (k * (k - 1)) / 2),
975  k,lp);
976  }
977 
978 
979  template <typename TL>
980  inline vector_t vector_lb(const TL lb, size_t m) {
981  vector_t v(m);
982  for (size_t i = 0; i < m; ++i)
983  v(i) = scalar_lb(lb);
984  return v;
985  }
986  template <typename TL>
987  inline vector_t vector_lb_constrain(const TL lb, size_t m) {
988  vector_t v(m);
989  for (size_t i = 0; i < m; ++i)
990  v(i) = scalar_lb_constrain(lb);
991  return v;
992  }
993  template <typename TL>
994  inline vector_t vector_lb_constrain(const TL lb, size_t m, T& lp) {
995  vector_t v(m);
996  for (size_t i = 0; i < m; ++i)
997  v(i) = scalar_lb_constrain(lb,lp);
998  return v;
999  }
1000 
1001  template <typename TL>
1002  inline row_vector_t row_vector_lb(const TL lb, size_t m) {
1003  row_vector_t v(m);
1004  for (size_t i = 0; i < m; ++i)
1005  v(i) = scalar_lb(lb);
1006  return v;
1007  }
1008  template <typename TL>
1009  inline row_vector_t row_vector_lb_constrain(const TL lb, size_t m) {
1010  row_vector_t v(m);
1011  for (size_t i = 0; i < m; ++i)
1012  v(i) = scalar_lb_constrain(lb);
1013  return v;
1014  }
1015  template <typename TL>
1016  inline row_vector_t row_vector_lb_constrain(const TL lb, size_t m, T& lp) {
1017  row_vector_t v(m);
1018  for (size_t i = 0; i < m; ++i)
1019  v(i) = scalar_lb_constrain(lb,lp);
1020  return v;
1021  }
1022 
1023  template <typename TL>
1024  inline matrix_t matrix_lb(const TL lb, size_t m, size_t n) {
1025  matrix_t v(m,n);
1026  for (size_t i = 0; i < m; ++i)
1027  for (size_t j = 0; j < n; ++j)
1028  v(i,j) = scalar_lb(lb);
1029  return v;
1030  }
1031  template <typename TL>
1032  inline matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n) {
1033  matrix_t v(m,n);
1034  for (size_t i = 0; i < m; ++i)
1035  for (size_t j = 0; j < n; ++j)
1036  v(i,j) = scalar_lb_constrain(lb);
1037  return v;
1038  }
1039  template <typename TL>
1040  inline matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n, T& lp) {
1041  matrix_t v(m,n);
1042  for (size_t i = 0; i < m; ++i)
1043  for (size_t j = 0; j < n; ++j)
1044  v(i,j) = scalar_lb_constrain(lb,lp);
1045  return v;
1046  }
1047 
1048 
1049 
1050  template <typename TU>
1051  inline vector_t vector_ub(const TU ub, size_t m) {
1052  vector_t v(m);
1053  for (size_t i = 0; i < m; ++i)
1054  v(i) = scalar_ub(ub);
1055  return v;
1056  }
1057  template <typename TU>
1058  inline vector_t vector_ub_constrain(const TU ub, size_t m) {
1059  vector_t v(m);
1060  for (size_t i = 0; i < m; ++i)
1061  v(i) = scalar_ub_constrain(ub);
1062  return v;
1063  }
1064  template <typename TU>
1065  inline vector_t vector_ub_constrain(const TU ub, size_t m, T& lp) {
1066  vector_t v(m);
1067  for (size_t i = 0; i < m; ++i)
1068  v(i) = scalar_ub_constrain(ub,lp);
1069  return v;
1070  }
1071 
1072  template <typename TU>
1073  inline row_vector_t row_vector_ub(const TU ub, size_t m) {
1074  row_vector_t v(m);
1075  for (size_t i = 0; i < m; ++i)
1076  v(i) = scalar_ub(ub);
1077  return v;
1078  }
1079  template <typename TU>
1080  inline row_vector_t row_vector_ub_constrain(const TU ub, size_t m) {
1081  row_vector_t v(m);
1082  for (size_t i = 0; i < m; ++i)
1083  v(i) = scalar_ub_constrain(ub);
1084  return v;
1085  }
1086  template <typename TU>
1087  inline row_vector_t row_vector_ub_constrain(const TU ub, size_t m, T& lp) {
1088  row_vector_t v(m);
1089  for (size_t i = 0; i < m; ++i)
1090  v(i) = scalar_ub_constrain(ub,lp);
1091  return v;
1092  }
1093 
1094  template <typename TU>
1095  inline matrix_t matrix_ub(const TU ub, size_t m, size_t n) {
1096  matrix_t v(m,n);
1097  for (size_t i = 0; i < m; ++i)
1098  for (size_t j = 0; j < n; ++j)
1099  v(i,j) = scalar_ub(ub);
1100  return v;
1101  }
1102  template <typename TU>
1103  inline matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n) {
1104  matrix_t v(m,n);
1105  for (size_t i = 0; i < m; ++i)
1106  for (size_t j = 0; j < n; ++j)
1107  v(i,j) = scalar_ub_constrain(ub);
1108  return v;
1109  }
1110  template <typename TU>
1111  inline matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n, T& lp) {
1112  matrix_t v(m,n);
1113  for (size_t i = 0; i < m; ++i)
1114  for (size_t j = 0; j < n; ++j)
1115  v(i,j) = scalar_ub_constrain(ub,lp);
1116  return v;
1117  }
1118 
1119 
1120  template <typename TL, typename TU>
1121  inline vector_t vector_lub(const TL lb, const TU ub, size_t m) {
1122  vector_t v(m);
1123  for (size_t i = 0; i < m; ++i)
1124  v(i) = scalar_lub(lb,ub);
1125  return v;
1126  }
1127  template <typename TL, typename TU>
1128  inline vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m) {
1129  vector_t v(m);
1130  for (size_t i = 0; i < m; ++i)
1131  v(i) = scalar_lub_constrain(lb,ub);
1132  return v;
1133  }
1134  template <typename TL, typename TU>
1135  inline vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m, T& lp) {
1136  vector_t v(m);
1137  for (size_t i = 0; i < m; ++i)
1138  v(i) = scalar_lub_constrain(lb,ub,lp);
1139  return v;
1140  }
1141 
1142  template <typename TL, typename TU>
1143  inline row_vector_t row_vector_lub(const TL lb, const TU ub, size_t m) {
1144  row_vector_t v(m);
1145  for (size_t i = 0; i < m; ++i)
1146  v(i) = scalar_lub(lb,ub);
1147  return v;
1148  }
1149  template <typename TL, typename TU>
1150  inline row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m) {
1151  row_vector_t v(m);
1152  for (size_t i = 0; i < m; ++i)
1153  v(i) = scalar_lub_constrain(lb,ub);
1154  return v;
1155  }
1156  template <typename TL, typename TU>
1157  inline row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m, T& lp) {
1158  row_vector_t v(m);
1159  for (size_t i = 0; i < m; ++i)
1160  v(i) = scalar_lub_constrain(lb,ub,lp);
1161  return v;
1162  }
1163 
1164  template <typename TL, typename TU>
1165  inline matrix_t matrix_lub(const TL lb, const TU ub, size_t m, size_t n) {
1166  matrix_t v(m,n);
1167  for (size_t i = 0; i < m; ++i)
1168  for (size_t j = 0; j < n; ++j)
1169  v(i,j) = scalar_lub(lb,ub);
1170  return v;
1171  }
1172  template <typename TL, typename TU>
1173  inline matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n) {
1174  matrix_t v(m,n);
1175  for (size_t i = 0; i < m; ++i)
1176  for (size_t j = 0; j < n; ++j)
1177  v(i,j) = scalar_lub_constrain(lb,ub);
1178  return v;
1179  }
1180  template <typename TL, typename TU>
1181  inline matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n, T& lp) {
1182  matrix_t v(m,n);
1183  for (size_t i = 0; i < m; ++i)
1184  for (size_t j = 0; j < n; ++j)
1185  v(i,j) = scalar_lub_constrain(lb,ub,lp);
1186  return v;
1187  }
1188 
1189 
1190 
1191  };
1192 
1193  }
1194 
1195 }
1196 
1197 #endif
A stream-based reader for integer, scalar, vector, matrix and array data types, with Jacobian calcula...
Definition: reader.hpp:34
row_vector_t row_vector_lb_constrain(const TL lb, size_t m, T &lp)
Definition: reader.hpp:1016
Eigen::Map< matrix_t > map_matrix_t
Definition: reader.hpp:67
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:702
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:644
Eigen::Map< vector_t > map_vector_t
Definition: reader.hpp:68
matrix_t matrix_lub(const TL lb, const TU ub, size_t m, size_t n)
Definition: reader.hpp:1165
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:624
T scalar_constrain()
Return the next scalar.
Definition: reader.hpp:167
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:331
int integer_ub_constrain(int ub, T &lp)
Return the next integer, checking that it is less than or equal to the specified upper bound.
Definition: reader.hpp:403
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:973
Eigen::Matrix< T, Eigen::Dynamic, 1 > simplex_constrain(size_t k)
Return the next simplex transformed vector of the specified length.
Definition: reader.hpp:780
matrix_t matrix_constrain(size_t m, size_t n, T &lp)
Return a matrix of the specified dimensionality made up of the next scalars arranged in column-major ...
Definition: reader.hpp:317
T scalar_ub_constrain(const TU ub)
Return the next scalar transformed to have the specified upper bound.
Definition: reader.hpp:589
matrix_t matrix_ub(const TU ub, size_t m, size_t n)
Definition: reader.hpp:1095
T prob_constrain()
Return the next scalar transformed to be a probability between 0 and 1.
Definition: reader.hpp:688
int integer_lub_constrain(int lb, int ub, T &lp)
Return the next integer, checking that it is less than or equal to the specified upper bound.
Definition: reader.hpp:457
vector_t vector_ub(const TU ub, size_t m)
Definition: reader.hpp:1051
vector_t vector_lb_constrain(const TL lb, size_t m, T &lp)
Definition: reader.hpp:994
vector_t vector_constrain(size_t m)
Return a column vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:218
T scalar_pos_constrain(T &lp)
Return the next scalar transformed to be positive, incrementing the specified reference with the log ...
Definition: reader.hpp:500
T scalar_pos_constrain()
Return the next scalar, transformed to be positive.
Definition: reader.hpp:486
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:605
row_vector_t row_vector_lub(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1143
vector_t vector_constrain(size_t m, T &lp)
Return a column vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:229
size_t available()
Return the number of scalars remaining to be read.
Definition: reader.hpp:101
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:374
vector_t vector_ub_constrain(const TU ub, size_t m)
Definition: reader.hpp:1058
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:517
row_vector_t row_vector_ub_constrain(const TU ub, size_t m, T &lp)
Definition: reader.hpp:1087
~reader()
Destroy this variable reader.
Definition: reader.hpp:94
int integer_lb_constrain(int lb, T &lp)
Return the next integer, checking that it is greater than or equal to the specified lower bound.
Definition: reader.hpp:360
size_t available_i()
Return the number of integers remaining to be read.
Definition: reader.hpp:110
matrix_t cov_matrix(size_t k)
Return the next covariance matrix with the specified dimensionality.
Definition: reader.hpp:943
vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m, T &lp)
Definition: reader.hpp:1135
Eigen::Map< row_vector_t > map_row_vector_t
Definition: reader.hpp:69
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:301
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:194
matrix_t corr_matrix_constrain(size_t k)
Return the next correlation matrix of the specified dimensionality.
Definition: reader.hpp:911
matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n)
Definition: reader.hpp:1032
matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n, T &lp)
Definition: reader.hpp:1181
vector_t vector_ub_constrain(const TU ub, size_t m, T &lp)
Definition: reader.hpp:1065
row_vector_t row_vector_ub(const TU ub, size_t m)
Definition: reader.hpp:1073
T scalar()
Return the next scalar in the sequence.
Definition: reader.hpp:155
T corr_constrain(T &lp)
Return the next scalar transformed to be a (partial) correlation between -1 and 1,...
Definition: reader.hpp:749
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:253
row_vector_t row_vector(size_t m)
Return a row vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:242
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:840
vector_t vector_lb_constrain(const TL lb, size_t m)
Definition: reader.hpp:987
vector_t simplex_constrain(size_t k, T &lp)
Return the next simplex of the specified size (using one fewer unconstrained scalars),...
Definition: reader.hpp:796
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:552
matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n)
Definition: reader.hpp:1173
row_vector_t row_vector_lb(const TL lb, size_t m)
Definition: reader.hpp:1002
Eigen::Matrix< T, 1, Eigen::Dynamic > row_vector_t
Definition: reader.hpp:65
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:347
row_vector_t row_vector_ub_constrain(const TU ub, size_t m)
Definition: reader.hpp:1080
matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n, T &lp)
Definition: reader.hpp:1040
vector_t simplex(size_t k)
Return a simplex of the specified size made up of the next scalars.
Definition: reader.hpp:763
vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1128
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:83
matrix_t corr_matrix(size_t k)
Returns the next correlation matrix of the specified dimensionality.
Definition: reader.hpp:897
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:390
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:571
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:443
T scalar_lb_constrain(const TL lb)
Return the next scalar transformed to have the specified lower bound.
Definition: reader.hpp:536
row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1150
row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m, T &lp)
Definition: reader.hpp:1157
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:926
int integer_constrain(T &log_prob)
Return the next integer in the integer sequence.
Definition: reader.hpp:144
matrix_t cov_matrix_constrain(size_t k)
Return the next covariance matrix of the specified dimensionality.
Definition: reader.hpp:957
row_vector_t row_vector_constrain(size_t m, T &lp)
Return a row vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:266
row_vector_t row_vector_lb_constrain(const TL lb, size_t m)
Definition: reader.hpp:1009
vector_t positive_ordered(size_t k)
Return the next vector of specified size containing positive values in ascending order.
Definition: reader.hpp:854
vector_t vector(size_t m)
Return a column vector of specified dimensionality made up of the next scalars.
Definition: reader.hpp:208
Eigen::Matrix< T, Eigen::Dynamic, 1 > vector_t
Definition: reader.hpp:64
matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n, T &lp)
Definition: reader.hpp:1111
T scalar_pos()
Return the next scalar, checking that it is positive.
Definition: reader.hpp:472
vector_t vector_lub(const TL lb, const TU ub, size_t m)
Definition: reader.hpp:1121
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:884
T prob()
Return the next scalar, checking that it is a valid value for a probability, between 0 (inclusive) an...
Definition: reader.hpp:674
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:662
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > matrix_t
Definition: reader.hpp:63
vector_t ordered_constrain(size_t k)
Return the next ordered vector of the specified length.
Definition: reader.hpp:825
vector_t ordered(size_t k)
Return the next vector of specified size containing values in ascending order.
Definition: reader.hpp:810
vector_t vector_lb(const TL lb, size_t m)
Definition: reader.hpp:980
T corr_constrain()
Return the next scalar transformed to be a correlation between -1 and 1.
Definition: reader.hpp:734
T scalar_constrain(T &log_prob)
Return the next scalar in the sequence, incrementing the specified reference with the log absolute Ja...
Definition: reader.hpp:182
int integer_constrain()
Return the next integer in the integer sequence.
Definition: reader.hpp:133
vector_t positive_ordered_constrain(size_t k)
Return the next positive ordered vector of the specified length.
Definition: reader.hpp:869
int integer()
Return the next integer in the integer sequence.
Definition: reader.hpp:119
T corr()
Return the next scalar, checking that it is a valid value for a correlation, between -1 (inclusive) a...
Definition: reader.hpp:720
matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n)
Definition: reader.hpp:1103
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:419
matrix_t matrix_lb(const TL lb, size_t m, size_t n)
Definition: reader.hpp:1024
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:287
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.
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_greater_or_equal(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result, const Policy &)
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...
bool check_cov_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 covariance matrix.
bool check_less_or_equal(const char *function, const T_y &y, const T_high &high, const char *name, T_result *result, const Policy &)
bool check_bounded(const char *function, const T_y &y, const T_low &low, const T_high &high, const char *name, T_result *result, const Policy &)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
T corr_constrain(const T x)
Return the result of transforming the specified scalar to have a valid correlation value between -1 a...
Definition: transform.hpp:924
Eigen::Matrix< T, Eigen::Dynamic, 1 > positive_ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing positive ordered vector derived from the specified free vector.
Definition: transform.hpp:1175
Eigen::Matrix< T, Eigen::Dynamic, 1 > simplex_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &y)
Return the simplex corresponding to the specified free vector.
Definition: transform.hpp:991
boost::math::tools::promote_args< T, TU >::type ub_constrain(const T x, const TU ub)
Return the upper-bounded value for the specified unconstrained scalar and upper bound.
Definition: transform.hpp:579
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: transform.hpp:1094
T prob_constrain(const T x)
Return a probability value constrained to fall between 0 and 1 (inclusive) for the specified free sca...
Definition: transform.hpp:848
T lb_constrain(const T x, const TL lb)
Return the lower-bounded value for the specified unconstrained input and specified lower bound.
Definition: transform.hpp:496
boost::math::tools::promote_args< T, TL, TU >::type lub_constrain(const T x, TL lb, TU ub)
Return the lower- and upper-bounded scalar derived by transforming the specified free scalar given th...
Definition: transform.hpp:684
T positive_constrain(const T x)
Return the positive value for the specified unconstrained input.
Definition: transform.hpp:423
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > corr_matrix_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, typename Eigen::Matrix< T, Eigen::Dynamic, 1 >::size_type k)
Return the correlation matrix of the specified dimensionality derived from the specified vector of un...
Definition: transform.hpp:1270
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > cov_matrix_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, typename Eigen::Matrix< T, Eigen::Dynamic, 1 >::size_type K)
Return the symmetric, positive-definite matrix of dimensions K by K resulting from transforming the s...
Definition: transform.hpp:1382
Probability, optimization and sampling library.
Definition: agrad.cpp:6

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