Skip to content

Commit

Permalink
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-buildbot committed Aug 2, 2024
1 parent 07f52a4 commit f144ba3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
13 changes: 5 additions & 8 deletions src/stan/analyze/mcmc/split_chains.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace analyze {
* @param index matrix column for parameter of interest
* @return samples matrix, shape (num_iters/2, num_chains*2)
*/
inline Eigen::MatrixXd
split_chains(const std::vector<Eigen::MatrixXd>& chains, const int index) {
inline Eigen::MatrixXd split_chains(const std::vector<Eigen::MatrixXd>& chains,
const int index) {
size_t num_chains = chains.size();
size_t num_samples = chains[0].rows();
size_t half = std::floor(num_samples / 2.0);
Expand All @@ -44,19 +44,17 @@ split_chains(const std::vector<Eigen::MatrixXd>& chains, const int index) {
* @param samples matrix of per-chain samples, shape (num_iters, num_chains)
* @return samples matrix reshaped as (num_iters/2, num_chains*2)
*/
inline Eigen::MatrixXd
split_chains(const Eigen::MatrixXd& samples) {
inline Eigen::MatrixXd split_chains(const Eigen::MatrixXd& samples) {
size_t num_chains = samples.cols();
size_t num_samples = samples.rows();
size_t half = std::floor(num_samples / 2.0);

Eigen::MatrixXd split_draws_matrix(half, num_chains * 2);
int split_i = 0;
for (std::size_t i = 0; i < num_chains; ++i) {
Eigen::Map<const Eigen::VectorXd> head_block(samples.col(i).data(),
Eigen::Map<const Eigen::VectorXd> head_block(samples.col(i).data(), half);
Eigen::Map<const Eigen::VectorXd> tail_block(samples.col(i).data() + half,
half);
Eigen::Map<const Eigen::VectorXd> tail_block(
samples.col(i).data() + half, half);

split_draws_matrix.col(split_i) = head_block;
split_draws_matrix.col(split_i + 1) = tail_block;
Expand All @@ -65,7 +63,6 @@ split_chains(const Eigen::MatrixXd& samples) {
return split_draws_matrix;
}


/**
* Splits each chain into two chains of equal length. When the
* number of total draws N is odd, the (N+1)/2th draw is ignored.
Expand Down
4 changes: 2 additions & 2 deletions src/stan/analyze/mcmc/split_rank_normalized_ess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ double ess(const Eigen::MatrixXd& chains) {
* @param chains matrix of per-chain draws, num_iters X chain
* @return potential scale reduction
*/
inline std::pair<double, double>
split_rank_normalized_ess(const Eigen::MatrixXd& chains) {
inline std::pair<double, double> split_rank_normalized_ess(
const Eigen::MatrixXd& chains) {
Eigen::MatrixXd split_draws_matrix = split_chains(chains);
if (!is_finite_and_varies(split_draws_matrix)
|| split_draws_matrix.rows() < 4) {
Expand Down
4 changes: 2 additions & 2 deletions src/stan/analyze/mcmc/split_rank_normalized_rhat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ inline double rhat(const Eigen::MatrixXd& chains) {
* @param chains matrix of per-chain samples, num_iters X chain
* @return potential scale reduction for the specified parameter
*/
inline std::pair<double, double>
split_rank_normalized_rhat(const Eigen::MatrixXd& chains) {
inline std::pair<double, double> split_rank_normalized_rhat(
const Eigen::MatrixXd& chains) {
Eigen::MatrixXd split_draws_matrix = split_chains(chains);
if (!is_finite_and_varies(split_draws_matrix)) {
return std::make_pair(std::numeric_limits<double>::quiet_NaN(),
Expand Down
30 changes: 13 additions & 17 deletions src/stan/mcmc/chainset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,15 @@ class chainset {

double mean(const std::string& name) const { return mean(index(name)); }

double sd(const int index) const {
return std::sqrt(variance(index));
}
double sd(const int index) const { return std::sqrt(variance(index)); }

double sd(const std::string& name) const { return sd(index(name)); }

double variance(const int index) const {
Eigen::MatrixXd samples = samples(chains_, index);
return (samples.array() - samples.mean()).square().sum() / (samples.size() - 1);
}
return (samples.array() - samples.mean()).square().sum()
/ (samples.size() - 1);
}

double variance(const std::string& name) const {
return variance(index(name));
Expand All @@ -182,7 +181,7 @@ class chainset {
double max_abs_deviation(const int index) const {
Eigen::VectorXd samples = samples(chains_, index);
return (samples.array() - samples.mean()).abs().maxCoeff();
}
}

double max_abs_deviation(const std::string& name) const {
return max_abs_deviation(index(name));
Expand All @@ -191,28 +190,27 @@ class chainset {
double quantile(const int index, const double prob) {
// Ensure the probability is within [0, 1]
if (prob < 0.0 || prob > 1.0) {
throw std::out_of_range("Probability must be between 0 and 1.");
throw std::out_of_range("Probability must be between 0 and 1.");
}
Eigen::MatrixXd samples = samples(chains_, index);
std::vector<double> sorted(samples.data(),
samples.data() + samples.size());
std::vector<double> sorted(samples.data(), samples.data() + samples.size());
std::sort(sorted.begin(), sorted.end());
size_t idx = static_cast<size_t>(prob * (sorted.size() - 1));
return sorted[idx];
}
}

double quantile(const std::string& name, const double prob) const {
return quantile(index(name), prob);
}

Eigen::VectorXd quantiles(const int index, const Eigen::VectorXd& probs) const {
Eigen::VectorXd quantiles(const int index,
const Eigen::VectorXd& probs) const {
// Ensure the probability is within [0, 1]
if (probs.minCoeff() < 0.0 || probs.maxCoeff() > 1.0) {
throw std::out_of_range("Probabilities must be between 0 and 1.");
throw std::out_of_range("Probabilities must be between 0 and 1.");
}
Eigen::MatrixXd samples = samples(chains_, index);
std::vector<double> sorted(samples.data(),
samples.data() + samples.size());
std::vector<double> sorted(samples.data(), samples.data() + samples.size());
std::sort(sorted.begin(), sorted.end());
Eigen::VectorXd quantiles(probs.size());
for (size_t i = 0; i < probs.size(); ++i) {
Expand Down Expand Up @@ -262,9 +260,7 @@ class chainset {
return std::min(ess_s, ess_s2);
}

double mcse_sd(const std::string& name) const {
return mcse_sd(index(name));
}
double mcse_sd(const std::string& name) const { return mcse_sd(index(name)); }
};

} // namespace mcmc
Expand Down

0 comments on commit f144ba3

Please sign in to comment.