-
Notifications
You must be signed in to change notification settings - Fork 0
The generic framework for solving approximate inference problem with BP #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Please compare your result with some known correct result, with an example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a comprehensive PyTorch-based Belief Propagation (BP) module for discrete factor graphs using the UAI file format. The implementation provides core BP algorithms, UAI parsing utilities, documentation, examples, and extensive unit tests. The design follows the tensor-contraction approach inspired by TensorInference.jl.
Changes:
- Implements complete belief propagation algorithm with message passing, convergence checking, and marginal computation
- Adds UAI format parser for reading probabilistic graphical models and evidence files
- Provides comprehensive test suite covering parsing, BP correctness, evidence handling, and integration scenarios
- Includes documentation with mathematical descriptions, API reference, and usage guides
- Adds example scripts demonstrating basic BP usage and evidence application
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
pytorch_bp/belief_propagation.py |
Core BP implementation with message passing, convergence, and evidence handling |
pytorch_bp/uai_parser.py |
UAI format parser for models and evidence files |
pytorch_bp/utils.py |
Utility functions (currently contains unused deep_copy_messages) |
pytorch_bp/__init__.py |
Module exports and public API definition |
tests/test_bp_basic.py |
Basic BP tests comparing against exact marginals |
tests/test_integration.py |
Integration tests for file I/O and full pipeline |
tests/test_uai_parser.py |
Parser validation tests |
tests/testcase.py |
Additional test cases for unary factors, chains, and normalization |
tests/__init__.py |
Test package initialization |
examples/simple_example.py |
Basic BP usage example |
examples/evidence_example.py |
Evidence application example |
examples/simple_model.uai |
Example UAI model file |
examples/simple_model.evid |
Example evidence file |
docs/mathematical_description.md |
Mathematical description of BP algorithm |
docs/api_reference.md |
Public API documentation |
docs/usage_guide.md |
Usage examples and tips |
README.md |
Complete rewrite with setup instructions, examples, and test documentation |
requirements.txt |
PyTorch dependency specification |
.gitignore |
Python cache file exclusions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
==========================================
+ Coverage 94.28% 94.68% +0.39%
==========================================
Files 3 6 +3
Lines 70 282 +212
==========================================
+ Hits 66 267 +201
- Misses 4 15 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Well done! @Morningliumengkun |
Summary
This update completes the PyTorch Belief Propagation (BP) module with core fixes,
documentation, examples, and comprehensive unit tests. It also documents
environment setup steps so others (or AI agents) can reproduce the correct setup
quickly.
Key Changes
einsumoperand mismatches and correctly handle single-variable factors inpytorch_bp/belief_propagation.py.read_model_from_stringinpytorch_bp/uai_parser.py, preserving original scopes and tables.docs/with mathematical description, API reference, andusage guide.
examples/with a simple UAI model and evidence examplescripts.
tests/for parser, BP correctness vs exact marginals, andintegration coverage.
README.mdto include environment setup(Windows/macOS/Linux), examples, and a table explaining unit tests.
.gitignoreto avoid committing Python cache files.How to Run
Notes
PYTHONPATH(documented inREADME.md) orpip install -e .sopytorch_bpimports resolve correctly.Testing
examples/asia-network/model.uai