Skip to content

LiveView of Bayesian inference, a web-delayed pulse of inference

Notifications You must be signed in to change notification settings

borodark/exmc_live

Repository files navigation

Exmc Live Inference

Streaming Bayesian inference in the browser. A Phoenix LiveView frontend for the Exmc probabilistic programming framework — watch MCMC posteriors form in real time.

With deep respect: this UI borrows the mental model and diagnostics expectations set by PyMC and ArviZ. The goal is to preserve correctness and ergonomics, while making the inference process observable as it unfolds.

Live Sampling

Why A Live PPL Experience?

PyMC gives excellent post-hoc diagnostics. Exmc Live makes those diagnostics visible during sampling:

  • Real-time trace and histogram updates as samples arrive.
  • Live diagnostics (ESS, divergences, mean/std) without polling.
  • A live posterior state updated online during sampling.
  • Clear latency telemetry to understand performance.

Quick Start

./start.sh            # http://localhost:4000
./start.sh iex        # same, with IEx shell attached

What It Does

  1. Pick a model (conjugate, two-parameter, or hierarchical)
  2. Enter observations and set warmup/sample counts
  3. Hit Sample — the NUTS sampler streams results to the browser via WebSocket

Live Sampling

The page updates live: trace plots, histograms, running diagnostics (mean, std, ESS), divergence counts, and latency metrics (warmup time, per-sample throughput). For the conjugate normal model, an analytic posterior comparison table appears after sampling completes.

Architecture

Browser ←WebSocket→ Phoenix.LiveView ←messages→ Exmc.NUTS.Sampler (Task)
          Chart.js hooks                {:exmc_sample, i, point_map, step_stat}
          (trace + histogram)           {:exmc_done, num_samples}
  • No polling. The sampler sends {:exmc_sample, ...} messages directly to the LiveView process.
  • Each batch of 5 samples triggers a push_event to the browser.
  • Chart.js hooks (TraceChart, HistogramChart) append points incrementally.

Models

Model Free RVs Description
Conjugate Normal 1 (mu) mu ~ N(0,10), `x
Two-Parameter 2 (mu, sigma) mu ~ N(0,10), sigma ~ Exp(1), x ~ N(mu,sigma).
Hierarchical 5 Two-group hierarchy: mu_global, sigma_global, mu_a, mu_b, sigma_obs.

CFD Observability

Visit http://localhost:4000/cfd for a CFD-oriented observability dashboard that matches the Exmc Live UX standard:

  • Residual traces for U and p
  • Halo exchange latency timeline
  • Per-partition residual tiles

The demo currently streams synthetic metrics but is structured to accept real CFD metrics via LiveView events.

Tests

# Unit tests (simulated messages, no real sampling)
mix test --exclude integration

# Full suite including end-to-end sampling
XLA_FLAGS="--xla_gpu_cuda_data_dir=/usr/lib/nvidia-cuda-toolkit" mix test --include integration

24 LiveView tests + 5 model tests + 4 controller tests = 33 total.

Environment

  • XLA_FLAGS required for models using lgamma (Exponential distribution). The start.sh script sets this automatically.
  • Port 4000 (dev), configurable via PORT env var in production.

Key Files

File Purpose
lib/exmc_live_web/live/inference_live.ex Main LiveView — state machine, message handling, rendering
lib/exmc_live/models.ex Three preset model builders
assets/js/hooks/trace_chart.js Chart.js hook for trace plots
assets/js/hooks/histogram_chart.js Chart.js hook for histograms
test/exmc_live_web/live/inference_live_test.exs 24 LiveView tests

About

LiveView of Bayesian inference, a web-delayed pulse of inference

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published