Deep Generative Models with Hard Linear Equality Constraints

Ruoyan Li, Dipti Ranjan Sahu, Guy Van den Broeck, Zhe ZengarXiv 2025

Abstract

While deep generative models (DGMs) have demonstrated remarkable success in capturing complex data distributions, they consistently fail to learn constraints that encode domain knowledge and thus require constraint integration. Existing solutions to this challenge have primarily relied on heuristic methods and often ignore the underlying data distribution, harming the generative performance. In this work, we propose a probabilistically sound approach for enforcing the hard constraints into DGMs to generate constraint-compliant and realistic data. This is achieved by our proposed gradient estimators that allow the constrained distribution, the data distribution conditioned on constraints, to be differentiably learned. We carry out extensive experiments with various DGM model architectures over five image datasets and three scientific applications in which domain knowledge is governed by linear equality constraints. We validate that the standard DGMs almost surely generate data violating the constraints. Among all the constraint integration strategies, ours not only guarantees the satisfaction of constraints in generation but also archives superior generative performance than the other methods across every benchmark.

Introduction: The Knowledge Gap in Generative Modeling

Deep generative models like VAEs and Diffusion models are exceptionally good at mimicking high-dimensional data distributions. However, they are often "knowledge-blind," failing to respect strict physical or mathematical rules—such as mass balance in chemistry or portfolio constraints in finance—that govern real-world data.

Existing attempts to enforce these rules typically fall into two categories: soft constraints (penalties) or post-processing projections. Soft constraints do not guarantee satisfaction, while projections often push samples into low-probability regions of the learned distribution, resulting in unrealistic outputs.

Visual comparison of constraint satisfaction strategies. Standard MAP violates constraints, while simple projection (Euc) moves samples to low-likelihood regions. The proposed method ("Ours") satisfies constraints while remaining in high-probability areas.

Proposed Methodology

The authors propose a framework that transforms the underlying distribution rather than individual samples. By sampling directly from a constrained distribution $p_\theta(z | Az = k)$, the model is restricted to the feasible space from the outset.

Differentiable Constrained Learning

A major challenge in training such models is that standard reparameterization tricks do not account for hard constraints. The authors introduce the Marginal Expectation gradient estimator, which provides a stable, differentiable proxy for the gradient by taking the expectation under the conditional marginal distribution.

Overview of the proposed framework. The model learns a constrained distribution $p_\theta(z | Az = k)$, with gradients estimated using the Marginal Expectation to ensure stable training.

For specific distributions like Gaussian or Poisson with common loss functions, the authors derived closed-form expected loss expressions. This allows for analytical training without the noise associated with Monte Carlo sampling. This framework is architecture-agnostic, demonstrating success across VAEs, Diffusion models, and Graph Neural Networks.

Experimental Validation

The framework was tested across a wide range of domains:

  • Image Synthesis: MNIST, CIFAR-10, and CelebA with brightness constraints.
  • Scientific Modeling: Predicting partial charges in Metal-Organic Frameworks (MOFs) and mass balance in chemical process units.
  • Finance: Portfolio weight allocation for S&P 500 stocks.

Key Results

  • 100% Compliance: The proposed method achieved zero constraint violations across all benchmarks, whereas standard DGMs failed nearly 100% of the time.
  • Improved Quality: Beyond mere compliance, the method improved generative quality, achieving lower FID scores in image tasks and lower Mean Absolute Deviation (MAD) in scientific applications compared to baselines like Physics-Informed Neural Networks (PINNs).
  • Efficiency: The computational overhead is minimal, with VAE training being less than 10% slower than unconstrained versions.

Conclusion and Future Directions

This work provides a probabilistically sound foundation for integrating hard linear equality constraints into deep generative models. By focusing on the distribution rather than the samples, it ensures both physical validity and high data realism. Future work will look to extend this framework to non-linear constraints, inequality constraints, and more complex latent distributions.

Summary updated

BibTeX
@misc{li2025deep,
  author = {Ruoyan Li and Dipti Ranjan Sahu and Guy Van den Broeck and Zhe Zeng},
  title = {{Deep Generative Models with Hard Linear Equality Constraints}},
  year = {2025},
  eprint = {2502.05416},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.05416},
}
Figure