Expand description
Fast Berry–Levinsohn–Pakes (BLP) estimation for random coefficients logit models.
This crate provides a demand-side estimator that mirrors the public API of pyBLP while embracing idiomatic Rust. It offers tools to
- manage product-level market data (
datamodule), - describe simulation draws for heterogeneous consumers (
integrationmodule), - solve the BLP contraction mapping (
solvingmodule), and - assemble a two-step GMM estimator (
estimationmodule).
The implementation focuses on clarity and extensibility. Heavy inline
documentation and unit tests illustrate the essential ingredients of BLP:
market partitioning, heterogeneous consumer integration, fixed-point solving,
and GMM objective evaluation. The goal is to provide a high-quality Rust
alternative to pyBLP while maintaining feature parity over time.
§Quick start
use blprs::data::{ProductData, ProductDataBuilder};
use blprs::integration::SimulationDraws;
use blprs::{Problem, ProblemOptions};
use nalgebra::{DMatrix, DVector};
// Assume we have N products and K1 linear, K2 nonlinear characteristics.
let market_ids = vec!["m1".to_string(), "m1".to_string(), "m2".to_string()];
let shares = DVector::from_vec(vec![0.3, 0.2, 0.4]);
let x1 = DMatrix::from_row_slice(3, 2, &[1.0, 10.0, 1.0, 15.0, 1.0, 12.0]);
let x2 = DMatrix::from_row_slice(3, 1, &[10.0, 15.0, 12.0]);
let instruments = x1.clone();
let products = ProductDataBuilder::new(market_ids, shares)
.x1(x1)
.x2(x2)
.instruments(instruments)
.build()
.expect("validated product data");
let draws = SimulationDraws::standard_normal(200, 1, 1234);
let problem = Problem::builder()
.products(products)
.draws(draws)
.options(ProblemOptions::default())
.build()
.expect("well-formed problem");
let sigma = DMatrix::from_row_slice(1, 1, &[2.0]);
let result = problem.solve(&sigma).expect("converged");
println!("Estimated betas: {:?}", result.beta);The crate is still under heavy development. Supply-side estimation,
optimal instruments, and many advanced pyBLP options are tracked in the
public roadmap.
Re-exports§
pub use estimation::BlpProblem;pub use estimation::EstimationResult;pub use estimation::Problem;pub use estimation::ProblemBuilder;pub use estimation::ProblemResults;pub use options::EstimationOptions;pub use options::GmmOptions;pub use options::ProblemOptions;pub use options::WeightingMatrix;pub use solving::ContractionOptions;pub use solving::ContractionSummary;
Modules§
- data
- Product-level data containers and validation utilities used by the BLP estimator.
- demand
- Demand-side primitives: share prediction and the BLP contraction mapping.
- error
- estimation
- High-level demand estimation pipeline that mirrors
pyBLP.Problem. - formulation
- Lightweight placeholder for pyBLP-style formulas.
- integration
- Monte Carlo integration helpers for simulating heterogeneous consumer tastes.
- options
- Configuration structures that mirror pyBLP’s solver and GMM options while remaining idiomatic Rust.
- solving
- Contraction solver configuration and diagnostics.