Lossless Bayesian Networks in C++
A complete implementation of Bayesian networks with exact inference capabilities, maintaining all probability information without approximation. Includes Objective-C visualization for macOS with precise probability display.
Abstract
This project presents a complete implementation of Bayesian networks in C++ with lossless probabilistic inference. Unlike approximate methods, our implementation maintains exact probability distributions throughout all computations, ensuring precise and deterministic results. The system includes comprehensive DAG validation, efficient CPT management, and a macOS visualization application for interactive exploration of probabilistic models.
Key Features
Comprehensive probabilistic reasoning capabilities
Lossless Representation
All probabilities stored and computed exactly without approximation, preserving full precision in all calculations. No rounding errors or numerical approximations.
Exact Inference
Variable elimination algorithm provides precise inference results with deterministic, reproducible outcomes. Guaranteed exactness in all probabilistic queries.
DAG Validation
Automatic cycle detection and topological sorting ensure valid directed acyclic graph structures. Comprehensive error handling for invalid network configurations.
Visualization
Interactive macOS app with exact precision display, color-coded nodes, and real-time inference visualization. Explore probabilistic models interactively.
Flexible API
Easy network construction with comprehensive error handling and support for arbitrary DAG structures. Intuitive interface for building complex probabilistic models.
File I/O
Network serialization and loading capabilities for persistent storage and sharing. Save and load complete network configurations with all probability tables.
Lossless Belief Propagation
Sum-product message passing algorithm for exact inference with influence tracing. Trace how probabilities flow through the network and identify causal pathways.
Reverse Belief Propagation
Diagnostic reasoning with lossless reverse tracing. Propagate beliefs from effects to causes, tracing how probabilities flow backwards through the network for diagnostic inference.
Documentation
Complete guides and references
Main Documentation
Comprehensive guide covering architecture, algorithms, mathematical foundations, and usage examples. Complete technical reference.
Presentation
Professional presentation slides covering key concepts, architecture, and examples. Ready for academic presentations.
Reference Manual
Complete API documentation with detailed descriptions of all classes, methods, and parameters. Developer reference guide.
Supplementary Material
Extensive mathematical proofs, correctness arguments, and detailed analysis. Includes proofs of factorization, variable elimination, belief propagation, and complexity analyses.
Document Preview
Installation
Get started in minutes
Building the C++ Library
# Clone the repository
git clone https://github.com/Sapana-Micro-Software/lossless-bayesian-networks.git
cd lossless-bayesian-networks
# Build the project
make
# Run examples
make run
Requirements
- C++17 compatible compiler (g++, clang++)
- Make
Building the macOS Visualization App
# Build the macOS app
make -f Makefile.macos
# Run the app
make -f Makefile.macos run
Requirements
- macOS 10.13 or later
- Xcode Command Line Tools
- clang++ with Objective-C++ support
Examples
See it in action
Medical Diagnosis
Disease diagnosis based on symptoms with exact probability calculations. Demonstrates practical application in medical decision support.
network.addNode("Disease", "Disease",
{"None", "Cold", "Flu"});
network.addNode("Symptom", "Fever", {"No", "Yes"});
network.addEdge("Disease", "Symptom");
Alarm Network
Classic Bayesian network example with burglary, earthquake, and alarm. Standard benchmark for probabilistic inference systems.
network.addNode("Burglary", "Burglary",
{"False", "True"});
network.addNode("Alarm", "Alarm", {"False", "True"});
network.addEdge("Burglary", "Alarm");
Belief Propagation
Trace influence through the network using lossless belief propagation. See how evidence propagates and affects probabilities throughout the network.
auto result = network.beliefPropagation(
queryNodes, evidence, true);
auto& beliefs = result.first;
auto& traces = result.second;
Reverse Belief Propagation
Diagnostic reasoning with reverse propagation. Given observed effects, infer causes using lossless reverse tracing through the network.
auto result = network.reverseBeliefPropagation(
queryNodes, evidence, true);
auto& beliefs = result.first;
auto& traces = result.second;