Diagnostics vignette · 0.8.0

When a chain runs but the geometry says no

Neal’s funnel shows why successful return status is not enough, and why a parameterization change usually beats tuning harder.

Available in JDistlib 0.8.0

The geometry

A wide mouth narrows into a difficult neck

Let y be normal with standard deviation 3 and x conditional on y be normal with variance exp(y). Negative y compresses x into a narrow neck while positive y permits a wide range. One Euclidean step size must traverse both regions.

DifferentiableLogDensity funnel = (state, gradient) -> {
  double y = state[0], x = state[1];
  double inverseVariance = Math.exp(-y);
  gradient[0] = -y / 9.0 - 0.5
      + 0.5 * x * x * inverseVariance;
  gradient[1] = -x * inverseVariance;
  return -0.5 * y * y / 9.0 - 0.5 * y
      - 0.5 * x * x * inverseVariance;
};

Review

Connect symptoms to evidence

Pairs

See the neck

A y-versus-x scatter reveals the changing scale and where divergent transitions accumulate.

Trace and rank

See unequal exploration

Chains may spend different proportions of time in the neck and mouth.

Energy

See poor transitions

Low E-BFMI indicates that momentum refreshes do not move effectively across energy levels.

McmcDiagnosticReport report = McmcDiagnostics.analyze(
    new String[] {"y", "x"}, chains);
ChartSpec pairs = DiagnosticGraphs.pairs("y", 0, "x", 1, chains);
ChartSpec energy = DiagnosticGraphs.energy(30, chains);
String review = InferenceHtmlReport.render(
    "Funnel review", report, null, pairs, energy);

Response order

Fix meaning and geometry before tuning

  1. Verify the targetCheck gradients, initial density, units, constraints, and prior implications.
  2. ReparameterizeFor hierarchical models, sample standardized latent effects and reconstruct their scale.
  3. Then tuneA higher target acceptance may reduce residual integration error after geometry improves.

Eight schools

Use a non-centered hierarchy

// Sample mu, logTau, and standard-normal z[j].
double tau = Math.exp(logTau);
double thetaJ = mu + tau * z[j];

This formulation decouples latent effects from a weakly identified group scale. The named eight-schools implementation in the example catalog includes the complete analytic gradient, and its test compares that gradient with finite differences.

Decision

Accept a fit only after the second run improves the evidence

Compare divergence counts, maximum depth, minimum E-BFMI, R-hat, bulk/tail ESS, and the same plots after reparameterization. Treat improvement as evidence; do not declare victory solely because one warning disappeared.