Hmc Checker [portable] File

# 2. ESS / total samples ess = az.ess(inference_data).to_array().values n_samples = inference_data.posterior.sizes["draw"] n_chains = inference_data.posterior.sizes["chain"] total_samples = n_samples * n_chains

print("HMC Checker Report") print("=" * 40) print(f"Overall status: {'✅ PASS' if report['passed'] else '❌ FAIL'}") if report["warnings"]: print("\n⚠️ Warnings:") for w in report["warnings"]: print(f" - {w}") if report["failures"]: print("\n❌ Failures:") for f in report["failures"]: print(f" - {f}") You could also wrap it as: hmc checker

# For demo, create dummy data import pymc as pm with pm.Model(): x = pm.Normal("x") trace = pm.sample(1000, chains=2, return_inferencedata=True) R-hat rhat = az

# 4. Tree depth if hasattr(inference_data, "sample_stats") and hasattr(inference_data.sample_stats, "tree_depth"): depths = inference_data.sample_stats.tree_depth.values max_depth = np.max(depths) # depends on sampler # typical max depth is 10 at_max = (depths == max_depth).mean() if at_max > max_tree_depth_fraction: results["warnings"].append(f"Frequent max tree depth ({at_max:.2f})") rhat_threshold): results["failures"].append(f"R-hat &gt

# 1. R-hat rhat = az.rhat(inference_data).to_array().values if np.any(rhat > rhat_threshold): results["failures"].append(f"R-hat > {rhat_threshold} for some parameters") results["passed"] = False

# 6. Energy plot check (text summary) if hasattr(inference_data, "sample_stats") and hasattr(inference_data.sample_stats, "energy"): energy = inference_data.sample_stats.energy.values # simple check: coefficient of variation across chains chain_means = energy.mean(axis=1) cv = np.std(chain_means) / np.mean(chain_means) if cv > 0.1: results["warnings"].append(f"Energy means vary across chains (CV={cv:.3f})")