This project trains a neural network to answer any Most Probable Explanation (MPE) query over a given probabilistic model. It is defined for Bayesian and Markov networks, probabilistic circuits (PCs), and neural autoregressive models (NAMs). Training needs no solved examples. ITSELF improves the answers at test time, and GUIDE trains a better starting network.
The task
An MPE query gives the values of some variables (the evidence \(\mathbf{e}\)) and asks for the most likely assignment to all the others (\(\mathbf{q}\)):
\[\mathrm{MPE}(\mathbf{Q}, \mathbf{e}) = \arg\max_{\mathbf{q}} \; \log p_{\mathcal{M}}(\mathbf{q}, \mathbf{e})\]The task is NP-hard in general and hard to approximate. The paper studies any-MPE: the split into evidence and query variables is not known before training.
How it works
- Query encoding: each variable gets two input nodes, set to (0, 1) for evidence value 0, (1, 0) for evidence value 1, and (0, 0) for a query variable. A model with \(n\) variables needs \(2n\) inputs and \(n\) sigmoid outputs.
- Self-supervised loss: the negative log-likelihood of the model, evaluated at the network’s continuous outputs. It can be evaluated and differentiated in polynomial time. An entropy penalty with weight \(\alpha > 0\) favors outputs close to 0 or 1.
- Training queries: sample a full assignment from the model, choose a random number of evidence variables, and keep only their values.
ITSELF
Inference Time Optimization using SELF-Supervised Loss starts from a random or pre-trained network and keeps running gradient updates on the test query with the same loss, until it converges. The experiments stop after at most 100 iterations (1,000 for NAMs). It needs no labels and no external MPE solver, and the answers typically improve with each iteration.
GUIDE
GUided Iterative Dual LEarning with Self-supervised Teacher trains two networks with the same structure. For each mini-batch:
- ITSELF updates the teacher on the mini-batch.
- A database keeps the best assignment found so far for each training example.
- The student learns from these assignments with a supervised loss, such as binary cross-entropy.
- The teacher is reset to the student.
The trained student answers queries in one forward pass, or serves as the starting point for ITSELF.
Results in the paper
The table counts the test sets on which each method had the higher average log-likelihood (Figure 3 of the paper). On the remaining test sets, the scores were similar.
| Model | Compared with | GUIDE + ITSELF higher | Other method higher | Test sets |
|---|---|---|---|---|
| Probabilistic circuits | MAX | 108 | 12 | 120 |
| Probabilistic circuits | ML | 115 | 5 | 120 |
| Probabilistic circuits | Seq | 113 | 7 | 120 |
| Probabilistic circuits | SSMP | 107 | 0 | 120 |
| Neural autoregressive models (MADE) | Hill climbing | 68 | 12 | 80 |
| Neural autoregressive models (MADE) | SSMP | 72 | 4 | 80 |
| Markov networks (high-treewidth grids) | AOBB | 11 | 5 | 16 |
| Markov networks (high-treewidth grids) | SSMP | 16 | 0 | 16 |
MAX, ML, and Seq are the polynomial-time max-product, max-marginal, and sequential approximations. SSMP here is a single network trained with the self-supervised loss and used in one forward pass. Hill climbing and AOBB (AND/OR branch and bound) had 60 seconds per test example.
- Without ITSELF, MAX beats a single forward pass on circuits: 71 to 49 against GUIDE and 81 to 39 against SSMP.
- Speed: single-pass inference is the fastest option for every model type. ITSELF takes longer, and GUIDE-trained networks generally need fewer ITSELF iterations than SSMP-trained ones. For circuits, MAX is faster than ITSELF on most datasets (Figure 80).
- Gap to exact solutions: on four smaller networks at four query ratios, Table 2 lists GUIDE + ITSELF as the best neural method in 12 of 16 cases (one is a tie at the printed precision) and GUIDE alone in the other four. These two methods have their largest gaps on Segmentation-15 at query ratio 0.9: 0.255 for GUIDE and 0.305 for GUIDE + ITSELF.
Scope
- The method is described for binary variables. Appendix B outlines extensions to multi-valued and continuous variables.
- The graphical-model experiments in Figure 3 use Markov networks. The paper reports none on Bayesian networks.
- Networks were trained for each probabilistic model and query ratio (Section 5.3).
- The paper says the method extends easily to marginal MAP in PCs and tractable graphical models. For NAMs and graphical models in general, evaluating the marginal MAP loss during training can be too expensive (Appendix B).
Use it in NeuPI
This example is from the NeuPI README. Define these first:
-
pgmis the probabilistic model andnits number of variables, as in the NeuPI quick start. -
train_loader,val_loader, andtest_loaderareDataLoaders overneupi.QueryDataset, with batch sizecfg["batch_size"]. Passper_example=TruetoQueryDataset.from_splitto draw a different set of query variables for every query; the quick start uses one set for all.
cfg = neupi.default_hparams("guide") # model_type: "pgm", "pc" (SPN) or "nam" (MADE)
model = neupi.MLP(output_size=n, embedding=neupi.DiscreteEmbedder(n), **cfg["model"])
optimizer = torch.optim.Adam(model.parameters(), **cfg["optimizer"])
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, **cfg["scheduler"])
trainer = neupi.GUIDETrainer(model, pgm, neupi.mpe_log_likelihood_loss, optimizer, **cfg["trainer"])
trainer.fit(train_loader, val_dataloader=val_loader, scheduler=scheduler, **cfg["fit"])
engine = neupi.ITSELF_Engine(trainer.model, pgm, neupi.mpe_log_likelihood_loss, torch.optim.Adam,
neupi.KNearestDiscretizer(pgm, **cfg["discretizers"]["knn"]), **cfg["itself"])
engine.run(test_loader)["final_assignments"] returns the answers.
NeuPI’s defaults are not the paper’s settings. In NeuPI 1.5.0, default_hparams uses a negative entropy_weight, which rewards soft outputs, while the paper uses a penalty. Epochs, dropout, and the number of ITSELF steps for NAMs also differ, and ITSELF runs a fixed number of steps unless you set tol. The example uses KNearestDiscretizer instead of the paper’s 0.5 threshold (ThresholdDiscretizer).