1 #ifndef STAN__COMMAND__PRINT_HPP
2 #define STAN__COMMAND__PRINT_HPP
18 else if (abs_value >= 1) {
20 width = int_part >= sig_figs ? int_part : sig_figs + 1;
21 precision = int_part >= sig_figs ? 0 : sig_figs - int_part;
25 width = 1 + frac_part + sig_figs;
26 precision = frac_part + sig_figs - 1;
29 if (value < 0) ++width;
55 const std::string& name,
57 std::ios_base::fmtflags& format) {
62 size_t fixed_threshold = 8;
63 size_t max_fixed_width = 0;
65 for (
int i = 0; i < x.size(); ++i) {
67 max_fixed_width = width > max_fixed_width ? width : max_fixed_width;
70 if (max_fixed_width + padding < fixed_threshold) {
71 format = std::ios_base::fixed;
72 max_fixed_width = name.length() > max_fixed_width ? name.length() : max_fixed_width;
73 return max_fixed_width + padding;
77 size_t scientific_width = sig_figs + 1 + 4;
78 if (x.minCoeff() < 0) ++scientific_width;
80 scientific_width = name.length() > scientific_width ? name.length() : scientific_width;
82 format = std::ios_base::scientific;
83 return scientific_width + padding;
88 const Eigen::Matrix<std::string, Eigen::Dynamic, 1>& headers,
90 Eigen::Matrix<std::ios_base::fmtflags, Eigen::Dynamic, 1>& formats) {
91 int n = values.cols();
92 Eigen::VectorXi column_widths(n);
94 for (
int i = 0; i < n; i++) {
102 std::cout <<
"USAGE: print <filename 1> [<filename 2> ... <filename N>]"
106 std::cout <<
"OPTIONS:" << std::endl << std::endl;
107 std::cout <<
" --autocorr=<chain_index>\tAppend the autocorrelations for the given chain"
110 std::cout <<
" --sig_figs=<int>\tSet significant figures of output (Defaults to 2)"
117 return (parameter_name.find(
"[") != std::string::npos);
122 return name.substr(0, name.find(
"["));
127 return name.substr(name.find(
"["));
131 std::vector<int>
dims;
135 int last_matrix_element = start_index;
136 while (last_matrix_element+1 < chains.
num_params()) {
138 last_matrix_element++;
143 std::stringstream ss(
matrix_index(chains, last_matrix_element));
148 while (ss.get() ==
',') {
157 if (dims.size() != index.size())
158 throw std::domain_error(
"next_index: size mismatch");
159 if (dims.size() == 0)
161 index[index.size()-1]++;
163 for (
int i = index.size()-1; i > 0; i--) {
164 if (index[i] > dims[i]) {
170 for (
size_t n = 0; n < dims.size(); n++) {
171 if (index[n] <= 0 || index[n] > dims[n]) {
172 std::stringstream message_stream(
"");
173 message_stream <<
"next_index: index[" << n <<
"] out of bounds. "
174 <<
"dims[" << n <<
"] = " << dims[n] <<
"; "
175 <<
"index[" << n <<
"] = " << index[n];
176 throw std::domain_error(message_stream.str());
184 if (dims.size() != index.size())
185 throw std::domain_error(
"next_index: size mismatch");
186 if (dims.size() == 0)
188 for (
size_t n = 0; n < dims.size(); n++) {
189 if (index[n] <= 0 || index[n] > dims[n]) {
190 std::stringstream message_stream(
"");
191 message_stream <<
"matrix_index: index[" << n <<
"] out of bounds. "
192 <<
"dims[" << n <<
"] = " << dims[n] <<
"; "
193 <<
"index[" << n <<
"] = " << index[n];
194 throw std::domain_error(message_stream.str());
200 for (
size_t i = 0; i < dims.size(); i++) {
201 offset += (index[i]-1) * prod;
fvar< T > fabs(const fvar< T > &x)
const std::string & param_name(int j) const
std::vector< int > dimensions(stan::mcmc::chains<> &chains, const int start_index)
void compute_width_and_precision(double value, int sig_figs, int &width, int &precision)
fvar< T > floor(const fvar< T > &x)
fvar< T > ceil(const fvar< T > &x)
void dims(const T &x, std::vector< int > &result)
std::string matrix_index(stan::mcmc::chains<> &chains, const int index)
Eigen::VectorXi calculate_column_widths(const Eigen::MatrixXd &values, const Eigen::Matrix< std::string, Eigen::Dynamic, 1 > &headers, const int sig_figs, Eigen::Matrix< std::ios_base::fmtflags, Eigen::Dynamic, 1 > &formats)
int compute_precision(double value, int sig_figs, bool scientific)
T prod(const std::vector< T > &v)
Returns the product of the coefficients of the specified standard vector.
An mcmc::chains object stores parameter names and dimensionalities along with samples from multiple c...
std::string base_param_name(stan::mcmc::chains<> &chains, const int index)
double e()
Return the base of the natural logarithm.
int compute_width(double value, int sig_figs)
bool is_matrix(const std::string ¶meter_name)
int calculate_column_width(const Eigen::VectorXd &x, const std::string &name, const int sig_figs, std::ios_base::fmtflags &format)
void next_index(std::vector< int > &index, const std::vector< int > &dims)
fvar< T > log10(const fvar< T > &x)