TL;DR
This paper introduces an open-source Python framework based on CVXPY that simplifies the prototyping of Discrete Latent Factor Models (DLFMs). By relaxing discrete hidden variables into continuous probabilities, the authors transform notoriously difficult, non-convex fitting problems into manageable biconvex ones solved via Block Coordinate Descent. This allows researchers to specify complex models with custom constraints and regularizations in just a few lines of code, eliminating the need for bespoke solvers.
What Problem Does This Paper Address?
Discrete Latent Factor Models (DLFMs)—such as hidden Markov models, mixture models, and clusterings—are essential tools across machine learning, neuroscience, and economics for capturing hidden states that drive observable data. However, fitting a DLFM to a dataset is fundamentally challenging. Because the latent factors are unobserved and discrete, fitting them typically requires solving an NP-hard, non-convex combinatorial optimization problem.
Currently, researchers must rely on highly customized solvers (like specific Expectation-Maximization (EM) algorithms or variational inference methods) tailored to one exact model instance. If a researcher wants to add a simple twist—such as enforcing sparsity, adding parameter constraints, or incorporating prior domain knowledge—they often have to redesign and re-implement the optimization algorithm from scratch. This high engineering barrier stifles rapid prototyping and experimentation.
Methods
The authors bridge this gap by introducing a generic framework that leverages Disciplined Convex Programming (DCP) and Disciplined Parameterized Programming (DPP) via CVXPY.
Their approach follows three key steps:
- Relaxation: They relax the strict, discrete "hard-encoded" latent factor constraints (where a sample belongs to exactly one hidden state) into "soft-encoded" continuous constraints (where a sample has a probability distribution over hidden states).
- Multi-Convex Formulation: They prove that this relaxed problem is biconvex. While the joint problem is still non-convex, fixing the latent factors makes the parameter problem convex, and fixing the parameters turns the latent factor problem into a simple linear program.
- Block Coordinate Descent (BCD): They implement a heuristic solver that alternates between solving for the model parameters (the P-problem) and the latent factors (the F-problem).
By utilizing CVXPY's DPP capabilities, the framework symbolically represents the problem data. This allows the BCD loop to update parameters and resolve the optimization steps rapidly without repeating the expensive canonicalization step.
Datasets
The framework was evaluated using synthetic datasets designed to replicate complex, domain-specific scenarios across four distinct use cases:
- Constrained $k$-means clustering: A toy dataset of 500 points in 2D space, where cluster centers were artificially constrained within a specific polyhedron.
- Mixture of linear regressions: A dataset of 500 samples in a 10-dimensional space generated from three distinct underlying linear models.
- Hierarchical forgetting Q-learning: A neuroscience-inspired dataset simulating 200 trials of an agent making decisions in a multi-armed bandit environment, where the agent switches between exploration and exploitation strategies.
- Input-output hidden Markov model (IO-HMM): A sequential dataset of 500 samples tracking a 3-state hidden Markov process with logistic outputs.
Key Insights and Ideas
- The Power of Biconvexity: The "aha moment" is realizing that even though DLFM fitting is globally non-convex and NP-hard, the mathematical structure naturally splits into two interconnected convex subproblems.
- Plug-and-Play Regularization: Because the subproblems conform to CVXPY's DCP rules, users can seamlessly inject complex regularizers. For example, in time-series data, users can add a Kullback-Leibler (KL) divergence term to the latent factors to penalize rapid, unrealistic state transitions, enforcing temporal smoothness.
- Declarative Prototyping: Instead of writing thousands of lines of custom C++ or matrix-heavy Python code for a new EM variant, developers can define parameters, losses, and constraints declaratively. The framework handles the optimization mechanics under the hood.
Key Results
The framework successfully recovered ground-truth parameters and latent states across all four experimental setups:
- Mixture of Regressions: The algorithm recovered the true 10-dimensional parameters almost perfectly, achieving a latent factor label recovery accuracy of 94%.
- Q-Learning Strategy Shifts: Without regularization, the model struggled to identify when the agent shifted strategies (71% accuracy). However, by easily adding a KL-divergence smoothing term to the F-problem, accuracy jumped to 93%, matching the ground-truth transition points tightly.
- IO-HMM: The framework accurately estimated the underlying $3 \times 3$ Markov transition matrix purely based on the recovered latent labels post-optimization.
Limitations and Future Work
While highly flexible, the framework has a few notable limitations:
- Local Minima: Like the standard EM algorithm, Block Coordinate Descent only guarantees convergence to a local minimum. Users may still need to run multiple random initializations to find the global optimum.
- Scalability Bottlenecks: For massive datasets, CVXPY's internal canonicalization step can become a bottleneck. The authors note that a non-DPP implementation is sometimes faster for very large problems.
- DCP Dependency: The loss functions and parameter constraints must strictly adhere to DCP rules. If a researcher wishes to use a non-DCP compliant metric, the framework cannot automatically parse or solve it.
Summary updated