hanalyze-bayes: Bayesian layer of hanalyze: HBM DSL, MCMC samplers, model comparison

[ bsd3, library, machine-learning, math, numeric, statistics ] [ Propose Tags ] [ Report a vulnerability ]

The Bayesian inference layer of the hanalyze toolkit, depending on hanalyze-core only (no dataframe), so it can be used as a standalone sampling library. A free-monad hierarchical Bayesian model DSL with in-house reverse-mode AD, samplers (NUTS after Hoffman & Gelman 2014, HMC, Metropolis-Hastings, slice, Gibbs, SMC), variational inference (ADVI), posterior predictive sampling, and model comparison via bridge sampling (marginal likelihood, Bayes factors, Bayesian model averaging). . Module names match the umbrella package hanalyze, which re-exports everything, so downstream imports stay identical. See README.md for the module map and a standalone usage example.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.0.1
Dependencies ad (>=4.4 && <4.6), aeson (>=2.0 && <2.3), array (>=0.5 && <0.6), async (>=2.2 && <2.3), base (>=4.14 && <5), containers (>=0.6 && <0.8), deepseq (>=1.4 && <1.6), hanalyze-core (==0.2.0.1), hmatrix (>=0.20 && <0.22), mwc-random (>=0.15 && <0.16), parallel (>=3.2 && <3.3), primitive (>=0.7 && <0.10), reflection (>=2.1 && <2.2), text (>=1.2 && <2.2), vector (>=0.12 && <0.14) [details]
Tested with ghc ==9.6.7
License BSD-3-Clause
Copyright 2026 Aelysce Project (Toshiaki Honda)
Author Toshiaki Honda
Maintainer frenzieddoll@gmail.com
Uploaded by frenzieddoll at 2026-08-13T05:54:46Z
Category Math, Statistics, Numeric, Machine Learning
Distributions
Reverse Dependencies 3 direct, 3 indirect [details]
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-08-13 [all 1 reports]

Readme for hanalyze-bayes-0.2.0.1

[back to package description]

hanalyze-bayes

The Bayesian inference layer of hanalyze: the hierarchical Bayesian model (HBM) DSL, the MCMC samplers, automatic differentiation, and Bayesian model comparison.

It depends on hanalyze-core only — not on dataframe. Sitting next to -frame directly above core, it can be used as a standalone sampling library without pulling in any data representation.

Main modules (26 in total)

HBM DSL (Hanalyze.Model.HBM.*)

Module Role
Model.HBM Facade over 8 submodules (Util / Distribution / Sampling / Model / Track / Eval / IR / Gradient). Normally the only import you need
Model.HBM.Model The polymorphic free-monad model DSL (sample / observe / dataNamed*)
Model.HBM.Distribution Polymorphic distribution ADT with densities and CDFs
Model.HBM.Eval log-joint / likelihood interpreter and DAG construction
Model.HBM.Gradient / Model.HBM.IR / Model.HBM.VecAD AD gradient compiler, intermediate representation, and the in-house reverse-mode AD (the per-draw hot path of NUTS)
Model.HBM.Ast / Model.HBM.Interp AST + JSON decoder of the dialog DSL and its interpreter

Samplers (Hanalyze.MCMC.*)

Module Role
MCMC.NUTS No-U-Turn Sampler — Hoffman & Gelman (2014) Algorithm 3. The workhorse sampler
MCMC.HMC Hamiltonian Monte Carlo with exact AD gradients
MCMC.MH / MCMC.Slice Random-walk Metropolis-Hastings / slice sampler (Neal 2003)
MCMC.Gibbs Gibbs sampler for conjugate priors (analytic full conditionals)
MCMC.SMC Sequential Monte Carlo over a tempered target
MCMC.BayesianTest Bayesian A/B test — samples the group mean difference with NUTS and decides via ROPE / HDI
MCMC.Progress Progress display aggregated across chains (stderr)

Inference and model comparison (Hanalyze.Stat.*)

Module Role
Stat.AD The automatic-differentiation layer behind HMC / NUTS
Stat.VI Variational inference (ADVI)
Stat.BridgeSampling Marginal likelihood log p(y) via bridge sampling (Meng & Wong 1996)
Stat.BayesFactor Bayes factors on top of bridge sampling (Kass & Raftery 1995)
Stat.BayesianModelAveraging True BMA from the log marginal likelihoods
Stat.PosteriorPredictive Prior / posterior predictive sampling (PyMC's sample_*_predictive)

Using it standalone

-- Chain and posterior statistics are core types, so depend on core too
-- if you touch them directly
build-depends: hanalyze-bayes, hanalyze-core, containers
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Map.Strict as Map
import Hanalyze.Model.HBM (ModelP, sample, observe, Distribution (..))
import Hanalyze.MCMC.NUTS (nutsPure, defaultNUTSConfig)
import Hanalyze.MCMC.Core (posteriorMean, posteriorSD)

myModel :: ModelP ()
myModel = do
  mu <- sample "mu" (Normal 0 10)
  observe "y" (Normal mu 2) [1.2, 2.3, 3.1, 2.8, 1.9]   -- observe takes [Double]

main = do
  -- nutsPure takes a seed (Word32) and returns a Chain purely and deterministically
  let chain = nutsPure myModel defaultNUTSConfig (Map.fromList [("mu", 0.0)]) 42
  print (posteriorMean "mu" chain, posteriorSD "mu" chain)
  -- (Just 2.2673259586131507,Just 0.8340460004499451)

Chain is a core type (Hanalyze.MCMC.Core), so posterior summaries (posteriorMean / posteriorSD / posteriorQuantile) and diagnostics (rhat / ess / hdi in Hanalyze.Stat.MCMC) come from core. Add the -viz layer (Hanalyze.Viz.*) when you need HTML reports or DAG figures.

repository README