Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmdstan/diagnose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main(int argc, const char *argv[]) {
stan::io::stan_csv_metadata metadata = csv_parsed[0].metadata;
std::vector<std::string> param_names = csv_parsed[0].header;
size_t num_params = param_names.size();
int num_samples = chains.num_samples();
int num_samples = chains.num_samples() * chains.num_chains();
std::vector<std::string> bad_n_eff_names;
std::vector<std::string> bad_rhat_names;
bool has_errors = false;
Expand Down
17 changes: 17 additions & 0 deletions src/test/interface/diagnose_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,20 @@ TEST(CommandDiagnose, mix) {
ss << expected_output.rdbuf();
EXPECT_EQ(1, count_matches(ss.str(), out.output));
}

TEST(CommandDiagnose, divergences) {
std::string path_separator;
path_separator.push_back(get_path_separator());
std::string command = "bin" + path_separator + "diagnose";
std::string csv_file = "src" + path_separator + "test" + path_separator
+ "interface" + path_separator + "example_output"
+ path_separator + "div_output*.csv";

run_command_output out = run_command(command + " " + csv_file);
ASSERT_FALSE(out.hasError) << "\"" << out.command << "\" quit with an error";

std::ifstream expected_output("src/test/interface/example_output/div.nom");
std::stringstream ss;
ss << expected_output.rdbuf();
EXPECT_EQ(1, count_matches(ss.str(), out.output));
}
20 changes: 20 additions & 0 deletions src/test/interface/example_output/div.nom
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Checking sampler transitions treedepth.
Treedepth satisfactory for all transitions.

Checking sampler transitions for divergences.
77 of 400 (19.25%) transitions ended with a divergence.
These divergent transitions indicate that HMC is not fully able to explore the posterior distribution.
Try increasing adapt delta closer to 1.
If this doesn't remove all divergences, try to reparameterize the model.

Checking E-BFMI - sampler transitions HMC potential energy.
E-BFMI satisfactory.

Rank-normalized split effective sample size satisfactory for all parameters.

The following parameters had rank-normalized split R-hat greater than 1.01:
x[1], x[2], x[3], x[4], x[5]
Such high values indicate incomplete mixing and biased estimation.
You should consider regularizating your model with additional prior information or a more effective parameterization.

Processing complete.
Loading