Functional Gradient Flows for Constrained Sampling

Shiyue Zhang, Longlin Yu, Ziheng Cheng, Cheng Zhang

Abstract

Sampling from complex probability distributions is a cornerstone of Bayesian inference, but it becomes significantly harder when those distributions are restricted to specific "constrained" domains, such as physical boundaries or strict parameter ranges. This paper introduces Constrained Functional Gradient Flow (CFG), a novel particle-based variational inference (ParVI) method. CFG uses neural networks to guide a set of particles toward a target distribution while mathematically ensuring they never escape the allowed domain. By incorporating a boundary condition and a "band-wise" numerical strategy, CFG achieves state-of-the-art performance and scalability for high-dimensional constrained problems.

Introduction: The Challenge of Constrained Domains

In probabilistic machine learning, we frequently need to sample from unnormalized distributions. Two main schools of thought dominate this space: Markov Chain Monte Carlo (MCMC), which is highly accurate but computationally slow, and Variational Inference (VI), which is fast but can lack flexibility. Particle-based Variational Inference (ParVI), such as the popular Stein Variational Gradient Descent (SVGD), attempts to combine the best of both worlds by moving a set of "particles" along a gradient flow to match the target distribution.

However, most ParVI methods assume particles can roam freely anywhere in continuous space ($\mathbb{R}^d$). In reality, many practical problems impose strict constraints:

  • Bayesian Lasso: Parameters might be constrained within an $\ell_1$-norm ball.
  • Monotonic Neural Networks: Weights must be constrained to ensure the output strictly increases with certain inputs (e.g., for fairness constraints).
  • Physical Systems: Particles might be restricted to specific geometric shapes or manifolds.

Existing methods for handling constraints, such as mirror maps or projections, are often computationally expensive or require custom designs for every new shape. This paper proposes a general, scalable solution that works for arbitrary inequality constraints.

Methodology: Constrained Functional Gradient Flow (CFG)

The core innovation of CFG lies in how it defines and trains the "velocity field" that dictates particle movement.

  1. Neural Velocity Fields: Instead of using traditional reproducing kernel Hilbert spaces (RKHS)—which scale poorly as the number of particles increases—CFG uses neural networks to learn the optimal direction to move the particles. This allows the computational cost to grow linearly ($O(N)$) rather than quadratically ($O(N^2)$).
  2. The Boundary Condition: To keep particles inside the valid domain $\Omega$, CFG enforces a strict condition: the velocity at the boundary must point inward, or at least not outward. Mathematically, this is expressed as $v_t \cdot \vec{n} \leq 0$, where $\vec{n}$ is the outward normal vector.
  3. Piece-wise Construction: The velocity design is split into two parts. If a particle steps outside the domain, a strong gradient pushes it back in. If it is inside, a neural network determines the best move to match the target distribution.
  4. Handling the Boundary Integral: Adding constraints to gradient flows introduces a complex "boundary integral" term into the training objective. The authors developed a band-wise approximation—a heuristic inspired by the geometric co-area formula that estimates this integral by looking at particles very close to the domain edge.
Particle evolution in constrained 2D toy domains (ring, heart, double moon, block) over 2000 iterations.

As illustrated above, CFG successfully navigates complex geometries, ensuring particles smoothly fill the target distribution without violating the domain boundaries.

Experiments and Key Results

The researchers evaluated CFG across a variety of settings, ranging from 2D toy domains to high-dimensional real-world datasets.

Datasets Evaluated

  • Toy 2D Domains: Complex shapes like a ring, a cardioid (heart-shape), a double-moon, and a block.
  • Bayesian Lasso/Bridge Regression: Synthetic 20-dimensional data and the real-world Diabetes dataset.
  • Monotonic Bayesian Neural Networks: Evaluated on the COMPAS dataset (predicting recidivism with fairness constraints) and the high-dimensional Blog Feedback dataset ($d=13,903$).

Performance and Scalability

CFG demonstrated significant improvements in sample efficiency and accuracy. On synthetic datasets, CFG outperformed kernel-based competitors like MIED, particularly when the number of particles was small, suggesting it extracts more useful gradient information per particle.

Convergence of Wasserstein-2 distance over iterations, comparing CFG against MSVGD and MIED baselines.

Quantitative metrics confirm this efficiency. As seen in the convergence plots, CFG rapidly minimizes the Wasserstein-2 distance to the target distribution, remaining highly competitive with or exceeding baseline methods.

Furthermore, CFG successfully handled the 13,903-dimensional Blog Feedback dataset. At this scale, traditional constrained sampling methods typically struggle or fail entirely due to the curse of dimensionality. Across all tasks, CFG robustly forced nearly 100% of particles to stay within the valid domain, even under tight constraints.

Key Insights and Theoretical Guarantees

  • Theoretical Convergence: The paper provides a rigorous proof that the particle distribution will converge to the target distribution in Total Variation (TV) distance, offering a solid mathematical foundation for the algorithm.
  • The "Reflection" Term: Incorporating the gradient of the boundary ($\nabla g$) directly into the neural network architecture acts like a "reflection" process. This prevents particles from getting stuck or clustering unnaturally at the walls.
  • Boundary Awareness is Critical: Ablation studies revealed that ignoring the boundary integral term during training causes the sampling to fail completely. The novel "band-wise" estimation is essential to the method's success.

Limitations and Future Work

While highly effective, CFG has a few limitations. The "band-wise" approximation relies on a bandwidth parameter $h$. Although the authors propose an adaptive scheme, it currently assumes a somewhat uniform distribution of particles near the boundary. Additionally, while the paper thoroughly addresses inequality constraints (e.g., $g(x) \leq 0$), extending this framework to complex equality constraints (such as sampling strictly on manifolds) remains an open challenge for future work. Finally, exploring alternative regularizers beyond the current $L_2$ norm for the functional gradient could yield further improvements.

Summary updated

BibTeX
@inproceedings{zhang2024functional,
  author = {Shiyue Zhang and Longlin Yu and Ziheng Cheng and Cheng Zhang},
  title = {{Functional Gradient Flows for Constrained Sampling}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=kpo6ZCgVZH},
}
Figure