exploring bayesian blp heterskedastic normal#2524
Open
NathanielF wants to merge 22 commits into
Open
Conversation
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2524 +/- ##
==========================================
+ Coverage 93.96% 94.14% +0.17%
==========================================
Files 95 98 +3
Lines 14371 15172 +801
==========================================
+ Hits 13504 14283 +779
- Misses 867 889 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
14 tasks
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Experimental Bayesian BLP - DO NOT MERGE YET. Awaiting @cluhmann 's review.
Bayesian BLP: structural demand on aggregate market-share panels
What this adds
A new$\xi_{jm}$ jointly, with the Berry (1994) heteroskedastic-Normal log-share-ratio likelihood.
BayesianBLPclass inpymc_marketing.customer_choicefor fitting structural random-coefficients logit demand on aggregate market-share data. Implements the joint-posterior reformulation of Berry, Levinsohn & Pakes (1995) following Jiang, Manchanda & Rossi (2009, QME) and Yang, Chen & Allenby (2003). Fit happens via NUTS over preference parameters and the latent product–market shocksFeatures
time_colandcounterfactual_shares/elasticitiesacceptperiods=/regions=filters.batch_shares(2 GiB cap with automatic sample-axis chunking + warning).New submodule:
taste_profilesPublic namespace exposing four posterior-summary lenses that exploit the Bayesian structure to characterise who buys in each market — analyses the classical BLP estimator can't produce because it has no posterior over$\xi$ :
buyer_nu_posteriorbrand_buyer_nudemand_concentration_ginitaste_type_demand_sharesensitive / modal / insensitivesharesPlus four convenience plotters (stacked area, market × dimension heatmap, brand × market heatmap, Gini-vs-price scatter) that return matplotlib Figures with
layout="constrained".Demo notebooks
bayesian_blp.ipynb(synthetic, 61 cells, sections 1–10). Methodology walkthrough on a panel with known truth: aggregate-data motivation, Halton quadrature, share integral, Berry log-share-ratio likelihood, model construction, parameter recovery, IV vs no-IV bias comparison, posterior elasticities, time-targeted counterfactuals, hierarchical pooling, multi-dim taste profiles.bayesian_blp_nevo.ipynb(34 cells, sections 1–8). Applies the same model to Nevo's (2000) cereal panel and validates the literature own-price elasticity rangeBoth registered in the example gallery with auto-generated thumbnails.
MixedLogitnow exported frompymc_marketing.customer_choice.API design highlights
BayesianBLP.iterate_posterior_samplesandBayesianBLP.batch_sharesare public methods (not underscore-prefixed) — promoted so thetaste_profilesadapter sits on a stable public boundary.save/loadraiseNotImplementedErrorwith a clear message rather than ship a placeholder round-trip that mis-serialisesmarket_data. Tracked for v2.RuntimeError("Model has no posterior; call .fit(...) before <name>().")) are consistent across every public function that needs a fitted model.Tests
109 tests across three files, all in the default
pytestsuite:test_bayesian_blp.py— 72 tests covering build, validation, prior predictive, fit, counterfactual, elasticities, time-aware behaviour, hierarchical parameterisation, numerical stability under extreme parameters,batch_shareschunking, save/load NotImplementedError.test_taste_profiles.py— 35 tests across validation, compute shapes, math correctness (Gini limits), multi-dim path, and plotter return types.test_taste_profiles_integration.py— 2 papermill-based integration tests (success-path + error-propagation guard) following the project'sscripts/run_notebooks/runner.pyhouse style with mockedpm.sample. Runs in ~13s under the default suite.Useful reference video lecture on the frequentist BLP model.
https://youtu.be/koSUtDemjMo?is=8J0TFciBo_-oDqtS
Related Issue
Checklist
pre-commit.ci autofixto auto-fix.📚 Documentation preview 📚: https://pymc-marketing--2524.org.readthedocs.build/en/2524/