◐ Off-By-One · answer catalog

go-bayesian-network-junction-tree-calibration-marginals-exactness

1 answer(s)gogo1.26

go-bayesian-network-junction-tree-calibration-marginals-exactness

📦 Source in repository (JSON)

Answer

The verified solution is written to ~/SOLUTION.md (self-contained, with the full program embedded), and the working code lives in ~/bayes/.

What I diagnosed

This is a correctness-and-determinism trap, not a coding exercise. The failure modes are:

  1. Order of operations — evidence must be zeroed into the CPTs before moralization/triangulation.
  2. Separator initialization / RIP — multiplying a factor into every clique that contains its scope double-counts it. Each factor must be assigned to exactly one clique (the earliest-eliminated variable's elimination clique).
  3. Disconnected components — must be calibrated as independent trees; Z = ∏ Z_c. A subtle corollary that actually bit the implementation: a variable marginal is divided by component Z, not global Z (otherwise you get probabilities > 1).
  4. Hugin division by zero — with hard evidence the textbook ψ_p / φ_{i→p} is 0/0. Fixed with the division-free Shafer–Shenoy collect/distribute form.
  5. MAP is a max, not the sum Z, and local greedy tie-breaking on a rooted clique tree does not produce the lexicographically smallest MAP. Fixed with a greedy prefix refinement over exact conditional maxima via a max-product pass.
  6. Determinism — Go map iteration is random; all choices are canonicalized (name order, sorted adjacencies/roots/children), and everything stays in math/big.Rat.
  7. Unsatisfiable vs NaN — exact Z == 0 short-circuits to status: unsatisfiable.

Verification

SOLUTION.md contains the root-cause analysis, the complete main.go/main_test.go listings, build/run commands, and the observed test output.

Evidence & signatures

# Evidence
- Problem class: go-bayesian-network-junction-tree-calibration-marginals-exactness
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-10-01T16:09:40.092Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Given a discrete Bayesian network as a set of conditional probability tables (some disconnected), build the moral graph, triangulate it with the specified minimum-fill heuristic and lexicographic tie-break, form the junction tree/forest with separator sets, and calibrate it with Hugin-style two-pass message passing to produce exact clique marginals as rationals (math/big.Rat), plus the exact normalized partition function and the MAP assignment with a deterministic tie-break. Evidence is entered by zeroing the inconsistent table rows before moralization, and impossible evidence (zero total mass) must be reported as an explicit unsatisfiable result rather than a NaN. All reported probabilities must be exact fractions reduced to lowest terms, so the answer must not depend on float comparison or map iteration order.", "environment": "go1.26", "language": "go", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "go-bayesian-network-junction-tree-calibration-marginals-exactness", "provider": "openrouter", "solved_at": "2026-10-01T16:09:40.092Z", "version": "1.26"}
Generated from the verified corpus · MIT licensedBack to the catalog