Run one complete analysis
Load a CSV and JDM file, compile the model, customize NUTS, run four chains, print diagnostics, plot convergence, summarize the posterior, and reach a conclusion.
Follow the worked analysis →One-stop MCMC learning center · 0.8.0+
You do not need to read every page or know Stan. Pick the route that matches how you want to define a model; return here later for examples, diagnostics, and advanced topics.
Java models · RJMCMC · JDM scripts · Stan source · MCMC reviewStart here
Load a CSV and JDM file, compile the model, customize NUTS, run four chains, print diagnostics, plot convergence, summarize the posterior, and reach a conclusion.
Follow the worked analysis →Use ModelBuilder, constraints, and model factors directly, then send the resulting BayesianModel through the same samplers and diagnostics.
Move between genuinely different parameter dimensions with Java-only add/drop/swap proposals, scale to sparse candidate universes, inspect inclusion mixing, export ragged draws, and resume exact checkpoints.
Open the reversible-jump route →Find runnable examples for MCMC, distributions, copulas, mixtures, transformations, custom laws, FDR, numerical solvers, and autodiff.
Choose an example catalog →Learn data binding and compilation, browse JDM and ordinary .stan models, or follow focused container, function, and solver tutorials.
Start with introductory material instead of jumping into compatibility tables. JDM is Stan-inspired, but using the pure-Java route requires no Stan knowledge.
Open beginner resources →Choose samplers and metrics, interpret R-hat/ESS/MCSE, investigate divergences, review plots, checkpoint runs, and inspect modern MCMC features.
Open review resources →Route A · recommended quick start
WorkedMcmcCsvJdmExample.java is a deliberately verbose, line-by-line-commented Java program. It uses the checked-in CSV dataset and JDM model, so it runs without downloads or editing.
y CSV column into a primitive double[].N/y, call ModelScript.compile, and check its gradient.P(mu > 0), an exact cross-check, a predictive draw, and a conclusion conditional on convergence.double[] y = readNumericColumn(csvPath, "y");
String source = new String(Files.readAllBytes(modelPath), UTF_8);
Map<String, double[]> data = new LinkedHashMap<>();
data.put("N", new double[] {y.length});
data.put("y", y);
CompiledModelScript compiled = ModelScript.compile(source, data);
BayesianModel model = compiled.model();
SamplingOptions options = SamplingOptions.builder()
.warmupIterations(600).sampleIterations(1200)
.targetAcceptance(0.90).maximumTreeDepth(11)
.adaptMassMatrix(true).denseMassMatrix(false).build();
ChainResult[] chains = Chains.parallel(
new NoUTurnSampler(), model, initialStates,
options, BASE_SEED, 4);
McmcDiagnosticReport report = McmcDiagnostics.analyze(
new String[] {"mu"}, chains);
From the repository root, compile the packaged JAR and examples with ./gradlew compileDocumentationExamples on macOS/Linux or gradlew.bat compileDocumentationExamples on Windows. The classpath wildcard deliberately remains valid when the project version changes.
macOS/Linux:
java -cp "build/libs/*:build/documentation-examples" \
examples.WorkedMcmcCsvJdmExampleWindows:
java -cp "build\libs\*;build\documentation-examples" examples.WorkedMcmcCsvJdmExampleOptional arguments are CSV_PATH JDM_PATH OUTPUT_DIRECTORY. The default output directory contains mu-trace.svg, mu-ranks.svg, mu-autocorrelation.svg, energy.svg, retained-draws.csv, diagnostics.json, and a self-contained report.html.
For the checked-in data, the seeded run has a posterior mean near 0.22, posterior SD near 0.35, and a 95% interval crossing zero. The example first verifies chain status, R-hat, ESS, divergences, depth, E-BFMI, and failures; only then does it conclude that computation is healthy but the data do not establish the sign of the mean.
Route B · pure Java
McmcWorkflowExamples.java constructs a beta-binomial model entirely with Java objects. The model definition changes, but gradient checking, SamplingOptions, parallel chains, diagnostics, and graph exports are the same.
BayesianModel model = new ModelBuilder()
.data("n", 10).data("y", 7)
.parameter("theta", Constraints.bounded(0, 1), 0.5)
.factor("prior", new String[] {"theta"},
ModelFactors.betaPrior("theta", 2, 2))
.factor("likelihood", new String[] {"n", "y", "theta"},
ModelFactors.binomialObservation("y", "n", "theta"))
.build();Use this route when models are assembled dynamically, data already live in Java services, or your team prefers compiler-checked Java APIs. For a CSV array bound to both the Java builder and JDM frontend, see McmcDataIngestionExamples.java. Continue with the model-layer reference and ModelBuilder JavaDoc.
Route C · trans-dimensional Java · expanded in 0.9.1
JDistlib’s Java-only RJMCMC layer stores variable-length parameter states. The general engine accounts for forward and reverse proposal densities, boundary-dependent move-selection probabilities, dimension matching, and Jacobians. The additive sparse-subset engine uses sorted integer indices when the candidate universe is much larger than a bit mask.
Follow a normalized linear-regression target through four add/drop/swap chains, model and inclusion diagnostics, ragged export, and exact checkpoint continuation.
Read the worked RJMCMC example →Download GSE93272, fit a subject random-intercept model, use GPU-assisted residual proposals, and continue bounded segments safely after reboots.
Read the sparse public-data tutorial →Use RJMCMC for genuine shape changes such as variable selection, change points, mixture components, or split/merge constructions. Use fixed-dimensional indicators when padding is simpler.
Review the RJMCMC contract →Route D · examples by feature
Browse ordinary Java integrations plus the JDM and Stan fixture catalogs. Filter by copula, mixture, transformation, FDR, custom distribution, MCMC, numerical integration, autodiff, or solvers.
Browse all feature examples →Study conjugate models, regression, hierarchy, robust likelihoods, difficult geometry, multimodality, simplexes, Gibbs updates, and dense metrics as named executable tests.
Browse the Bayesian showcase →For an applied narrative rather than an API catalog, use the posterior-prediction vignette or the difficult-chain diagnostics vignette.
Route E · JDM and Stan source
Bind CSV-derived arrays and compare in-memory, cached, and ahead-of-time compilation.
Open the JDM tutorial →Find regression, count, robust, survival, Wiener reaction-time, constraints, control flow, file-backed data, and generated quantities.
Browse JDM examples →Inspect arrays, matrices, tuples, functions, sparse kernels, solvers, and probability models compiled by JDistlib.
Browse.stan fixtures →Compare data, compilation, sampling, generated quantities, output, and execution semantics.
Open the Stan-user guide →Learn multidimensional arrays, matrix operations, tuples, overloads, external functions, and probability suffixes.
Containers tutorial →Use Java or script callbacks, sensitivities, stiff integration, and higher-index projection.
Solver tutorial →No Stan background required
Begin with the complete JDM quick start or avoid scripts with the pure-Java route. Then read the JDM data and compilation tutorial; it explains the blocks in the context of runnable Java.
The official Stan project maintains a curated introductory tutorials page. Continue with its User’s Guide for example models and programming techniques, then return to JDistlib’s migration guide.
Tune, diagnose, and extend
Review warmup, metrics, R-hat, ESS, MCSE, divergences, tree depth, E-BFMI, plots, performance, checkpoints, and failures.
Open inference reference →Use trace, rank, pairs, and energy evidence to distinguish too few draws from difficult geometry.
Open diagnostics vignette →Read about staged warmup, metrics, exact NUTS checkpoints, adjusted MCLMC, additional kernels, streaming, and future work.
Modern MCMC guide →