blog_04-computation-and-sampling
Simulation and estimation via Linear Programming
January 26, 2026
Part of the blog “Math of Choice”, based on Alfred Galichon’s forthcoming book, Discrete Choice Models: Mathematical Methods, Econometrics, and Data Science, Princeton University Press, April 2026.
In our previous posts, we built a beautiful theoretical cathedral. We saw that random utility models are governed by entropy, and that recovering preferences from data is an optimal transport problem. But for the applied econometrician or data scientist, a nagging question remains: how do we actually compute these things?
Unless we stick to the logit model (where integrals dissolve into simple logarithms), calculating market shares requires integrating over high-dimensional probability distributions. Closed-form solutions are rare. Today, we leave the world of exact integrals for the world of sampling and simulation. We will see how to turn our theoretical insights into tractable algorithms using Monte Carlo simulation and linear programming.
The Direct Problem: Simulation
Let’s start with the “Direct Problem”: given a vector of systematic utilities \(U\) and a distribution of random shocks \(\mathcal{P}\), how do we predict market shares? When the integral defining the welfare function \(G(U)\) is too complex to solve analytically, we approximate it. We draw a sample of \(I\) simulated consumers, each with a vector of utility shocks \(\varepsilon_i\) drawn from \(\mathcal{P}\). This creates an empirical distribution \(\mathcal{P}_I\), which assigns a weight of \(1/I\) to each observation.
We then define empirical estimators for our core quantities. The empirical welfare \(\hat{G}(U)\) is simply the average of the maximum utilities achieved by our simulated consumers:
$$ \hat{G}(U) = \frac{1}{I}\sum_{i \in [I]}\max_{y\in [Y]}\left\{ U_{y}+\varepsilon_{iy}, \varepsilon_{i0}\right\} $$
Similarly, the predicted market share \(\hat{\pi}_y(U)\) is just the fraction of simulated consumers for whom option \(y\) provides the highest utility. This is the standard “frequency simulator” approach used widely in econometrics.
The Inverse Problem: Estimation via Linear Programming
The “Inverse Problem” is where things get interesting. Suppose we observe market shares \(\pi\) and want to recover \(U\), but we cannot compute the analytical inverse demand. Can we use our simulated consumers to solve this?
Yes. We leverage the Optimal Transport connection we discovered in the previous post. We are looking for the utility vector that matches the observed market shares given our specific sample of random shocks.
This turns into a discrete Optimal Transport problem between the \(I\) simulated consumers (each with mass \(1/I\)) and the \(Y+1\) product categories (with masses \(\pi_y\)).
The Primal Problem (Assignment):
We try to find an assignment matrix \(\lambda_{iy}\) that maximizes the correlation between the simulated shocks and the choices, subject to the marginal constraints:
$$ \max_{\lambda_{iy} \geq 0} \sum_{i,y} \lambda_{iy} \varepsilon_{iy} \quad \text{s.t.} \quad \sum_y \lambda_{iy} = \frac{1}{I}, \quad \sum_i \lambda_{iy} = \pi_y $$
The Dual Problem (Pricing/Utility Recovery):
The dual of this linear program provides exactly what we are looking for. The dual variables associated with the market share constraints correspond to the systematic utilities \(U\):
$$
\begin{aligned}
\min_{u_{i}, U_{y}} \quad & \frac{1}{I}\sum_{i \in [I]} u_{i} – \sum_{y\in [Y]} \pi_{y} U_{y} \\
\text{s.t.} \quad & u_{i} – U_{y} \geq \varepsilon_{iy}, \quad U_0=0
\end{aligned}
$$
This is a standard linear programming (LP) problem. The constraints \(u_i \geq U_y + \varepsilon_{iy}\) ensure that each simulated consumer is assigned to their optimal choice given the prices (utilities) \(U\).
Why is this powerful?
This approach, which we proposed in our “Cupid’s invisible hand” paper with Bernard Salanié, transforms a difficult non-linear statistical inversion into a standard optimization problem.
- Universal: it works for any distribution \(\mathcal{P}\) from which you can sample—Normal, Student-t, mixtures, etc. You are not locked into the Logit/Gumbel world.
- Scalable: we can solve this efficiently using modern LP solvers like Gurobi or CPLEX.
- Consistent: Chiong, Galichon, and Shum proved that, as the number of simulated consumers \(I\) grows to infinity, the estimated utilities \(U^I\) converge almost surely to the true vector \(U\).
By treating the random utility model as an assignment problem between simulated agents and observed shares, we bridge the gap between abstract theory and computational practice.
In the next post, we will look at Generalized Extreme Value (GEV) models, which provide a middle ground: analytical tractability like Logit, but with flexible correlation patterns.
Reference
Galichon, Alfred. 2026. Discrete Choice Models: Mathematical Methods, Econometrics, and Data Science. Princeton University Press. Chapter 1, Section 1.4.
Galichon, Alfred, and Bernard Salanié. “Cupid’s invisible hand: Social surplus and identification in matching models.” The Review of Economic Studies 89, no. 5 (2022): 2600-2629.
