Skip to content

Commit 58426a0

Browse files
authored
Merge pull request #1321 from stan-dev/fix/diagnose-num-chains
Fix/diagnose num chains
2 parents fc3300c + c7bf5f1 commit 58426a0

File tree

5 files changed

+552
-1
lines changed

5 files changed

+552
-1
lines changed

src/cmdstan/diagnose.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(int argc, const char *argv[]) {
7676
stan::io::stan_csv_metadata metadata = csv_parsed[0].metadata;
7777
std::vector<std::string> param_names = csv_parsed[0].header;
7878
size_t num_params = param_names.size();
79-
int num_samples = chains.num_samples();
79+
int num_samples = chains.num_samples() * chains.num_chains();
8080
std::vector<std::string> bad_n_eff_names;
8181
std::vector<std::string> bad_rhat_names;
8282
bool has_errors = false;

src/test/interface/diagnose_test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,20 @@ TEST(CommandDiagnose, mix) {
9696
ss << expected_output.rdbuf();
9797
EXPECT_EQ(1, count_matches(ss.str(), out.output));
9898
}
99+
100+
TEST(CommandDiagnose, divergences) {
101+
std::string path_separator;
102+
path_separator.push_back(get_path_separator());
103+
std::string command = "bin" + path_separator + "diagnose";
104+
std::string csv_file = "src" + path_separator + "test" + path_separator
105+
+ "interface" + path_separator + "example_output"
106+
+ path_separator + "div_output*.csv";
107+
108+
run_command_output out = run_command(command + " " + csv_file);
109+
ASSERT_FALSE(out.hasError) << "\"" << out.command << "\" quit with an error";
110+
111+
std::ifstream expected_output("src/test/interface/example_output/div.nom");
112+
std::stringstream ss;
113+
ss << expected_output.rdbuf();
114+
EXPECT_EQ(1, count_matches(ss.str(), out.output));
115+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Checking sampler transitions treedepth.
2+
Treedepth satisfactory for all transitions.
3+
4+
Checking sampler transitions for divergences.
5+
77 of 400 (19.25%) transitions ended with a divergence.
6+
These divergent transitions indicate that HMC is not fully able to explore the posterior distribution.
7+
Try increasing adapt delta closer to 1.
8+
If this doesn't remove all divergences, try to reparameterize the model.
9+
10+
Checking E-BFMI - sampler transitions HMC potential energy.
11+
E-BFMI satisfactory.
12+
13+
Rank-normalized split effective sample size satisfactory for all parameters.
14+
15+
The following parameters had rank-normalized split R-hat greater than 1.01:
16+
x[1], x[2], x[3], x[4], x[5]
17+
Such high values indicate incomplete mixing and biased estimation.
18+
You should consider regularizating your model with additional prior information or a more effective parameterization.
19+
20+
Processing complete.

0 commit comments

Comments
 (0)