Skip to content

Commit

Permalink
Merge branch 'feature/3299-chainset' of https://github.com/stan-dev/stan
Browse files Browse the repository at this point in the history
 into feature/3299-chainset
  • Loading branch information
mitzimorris committed Oct 18, 2024
2 parents 65f1c57 + 9fed191 commit c55f787
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/stan/analyze/mcmc/split_rank_normalized_ess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ double ess(const Eigen::MatrixXd& chains) {
// compute the per-chain autocovariance
for (size_t i = 0; i < num_chains; ++i) {
chain_mean(i) = chains.col(i).mean();
Eigen::Map<const Eigen::VectorXd> draw_col(chains.col(i).data(),
num_draws);
Eigen::Map<const Eigen::VectorXd> draw_col(chains.col(i).data(), num_draws);
Eigen::VectorXd cov_col(num_draws);
autocovariance<double>(draw_col, cov_col);
acov.col(i) = cov_col;
Expand Down
16 changes: 9 additions & 7 deletions src/test/unit/analyze/mcmc/split_rank_normalized_ess_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <string>
#include <cmath>


TEST(RankNormalizedEss, test_basic_bulk_tail_ess) {
std::stringstream out;
Eigen::MatrixXd chains_lp(1000, 4);
Expand All @@ -19,9 +18,11 @@ TEST(RankNormalizedEss, test_basic_bulk_tail_ess) {

for (size_t i = 0; i < 4; ++i) {
std::stringstream fname;
fname << "src/test/unit/analyze/mcmc/test_csv_files/bern" << (i + 1) << ".csv";
fname << "src/test/unit/analyze/mcmc/test_csv_files/bern" << (i + 1)
<< ".csv";
std::ifstream bern_stream(fname.str(), std::ifstream::in);
stan::io::stan_csv bern_csv = stan::io::stan_csv_reader::parse(bern_stream, &out);
stan::io::stan_csv bern_csv
= stan::io::stan_csv_reader::parse(bern_stream, &out);
bern_stream.close();
chains_lp.col(i) = bern_csv.samples.col(0);
chains_theta.col(i) = bern_csv.samples.col(7);
Expand All @@ -36,13 +37,15 @@ TEST(RankNormalizedEss, test_basic_bulk_tail_ess) {
double ess_theta_expect = 1377.503;
double ess_theta_bulk_expect = 1407.5124;
double ess_theta_tail_expect = 1291.7131;

auto ess_basic_lp = stan::analyze::ess(chains_lp);
auto old_ess_basic_lp = stan::analyze::compute_effective_sample_size(draws_lp, sizes);
auto old_ess_basic_lp
= stan::analyze::compute_effective_sample_size(draws_lp, sizes);
auto ess_lp = stan::analyze::split_rank_normalized_ess(chains_lp);

auto ess_basic_theta = stan::analyze::ess(chains_theta);
auto old_ess_basic_theta = stan::analyze::compute_effective_sample_size(draws_theta, sizes);
auto old_ess_basic_theta
= stan::analyze::compute_effective_sample_size(draws_theta, sizes);
auto ess_theta = stan::analyze::split_rank_normalized_ess(chains_theta);

EXPECT_NEAR(ess_lp_expect, ess_basic_lp, 0.001);
Expand All @@ -58,7 +61,6 @@ TEST(RankNormalizedEss, test_basic_bulk_tail_ess) {
EXPECT_NEAR(ess_theta_tail_expect, ess_theta.second, 0.001);
}


TEST(RankNormalizedEss, short_chains_fail) {
std::stringstream out;
std::ifstream eight_schools_5iters_1_stream, eight_schools_5iters_2_stream;
Expand Down

0 comments on commit c55f787

Please sign in to comment.