Generating Likely Counterfactuals Using Sum-Product Networks

Jiri Nemecek, Tomás Pevný, Jakub Marecek · OpenReview

Abstract

Explainability of decisions made by AI systems is driven by both recent regulation and user demand. These decisions are often explainable only post hoc, after the fact. In counterfactual explanations, one may ask what constitutes the best counterfactual explanation. Clearly, multiple criteria must be taken into account, although "distance from the sample" is a key criterion. Recent methods that consider the plausibility of a counterfactual seem to sacrifice this original objective. Here, we present a system that provides high-likelihood explanations that are, at the same time, close and sparse. We show that the search for the most likely explanations satisfying many common desiderata for counterfactual explanations can be modeled using mixed-integer optimization (MIO). In the process, we propose an MIO formulation of a Sum-Product Network (SPN) and use the SPN to estimate the likelihood of a counterfactual, which can be of independent interest.

Introduction: The Plausibility Gap

When an AI system denies a loan application or flags a transaction, users naturally seek recourse: "What would I need to change to get a different outcome?" This is the core of counterfactual explanations (CE). While early research focused primarily on finding the "closest" possible change (minimizing distance), this often led to unrealistic suggestions—scenarios that are mathematically close but practically impossible, such as a 20-year-old with 30 years of professional experience.

A robust counterfactual must satisfy several desiderata: it must be valid (change the decision), close/sparse (minimal changes), actionable (respecting immutable features), and, crucially, plausible (realistic within the data distribution). As shown in the comparison below, many existing methods fail to satisfy all these criteria simultaneously, often struggling with complex data or exogenous constraints.

Comparison of counterfactual methods across key desiderata, highlighting LiCE's comprehensive coverage.

Methodology: Bridging Probabilistic Circuits and Optimization

To address the "Plausibility Gap," we introduce LiCE (Likely Counterfactual Explanations). Our framework bridges two distinct fields: Probabilistic Circuits and Discrete Optimization.

Sum-Product Networks (SPNs)

We utilize SPNs as a tractable probabilistic model. Unlike deep generative models like VAEs, SPNs allow for the exact calculation of data likelihood and excel at handling mixed categorical and continuous features. In LiCE, plausibility is explicitly defined as the likelihood of a sample under the data's true distribution as modeled by the SPN.

Mixed-Integer Optimization (MIO)

To find the globally optimal counterfactual, we embed the trained SPN directly into an MIO solver. This is achieved by performing calculations in log-space to maintain linearity and approximating the "Sum" nodes of the SPN using a max function. This linearization allows industry-standard solvers like Gurobi to navigate the probability distribution as a set of linear constraints, enabling users to either maximize plausibility or enforce a specific plausibility threshold.

Empirical Evaluation

We evaluated LiCE against several state-of-the-art methods using real-world tabular datasets (GMSC, Adult, German Credit) and synthetic Bayesian networks.

Key Results

  • Success Rate: LiCE achieved a ~100% success rate in finding valid counterfactuals, whereas generative competitors like C-CHVAE often failed on complex samples.
  • Approximation Accuracy: The error introduced by our "log-max" MIO approximation was minimal, averaging only 2.9% compared to the true SPN output.
  • Qualitative Plausibility: On the German Credit dataset, LiCE consistently found more intuitive explanations. While other methods suggested counter-intuitive changes like doubling the credit amount, LiCE identified realistic paths, such as slightly decreasing the loan duration to reach a high-likelihood region of the data space.
Log-likelihood of counterfactuals on the Credit dataset. LiCE (red diamond) and MIO (yellow diamond) successfully find counterfactuals in high-likelihood (lighter) regions compared to baseline methods.

Conclusion

LiCE provides a mathematically rigorous way to generate counterfactuals that are both close to the original data and highly realistic. By formulating the search as a mixed-integer optimization problem over a Sum-Product Network, we ensure global optimality and high success rates across diverse datasets. Future work will focus on reducing the computational cost of the MIO formulation for even larger networks and exploring applications in robust classification and data cleaning.

Summary updated

BibTeX
@inproceedings{nemecek2025generating,
  author = {Jiri Nemecek and Tomás Pevný and Jakub Marecek},
  title = {{Generating Likely Counterfactuals Using Sum-Product Networks}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=rGyi8NNqB0},
}
Figure