| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Inference.SMC
Description
Sequential Monte Carlo on a discrete hidden Markov model.
A 2-state HMM with binary observations. Exact inference by enumeration of all 2^T state sequences. SMC particle filter approximates the same posterior. Oracle: L1 distance between SMC and exact marginal < 0.1.
Synopsis
- data State
- transProb :: State -> State -> Double
- obsProb :: Int -> State -> Double
- initialP :: State -> Double
- exactFiltering :: [Int] -> [(State, Double)]
- particleFilter :: [Int] -> Int -> [(State, Double)]
- type SMCPoly = 'Prod ('Prod ('Const State) ('Exp ())) ('Const Double)
- smcIn :: () -> Dir SMCPoly
- smcSystem :: Int -> System (Prob (->) Double) State SMCPoly
- smcTotalWeight :: Int -> State -> Double
- trace5 :: [Int]
- l1Distance :: [(State, Double)] -> [(State, Double)] -> Double
Model
Exact inference
exactFiltering :: [Int] -> [(State, Double)] Source #
Exact filtering P(S_T | O_{1:T}) by enumeration. Returns [(S, normalised probability)].
SMC particle filter
particleFilter :: [Int] -> Int -> [(State, Double)] Source #
Run a particle filter and return empirical final filtering distribution. n particles, deterministic RNG (seed = 42), systematic resampling.
Polynomial shape oracle
type SMCPoly = 'Prod ('Prod ('Const State) ('Exp ())) ('Const Double) Source #
SMC polynomial: particle stream paired with a weight annotation.
Mono () State— the particle is an output position; the input direction is trivial (()) because the particle is sampled, not supplied.Const Double— the weight is an output position with no direction, so it cannot be fed back as an input.
Written directly in Poly constructors because Mono is a type synonym.
smcIn :: () -> Dir SMCPoly Source #
Canonical input direction for the SMC polynomial: advance one step.
smcSystem :: Int -> System (Prob (->) Double) State SMCPoly Source #
One-step SMC kernel for a fixed observation.
Given current hidden state s and observation o, transition to s'
according to transProb and emit the particle s' together with weight
obsProb o s'. The weight is part of the output position, not an input
direction, which is exactly the instance-table claim.
smcTotalWeight :: Int -> State -> Double Source #
Total expected weight emitted by one SMC step starting from s for
observation o. This is the marginal likelihood P(o | s).