Markov Chain Monte Carlo Calculator

Build reliable chains for Boltzmann and Gaussian targets. See acceptance, autocorrelation, and effective sample size. Download tables, validate settings, and compare runs quickly today.

Calculator Inputs

Responsive grid: 3 columns large, 2 medium, 1 small

All targets are sampled up to normalization.
Reported with autocorrelation-aware uncertainty.
Choose near a typical region to reduce burn-in.
Gaussian random-walk proposal: x′ = x + σprop·N(0,1).
After burn-in and thinning are applied.
Discard early states before equilibrium.
Save every k-th step to reduce storage.
Used only for the displayed histogram table.
Set to reproduce the same chain exactly.

Target parameters Only relevant fields are used.

Example Data Table

These example settings illustrate typical stable runs. Your numbers will differ because sampling is stochastic.

Target Key parameters σprop Burn Thin Saved Typical acceptance Typical ⟨x⟩
Harmonic Boltzmann β=1, k=1 1.0 1000 2 5000 35–65% ≈ 0
Double-well Boltzmann β=1, a=1, b=4 0.9 3000 3 8000 25–55% ≈ 0 (symmetric)
Gaussian μ=2, σ=0.7 0.7 800 2 6000 40–70% ≈ 2

Formula Used

This tool uses the Metropolis-Hastings rule to sample a one-dimensional target density p(x).

  • Proposal: x′ = x + σprop·N(0,1)
  • Acceptance probability: α = min(1, p(x′)/p(x))
  • Boltzmann targets: p(x) ∝ exp(−β U(x))

For correlated samples, uncertainty is estimated using the integrated autocorrelation time:

  • τint = 1/2 + Σ ρ(ℓ) (sum stops when ρ becomes non-positive)
  • Neff ≈ N / (2 τint)
  • SE(mean) ≈ √(Var / Neff)

How to Use This Calculator

  1. Select a target distribution and an observable to estimate.
  2. Choose a proposal step size so acceptance stays moderate.
  3. Set burn-in to remove early transient behavior.
  4. Use thinning if you need fewer stored points.
  5. Run the simulation and review τint and Neff.
  6. Download CSV for the full chain or PDF for a report.
Tip: If τint is large, increase steps or improve proposals.

Why Markov chain sampling appears across physics

MCMC is essential when direct sampling is hard but relative probabilities are available. In physics this includes Boltzmann ensembles and Bayesian calibration of models. It is also used in lattice models and rare-event sampling where solutions are unavailable. Correlation can hide under error bars, so diagnostics matter.

Metropolis–Hastings steps implemented by this calculator

The calculator uses a Gaussian random-walk proposal x′ = x + σpropN(0,1) and Metropolis acceptance α = min(1, p(x′)/p(x)). For Boltzmann targets p(x) ∝ exp(−βU(x)), the log ratio is −β[U(x′)−U(x)]. Only ratios are required, so normalization constants never enter the decision.

Using acceptance data to tune the proposal scale

σprop controls exploration. Very small steps give high acceptance (>80%) but slow movement. Very large steps yield frequent rejection (<20%). For many stable 1D cases, 30–70% acceptance balances travel distance and acceptance, though τint is the final judge.

Burn-in, thinning, and total computational work

Total iterations equal burn + samples×thin, matching the internal loop. Burn-in discards initial transients, especially when x0 starts far from typical regions. Thinning reduces stored points; it does not remove correlation, so prefer larger chains unless storage is limited.

Autocorrelation time and effective sample size diagnostics

The tool estimates the integrated autocorrelation time τint from the autocorrelation sequence until it turns non‑positive. Effective sample size is Neff ≈ N/(2τint). Example: N=5000 and τint=8 gives Neff≈312, and the standard error scales as √(Var/Neff).

Interpreting harmonic and double-well thermodynamic targets

For the harmonic potential U=½kx², increasing β or k tightens the distribution, with typical fluctuations ∝ 1/√(βk). The double-well U=ax⁴−bx² has minima near ±√(b/2a). At high β, barrier crossings become rare and τint grows.

Spotting poor mixing, multimodality, and stuck chains

Use the histogram to spot multimodality or long tails. A symmetric double-well should show both wells over long runs; one‑sided occupancy often means poor mixing. Watch for large τint, low Neff, or means that drift across seeds—then increase steps, adjust σprop, or change x0.

Exporting results for reproducible physics reporting

Export CSV to compute custom observables, re-bin histograms, or compare chains. The PDF summarizes acceptance, τint, Neff, and uncertainty for x and your chosen observable. Fix the seed to reproduce identical chains when documenting parameter scans or proposal tuning studies.

FAQs

1) What acceptance rate should I target?

For many one-dimensional problems, 30–70% is a practical range. Below ~20% proposals are too aggressive; above ~80% steps are often too small and mixing slows. Use τint and Neff to confirm.

2) Why do repeated runs give slightly different means?

MCMC is stochastic, so finite chains fluctuate. If Neff is small, estimates vary more. Increase saved samples, reduce τint by tuning σprop, and ensure burn-in is long enough.

3) Do I need thinning?

Not usually for correctness. Thinning mainly reduces stored points and file size. The uncertainty calculation already accounts for autocorrelation using τint. If storage is fine, prefer keeping more samples rather than discarding them.

4) How is the uncertainty of the mean computed?

The tool estimates τint from the autocorrelation function, then computes Neff ≈ N/(2τint). The standard error is SE ≈ √(Var/Neff). This inflates errors when samples are strongly correlated.

5) Why does the double-well chain sometimes stay in one well?

At larger β, barrier crossings become rare, so the chain can remain near one mode for long periods. Increase steps, try different x0, or lower β to test mixing. Consider adjusting σprop if acceptance is extreme.

6) How can I reproduce the same results exactly?

Enter an integer seed and keep all inputs unchanged. The pseudo-random sequence and the resulting chain will match run-to-run, enabling consistent comparisons between proposal scales or target parameter settings.

7) Which observable is best for energy-related estimates?

Select U(x) to estimate mean potential energy for the Boltzmann targets. For fluctuation measures, use x² or x⁴. Compare means with their standard errors and watch Neff to ensure the estimate is well-resolved.

Related Calculators

metropolis monte carlokinetic monte carlodiscrete element methodconjugate heat transferquantum monte carlomultibody dynamicsstiff ode solveradaptive mesh refinementparticle in celldissipative particle dynamics

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.