|
| 1 | +## PyTorch BP API Reference |
| 2 | + |
| 3 | +This reference documents the public API exported from `bpdecoderplus.pytorch_bp`. |
| 4 | + |
| 5 | +### UAI Parsing |
| 6 | + |
| 7 | +- `read_model_file(path, factor_eltype=torch.float64) -> UAIModel` |
| 8 | + Parse a UAI `.uai` model file. |
| 9 | + |
| 10 | +- `read_model_from_string(content, factor_eltype=torch.float64) -> UAIModel` |
| 11 | + Parse a UAI model from an in-memory string. |
| 12 | + |
| 13 | +- `read_evidence_file(path) -> Dict[int, int]` |
| 14 | + Parse a UAI `.evid` file and return evidence as 1-based indices. |
| 15 | + |
| 16 | +### Data Structures |
| 17 | + |
| 18 | +- `Factor(vars: List[int], values: torch.Tensor)` |
| 19 | + Container for a factor scope and its tensor. |
| 20 | + |
| 21 | +- `UAIModel(nvars: int, cards: List[int], factors: List[Factor])` |
| 22 | + Holds all model metadata for BP. |
| 23 | + |
| 24 | +### Belief Propagation |
| 25 | + |
| 26 | +- `BeliefPropagation(uai_model: UAIModel)` |
| 27 | + Builds factor graph adjacency for BP. |
| 28 | + |
| 29 | +- `initial_state(bp: BeliefPropagation) -> BPState` |
| 30 | + Initialize messages to uniform vectors. |
| 31 | + |
| 32 | +- `collect_message(bp, state, normalize=True)` |
| 33 | + Update factor-to-variable messages in place. |
| 34 | + |
| 35 | +- `process_message(bp, state, normalize=True, damping=0.2)` |
| 36 | + Update variable-to-factor messages in place. |
| 37 | + |
| 38 | +- `belief_propagate(bp, max_iter=100, tol=1e-6, damping=0.2, normalize=True)` |
| 39 | + Run the full BP loop and return `(BPState, BPInfo)`. |
| 40 | + |
| 41 | +- `compute_marginals(state, bp) -> Dict[int, torch.Tensor]` |
| 42 | + Compute marginal distributions after convergence. |
| 43 | + |
| 44 | +- `apply_evidence(bp, evidence: Dict[int, int]) -> BeliefPropagation` |
| 45 | + Return a new BP object with evidence applied to factor tensors. |
0 commit comments