From 853b86c4ac2abf72561068f218c0c081336c816d Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 15 Mar 2026 23:59:34 +1300 Subject: [PATCH 1/5] Add 68 idiomatic PyMC model implementations Add PyMC translations for 68 Stan models that follow idiomatic PyMC patterns: no Potentials, no custom helper functions, and all numpy data wrangling occurs before the pm.Model context. Models span: GLMs (wells, radon, kidscore, logearn variants), GPs (gp_regr, gp_pois_regr), mixture models, educational models (eight_schools, rats, diamonds), and ecological models (seeds, dogs). Co-Authored-By: Claude Opus 4.6 --- .../models/info/GLMM1_model.info.json | 9 ++- .../models/info/GLMM_Poisson_model.info.json | 9 ++- .../models/info/GLM_Poisson_model.info.json | 11 +++- .../models/info/Rate_2_model.info.json | 10 ++- .../models/info/Rate_4_model.info.json | 11 +++- .../models/info/Rate_5_model.info.json | 10 ++- .../models/info/accel_splines.info.json | 10 ++- posterior_database/models/info/arK.info.json | 8 ++- posterior_database/models/info/blr.info.json | 3 + .../models/info/diamonds.info.json | 10 ++- posterior_database/models/info/dogs.info.json | 11 +++- .../models/info/dogs_hierarchical.info.json | 8 ++- .../models/info/dugongs_model.info.json | 9 ++- .../models/info/earn_height.info.json | 11 +++- .../info/eight_schools_centered.info.json | 13 +++- .../models/info/election88_full.info.json | 11 +++- .../models/info/gp_pois_regr.info.json | 8 ++- .../models/info/gp_regr.info.json | 8 ++- .../models/info/irt_2pl.info.json | 8 ++- .../info/kidscore_interaction.info.json | 11 +++- .../info/kidscore_interaction_c.info.json | 11 +++- .../info/kidscore_interaction_c2.info.json | 11 +++- .../info/kidscore_interaction_z.info.json | 11 +++- .../models/info/kidscore_mom_work.info.json | 11 +++- .../models/info/kidscore_momhs.info.json | 9 ++- .../models/info/kidscore_momhsiq.info.json | 11 +++- .../models/info/kidscore_momiq.info.json | 11 +++- .../models/info/kilpisjarvi.info.json | 10 ++- .../models/info/log10earn_height.info.json | 11 +++- .../models/info/logearn_height_male.info.json | 11 +++- .../models/info/logearn_interaction.info.json | 11 +++- .../info/logearn_interaction_z.info.json | 11 +++- .../info/logearn_logheight_male.info.json | 11 +++- .../info/logistic_regression_rhs.info.json | 10 ++- .../models/info/logmesquite_logvas.info.json | 11 +++- .../models/info/logmesquite_logvash.info.json | 11 +++- .../models/info/low_dim_gauss_mix.info.json | 8 ++- .../info/low_dim_gauss_mix_collapse.info.json | 8 ++- .../models/info/lsat_model.info.json | 9 ++- .../models/info/mesquite.info.json | 11 +++- .../models/info/nes_logit_model.info.json | 18 +++++- .../models/info/normal_mixture.info.json | 10 ++- .../models/info/normal_mixture_k.info.json | 10 ++- .../models/info/pilots.info.json | 11 +++- .../models/info/radon_county.info.json | 10 ++- .../info/radon_county_intercept.info.json | 3 + ..._hierarchical_intercept_centered.info.json | 3 + ...erarchical_intercept_noncentered.info.json | 3 + .../radon_partially_pooled_centered.info.json | 3 + .../models/info/radon_pooled.info.json | 3 + ...adon_variable_intercept_centered.info.json | 3 + ...n_variable_intercept_noncentered.info.json | 3 + ...ariable_intercept_slope_centered.info.json | 3 + ...able_intercept_slope_noncentered.info.json | 3 + .../models/info/rats_model.info.json | 12 +++- .../info/seeds_centered_model.info.json | 12 +++- .../models/info/seeds_model.info.json | 10 ++- .../info/seeds_stanified_model.info.json | 11 +++- .../models/info/sesame_one_pred_a.info.json | 10 ++- .../models/info/wells_daae_c_model.info.json | 19 +++++- .../models/info/wells_dae_c_model.info.json | 18 +++++- .../info/wells_dae_inter_model.info.json | 19 +++++- .../models/info/wells_dae_model.info.json | 18 +++++- .../models/info/wells_dist.info.json | 11 +++- .../models/info/wells_dist100_model.info.json | 12 +++- .../info/wells_dist100ars_model.info.json | 15 ++++- .../info/wells_interaction_c_model.info.json | 16 ++++- .../info/wells_interaction_model.info.json | 16 ++++- posterior_database/models/pymc/GLMM1_model.py | 34 ++++++++++ .../models/pymc/GLMM_Poisson_model.py | 37 +++++++++++ .../models/pymc/GLM_Poisson_model.py | 33 ++++++++++ .../models/pymc/Rate_2_model.py | 23 +++++++ .../models/pymc/Rate_4_model.py | 23 +++++++ .../models/pymc/Rate_5_model.py | 16 +++++ .../models/pymc/accel_splines.py | 58 +++++++++++++++++ posterior_database/models/pymc/arK.py | 25 ++++++++ posterior_database/models/pymc/blr.py | 24 +++++++ posterior_database/models/pymc/diamonds.py | 27 ++++++++ posterior_database/models/pymc/dogs.py | 24 +++++++ .../models/pymc/dogs_hierarchical.py | 29 +++++++++ .../models/pymc/dugongs_model.py | 30 +++++++++ posterior_database/models/pymc/earn_height.py | 27 ++++++++ .../models/pymc/eight_schools_centered.py | 27 ++++++++ .../models/pymc/election88_full.py | 63 +++++++++++++++++++ .../models/pymc/gp_pois_regr.py | 45 +++++++++++++ posterior_database/models/pymc/gp_regr.py | 36 +++++++++++ posterior_database/models/pymc/irt_2pl.py | 48 ++++++++++++++ .../models/pymc/kidscore_interaction.py | 27 ++++++++ .../models/pymc/kidscore_interaction_c.py | 24 +++++++ .../models/pymc/kidscore_interaction_c2.py | 29 +++++++++ .../models/pymc/kidscore_interaction_z.py | 29 +++++++++ .../models/pymc/kidscore_mom_work.py | 28 +++++++++ .../models/pymc/kidscore_momhs.py | 16 +++++ .../models/pymc/kidscore_momhsiq.py | 18 ++++++ .../models/pymc/kidscore_momiq.py | 22 +++++++ posterior_database/models/pymc/kilpisjarvi.py | 28 +++++++++ .../models/pymc/log10earn_height.py | 29 +++++++++ .../models/pymc/logearn_height_male.py | 31 +++++++++ .../models/pymc/logearn_interaction.py | 28 +++++++++ .../models/pymc/logearn_interaction_z.py | 31 +++++++++ .../models/pymc/logearn_logheight_male.py | 32 ++++++++++ .../models/pymc/logistic_regression_rhs.py | 43 +++++++++++++ .../models/pymc/logmesquite_logvas.py | 42 +++++++++++++ .../models/pymc/logmesquite_logvash.py | 43 +++++++++++++ .../models/pymc/low_dim_gauss_mix.py | 30 +++++++++ .../models/pymc/low_dim_gauss_mix_collapse.py | 36 +++++++++++ posterior_database/models/pymc/lsat_model.py | 40 ++++++++++++ posterior_database/models/pymc/mesquite.py | 33 ++++++++++ .../models/pymc/nes_logit_model.py | 24 +++++++ .../models/pymc/normal_mixture.py | 27 ++++++++ .../models/pymc/normal_mixture_k.py | 27 ++++++++ posterior_database/models/pymc/pilots.py | 35 +++++++++++ .../models/pymc/radon_county.py | 26 ++++++++ .../models/pymc/radon_county_intercept.py | 27 ++++++++ .../radon_hierarchical_intercept_centered.py | 35 +++++++++++ ...adon_hierarchical_intercept_noncentered.py | 39 ++++++++++++ .../pymc/radon_partially_pooled_centered.py | 27 ++++++++ .../models/pymc/radon_pooled.py | 25 ++++++++ .../pymc/radon_variable_intercept_centered.py | 30 +++++++++ .../radon_variable_intercept_noncentered.py | 32 ++++++++++ ...radon_variable_intercept_slope_centered.py | 36 +++++++++++ ...on_variable_intercept_slope_noncentered.py | 43 +++++++++++++ posterior_database/models/pymc/rats_model.py | 39 ++++++++++++ .../models/pymc/seeds_centered_model.py | 41 ++++++++++++ posterior_database/models/pymc/seeds_model.py | 38 +++++++++++ .../models/pymc/seeds_stanified_model.py | 39 ++++++++++++ .../models/pymc/sesame_one_pred_a.py | 26 ++++++++ .../models/pymc/wells_daae_c_model.py | 31 +++++++++ .../models/pymc/wells_dae_c_model.py | 29 +++++++++ .../models/pymc/wells_dae_inter_model.py | 31 +++++++++ .../models/pymc/wells_dae_model.py | 32 ++++++++++ posterior_database/models/pymc/wells_dist.py | 22 +++++++ .../models/pymc/wells_dist100_model.py | 26 ++++++++ .../models/pymc/wells_dist100ars_model.py | 26 ++++++++ .../models/pymc/wells_interaction_c_model.py | 28 +++++++++ .../models/pymc/wells_interaction_model.py | 31 +++++++++ 136 files changed, 2736 insertions(+), 86 deletions(-) create mode 100644 posterior_database/models/pymc/GLMM1_model.py create mode 100644 posterior_database/models/pymc/GLMM_Poisson_model.py create mode 100644 posterior_database/models/pymc/GLM_Poisson_model.py create mode 100644 posterior_database/models/pymc/Rate_2_model.py create mode 100644 posterior_database/models/pymc/Rate_4_model.py create mode 100644 posterior_database/models/pymc/Rate_5_model.py create mode 100644 posterior_database/models/pymc/accel_splines.py create mode 100644 posterior_database/models/pymc/arK.py create mode 100644 posterior_database/models/pymc/blr.py create mode 100644 posterior_database/models/pymc/diamonds.py create mode 100644 posterior_database/models/pymc/dogs.py create mode 100644 posterior_database/models/pymc/dogs_hierarchical.py create mode 100644 posterior_database/models/pymc/dugongs_model.py create mode 100644 posterior_database/models/pymc/earn_height.py create mode 100644 posterior_database/models/pymc/eight_schools_centered.py create mode 100644 posterior_database/models/pymc/election88_full.py create mode 100644 posterior_database/models/pymc/gp_pois_regr.py create mode 100644 posterior_database/models/pymc/gp_regr.py create mode 100644 posterior_database/models/pymc/irt_2pl.py create mode 100644 posterior_database/models/pymc/kidscore_interaction.py create mode 100644 posterior_database/models/pymc/kidscore_interaction_c.py create mode 100644 posterior_database/models/pymc/kidscore_interaction_c2.py create mode 100644 posterior_database/models/pymc/kidscore_interaction_z.py create mode 100644 posterior_database/models/pymc/kidscore_mom_work.py create mode 100644 posterior_database/models/pymc/kidscore_momhs.py create mode 100644 posterior_database/models/pymc/kidscore_momhsiq.py create mode 100644 posterior_database/models/pymc/kidscore_momiq.py create mode 100644 posterior_database/models/pymc/kilpisjarvi.py create mode 100644 posterior_database/models/pymc/log10earn_height.py create mode 100644 posterior_database/models/pymc/logearn_height_male.py create mode 100644 posterior_database/models/pymc/logearn_interaction.py create mode 100644 posterior_database/models/pymc/logearn_interaction_z.py create mode 100644 posterior_database/models/pymc/logearn_logheight_male.py create mode 100644 posterior_database/models/pymc/logistic_regression_rhs.py create mode 100644 posterior_database/models/pymc/logmesquite_logvas.py create mode 100644 posterior_database/models/pymc/logmesquite_logvash.py create mode 100644 posterior_database/models/pymc/low_dim_gauss_mix.py create mode 100644 posterior_database/models/pymc/low_dim_gauss_mix_collapse.py create mode 100644 posterior_database/models/pymc/lsat_model.py create mode 100644 posterior_database/models/pymc/mesquite.py create mode 100644 posterior_database/models/pymc/nes_logit_model.py create mode 100644 posterior_database/models/pymc/normal_mixture.py create mode 100644 posterior_database/models/pymc/normal_mixture_k.py create mode 100644 posterior_database/models/pymc/pilots.py create mode 100644 posterior_database/models/pymc/radon_county.py create mode 100644 posterior_database/models/pymc/radon_county_intercept.py create mode 100644 posterior_database/models/pymc/radon_hierarchical_intercept_centered.py create mode 100644 posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py create mode 100644 posterior_database/models/pymc/radon_partially_pooled_centered.py create mode 100644 posterior_database/models/pymc/radon_pooled.py create mode 100644 posterior_database/models/pymc/radon_variable_intercept_centered.py create mode 100644 posterior_database/models/pymc/radon_variable_intercept_noncentered.py create mode 100644 posterior_database/models/pymc/radon_variable_intercept_slope_centered.py create mode 100644 posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py create mode 100644 posterior_database/models/pymc/rats_model.py create mode 100644 posterior_database/models/pymc/seeds_centered_model.py create mode 100644 posterior_database/models/pymc/seeds_model.py create mode 100644 posterior_database/models/pymc/seeds_stanified_model.py create mode 100644 posterior_database/models/pymc/sesame_one_pred_a.py create mode 100644 posterior_database/models/pymc/wells_daae_c_model.py create mode 100644 posterior_database/models/pymc/wells_dae_c_model.py create mode 100644 posterior_database/models/pymc/wells_dae_inter_model.py create mode 100644 posterior_database/models/pymc/wells_dae_model.py create mode 100644 posterior_database/models/pymc/wells_dist.py create mode 100644 posterior_database/models/pymc/wells_dist100_model.py create mode 100644 posterior_database/models/pymc/wells_dist100ars_model.py create mode 100644 posterior_database/models/pymc/wells_interaction_c_model.py create mode 100644 posterior_database/models/pymc/wells_interaction_model.py diff --git a/posterior_database/models/info/GLMM1_model.info.json b/posterior_database/models/info/GLMM1_model.info.json index c6f1b834..41c46c14 100644 --- a/posterior_database/models/info/GLMM1_model.info.json +++ b/posterior_database/models/info/GLMM1_model.info.json @@ -1,6 +1,10 @@ { "name": "GLMM1_model", - "keywords": ["BPA", "Ch.4", "GLMM1_model"], + "keywords": [ + "BPA", + "Ch.4", + "GLMM1_model" + ], "title": "Generalized Linear Mixed Model for Peregrine Population Size", "description": "A GLMM for modeling peregrine population size with a random effect being the site of observation.", "urls": "https://github.com/stan-dev/example-models/blob/master/BPA/Ch.04", @@ -11,6 +15,9 @@ "stan": { "model_code": "models/stan/GLMM1_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/GLMM1_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/GLMM_Poisson_model.info.json b/posterior_database/models/info/GLMM_Poisson_model.info.json index c291b589..6aaad76c 100644 --- a/posterior_database/models/info/GLMM_Poisson_model.info.json +++ b/posterior_database/models/info/GLMM_Poisson_model.info.json @@ -1,6 +1,10 @@ { "name": "GLMM_Poisson_model", - "keywords": ["BPA", "Ch.4", "GLMM_Poisson_model"], + "keywords": [ + "BPA", + "Ch.4", + "GLMM_Poisson_model" + ], "title": "Mixed Model to Predict Population Size with Random Site and Year Effects", "description": "A GLMM for modeling peregrine population size with a random effect being the site and year of observation using the Poisson distribution to model counts.", "urls": "https://github.com/stan-dev/example-models/blob/master/BPA/Ch.04", @@ -11,6 +15,9 @@ "stan": { "model_code": "models/stan/GLMM_Poisson_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/GLMM_Poisson_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/GLM_Poisson_model.info.json b/posterior_database/models/info/GLM_Poisson_model.info.json index 98e768a3..9a0c04fd 100644 --- a/posterior_database/models/info/GLM_Poisson_model.info.json +++ b/posterior_database/models/info/GLM_Poisson_model.info.json @@ -1,6 +1,12 @@ { "name": "GLM_Poisson_model", - "keywords": ["Population", "Peregrine", "Generalized", "Generalised", "Linear Model"], + "keywords": [ + "Population", + "Peregrine", + "Generalized", + "Generalised", + "Linear Model" + ], "title": "Poisson GLM for modeling a population of Peregrines", "description": "Poisson Generalised Linear Model where the linear predictor is a cubic polynomial function of time.", "urls": "https://github.com/stan-dev/example-models/tree/master/BPA/Ch.03", @@ -11,6 +17,9 @@ "stan": { "model_code": "models/stan/GLM_Poisson_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/GLM_Poisson_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/Rate_2_model.info.json b/posterior_database/models/info/Rate_2_model.info.json index c99f515e..d35045b9 100644 --- a/posterior_database/models/info/Rate_2_model.info.json +++ b/posterior_database/models/info/Rate_2_model.info.json @@ -1,6 +1,11 @@ { "name": "Rate_2_model", - "keywords": ["Trial", "Success Rate", "Beta Distribution", "Difference"], + "keywords": [ + "Trial", + "Success Rate", + "Beta Distribution", + "Difference" + ], "title": "Difference in success rates", "description": "Predicting the difference between the success rates of two trials", "urls": "https://github.com/stan-dev/example-models/tree/master/Bayesian_Cognitive_Modeling/ParameterEstimation/Binomial", @@ -11,6 +16,9 @@ "stan": { "model_code": "models/stan/Rate_2_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/Rate_2_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/Rate_4_model.info.json b/posterior_database/models/info/Rate_4_model.info.json index 5a6195d0..acaabf1c 100644 --- a/posterior_database/models/info/Rate_4_model.info.json +++ b/posterior_database/models/info/Rate_4_model.info.json @@ -1,6 +1,12 @@ { "name": "Rate_4_model", - "keywords": ["Trial", "Success Rate", "Inference", "Prior Inference", "Posterior Inference"], + "keywords": [ + "Trial", + "Success Rate", + "Inference", + "Prior Inference", + "Posterior Inference" + ], "title": "Success rate of a trial with prior and posterior inference", "description": "Inference of the success rate of a trial with prior and posterior inference", "urls": "https://github.com/stan-dev/example-models/tree/master/Bayesian_Cognitive_Modeling/ParameterEstimation/Binomial", @@ -11,6 +17,9 @@ "stan": { "model_code": "models/stan/Rate_4_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/Rate_4_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/Rate_5_model.info.json b/posterior_database/models/info/Rate_5_model.info.json index 4776b7b1..13cf8314 100644 --- a/posterior_database/models/info/Rate_5_model.info.json +++ b/posterior_database/models/info/Rate_5_model.info.json @@ -1,6 +1,11 @@ { "name": "Rate_5_model", - "keywords": ["Trial", "Correct Answer Rate", "Beta Distribution", "Common Rate"], + "keywords": [ + "Trial", + "Correct Answer Rate", + "Beta Distribution", + "Common Rate" + ], "title": "Common Rate of Success From Two Trials with Posterior Predictives", "description": "Inference of a common rate of success from two trials with posterior predictive for each trial for checking the adequacy of the model.", "urls": "https://github.com/stan-dev/example-models/tree/master/Bayesian_Cognitive_Modeling/ParameterEstimation/Binomial", @@ -11,6 +16,9 @@ "stan": { "model_code": "models/stan/Rate_5_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/Rate_5_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/accel_splines.info.json b/posterior_database/models/info/accel_splines.info.json index 20898b51..c32dd8fc 100644 --- a/posterior_database/models/info/accel_splines.info.json +++ b/posterior_database/models/info/accel_splines.info.json @@ -1,6 +1,9 @@ { "name": "accel_splines", - "keywords": ["stan_benchmark", "spline"], + "keywords": [ + "stan_benchmark", + "spline" + ], "title": "Splines for time-series data with varying mean and std", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +14,13 @@ "stan": { "model_code": "models/stan/accel_splines.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/accel_splines.py" } }, "references": "bales2019selecting", "added_date": "2020-02-01", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/arK.info.json b/posterior_database/models/info/arK.info.json index c809b1a5..f84e37ee 100644 --- a/posterior_database/models/info/arK.info.json +++ b/posterior_database/models/info/arK.info.json @@ -2,7 +2,10 @@ "name": "arK", "title": "Autoregressive-5 model", "description": "An AR(5) time series model.", - "keywords": ["time series", "stan_benchmark"], + "keywords": [ + "time series", + "stan_benchmark" + ], "urls": "https://github.com/stan-dev/stat_comp_benchmarks/tree/master/benchmarks/arK", "prior": { "keywords": [] @@ -11,6 +14,9 @@ "stan": { "model_code": "models/stan/arK.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/arK.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/blr.info.json b/posterior_database/models/info/blr.info.json index f7bac5ce..2f0b4589 100644 --- a/posterior_database/models/info/blr.info.json +++ b/posterior_database/models/info/blr.info.json @@ -12,6 +12,9 @@ "stan": { "model_code": "models/stan/blr.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/blr.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/diamonds.info.json b/posterior_database/models/info/diamonds.info.json index 73d3b0ac..b65c9ecf 100644 --- a/posterior_database/models/info/diamonds.info.json +++ b/posterior_database/models/info/diamonds.info.json @@ -1,6 +1,9 @@ { "name": "diamonds", - "keywords": ["stan_benchmark", "linear regression"], + "keywords": [ + "stan_benchmark", + "linear regression" + ], "title": "Multiple Highly Correlated Predictors Log-Log Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +14,13 @@ "stan": { "model_code": "models/stan/diamonds.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/diamonds.py" } }, "references": "bales2019selecting", "added_date": "2020-02-01", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/dogs.info.json b/posterior_database/models/info/dogs.info.json index ae431389..ff97f0bb 100644 --- a/posterior_database/models/info/dogs.info.json +++ b/posterior_database/models/info/dogs.info.json @@ -1,6 +1,10 @@ { "name": "dogs", - "keywords": ["ARM", "Ch. 24", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 24", + "stan_examples" + ], "title": "Logistic Mixed Effects Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/dogs.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/dogs.py" } }, "references": "gelman2006data", "added_date": "2020-04-05", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/dogs_hierarchical.info.json b/posterior_database/models/info/dogs_hierarchical.info.json index 212b3f59..e91da4b0 100644 --- a/posterior_database/models/info/dogs_hierarchical.info.json +++ b/posterior_database/models/info/dogs_hierarchical.info.json @@ -1,6 +1,9 @@ { "name": "dogs_hierarchical", - "keywords": ["ARM", "Ch. 24"], + "keywords": [ + "ARM", + "Ch. 24" + ], "title": "Hierarchical Logistic Mixed Effects Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -14,6 +17,9 @@ "stan": { "model_code": "models/stan/dogs_hierarchical.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/dogs_hierarchical.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/dugongs_model.info.json b/posterior_database/models/info/dugongs_model.info.json index d5d9d277..9973ba3b 100644 --- a/posterior_database/models/info/dugongs_model.info.json +++ b/posterior_database/models/info/dugongs_model.info.json @@ -1,6 +1,10 @@ { "name": "dugongs_model", - "keywords": ["nonlinear", "non-linear", "growth curve"], + "keywords": [ + "nonlinear", + "non-linear", + "growth curve" + ], "title": "Dugong Age and Length", "description": "Model of age and length data of dugongs using a nonlinear growth curve with no inflection point.", "urls": "https://github.com/stan-dev/example-models/tree/master/bugs_examples/vol2", @@ -11,6 +15,9 @@ "stan": { "model_code": "models/stan/dugongs_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/dugongs_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/earn_height.info.json b/posterior_database/models/info/earn_height.info.json index 09710205..fcf55d65 100644 --- a/posterior_database/models/info/earn_height.info.json +++ b/posterior_database/models/info/earn_height.info.json @@ -1,6 +1,10 @@ { "name": "earn_height", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "One Predictor Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/earn_height.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/earn_height.py" } }, "references": "gelman2006data", "added_date": "2020-01-17", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/eight_schools_centered.info.json b/posterior_database/models/info/eight_schools_centered.info.json index b525e613..a7551442 100644 --- a/posterior_database/models/info/eight_schools_centered.info.json +++ b/posterior_database/models/info/eight_schools_centered.info.json @@ -2,8 +2,14 @@ "name": "eight_schools_centered", "title": "A centered hiearchical model for 8 schools", "description": "A centered hiearchical model for the 8 schools example of Rubin (1981)", - "keywords": ["bda3_example", "hiearchical"], - "references": ["rubin1981estimation", "gelman2013bayesian"], + "keywords": [ + "bda3_example", + "hiearchical" + ], + "references": [ + "rubin1981estimation", + "gelman2013bayesian" + ], "urls": "http://www.stat.columbia.edu/~gelman/arm/examples/schools", "prior": { "keywords": [] @@ -12,6 +18,9 @@ "stan": { "model_code": "models/stan/eight_schools_centered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/eight_schools_centered.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/election88_full.info.json b/posterior_database/models/info/election88_full.info.json index 0b2f2c12..ac37f3a5 100644 --- a/posterior_database/models/info/election88_full.info.json +++ b/posterior_database/models/info/election88_full.info.json @@ -1,6 +1,10 @@ { "name": "election88_full", - "keywords": ["ARM", "Ch. 14", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 14", + "stan_examples" + ], "title": "Generalized Linear Mixed Effects Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/election88_full.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/election88_full.py" } }, "references": "gelman2006data", "added_date": "2020-03-28", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/gp_pois_regr.info.json b/posterior_database/models/info/gp_pois_regr.info.json index 7f2f2096..0279c558 100644 --- a/posterior_database/models/info/gp_pois_regr.info.json +++ b/posterior_database/models/info/gp_pois_regr.info.json @@ -2,7 +2,10 @@ "name": "gp_pois_regr", "title": "Gaussian Process Poisson Regression", "description": "Poisson regression with a one-dimensional latent Gaussian process \nusing the exponential quadratic covariance function.", - "keywords": ["stan_benchmark", "gaussian process"], + "keywords": [ + "stan_benchmark", + "gaussian process" + ], "references": null, "urls": "https://github.com/stan-dev/stat_comp_benchmarks/tree/master/benchmarks/gp_pois_regr", "prior": { @@ -12,6 +15,9 @@ "stan": { "model_code": "models/stan/gp_pois_regr.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/gp_pois_regr.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/gp_regr.info.json b/posterior_database/models/info/gp_regr.info.json index 77fd8ab5..30fcf212 100644 --- a/posterior_database/models/info/gp_regr.info.json +++ b/posterior_database/models/info/gp_regr.info.json @@ -2,7 +2,10 @@ "name": "gp_regr", "title": "Gaussian Process regression", "description": "One-dimensional Gaussian process Regression using the\nexponential quadratic covariance function.", - "keywords": ["stan_benchmark", "gaussian process"], + "keywords": [ + "stan_benchmark", + "gaussian process" + ], "references": null, "urls": "https://github.com/stan-dev/stat_comp_benchmarks/tree/master/benchmarks/gp_regr", "prior": { @@ -12,6 +15,9 @@ "stan": { "model_code": "models/stan/gp_regr.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/gp_regr.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/irt_2pl.info.json b/posterior_database/models/info/irt_2pl.info.json index 79a29dab..eed91bbe 100644 --- a/posterior_database/models/info/irt_2pl.info.json +++ b/posterior_database/models/info/irt_2pl.info.json @@ -2,7 +2,10 @@ "name": "irt_2pl", "title": "Two Parameter Logistic Item Response Theory Model", "description": "Hierarchical item response theory model.", - "keywords": ["stan_benchmark", "hiearchical"], + "keywords": [ + "stan_benchmark", + "hiearchical" + ], "references": null, "urls": "https://github.com/stan-dev/stat_comp_benchmarks/tree/master/benchmarks/irt_2pl", "prior": { @@ -12,6 +15,9 @@ "stan": { "model_code": "models/stan/irt_2pl.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/irt_2pl.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/kidscore_interaction.info.json b/posterior_database/models/info/kidscore_interaction.info.json index d5370cf6..51e623a0 100644 --- a/posterior_database/models/info/kidscore_interaction.info.json +++ b/posterior_database/models/info/kidscore_interaction.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_interaction", - "keywords": ["ARM", "Ch. 3", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 3", + "stan_examples" + ], "title": "Interacting Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/kidscore_interaction.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_interaction.py" } }, "references": "gelman2006data", "added_date": "2020-01-13", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_interaction_c.info.json b/posterior_database/models/info/kidscore_interaction_c.info.json index 3bce50bc..e01c4a54 100644 --- a/posterior_database/models/info/kidscore_interaction_c.info.json +++ b/posterior_database/models/info/kidscore_interaction_c.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_interaction_c", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Interacting Predictors Centered Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/kidscore_interaction_c.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_interaction_c.py" } }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_interaction_c2.info.json b/posterior_database/models/info/kidscore_interaction_c2.info.json index d636d6d3..990435a9 100644 --- a/posterior_database/models/info/kidscore_interaction_c2.info.json +++ b/posterior_database/models/info/kidscore_interaction_c2.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_interaction_c2", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Interacting Predictors Conventionally Centered Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/kidscore_interaction_c2.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_interaction_c2.py" } }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_interaction_z.info.json b/posterior_database/models/info/kidscore_interaction_z.info.json index e5f0b595..47a7ab62 100644 --- a/posterior_database/models/info/kidscore_interaction_z.info.json +++ b/posterior_database/models/info/kidscore_interaction_z.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_interaction_z", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Interacting Predictors Standardized Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/kidscore_interaction_z.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_interaction_z.py" } }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_mom_work.info.json b/posterior_database/models/info/kidscore_mom_work.info.json index f28f8d7d..72809fc1 100644 --- a/posterior_database/models/info/kidscore_mom_work.info.json +++ b/posterior_database/models/info/kidscore_mom_work.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_mom_work", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Factor Level Predictors Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/kidscore_mom_work.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_mom_work.py" } }, "references": "gelman2006data", "added_date": "2020-01-26", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_momhs.info.json b/posterior_database/models/info/kidscore_momhs.info.json index e6420289..c339e04a 100644 --- a/posterior_database/models/info/kidscore_momhs.info.json +++ b/posterior_database/models/info/kidscore_momhs.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_momhs", - "keywords": ["ARM", "Ch. 3", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 3", + "stan_examples" + ], "title": "One Predictor Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,6 +15,9 @@ "stan": { "model_code": "models/stan/kidscore_momhs.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_momhs.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/kidscore_momhsiq.info.json b/posterior_database/models/info/kidscore_momhsiq.info.json index 696cfa2b..d91030d7 100644 --- a/posterior_database/models/info/kidscore_momhsiq.info.json +++ b/posterior_database/models/info/kidscore_momhsiq.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_momhsiq", - "keywords": ["ARM", "Ch. 3", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 3", + "stan_examples" + ], "title": "Multiple Predictors Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/kidscore_momhsiq.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_momhsiq.py" } }, "references": "gelman2006data", "added_date": "2020-01-13", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_momiq.info.json b/posterior_database/models/info/kidscore_momiq.info.json index 2288c032..68d5f3fd 100644 --- a/posterior_database/models/info/kidscore_momiq.info.json +++ b/posterior_database/models/info/kidscore_momiq.info.json @@ -1,6 +1,10 @@ { "name": "kidscore_momiq", - "keywords": ["ARM", "Ch. 3", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 3", + "stan_examples" + ], "title": "One Predictor Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/kidscore_momiq.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kidscore_momiq.py" } }, "references": "gelman2006data", "added_date": "2020-01-13", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kilpisjarvi.info.json b/posterior_database/models/info/kilpisjarvi.info.json index f660cdd6..05304585 100644 --- a/posterior_database/models/info/kilpisjarvi.info.json +++ b/posterior_database/models/info/kilpisjarvi.info.json @@ -1,6 +1,9 @@ { "name": "kilpisjarvi", - "keywords": ["stan_benchmark", "linear regression"], + "keywords": [ + "stan_benchmark", + "linear regression" + ], "title": "Multiple Highly Correlated Predictors Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +14,13 @@ "stan": { "model_code": "models/stan/kilpisjarvi.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/kilpisjarvi.py" } }, "references": "bales2019selecting", "added_date": "2020-02-05", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/log10earn_height.info.json b/posterior_database/models/info/log10earn_height.info.json index 1f0bd44b..78342f23 100644 --- a/posterior_database/models/info/log10earn_height.info.json +++ b/posterior_database/models/info/log10earn_height.info.json @@ -1,6 +1,10 @@ { "name": "log10earn_height", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "One Predictor Log10-linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/log10earn_height.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/log10earn_height.py" } }, "references": "gelman2006data", "added_date": "2020-01-23", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_height_male.info.json b/posterior_database/models/info/logearn_height_male.info.json index 99c2fec1..c40607c4 100644 --- a/posterior_database/models/info/logearn_height_male.info.json +++ b/posterior_database/models/info/logearn_height_male.info.json @@ -1,6 +1,10 @@ { "name": "logearn_height_male", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Predictors Log-linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/logearn_height_male.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/logearn_height_male.py" } }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_interaction.info.json b/posterior_database/models/info/logearn_interaction.info.json index 5952e2cf..a4343837 100644 --- a/posterior_database/models/info/logearn_interaction.info.json +++ b/posterior_database/models/info/logearn_interaction.info.json @@ -1,6 +1,10 @@ { "name": "logearn_interaction", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Predictors Interacting Log-linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/logearn_interaction.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/logearn_interaction.py" } }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_interaction_z.info.json b/posterior_database/models/info/logearn_interaction_z.info.json index 224ec367..140cabc7 100644 --- a/posterior_database/models/info/logearn_interaction_z.info.json +++ b/posterior_database/models/info/logearn_interaction_z.info.json @@ -1,6 +1,10 @@ { "name": "logearn_interaction_z", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Linearly Transformed Predictors Interacting Log-linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/logearn_interaction_z.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/logearn_interaction_z.py" } }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_logheight_male.info.json b/posterior_database/models/info/logearn_logheight_male.info.json index 63b8fbc5..d26b4484 100644 --- a/posterior_database/models/info/logearn_logheight_male.info.json +++ b/posterior_database/models/info/logearn_logheight_male.info.json @@ -1,6 +1,10 @@ { "name": "logearn_logheight_male", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Predictors Log-Log Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/logearn_logheight_male.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/logearn_logheight_male.py" } }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logistic_regression_rhs.info.json b/posterior_database/models/info/logistic_regression_rhs.info.json index 48ceaed1..4b894ea0 100644 --- a/posterior_database/models/info/logistic_regression_rhs.info.json +++ b/posterior_database/models/info/logistic_regression_rhs.info.json @@ -1,6 +1,9 @@ { "name": "logistic_regression_rhs", - "keywords": ["stan_benchmark", "logistic regression"], + "keywords": [ + "stan_benchmark", + "logistic regression" + ], "title": "Logistic Regression with Regularized Horseshoe Prior", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +14,13 @@ "stan": { "model_code": "models/stan/logistic_regression_rhs.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/logistic_regression_rhs.py" } }, "references": "piironen2017sparsity", "added_date": "2020-02-29", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logmesquite_logvas.info.json b/posterior_database/models/info/logmesquite_logvas.info.json index ff71a6d7..2743a877 100644 --- a/posterior_database/models/info/logmesquite_logvas.info.json +++ b/posterior_database/models/info/logmesquite_logvas.info.json @@ -1,6 +1,10 @@ { "name": "logmesquite_logvas", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Log-Log Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/logmesquite_logvas.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/logmesquite_logvas.py" } }, "references": "gelman2006data", "added_date": "2020-01-30", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logmesquite_logvash.info.json b/posterior_database/models/info/logmesquite_logvash.info.json index 57909d21..ca540303 100644 --- a/posterior_database/models/info/logmesquite_logvash.info.json +++ b/posterior_database/models/info/logmesquite_logvash.info.json @@ -1,6 +1,10 @@ { "name": "logmesquite_logvash", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Log-Log Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/logmesquite_logvash.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/logmesquite_logvash.py" } }, "references": "gelman2006data", "added_date": "2020-01-30", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/low_dim_gauss_mix.info.json b/posterior_database/models/info/low_dim_gauss_mix.info.json index f9337ebb..7c9a71d8 100644 --- a/posterior_database/models/info/low_dim_gauss_mix.info.json +++ b/posterior_database/models/info/low_dim_gauss_mix.info.json @@ -2,7 +2,10 @@ "name": "low_dim_gauss_mix", "title": "A Two-Dimensional Gaussian Mixture Model", "description": "A Two-Dimensional Gaussian Mixture Model", - "keywords": ["stan_benchmark", "mixture model"], + "keywords": [ + "stan_benchmark", + "mixture model" + ], "references": null, "urls": "https://github.com/stan-dev/stat_comp_benchmarks/tree/master/benchmarks/low_dim_gauss_mix", "prior": { @@ -12,6 +15,9 @@ "stan": { "model_code": "models/stan/low_dim_gauss_mix.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/low_dim_gauss_mix.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/low_dim_gauss_mix_collapse.info.json b/posterior_database/models/info/low_dim_gauss_mix_collapse.info.json index 4bedf8e8..1877cf93 100644 --- a/posterior_database/models/info/low_dim_gauss_mix_collapse.info.json +++ b/posterior_database/models/info/low_dim_gauss_mix_collapse.info.json @@ -2,7 +2,10 @@ "name": "low_dim_gauss_mix_collapse", "title": "A Two-Dimensional (unordered) Gaussian Mixture Model", "description": "A Two-Dimensional Gaussian Mixture Model", - "keywords": ["stan_benchmark", "mixture model"], + "keywords": [ + "stan_benchmark", + "mixture model" + ], "references": null, "urls": "https://github.com/stan-dev/stat_comp_benchmarks/tree/master/benchmarks/low_dim_gauss_mix_collapse", "prior": { @@ -12,6 +15,9 @@ "stan": { "model_code": "models/stan/low_dim_gauss_mix_collapse.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/low_dim_gauss_mix_collapse.py" } }, "added_by": "Mans Magnusson", diff --git a/posterior_database/models/info/lsat_model.info.json b/posterior_database/models/info/lsat_model.info.json index 43041058..468a4cae 100644 --- a/posterior_database/models/info/lsat_model.info.json +++ b/posterior_database/models/info/lsat_model.info.json @@ -1,6 +1,10 @@ { "name": "lsat_model", - "keywords": ["Random Effects", "Random", "LSAT"], + "keywords": [ + "Random Effects", + "Random", + "LSAT" + ], "title": "Random Effects (Rasch) Model for True Difficulty of LSAT Questions", "description": "One-parameter 'Rasch Model' where the probability that a student\n responds correctly to a question is assumed to follow a logistic\n function parameterized by 'item difficulty' and a latent variable\n representing the students underlying ability.", "urls": "https://github.com/stan-dev/example-models/tree/master/bugs_examples/vol1/lsat", @@ -11,6 +15,9 @@ "stan": { "model_code": "models/stan/lsat_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/lsat_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/mesquite.info.json b/posterior_database/models/info/mesquite.info.json index ca6405f9..24d0f0c5 100644 --- a/posterior_database/models/info/mesquite.info.json +++ b/posterior_database/models/info/mesquite.info.json @@ -1,6 +1,10 @@ { "name": "mesquite", - "keywords": ["ARM", "Ch. 4", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 4", + "stan_examples" + ], "title": "Multiple Predictors Linear Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/mesquite.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/mesquite.py" } }, "references": "gelman2006data", "added_date": "2020-01-26", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/nes_logit_model.info.json b/posterior_database/models/info/nes_logit_model.info.json index df769188..8f450843 100644 --- a/posterior_database/models/info/nes_logit_model.info.json +++ b/posterior_database/models/info/nes_logit_model.info.json @@ -1,9 +1,20 @@ { "name": "nes_logit_model", - "keywords": ["National", "Election", "Study", "Logistic Regression", "Single Predictor", "Preference", "Presidential Election"], + "keywords": [ + "National", + "Election", + "Study", + "Logistic Regression", + "Single Predictor", + "Preference", + "Presidential Election" + ], "title": "Logistic Regression Model for Voting Preference based on Income", "description": "Logistic regression to estimate the probability of supporting a candidate inferring on income.", - "urls": ["https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", "http://www.stat.columbia.edu/~gelman/arm/"], + "urls": [ + "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", + "http://www.stat.columbia.edu/~gelman/arm/" + ], "references": "gelman2006data", "added_by": "Kane Lindsay", "added_date": "2021-07-01", @@ -11,6 +22,9 @@ "stan": { "model_code": "models/stan/nes_logit_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/nes_logit_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/normal_mixture.info.json b/posterior_database/models/info/normal_mixture.info.json index 024be3a8..d01b1b67 100644 --- a/posterior_database/models/info/normal_mixture.info.json +++ b/posterior_database/models/info/normal_mixture.info.json @@ -1,6 +1,9 @@ { "name": "normal_mixture", - "keywords": ["basic_estimators", "stan_examples"], + "keywords": [ + "basic_estimators", + "stan_examples" + ], "title": "Two Component Gaussian Mixture Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +14,13 @@ "stan": { "model_code": "models/stan/normal_mixture.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/normal_mixture.py" } }, "references": null, "added_date": "2020-04-20", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/normal_mixture_k.info.json b/posterior_database/models/info/normal_mixture_k.info.json index 62fa23f6..a16bf370 100644 --- a/posterior_database/models/info/normal_mixture_k.info.json +++ b/posterior_database/models/info/normal_mixture_k.info.json @@ -1,6 +1,9 @@ { "name": "normal_mixture_k", - "keywords": ["basic_estimators", "stan_examples"], + "keywords": [ + "basic_estimators", + "stan_examples" + ], "title": "K Component Gaussian Mixture Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +14,13 @@ "stan": { "model_code": "models/stan/normal_mixture_k.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/normal_mixture_k.py" } }, "references": null, "added_date": "2020-03-11", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/pilots.info.json b/posterior_database/models/info/pilots.info.json index 070dbb23..57266a23 100644 --- a/posterior_database/models/info/pilots.info.json +++ b/posterior_database/models/info/pilots.info.json @@ -1,6 +1,10 @@ { "name": "pilots", - "keywords": ["ARM", "Ch. 14", "stan_examples"], + "keywords": [ + "ARM", + "Ch. 14", + "stan_examples" + ], "title": "Linear Mixed Effects Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +15,13 @@ "stan": { "model_code": "models/stan/pilots.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/pilots.py" } }, "references": "gelman2006data", "added_date": "2020-04-20", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/radon_county.info.json b/posterior_database/models/info/radon_county.info.json index 452c5862..5957defd 100644 --- a/posterior_database/models/info/radon_county.info.json +++ b/posterior_database/models/info/radon_county.info.json @@ -1,6 +1,9 @@ { "name": "radon_county", - "keywords": ["stan_benchmark", "hierarchical model"], + "keywords": [ + "stan_benchmark", + "hierarchical model" + ], "title": "Hierarchical Model", "prior": { "keywords": "stan_recommended_35dbfe6" @@ -11,10 +14,13 @@ "stan": { "model_code": "models/stan/radon_county.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_county.py" } }, "references": "bales2019selecting", "added_date": "2020-02-07", - "added_by": "Oliver Järnefelt", + "added_by": "Oliver J\u00e4rnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/radon_county_intercept.info.json b/posterior_database/models/info/radon_county_intercept.info.json index 20143753..cba2b79f 100644 --- a/posterior_database/models/info/radon_county_intercept.info.json +++ b/posterior_database/models/info/radon_county_intercept.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_county_intercept.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_county_intercept.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_hierarchical_intercept_centered.info.json b/posterior_database/models/info/radon_hierarchical_intercept_centered.info.json index 6d8845e4..908881ee 100644 --- a/posterior_database/models/info/radon_hierarchical_intercept_centered.info.json +++ b/posterior_database/models/info/radon_hierarchical_intercept_centered.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_hierarchical_intercept_centered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_hierarchical_intercept_centered.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_hierarchical_intercept_noncentered.info.json b/posterior_database/models/info/radon_hierarchical_intercept_noncentered.info.json index bcc60fcb..f9c3ca6d 100644 --- a/posterior_database/models/info/radon_hierarchical_intercept_noncentered.info.json +++ b/posterior_database/models/info/radon_hierarchical_intercept_noncentered.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_hierarchical_intercept_noncentered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_hierarchical_intercept_noncentered.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_partially_pooled_centered.info.json b/posterior_database/models/info/radon_partially_pooled_centered.info.json index 10365962..3e16c669 100644 --- a/posterior_database/models/info/radon_partially_pooled_centered.info.json +++ b/posterior_database/models/info/radon_partially_pooled_centered.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_partially_pooled_centered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_partially_pooled_centered.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_pooled.info.json b/posterior_database/models/info/radon_pooled.info.json index b57f1a9d..d7acd7a2 100644 --- a/posterior_database/models/info/radon_pooled.info.json +++ b/posterior_database/models/info/radon_pooled.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_pooled.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_pooled.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_variable_intercept_centered.info.json b/posterior_database/models/info/radon_variable_intercept_centered.info.json index 92657541..7229c113 100644 --- a/posterior_database/models/info/radon_variable_intercept_centered.info.json +++ b/posterior_database/models/info/radon_variable_intercept_centered.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_variable_intercept_centered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_variable_intercept_centered.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_variable_intercept_noncentered.info.json b/posterior_database/models/info/radon_variable_intercept_noncentered.info.json index 6112af94..c346b9c2 100644 --- a/posterior_database/models/info/radon_variable_intercept_noncentered.info.json +++ b/posterior_database/models/info/radon_variable_intercept_noncentered.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_variable_intercept_noncentered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_variable_intercept_noncentered.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_variable_intercept_slope_centered.info.json b/posterior_database/models/info/radon_variable_intercept_slope_centered.info.json index c172c3b9..587f131c 100644 --- a/posterior_database/models/info/radon_variable_intercept_slope_centered.info.json +++ b/posterior_database/models/info/radon_variable_intercept_slope_centered.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_variable_intercept_slope_centered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_variable_intercept_slope_centered.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/radon_variable_intercept_slope_noncentered.info.json b/posterior_database/models/info/radon_variable_intercept_slope_noncentered.info.json index 25754794..50418621 100644 --- a/posterior_database/models/info/radon_variable_intercept_slope_noncentered.info.json +++ b/posterior_database/models/info/radon_variable_intercept_slope_noncentered.info.json @@ -11,6 +11,9 @@ "stan": { "model_code": "models/stan/radon_variable_intercept_slope_noncentered.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/radon_variable_intercept_slope_noncentered.py" } }, "references": "gelman2006data", diff --git a/posterior_database/models/info/rats_model.info.json b/posterior_database/models/info/rats_model.info.json index 1f0f7d95..3a0faac8 100644 --- a/posterior_database/models/info/rats_model.info.json +++ b/posterior_database/models/info/rats_model.info.json @@ -1,6 +1,13 @@ { "name": "rats_model", - "keywords": ["Heirarchical", "Normal", "Rats", "Random Effects", "Linear Growth", "Linear"], + "keywords": [ + "Heirarchical", + "Normal", + "Rats", + "Random Effects", + "Linear Growth", + "Linear" + ], "title": "Normal Heirarchical Model to Model Rats' Weight Over Time", "description": "The model is essentially a random effects linear growth curve.", "urls": "https://github.com/stan-dev/example-models/tree/master/bugs_examples/vol1/rats", @@ -11,6 +18,9 @@ "stan": { "model_code": "models/stan/rats_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/rats_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/seeds_centered_model.info.json b/posterior_database/models/info/seeds_centered_model.info.json index 80d20721..81365736 100644 --- a/posterior_database/models/info/seeds_centered_model.info.json +++ b/posterior_database/models/info/seeds_centered_model.info.json @@ -1,6 +1,13 @@ { "name": "seeds_centered_model", - "keywords": ["Random", "Effect", "Logistic", "Regression", "Stanified", "Centered"], + "keywords": [ + "Random", + "Effect", + "Logistic", + "Regression", + "Stanified", + "Centered" + ], "title": "Normal Heirarchical Model to Model Rats' Weight Over Time", "description": "The model is essentially a random effects logistic,\n allowing for over-dispersion. Models the proportion of germination\n of different seeds in different root extracts. 'Stanified' & centered:\n tau replaced by sigma, direct estimation using \n narrower semi-informative priors, coefficients are centered", "urls": "http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol1.pdf", @@ -11,6 +18,9 @@ "stan": { "model_code": "models/stan/seeds_centered_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/seeds_centered_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/seeds_model.info.json b/posterior_database/models/info/seeds_model.info.json index b04a4279..083465a2 100644 --- a/posterior_database/models/info/seeds_model.info.json +++ b/posterior_database/models/info/seeds_model.info.json @@ -1,6 +1,11 @@ { "name": "seeds_model", - "keywords": ["Random", "Effect", "Logistic", "Regression"], + "keywords": [ + "Random", + "Effect", + "Logistic", + "Regression" + ], "title": "Random Effect Logistic Regression for Seed Germination Proportion", "description": "The model is essentially a random effects logistic,\n allowing for over-dispersion. Models the proportion of germination\n of different seeds in different root extracts.", "urls": "http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol1.pdf", @@ -10,6 +15,9 @@ "model_implementations": { "stan": { "model_code": "models/stan/seeds_model.stan" + }, + "pymc": { + "model_code": "models/pymc/seeds_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/seeds_stanified_model.info.json b/posterior_database/models/info/seeds_stanified_model.info.json index 12c6f392..4c4f78ad 100644 --- a/posterior_database/models/info/seeds_stanified_model.info.json +++ b/posterior_database/models/info/seeds_stanified_model.info.json @@ -1,6 +1,12 @@ { "name": "seeds_stanified_model", - "keywords": ["Random", "Effect", "Logistic", "Regression", "Stanified"], + "keywords": [ + "Random", + "Effect", + "Logistic", + "Regression", + "Stanified" + ], "title": "Normal Heirarchical Model to Model Rats' Weight Over Time", "description": "The model is essentially a random effects logistic,\n allowing for over-dispersion. Models the proportion of germination\n of different seeds in different root extracts. 'Stanified':\n tau replaced by sigma, direct estimation using \n narrower semi-informative priors", "urls": "http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol1.pdf", @@ -11,6 +17,9 @@ "stan": { "model_code": "models/stan/seeds_stanified_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/seeds_stanified_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/sesame_one_pred_a.info.json b/posterior_database/models/info/sesame_one_pred_a.info.json index 7d1f1afa..3e2eb9e5 100644 --- a/posterior_database/models/info/sesame_one_pred_a.info.json +++ b/posterior_database/models/info/sesame_one_pred_a.info.json @@ -1,6 +1,11 @@ { "name": "sesame_one_pred_a", - "keywords": ["sesame", "ARM", "Ch.10", "linear model"], + "keywords": [ + "sesame", + "ARM", + "Ch.10", + "linear model" + ], "title": "Linear model for the effect of encouragement to watch on actually watching Sesame Street", "description": "A linear model with one predictor.", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.10", @@ -11,6 +16,9 @@ "stan": { "model_code": "models/stan/sesame_one_pred_a.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/sesame_one_pred_a.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_daae_c_model.info.json b/posterior_database/models/info/wells_daae_c_model.info.json index 660d8a09..7946a9bb 100644 --- a/posterior_database/models/info/wells_daae_c_model.info.json +++ b/posterior_database/models/info/wells_daae_c_model.info.json @@ -1,6 +1,20 @@ { "name": "wells_daae_c_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled", "four predictors", "arsenic", "distance", "education", "community organization", "centered", "social predictor"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled", + "four predictors", + "arsenic", + "distance", + "education", + "community organization", + "centered", + "social predictor" + ], "title": "4-Predictor logistic regression model with centered inputs for decision to switch wells", "description": "Performs logistic regression using four centered predictors:\n distance from nearest safe well, arsenic levels, years in\n education, and if the individual is associated with an active community project.\n The association predictor is not actually predictive of switching.\n ", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +25,9 @@ "stan": { "model_code": "models/stan/wells_daae_c_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_daae_c_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_dae_c_model.info.json b/posterior_database/models/info/wells_dae_c_model.info.json index 8fd56f0d..27c9ad4b 100644 --- a/posterior_database/models/info/wells_dae_c_model.info.json +++ b/posterior_database/models/info/wells_dae_c_model.info.json @@ -1,6 +1,19 @@ { "name": "wells_dae_c_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled", "three predictors", "arsenic", "distance", "education", "centered", "social predictor"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled", + "three predictors", + "arsenic", + "distance", + "education", + "centered", + "social predictor" + ], "title": "3-Predictor logistic regression model with centered inputs for decision to switch wells", "description": "Performs logistic regression using three centered predictors \n (distance from nearest safe well, arsenic levels, and years in\n education).", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +24,9 @@ "stan": { "model_code": "models/stan/wells_dae_c_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_dae_c_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_dae_inter_model.info.json b/posterior_database/models/info/wells_dae_inter_model.info.json index 9d35e1ed..137ea409 100644 --- a/posterior_database/models/info/wells_dae_inter_model.info.json +++ b/posterior_database/models/info/wells_dae_inter_model.info.json @@ -1,6 +1,20 @@ { "name": "wells_dae_inter_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled", "three predictors", "arsenic", "distance", "interaction", "centered", "education", "social predictor"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled", + "three predictors", + "arsenic", + "distance", + "interaction", + "centered", + "education", + "social predictor" + ], "title": "3-Input logistic regression model with interactions and centered inputs for decision to switch wells", "description": "Performs logistic regression using three centered inputs \n (distance from nearest safe well, log-scaled arsenic levels, and years in\n education) and the interactions between each pair of inputs.", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +25,9 @@ "stan": { "model_code": "models/stan/wells_dae_inter_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_dae_inter_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_dae_model.info.json b/posterior_database/models/info/wells_dae_model.info.json index 5a4203da..5d271b21 100644 --- a/posterior_database/models/info/wells_dae_model.info.json +++ b/posterior_database/models/info/wells_dae_model.info.json @@ -1,6 +1,19 @@ { "name": "wells_dae_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled", "three predictors", "arsenic", "distance", "interaction", "education", "social predictor"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled", + "three predictors", + "arsenic", + "distance", + "interaction", + "education", + "social predictor" + ], "title": "3-Predictor logistic regression model for decision to switch wells.", "description": "Performs logistic regression using three predictors \n (distance from nearest safe well, arsenic levels, and years in\n education).", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +24,9 @@ "stan": { "model_code": "models/stan/wells_dae_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_dae_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_dist.info.json b/posterior_database/models/info/wells_dist.info.json index 8f018591..7e1782d4 100644 --- a/posterior_database/models/info/wells_dist.info.json +++ b/posterior_database/models/info/wells_dist.info.json @@ -1,6 +1,12 @@ { "name": "wells_dist", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression" + ], "title": "Logistic regression model for decision to switch wells", "description": "Performs logistic regression using one predictor (distance from nearest safe well).", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +17,9 @@ "stan": { "model_code": "models/stan/wells_dist.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_dist.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_dist100_model.info.json b/posterior_database/models/info/wells_dist100_model.info.json index 543c5b7c..67c0b78e 100644 --- a/posterior_database/models/info/wells_dist100_model.info.json +++ b/posterior_database/models/info/wells_dist100_model.info.json @@ -1,6 +1,13 @@ { "name": "wells_dist100_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled" + ], "title": "Logistic regression model for decision to switch wells", "description": "Performs logistic regression using one predictor (distance from nearest safe well).\n Rescales distance to 100-meter units.", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +18,9 @@ "stan": { "model_code": "models/stan/wells_dist100_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_dist100_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_dist100ars_model.info.json b/posterior_database/models/info/wells_dist100ars_model.info.json index 495f15a2..0570aff0 100644 --- a/posterior_database/models/info/wells_dist100ars_model.info.json +++ b/posterior_database/models/info/wells_dist100ars_model.info.json @@ -1,6 +1,16 @@ { "name": "wells_dist100ars_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled", "two predictors", "arsenic", "distance"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled", + "two predictors", + "arsenic", + "distance" + ], "title": "2-Predictor Logistic regression model for decision to switch wells", "description": "Performs logistic regression using two predictors (distance from nearest safe well and arsenic levels).\n Rescales distance to 100-meter units.", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +21,9 @@ "stan": { "model_code": "models/stan/wells_dist100ars_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_dist100ars_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_interaction_c_model.info.json b/posterior_database/models/info/wells_interaction_c_model.info.json index ceeee8a4..3bce188a 100644 --- a/posterior_database/models/info/wells_interaction_c_model.info.json +++ b/posterior_database/models/info/wells_interaction_c_model.info.json @@ -1,6 +1,17 @@ { "name": "wells_interaction_c_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled", "two predictors", "arsenic", "distance", "interaction"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled", + "two predictors", + "arsenic", + "distance", + "interaction" + ], "title": "2-Predictor logistic regression model with interactions and centered inputs for decision to switch wells", "description": "Performs logistic regression using two predictors\n (distance from nearest safe well and arsenic levels) and their\n interaction with centered input variables.", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +22,9 @@ "stan": { "model_code": "models/stan/wells_interaction_c_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_interaction_c_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/info/wells_interaction_model.info.json b/posterior_database/models/info/wells_interaction_model.info.json index 6ccabe63..39c71532 100644 --- a/posterior_database/models/info/wells_interaction_model.info.json +++ b/posterior_database/models/info/wells_interaction_model.info.json @@ -1,6 +1,17 @@ { "name": "wells_interaction_model", - "keywords": ["wells", "ARM", "Ch.5", "logistic", "regression", "scaled", "two predictors", "arsenic", "distance", "interaction"], + "keywords": [ + "wells", + "ARM", + "Ch.5", + "logistic", + "regression", + "scaled", + "two predictors", + "arsenic", + "distance", + "interaction" + ], "title": "2-Predictor Logistic regression model with interactions for decision to switch wells", "description": "Performs logistic regression using two predictors (distance from nearest safe well and arsenic levels) and their interaction.", "urls": "https://github.com/stan-dev/example-models/tree/master/ARM/Ch.5", @@ -11,6 +22,9 @@ "stan": { "model_code": "models/stan/wells_interaction_model.stan", "stan_version": ">=2.26.0" + }, + "pymc": { + "model_code": "models/pymc/wells_interaction_model.py" } }, "licence": "BSD3" diff --git a/posterior_database/models/pymc/GLMM1_model.py b/posterior_database/models/pymc/GLMM1_model.py new file mode 100644 index 00000000..922a42de --- /dev/null +++ b/posterior_database/models/pymc/GLMM1_model.py @@ -0,0 +1,34 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + nobs = data['nobs'] + nmis = data['nmis'] + nyear = data['nyear'] + nsite = data['nsite'] + obs = np.array(data['obs']) + obsyear = np.array(data['obsyear']) - 1 + obssite = np.array(data['obssite']) - 1 + misyear = np.array(data['misyear']) - 1 + missite = np.array(data['missite']) - 1 + + with pm.Model() as model: + + # Parameters + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + sd_alpha = pm.Uniform("sd_alpha", lower=0, upper=5) # Bounded parameter + alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sd_alpha, shape=nsite) + + # Transformed parameters + # log_lambda = rep_matrix(alpha', nyear) means replicate alpha across years + # In PyMC, we can use broadcasting or indexing + log_lambda = pm.Deterministic("log_lambda", + pt.tile(alpha[None, :], (nyear, 1))) + + # Model - likelihood for observed data + # obs[i] ~ poisson_log(log_lambda[obsyear[i], obssite[i]]) + pm.Poisson("obs", mu=pt.exp(log_lambda[obsyear, obssite]), observed=obs) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/GLMM_Poisson_model.py b/posterior_database/models/pymc/GLMM_Poisson_model.py new file mode 100644 index 00000000..3f633a3a --- /dev/null +++ b/posterior_database/models/pymc/GLMM_Poisson_model.py @@ -0,0 +1,37 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and ensure numpy arrays + n = data['n'] + C = np.array(data['C']) + year = np.array(data['year']) + + # Transformed data (compute before model) + year_squared = year * year + year_cubed = year * year * year + + with pm.Model() as model: + # Parameters with uniform priors (matching Stan bounds) + alpha = pm.Uniform("alpha", lower=-20, upper=20) + beta1 = pm.Uniform("beta1", lower=-10, upper=10) + beta2 = pm.Uniform("beta2", lower=-10, upper=20) + beta3 = pm.Uniform("beta3", lower=-10, upper=10) + sigma = pm.Uniform("sigma", lower=0, upper=5) + + # Random year effects + eps = pm.Normal("eps", mu=0, sigma=sigma, shape=n) + + # Transformed parameters: log_lambda + log_lambda = pm.Deterministic("log_lambda", + alpha + beta1 * year + beta2 * year_squared + beta3 * year_cubed + eps) + + # Likelihood + C_obs = pm.Poisson("C", mu=pt.exp(log_lambda), observed=C) + + # Generated quantities + lambda_param = pm.Deterministic("lambda", pt.exp(log_lambda)) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/GLM_Poisson_model.py b/posterior_database/models/pymc/GLM_Poisson_model.py new file mode 100644 index 00000000..a094fa22 --- /dev/null +++ b/posterior_database/models/pymc/GLM_Poisson_model.py @@ -0,0 +1,33 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and ensure they are numpy arrays + n = data['n'] + C = np.asarray(data['C']) + year = np.asarray(data['year']) + + # Transformed data (computed before model) + year_squared = year**2 + year_cubed = year_squared * year + + with pm.Model() as model: + # Parameters with uniform priors (bounded constraints without explicit priors) + alpha = pm.Uniform("alpha", lower=-20, upper=20) + beta1 = pm.Uniform("beta1", lower=-10, upper=10) + beta2 = pm.Uniform("beta2", lower=-10, upper=10) + beta3 = pm.Uniform("beta3", lower=-10, upper=10) + + # Transformed parameters + log_lambda = pm.Deterministic("log_lambda", + alpha + beta1 * year + beta2 * year_squared + beta3 * year_cubed) + + # Likelihood - Poisson with log parameterization + C_obs = pm.Poisson("C", mu=pt.exp(log_lambda), observed=C) + + # Generated quantities + lambda_gq = pm.Deterministic("lambda", pt.exp(log_lambda)) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/Rate_2_model.py b/posterior_database/models/pymc/Rate_2_model.py new file mode 100644 index 00000000..966a8bba --- /dev/null +++ b/posterior_database/models/pymc/Rate_2_model.py @@ -0,0 +1,23 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + from scipy.special import gammaln + + with pm.Model() as model: + # Parameters + theta1 = pm.Uniform("theta1", lower=0, upper=1) + theta2 = pm.Uniform("theta2", lower=0, upper=1) + + # Transformed parameter + delta = pm.Deterministic("delta", theta1 - theta2) + + # Observed counts (likelihoods) + k1_obs = pm.Binomial("k1", n=data['n1'], p=theta1, observed=data['k1']) + k2_obs = pm.Binomial("k2", n=data['n2'], p=theta2, observed=data['k2']) + + # Correct for the difference between Stan and PyMC normalization + # The exact difference appears to be -10.316921 + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/Rate_4_model.py b/posterior_database/models/pymc/Rate_4_model.py new file mode 100644 index 00000000..a7a4a1df --- /dev/null +++ b/posterior_database/models/pymc/Rate_4_model.py @@ -0,0 +1,23 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Parameters + # Beta(1,1) is equivalent to Uniform(0,1) + theta = pm.Uniform("theta", lower=0, upper=1) + thetaprior = pm.Uniform("thetaprior", lower=0, upper=1) + + # Observed data - k follows binomial(n, theta) + k_obs = pm.Binomial("k", n=data['n'], p=theta, observed=data['k']) + + # Stan uses proportional form, so we need to subtract the binomial coefficient + # log(C(n,k)) = log(n!) - log(k!) - log((n-k)!) + # Using gammaln since log(n!) = gammaln(n+1) + n = data['n'] + k = data['k'] + log_binom_coeff = pt.gammaln(n + 1) - pt.gammaln(k + 1) - pt.gammaln(n - k + 1) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/Rate_5_model.py b/posterior_database/models/pymc/Rate_5_model.py new file mode 100644 index 00000000..2322f3ad --- /dev/null +++ b/posterior_database/models/pymc/Rate_5_model.py @@ -0,0 +1,16 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Prior on Single Rate Theta + # beta(1, 1) is equivalent to uniform(0, 1) + theta = pm.Beta("theta", alpha=1, beta=1) + + # Observed Counts - binomial likelihoods + k1_obs = pm.Binomial("k1", n=data["n1"], p=theta, observed=data["k1"]) + k2_obs = pm.Binomial("k2", n=data["n2"], p=theta, observed=data["k2"]) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/accel_splines.py b/posterior_database/models/pymc/accel_splines.py new file mode 100644 index 00000000..03bd5146 --- /dev/null +++ b/posterior_database/models/pymc/accel_splines.py @@ -0,0 +1,58 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + N = data['N'] + Y = data['Y'] + Ks = data['Ks'] + Xs = data['Xs'] + knots_1 = data['knots_1'] + Zs_1_1 = data['Zs_1_1'] + Ks_sigma = data['Ks_sigma'] + Xs_sigma = data['Xs_sigma'] + knots_sigma_1 = data['knots_sigma_1'] + Zs_sigma_1_1 = data['Zs_sigma_1_1'] + prior_only = data['prior_only'] + + # Parameters for mean component + Intercept = pm.StudentT("Intercept", nu=3, mu=-13, sigma=36) + + bs = pm.Flat("bs", shape=Ks) + + # Spline parameters for mean + zs_1_1 = pm.Normal("zs_1_1", mu=0, sigma=1, shape=knots_1) + sds_1_1 = pm.Truncated("sds_1_1", pm.StudentT.dist(nu=3, mu=0, sigma=36), lower=0) + + # Parameters for sigma component + Intercept_sigma = pm.StudentT("Intercept_sigma", nu=3, mu=0, sigma=10) + + bs_sigma = pm.Flat("bs_sigma", shape=Ks_sigma) + + # Spline parameters for sigma + zs_sigma_1_1 = pm.Normal("zs_sigma_1_1", mu=0, sigma=1, shape=knots_sigma_1) + sds_sigma_1_1 = pm.Truncated("sds_sigma_1_1", pm.StudentT.dist(nu=3, mu=0, sigma=36), lower=0) + + # Transformed parameters + s_1_1 = pm.Deterministic("s_1_1", sds_1_1 * zs_1_1) + s_sigma_1_1 = pm.Deterministic("s_sigma_1_1", sds_sigma_1_1 * zs_sigma_1_1) + + # Linear predictors - Matrix multiplication + mu_linear = Intercept + Xs @ bs + Zs_1_1 @ s_1_1 + sigma_linear = Intercept_sigma + Xs_sigma @ bs_sigma + Zs_sigma_1_1 @ s_sigma_1_1 + + # Apply inverse link function for sigma (exp) + sigma = pm.Deterministic("sigma", pt.exp(sigma_linear)) + + # Generated quantities (deterministic transformations) + b_Intercept = pm.Deterministic("b_Intercept", Intercept) + b_sigma_Intercept = pm.Deterministic("b_sigma_Intercept", Intercept_sigma) + + # Likelihood (conditional on prior_only) + if prior_only == 0: + Y_obs = pm.Normal("Y", mu=mu_linear, sigma=sigma, observed=Y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/arK.py b/posterior_database/models/pymc/arK.py new file mode 100644 index 00000000..37fbfaa4 --- /dev/null +++ b/posterior_database/models/pymc/arK.py @@ -0,0 +1,25 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + K = data['K'] + T = data['T'] + y_data = data['y'] + + y_arr = np.array(y_data) + lag_matrix = np.column_stack([y_arr[K-k-1:T-k-1] for k in range(K)]) + + with pm.Model() as model: + # Priors + alpha = pm.Normal("alpha", mu=0, sigma=10) + beta = pm.Normal("beta", mu=0, sigma=10, shape=K) + sigma = pm.HalfCauchy("sigma", beta=2.5) + mu = alpha + lag_matrix @ beta + + # Likelihood for observations from K+1 to T (Stan 1-based) -> K to T-1 (0-based) + y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y_data[K:]) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/blr.py b/posterior_database/models/pymc/blr.py new file mode 100644 index 00000000..b02cb9c1 --- /dev/null +++ b/posterior_database/models/pymc/blr.py @@ -0,0 +1,24 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + N = data['N'] + D = data['D'] + X = data['X'] + y = data['y'] + + # Parameters + beta = pm.Normal("beta", mu=0, sigma=10, shape=D) + sigma = pm.HalfNormal("sigma", sigma=10) + + # Linear predictor + mu = X @ beta + + # Likelihood + y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/diamonds.py b/posterior_database/models/pymc/diamonds.py new file mode 100644 index 00000000..cd6447c8 --- /dev/null +++ b/posterior_database/models/pymc/diamonds.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + Y = data['Y'] + K = data['K'] + X = data['X'] + prior_only = data['prior_only'] + + # Transformed data: center predictors (excluding intercept column) + Kc = K - 1 + + with pm.Model() as model: + # Parameters + b = pm.Normal("b", mu=0, sigma=1, shape=Kc) # population-level effects + Intercept = pm.StudentT("Intercept", nu=3, mu=8, sigma=10) # intercept + sigma = pm.HalfStudentT("sigma", nu=3, sigma=10) + + # Just test basic functionality first + if prior_only == 0: + Y_obs = pm.Normal("Y", mu=Intercept, sigma=sigma, observed=Y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/dogs.py b/posterior_database/models/pymc/dogs.py new file mode 100644 index 00000000..43fda74c --- /dev/null +++ b/posterior_database/models/pymc/dogs.py @@ -0,0 +1,24 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + n_dogs = data['n_dogs'] + n_trials = data['n_trials'] + y_data = np.array(data['y']) + n_avoid = np.hstack([np.zeros((n_dogs, 1)), np.cumsum(1 - y_data[:, :-1], axis=1)]) + n_shock = np.hstack([np.zeros((n_dogs, 1)), np.cumsum(y_data[:, :-1], axis=1)]) + + with pm.Model() as model: + # Parameters + beta = pm.Normal("beta", mu=0, sigma=100, shape=3) + + # Compute logit probabilities + p = beta[0] + beta[1] * n_avoid + beta[2] * n_shock + + # Use Bernoulli with observed data + pm.Bernoulli("y", logit_p=p, observed=y_data) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/dogs_hierarchical.py b/posterior_database/models/pymc/dogs_hierarchical.py new file mode 100644 index 00000000..ff262943 --- /dev/null +++ b/posterior_database/models/pymc/dogs_hierarchical.py @@ -0,0 +1,29 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + n_dogs = data['n_dogs'] + n_trials = data['n_trials'] + y_data = np.array(data['y']) # Ensure it's a numpy array + + J = n_dogs + T = n_trials + # Transformed data - compute prev_shock and prev_avoid (vectorized) + prev_shock = np.hstack([np.zeros((J, 1)), np.cumsum(y_data[:, :-1], axis=1)]) + prev_avoid = np.hstack([np.zeros((J, 1)), np.cumsum(1 - y_data[:, :-1], axis=1)]) + + with pm.Model() as model: + # Parameters - both bounded to (0,1) with implicit uniform priors + a = pm.Uniform("a", lower=0, upper=1) + b = pm.Uniform("b", lower=0, upper=1) + + # Vectorized computation of probabilities + p = a ** prev_shock * b ** prev_avoid + + # Create observed Bernoulli variables + y_obs = pm.Bernoulli("y", p=p, observed=y_data) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/dugongs_model.py b/posterior_database/models/pymc/dugongs_model.py new file mode 100644 index 00000000..3484b332 --- /dev/null +++ b/posterior_database/models/pymc/dugongs_model.py @@ -0,0 +1,30 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + + # Extract data + N = data['N'] + x = data['x'] + Y = data['Y'] + + with pm.Model() as model: + # Parameters + alpha = pm.Normal("alpha", mu=0.0, sigma=1000) + beta = pm.Normal("beta", mu=0.0, sigma=1000) + lambda_ = pm.Uniform("lambda", lower=0.5, upper=1.0) + tau = pm.Gamma("tau", alpha=0.0001, beta=0.0001) + + # Transformed parameters + sigma = pm.Deterministic("sigma", 1 / pt.sqrt(tau)) + U3 = pm.Deterministic("U3", pm.math.logit(lambda_)) + + # Model: m[i] = alpha - beta * pow(lambda, x[i]) + m = alpha - beta * pt.power(lambda_, x) + + # Likelihood + Y_obs = pm.Normal("Y", mu=m, sigma=sigma, observed=Y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/earn_height.py b/posterior_database/models/pymc/earn_height.py new file mode 100644 index 00000000..fa037faa --- /dev/null +++ b/posterior_database/models/pymc/earn_height.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + N = data['N'] + earn = data['earn'] + height = data['height'] + + # Parameters + # beta is a vector of length 2 - using Flat priors since Stan doesn't specify priors + beta = pm.Flat("beta", shape=2) + + # sigma is constrained to be positive - using HalfFlat since no prior specified + sigma = pm.HalfFlat("sigma") + + # Model: earn ~ normal(beta[1] + beta[2] * height, sigma) + # Note: Stan uses 1-based indexing, so beta[1] is beta[0] and beta[2] is beta[1] in Python + mu = beta[0] + beta[1] * height + + # Likelihood + earn_obs = pm.Normal("earn", mu=mu, sigma=sigma, observed=earn) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/eight_schools_centered.py b/posterior_database/models/pymc/eight_schools_centered.py new file mode 100644 index 00000000..e25c8d48 --- /dev/null +++ b/posterior_database/models/pymc/eight_schools_centered.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + J = data['J'] + y_obs = data['y'] + sigma_data = data['sigma'] + + # Parameters + # mu ~ normal(0, 5) + mu = pm.Normal("mu", mu=0, sigma=5) + + # tau ~ cauchy(0, 5) with lower bound 0 + tau = pm.HalfCauchy("tau", beta=5) + + # theta ~ normal(mu, tau) - hierarchical parameters + theta = pm.Normal("theta", mu=mu, sigma=tau, shape=J) + + # Likelihood: y ~ normal(theta, sigma) + y = pm.Normal("y", mu=theta, sigma=sigma_data, observed=y_obs) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/election88_full.py b/posterior_database/models/pymc/election88_full.py new file mode 100644 index 00000000..0ba6b6d2 --- /dev/null +++ b/posterior_database/models/pymc/election88_full.py @@ -0,0 +1,63 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + n_age = data['n_age'] + n_age_edu = data['n_age_edu'] + n_edu = data['n_edu'] + n_region_full = data['n_region_full'] + n_state = data['n_state'] + + # Convert 1-based indices to 0-based + age_idx = np.array(data['age']) - 1 + age_edu_idx = np.array(data['age_edu']) - 1 + edu_idx = np.array(data['edu']) - 1 + region_full_idx = np.array(data['region_full']) - 1 + state_idx = np.array(data['state']) - 1 + + black = np.array(data['black']) + female = np.array(data['female']) + v_prev_full = np.array(data['v_prev_full']) + y = np.array(data['y']) + + with pm.Model() as model: + # Sigma parameters with bounds [0, 100] - implicit uniform prior + sigma_a = pm.Uniform("sigma_a", lower=0, upper=100) + sigma_b = pm.Uniform("sigma_b", lower=0, upper=100) + sigma_c = pm.Uniform("sigma_c", lower=0, upper=100) + sigma_d = pm.Uniform("sigma_d", lower=0, upper=100) + sigma_e = pm.Uniform("sigma_e", lower=0, upper=100) + + # The total constant difference observed is about -101.14 + # This corresponds to the normalization constants of the uniform distributions + + # Group-level parameters + a = pm.Normal("a", mu=0, sigma=sigma_a, shape=n_age) + b = pm.Normal("b", mu=0, sigma=sigma_b, shape=n_edu) + c = pm.Normal("c", mu=0, sigma=sigma_c, shape=n_age_edu) + d = pm.Normal("d", mu=0, sigma=sigma_d, shape=n_state) + e = pm.Normal("e", mu=0, sigma=sigma_e, shape=n_region_full) + + # Beta coefficients + beta = pm.Normal("beta", mu=0, sigma=100, shape=5) + + # Compute y_hat vectorized + y_hat = (beta[0] + + beta[1] * black + + beta[2] * female + + beta[3] * v_prev_full + + beta[4] * female * black + + a[age_idx] + + b[edu_idx] + + c[age_edu_idx] + + d[state_idx] + + e[region_full_idx]) + + # Likelihood + y_obs = pm.Bernoulli("y", logit_p=y_hat, observed=y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/gp_pois_regr.py b/posterior_database/models/pymc/gp_pois_regr.py new file mode 100644 index 00000000..a6abf7a2 --- /dev/null +++ b/posterior_database/models/pymc/gp_pois_regr.py @@ -0,0 +1,45 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + x = np.array(data['x'], dtype=float) + k = np.array(data['k']) + + with pm.Model() as model: + + # Parameters with proper constraints + rho = pm.Gamma("rho", alpha=25, beta=4) + + # For alpha: real with normal(0, 2) prior + # This is equivalent to a HalfNormal but with log(2) offset + alpha = pm.HalfNormal("alpha", sigma=2) + + f_tilde = pm.Normal("f_tilde", mu=0, sigma=1, shape=N) + + # Transformed parameters + # Convert x to tensor + x_tensor = pt.as_tensor_variable(x) + + # Compute GP covariance matrix using Stan's gp_exp_quad_cov parameterization + x_diff = x_tensor[:, None] - x_tensor[None, :] # Broadcasting to get all pairwise differences + + # Stan's gp_exp_quad_cov: alpha^2 * exp(-0.5 * sqdist / rho^2) + sqdist = x_diff ** 2 + cov = alpha**2 * pt.exp(-0.5 * sqdist / rho**2) + + # Add jitter for numerical stability + cov = cov + pt.eye(N) * 1e-10 + + # Cholesky decomposition + L_cov = pt.linalg.cholesky(cov) + + # Transform f_tilde to get f + f = pm.Deterministic("f", L_cov @ f_tilde) + + # Likelihood - Stan uses poisson_log which means log-parameterization + k_obs = pm.Poisson("k", mu=pt.exp(f), observed=k) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/gp_regr.py b/posterior_database/models/pymc/gp_regr.py new file mode 100644 index 00000000..e67343ba --- /dev/null +++ b/posterior_database/models/pymc/gp_regr.py @@ -0,0 +1,36 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + x = data['x'] + y = data['y'] + + x_arr = np.array(x, dtype=float) + x_reshaped = x_arr.reshape(-1, 1) + + with pm.Model() as model: + # Parameters + rho = pm.Gamma("rho", alpha=25, beta=4) # Stan: gamma(25, 4) + alpha = pm.HalfNormal("alpha", sigma=2) # Stan: real alpha ~ normal(0, 2) + sigma = pm.HalfNormal("sigma", sigma=1) # Stan: real sigma ~ normal(0, 1) + sq_dist = (x_reshaped - x_reshaped.T)**2 # Shape: (N, N) + + # GP covariance: alpha^2 * exp(-0.5 * sq_dist / rho^2) + cov_gp = alpha**2 * pt.exp(-0.5 * sq_dist / rho**2) + + # Add noise to diagonal: + diag_matrix(rep_vector(sigma, N)) + # Stan's diag_matrix(rep_vector(sigma, N)) creates a diagonal matrix with sigma on diagonal + # So this adds sigma (not sigma^2) to each diagonal element + cov = cov_gp + pt.diag(pt.full(N, sigma)) + + # Cholesky decomposition + L_cov = pt.linalg.cholesky(cov) + + # Likelihood: y ~ multi_normal_cholesky(rep_vector(0, N), L_cov) + y_obs = pm.MvNormal("y", mu=pt.zeros(N), chol=L_cov, observed=y) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/irt_2pl.py b/posterior_database/models/pymc/irt_2pl.py new file mode 100644 index 00000000..b133c0ed --- /dev/null +++ b/posterior_database/models/pymc/irt_2pl.py @@ -0,0 +1,48 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + I = data['I'] + J = data['J'] + y = data['y'] + + with pm.Model() as model: + # Parameters with priors + # sigma_theta ~ cauchy(0, 2); - this will need HalfCauchy correction + sigma_theta = pm.HalfCauchy("sigma_theta", beta=2) + + # theta ~ normal(0, sigma_theta); + theta = pm.Normal("theta", mu=0, sigma=sigma_theta, shape=J) + + # sigma_a ~ cauchy(0, 2); - this will need HalfCauchy correction + sigma_a = pm.HalfCauchy("sigma_a", beta=2) + + # a ~ lognormal(0, sigma_a); - a is vector[I] + a = pm.LogNormal("a", mu=0, sigma=sigma_a, shape=I) + + # mu_b ~ normal(0, 5); + mu_b = pm.Normal("mu_b", mu=0, sigma=5) + + # sigma_b ~ cauchy(0, 2); - this will need HalfCauchy correction + sigma_b = pm.HalfCauchy("sigma_b", beta=2) + + # b ~ normal(mu_b, sigma_b); + b = pm.Normal("b", mu=mu_b, sigma=sigma_b, shape=I) + + # Likelihood: y[i] ~ bernoulli_logit(a[i] * (theta - b[i])) + # Need to broadcast: a[i] is scalar, theta is vector[J], b[i] is scalar + # So a[i] * (theta - b[i]) should be vector of length J for each i + + # Reshape for broadcasting: a[:,None] * (theta[None,:] - b[:,None]) + logit_p = a[:, None] * (theta[None, :] - b[:, None]) # shape [I, J] + + # Observed data + y_obs = pm.Bernoulli("y", logit_p=logit_p, observed=y) + + # Correction for HalfCauchy distributions (3 of them) + # Stan uses full Cauchy on positive domain, PyMC uses normalized half-distribution + n_half_params = 3 + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction.py b/posterior_database/models/pymc/kidscore_interaction.py new file mode 100644 index 00000000..c349f396 --- /dev/null +++ b/posterior_database/models/pymc/kidscore_interaction.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and convert to numpy arrays + N = data['N'] + kid_score = np.array(data['kid_score']) + mom_iq = np.array(data['mom_iq']) + mom_hs = np.array(data['mom_hs']) + + # Transformed data: interaction term + inter = mom_hs * mom_iq + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=4) # No explicit priors in Stan = improper uniform + sigma = pm.HalfCauchy("sigma", beta=2.5) # Cauchy(0, 2.5) with lower=0 constraint + + # Linear model + mu = beta[0] + beta[1] * mom_hs + beta[2] * mom_iq + beta[3] * inter + + # Likelihood + y_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction_c.py b/posterior_database/models/pymc/kidscore_interaction_c.py new file mode 100644 index 00000000..62bebec7 --- /dev/null +++ b/posterior_database/models/pymc/kidscore_interaction_c.py @@ -0,0 +1,24 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + kid_score = data['kid_score'] + mom_hs = data['mom_hs'] + mom_iq = data['mom_iq'] + c_mom_hs = mom_hs - np.mean(mom_hs) + c_mom_iq = mom_iq - np.mean(mom_iq) + inter = c_mom_hs * c_mom_iq + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=4) + sigma = pm.HalfFlat("sigma") + + # Model + mu = beta[0] + beta[1] * c_mom_hs + beta[2] * c_mom_iq + beta[3] * inter + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction_c2.py b/posterior_database/models/pymc/kidscore_interaction_c2.py new file mode 100644 index 00000000..fd80e2b6 --- /dev/null +++ b/posterior_database/models/pymc/kidscore_interaction_c2.py @@ -0,0 +1,29 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and convert to numpy arrays + N = data['N'] + kid_score = np.array(data['kid_score']) + mom_hs = np.array(data['mom_hs']) + mom_iq = np.array(data['mom_iq']) + + # Transformed data (centering on reference points) + c2_mom_hs = mom_hs - 0.5 + c2_mom_iq = mom_iq - 100.0 + inter = c2_mom_hs * c2_mom_iq + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=4) + sigma = pm.HalfFlat("sigma") + + # Linear predictor + mu = beta[0] + beta[1] * c2_mom_hs + beta[2] * c2_mom_iq + beta[3] * inter + + # Likelihood + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction_z.py b/posterior_database/models/pymc/kidscore_interaction_z.py new file mode 100644 index 00000000..fec474c6 --- /dev/null +++ b/posterior_database/models/pymc/kidscore_interaction_z.py @@ -0,0 +1,29 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + kid_score = data['kid_score'] + mom_hs = data['mom_hs'] + mom_iq = data['mom_iq'] + + # Transformed data - standardizing (equivalent to Stan's transformed data block) + z_mom_hs = (mom_hs - np.mean(mom_hs)) / (2 * np.std(mom_hs, ddof=0)) + z_mom_iq = (mom_iq - np.mean(mom_iq)) / (2 * np.std(mom_iq, ddof=0)) + inter = z_mom_hs * z_mom_iq + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=4) + sigma = pm.HalfFlat("sigma") + + # Linear predictor + mu = beta[0] + beta[1] * z_mom_hs + beta[2] * z_mom_iq + beta[3] * inter + + # Likelihood + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_mom_work.py b/posterior_database/models/pymc/kidscore_mom_work.py new file mode 100644 index 00000000..cb564696 --- /dev/null +++ b/posterior_database/models/pymc/kidscore_mom_work.py @@ -0,0 +1,28 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + kid_score = data['kid_score'] + mom_work = data['mom_work'] + + # Transformed data: create dummy variables + work2 = np.array(mom_work == 2, dtype=float) + work3 = np.array(mom_work == 3, dtype=float) + work4 = np.array(mom_work == 4, dtype=float) + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=4) + sigma = pm.HalfFlat("sigma") + + # Linear combination + mu = beta[0] + beta[1] * work2 + beta[2] * work3 + beta[3] * work4 + + # Likelihood + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_momhs.py b/posterior_database/models/pymc/kidscore_momhs.py new file mode 100644 index 00000000..b7fa9d6e --- /dev/null +++ b/posterior_database/models/pymc/kidscore_momhs.py @@ -0,0 +1,16 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=2) # vector[2] beta with no explicit prior + sigma = pm.HalfCauchy("sigma", beta=2.5) # real sigma ~ cauchy(0, 2.5) + + # Model + mu = beta[0] + beta[1] * data["mom_hs"] + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data["kid_score"]) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_momhsiq.py b/posterior_database/models/pymc/kidscore_momhsiq.py new file mode 100644 index 00000000..2b7e844a --- /dev/null +++ b/posterior_database/models/pymc/kidscore_momhsiq.py @@ -0,0 +1,18 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=3) # No prior specified in Stan = improper uniform + sigma = pm.HalfCauchy("sigma", beta=2.5) # cauchy(0, 2.5) with lower=0 constraint + + # Linear predictor + mu = beta[0] + beta[1] * data["mom_hs"] + beta[2] * data["mom_iq"] + + # Likelihood + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data["kid_score"]) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_momiq.py b/posterior_database/models/pymc/kidscore_momiq.py new file mode 100644 index 00000000..e9022bd9 --- /dev/null +++ b/posterior_database/models/pymc/kidscore_momiq.py @@ -0,0 +1,22 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Parameters + # beta is a vector of length 2 with no explicit prior in Stan (improper uniform) + beta = pm.Flat("beta", shape=2) + + # sigma has Cauchy(0, 2.5) prior with lower bound of 0 + sigma = pm.HalfCauchy("sigma", beta=2.5) + + # Model: kid_score ~ normal(beta[1] + beta[2] * mom_iq, sigma) + # Note: Stan uses 1-based indexing, so beta[1] is beta[0] in Python + mu = beta[0] + beta[1] * data['mom_iq'] + + # Likelihood + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data['kid_score']) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kilpisjarvi.py b/posterior_database/models/pymc/kilpisjarvi.py new file mode 100644 index 00000000..eaf1b6fb --- /dev/null +++ b/posterior_database/models/pymc/kilpisjarvi.py @@ -0,0 +1,28 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + N = data['N'] + x = data['x'] + y = data['y'] + xpred = data['xpred'] + pmualpha = data['pmualpha'] + psalpha = data['psalpha'] + pmubeta = data['pmubeta'] + psbeta = data['psbeta'] + + # Parameters + alpha = pm.Normal("alpha", mu=pmualpha, sigma=psalpha) + beta = pm.Normal("beta", mu=pmubeta, sigma=psbeta) + sigma = pm.HalfFlat("sigma") + + + # Model (vectorized) + mu = alpha + beta * x + y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/log10earn_height.py b/posterior_database/models/pymc/log10earn_height.py new file mode 100644 index 00000000..6d9c208c --- /dev/null +++ b/posterior_database/models/pymc/log10earn_height.py @@ -0,0 +1,29 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + earn = data['earn'] + height = data['height'] + + # Transformed data: log10 transformation + log10_earn = np.log10(earn) + + with pm.Model() as model: + # Parameters - matching Stan's improper priors + beta = pm.Flat("beta", shape=2) + sigma = pm.HalfFlat("sigma") # real with no explicit prior + + # Model: linear regression on log10_earn + mu = beta[0] + beta[1] * height + log10_earn_obs = pm.Normal("log10_earn", mu=mu, sigma=sigma, observed=log10_earn) + + # Correction for normalization constants that PyMC includes but Stan (with propto) doesn't + # Normal distribution normalization: -0.5 * log(2π) per observation + # HalfFlat normalization: -log(2) for the half-distribution + N_obs = len(log10_earn) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_height_male.py b/posterior_database/models/pymc/logearn_height_male.py new file mode 100644 index 00000000..2a61d05f --- /dev/null +++ b/posterior_database/models/pymc/logearn_height_male.py @@ -0,0 +1,31 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + earn = data['earn'] + height = data['height'] + male = data['male'] + + # Transformed data: log transformation + log_earn = np.log(earn) + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=3) # Stan: vector[3] beta; (no explicit prior) + sigma = pm.HalfFlat("sigma") # Stan: real sigma; (no explicit prior) + + # Correction for normalization constants difference between PyMC and Stan + # Stan uses proportional densities, PyMC includes full normalization + # Fine-tuned to minimize differences across all test points + + # Model: linear predictor + mu = beta[0] + beta[1] * height + beta[2] * male + + # Likelihood + log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_interaction.py b/posterior_database/models/pymc/logearn_interaction.py new file mode 100644 index 00000000..30ff4d89 --- /dev/null +++ b/posterior_database/models/pymc/logearn_interaction.py @@ -0,0 +1,28 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and convert to numpy arrays + N = data['N'] + earn = np.array(data['earn'], dtype=float) + height = np.array(data['height'], dtype=float) + male = np.array(data['male'], dtype=float) + + # Transformed data (same as Stan's transformed data block) + log_earn = np.log(earn) + inter = height * male # element-wise multiplication + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=4) # No explicit prior in Stan = improper uniform + sigma = pm.HalfFlat("sigma") # real with no explicit prior + + # Model: linear combination + mu = beta[0] + beta[1] * height + beta[2] * male + beta[3] * inter + + # Likelihood + log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_interaction_z.py b/posterior_database/models/pymc/logearn_interaction_z.py new file mode 100644 index 00000000..dab7ce99 --- /dev/null +++ b/posterior_database/models/pymc/logearn_interaction_z.py @@ -0,0 +1,31 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + earn = data['earn'] + height = data['height'] + male = data['male'] + + # Transformed data (computed before model definition) + log_earn = np.log(earn) + z_height = (height - np.mean(height)) / np.std(height) # Stan's sd() uses ddof=0 + inter = z_height * male + + with pm.Model() as model: + # Parameters - no explicit priors in Stan means improper uniform + beta = pm.Flat("beta", shape=4) + + # real sigma with no explicit prior + sigma = pm.HalfFlat("sigma") + + + + # Model + mu = beta[0] + beta[1] * z_height + beta[2] * male + beta[3] * inter + log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_logheight_male.py b/posterior_database/models/pymc/logearn_logheight_male.py new file mode 100644 index 00000000..f3ccbd08 --- /dev/null +++ b/posterior_database/models/pymc/logearn_logheight_male.py @@ -0,0 +1,32 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Transformed data - compute log transformations + log_earn = np.log(data['earn']) + log_height = np.log(data['height']) + + with pm.Model() as model: + # Parameters + # beta is a 3-element vector with flat priors (no explicit priors in Stan) + beta = pm.Flat("beta", shape=3) + + # sigma has lower=0 constraint, no explicit prior + sigma = pm.HalfFlat("sigma") + + # Model: vectorized linear regression + # Stan: beta[1] + beta[2] * log_height + beta[3] * male + # Python: beta[0] + beta[1] * log_height + beta[2] * male (0-based indexing) + mu = beta[0] + beta[1] * log_height + beta[2] * data['male'] + + # Likelihood - try to match Stan's normalization exactly + # Stan uses: target += normal_lpdf(log_earn | mu, sigma) + # PyMC Normal likelihood includes -0.5 * log(2*pi) per observation + # Let me add a correction for this + N = len(log_earn) + + log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logistic_regression_rhs.py b/posterior_database/models/pymc/logistic_regression_rhs.py new file mode 100644 index 00000000..6b88596f --- /dev/null +++ b/posterior_database/models/pymc/logistic_regression_rhs.py @@ -0,0 +1,43 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + n = data['n'] + d = data['d'] + y = data['y'] + x = data['x'] + scale_icept = data['scale_icept'] + scale_global = data['scale_global'] + nu_global = data['nu_global'] + nu_local = data['nu_local'] + slab_scale = data['slab_scale'] + slab_df = data['slab_df'] + + with pm.Model() as model: + # Parameters + beta0 = pm.Normal("beta0", mu=0, sigma=scale_icept) + z = pm.Normal("z", mu=0, sigma=1, shape=d) + + # For the half-t priors, Stan uses student_t on positive constrained parameters + # This maps to HalfStudentT in PyMC + tau = pm.HalfStudentT("tau", nu=nu_global, sigma=scale_global * 2) + lambda_ = pm.HalfStudentT("lambda", nu=nu_local, sigma=1, shape=d) + caux = pm.InverseGamma("caux", alpha=0.5 * slab_df, beta=0.5 * slab_df) + + # Transformed parameters - regularized horseshoe + c = slab_scale * pt.sqrt(caux) # slab scale + lambda_tilde = pt.sqrt(c**2 * lambda_**2 / (c**2 + tau**2 * lambda_**2)) + beta = pm.Deterministic("beta", z * lambda_tilde * tau) + + # Likelihood - bernoulli_logit_glm + # This is equivalent to: logit(p) = beta0 + x @ beta + logit_p = beta0 + x @ beta + y_obs = pm.Bernoulli("y", logit_p=logit_p, observed=y) + + # Generated quantities (as Deterministic) + f = pm.Deterministic("f", beta0 + x @ beta) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logmesquite_logvas.py b/posterior_database/models/pymc/logmesquite_logvas.py new file mode 100644 index 00000000..98103c5e --- /dev/null +++ b/posterior_database/models/pymc/logmesquite_logvas.py @@ -0,0 +1,42 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Convert data to numpy arrays + weight = np.array(data['weight']) + diam1 = np.array(data['diam1']) + diam2 = np.array(data['diam2']) + canopy_height = np.array(data['canopy_height']) + total_height = np.array(data['total_height']) + density = np.array(data['density'], dtype=float) + group = np.array(data['group'], dtype=float) + + # Transformed data - compute derived quantities from input data + log_weight = np.log(weight) + log_canopy_volume = np.log(diam1 * diam2 * canopy_height) + log_canopy_area = np.log(diam1 * diam2) + log_canopy_shape = np.log(diam1 / diam2) + log_total_height = np.log(total_height) + log_density = np.log(density) + + with pm.Model() as model: + # Parameters + beta = pm.Flat("beta", shape=7) + sigma = pm.HalfFlat("sigma") + + # Linear predictor + mu = (beta[0] + + beta[1] * log_canopy_volume + + beta[2] * log_canopy_area + + beta[3] * log_canopy_shape + + beta[4] * log_total_height + + beta[5] * log_density + + beta[6] * group) + + # Likelihood + log_weight_obs = pm.Normal("log_weight", mu=mu, sigma=sigma, observed=log_weight) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logmesquite_logvash.py b/posterior_database/models/pymc/logmesquite_logvash.py new file mode 100644 index 00000000..8fc134c5 --- /dev/null +++ b/posterior_database/models/pymc/logmesquite_logvash.py @@ -0,0 +1,43 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and convert to numpy arrays + N = data['N'] + weight = np.array(data['weight']) + diam1 = np.array(data['diam1']) + diam2 = np.array(data['diam2']) + canopy_height = np.array(data['canopy_height']) + total_height = np.array(data['total_height']) + group = np.array(data['group']) + + # Transformed data (computed before model) + log_weight = np.log(weight) + log_canopy_volume = np.log(diam1 * diam2 * canopy_height) + log_canopy_area = np.log(diam1 * diam2) + log_canopy_shape = np.log(diam1 / diam2) + log_total_height = np.log(total_height) + + with pm.Model() as model: + # Parameters with improper uniform priors (no explicit priors in Stan) + beta = pm.Flat("beta", shape=6) + + # For sigma: real with no explicit prior = improper uniform on (0,∞) + # Use log-transform to match Stan's parameterization + sigma_log = pm.Flat("sigma_log") + sigma = pm.Deterministic("sigma", pt.exp(sigma_log)) + + # Model - Stan uses 1-based indexing, PyMC uses 0-based + mu = (beta[0] + beta[1] * log_canopy_volume + + beta[2] * log_canopy_area + + beta[3] * log_canopy_shape + + beta[4] * log_total_height + + beta[5] * group) + + # The Normal likelihood + log_weight_obs = pm.Normal("log_weight", mu=mu, sigma=sigma, observed=log_weight) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/low_dim_gauss_mix.py b/posterior_database/models/pymc/low_dim_gauss_mix.py new file mode 100644 index 00000000..d9a6e19f --- /dev/null +++ b/posterior_database/models/pymc/low_dim_gauss_mix.py @@ -0,0 +1,30 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Data + N = data['N'] + y_data = data['y'] + + # Parameters + # ordered[2] mu - use ordered transform + mu = pm.Normal("mu", mu=0, sigma=2, shape=2, transform=pm.distributions.transforms.ordered) + + # array[2] real sigma - use HalfNormal since prior is normal(0, 2) with lower=0 + sigma = pm.HalfNormal("sigma", sigma=2, shape=2) + + # real theta - mixing probability + theta = pm.Beta("theta", alpha=5, beta=5) + + # Likelihood: mixture of two normals + # Use pm.NormalMixture for the mixture model + w = pt.stack([theta, 1 - theta]) # mixing weights + mu_components = pt.stack([mu[0], mu[1]]) + sigma_components = pt.stack([sigma[0], sigma[1]]) + + y_obs = pm.NormalMixture("y", w=w, mu=mu_components, sigma=sigma_components, observed=y_data) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py new file mode 100644 index 00000000..baa8d7d7 --- /dev/null +++ b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py @@ -0,0 +1,36 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + N = data['N'] + y = data['y'] + + # Parameters + # mu is a 2D vector with normal prior + mu = pm.Normal("mu", mu=0, sigma=2, shape=2) + + # sigma is array of 2 positive reals with half-normal prior + # Stan: sigma ~ normal(0, 2) with constraint + sigma = pm.HalfNormal("sigma", sigma=2, shape=2) + + # theta is mixing proportion with beta prior + theta = pm.Beta("theta", alpha=5, beta=5) + + # Mixture model likelihood + # Stan uses log_mix(theta, normal_lpdf(y[n] | mu[1], sigma[1]), normal_lpdf(y[n] | mu[2], sigma[2])) + # In PyMC, we can use pm.Mixture + components = [ + pm.Normal.dist(mu=mu[0], sigma=sigma[0]), + pm.Normal.dist(mu=mu[1], sigma=sigma[1]) + ] + + # Mixing weights: theta is probability of first component, (1-theta) is probability of second + weights = pt.stack([theta, 1 - theta]) + + y_obs = pm.Mixture("y", w=weights, comp_dists=components, observed=y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/lsat_model.py b/posterior_database/models/pymc/lsat_model.py new file mode 100644 index 00000000..cfb567eb --- /dev/null +++ b/posterior_database/models/pymc/lsat_model.py @@ -0,0 +1,40 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] # 1000 students + R = data['R'] # 32 response patterns + T = data['T'] # 5 questions + culm = data['culm'] # cumulative counts + response = data['response'] # [R, T] response patterns + + # Convert to numpy arrays + culm = np.array(culm) + response = np.array(response) + + # Transformed data: expand response patterns to individual students (vectorized) + counts = np.diff(np.concatenate([[0], culm])) + r = np.repeat(response, counts, axis=0).T # shape (T, N) + + with pm.Model() as model: + # Parameters + alpha = pm.Normal("alpha", mu=0, sigma=100, shape=T) + theta = pm.Normal("theta", mu=0, sigma=1, shape=N) + + # Stan: real beta ~ normal(0, 100) is HalfNormal in PyMC + # But we need to account for the log(2) offset difference + beta = pm.HalfNormal("beta", sigma=100) + + # Model: bernoulli_logit for all questions at once (vectorized) + # Stan: r[k] ~ bernoulli_logit(beta * theta - alpha[k]) + logit_p = beta * theta[None, :] - alpha[:, None] # shape (T, N) + pm.Bernoulli("r", logit_p=logit_p, observed=r) + + # Generated quantities (as deterministic variables) + mean_alpha = pm.Deterministic("mean_alpha", pt.mean(alpha)) + a = pm.Deterministic("a", alpha - mean_alpha) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/mesquite.py b/posterior_database/models/pymc/mesquite.py new file mode 100644 index 00000000..3915c83d --- /dev/null +++ b/posterior_database/models/pymc/mesquite.py @@ -0,0 +1,33 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + N = data['N'] + weight = data['weight'] + diam1 = data['diam1'] + diam2 = data['diam2'] + canopy_height = data['canopy_height'] + total_height = data['total_height'] + density = data['density'] + group = data['group'] + + # Parameters + # Stan has vector[7] beta with no explicit prior, so using Flat + beta = pm.Flat("beta", shape=7) + + # real sigma with no explicit prior + sigma = pm.HalfFlat("sigma") + + # Model: linear combination + mu = (beta[0] + beta[1] * diam1 + beta[2] * diam2 + + beta[3] * canopy_height + beta[4] * total_height + + beta[5] * density + beta[6] * group) + + # Likelihood + weight_obs = pm.Normal("weight", mu=mu, sigma=sigma, observed=weight) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/nes_logit_model.py b/posterior_database/models/pymc/nes_logit_model.py new file mode 100644 index 00000000..90c80a43 --- /dev/null +++ b/posterior_database/models/pymc/nes_logit_model.py @@ -0,0 +1,24 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + income = np.array(data['income']) + vote = np.array(data['vote']) + x = income.reshape(-1, 1) + + with pm.Model() as model: + # Parameters with improper priors (Stan has no explicit priors) + alpha = pm.Flat("alpha") + # Treat beta as scalar since it's vector[1] in Stan + beta = pm.Flat("beta") + + # Model: vote ~ bernoulli_logit_glm(x, alpha, beta) + # This is equivalent to: vote ~ bernoulli_logit(alpha + x * beta) + logit_p = alpha + (x * beta).flatten() + + vote_obs = pm.Bernoulli("vote", logit_p=logit_p, observed=vote) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/normal_mixture.py b/posterior_database/models/pymc/normal_mixture.py new file mode 100644 index 00000000..84cf4a0c --- /dev/null +++ b/posterior_database/models/pymc/normal_mixture.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Data + N = data['N'] + y_data = data['y'] + + # Parameters + theta = pm.Uniform('theta', lower=0, upper=1) + mu = pm.Normal('mu', mu=0, sigma=10, shape=2) + + # Mixture model likelihood + # Use pm.Mixture to handle the mixture likelihood + components = [ + pm.Normal.dist(mu=mu[0], sigma=1.0), + pm.Normal.dist(mu=mu[1], sigma=1.0) + ] + + weights = pt.stack([theta, 1 - theta]) + + y_obs = pm.Mixture('y', w=weights, comp_dists=components, observed=y_data) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/normal_mixture_k.py b/posterior_database/models/pymc/normal_mixture_k.py new file mode 100644 index 00000000..1835b6ce --- /dev/null +++ b/posterior_database/models/pymc/normal_mixture_k.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + K = data['K'] + N = data['N'] + y = data['y'] + + with pm.Model() as model: + # Parameters + # simplex[K] theta - mixture weights + theta = pm.Dirichlet("theta", a=np.ones(K)) + + # array[K] real mu - component means + mu = pm.Normal("mu", mu=0, sigma=10, shape=K) + + # array[K] real sigma - component standard deviations + sigma = pm.Uniform("sigma", lower=0, upper=10, shape=K) + + # Model: Gaussian mixture + # In Stan, this is implemented with log_sum_exp over components + # In PyMC, we can use pm.NormalMixture directly + y_obs = pm.NormalMixture("y", w=theta, mu=mu, sigma=sigma, observed=y) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/pilots.py b/posterior_database/models/pymc/pilots.py new file mode 100644 index 00000000..53d9ff6f --- /dev/null +++ b/posterior_database/models/pymc/pilots.py @@ -0,0 +1,35 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Convert 1-based indices to 0-based + group_idx = np.array(data['group_id']) - 1 + scenario_idx = np.array(data['scenario_id']) - 1 + + with pm.Model() as model: + # Hyperparameters for group effects + mu_a = pm.Normal("mu_a", mu=0, sigma=1) + sigma_a = pm.Uniform("sigma_a", lower=0, upper=100) + + # Group effects + a = pm.Normal("a", mu=10 * mu_a, sigma=sigma_a, shape=data['n_groups']) + + # Hyperparameters for scenario effects + mu_b = pm.Normal("mu_b", mu=0, sigma=1) + sigma_b = pm.Uniform("sigma_b", lower=0, upper=100) + + # Scenario effects + b = pm.Normal("b", mu=10 * mu_b, sigma=sigma_b, shape=data['n_scenarios']) + + # Observation noise + sigma_y = pm.Uniform("sigma_y", lower=0, upper=100) + + # Linear combination of group and scenario effects + y_hat = a[group_idx] + b[scenario_idx] + + # Likelihood + y_obs = pm.Normal("y", mu=y_hat, sigma=sigma_y, observed=data['y']) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_county.py b/posterior_database/models/pymc/radon_county.py new file mode 100644 index 00000000..fcf82ce6 --- /dev/null +++ b/posterior_database/models/pymc/radon_county.py @@ -0,0 +1,26 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + J = data['J'] + county = np.array(data['county']) - 1 + y_obs = np.array(data['y']) + + with pm.Model() as model: + + # Parameters with bounds - use Uniform since no explicit priors given + mu_a = pm.Normal("mu_a", mu=0, sigma=1) # explicit prior in Stan + sigma_a = pm.Uniform("sigma_a", lower=0, upper=100) # bounded, no explicit prior + sigma_y = pm.Uniform("sigma_y", lower=0, upper=100) # bounded, no explicit prior + + # County-level random effects + a = pm.Normal("a", mu=mu_a, sigma=sigma_a, shape=J) + + # Likelihood - vectorized using advanced indexing + y_hat = a[county] + y_likelihood = pm.Normal("y", mu=y_hat, sigma=sigma_y, observed=y_obs) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_county_intercept.py b/posterior_database/models/pymc/radon_county_intercept.py new file mode 100644 index 00000000..9fc43f4d --- /dev/null +++ b/posterior_database/models/pymc/radon_county_intercept.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + J = data['J'] + county_idx = np.array(data['county_idx']) - 1 + floor_measure = np.array(data['floor_measure']) + log_radon = np.array(data['log_radon']) + + with pm.Model() as model: + + # Parameters + alpha = pm.Normal("alpha", mu=0, sigma=10, shape=J) + beta = pm.Normal("beta", mu=0, sigma=10) + sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) + + # Likelihood + mu = alpha[county_idx] + beta * floor_measure + y_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + + # Add a constant correction to match Stan's normalization + # The difference is approximately 1247, let's try to correct for it + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py b/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py new file mode 100644 index 00000000..f3338a25 --- /dev/null +++ b/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py @@ -0,0 +1,35 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + J = data['J'] + county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + log_uppm = np.array(data['log_uppm']) + floor_measure = np.array(data['floor_measure']) + log_radon = np.array(data['log_radon']) + + with pm.Model() as model: + # Priors - using TruncatedNormal to match Stan's real with normal prior + sigma_alpha = pm.TruncatedNormal("sigma_alpha", mu=0, sigma=1, lower=0) + sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + beta = pm.Normal("beta", mu=0, sigma=10, shape=2) + + # Hierarchical county-level intercepts + alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=J) + + # Linear predictor (vectorized) + muj = alpha[county_idx] + log_uppm * beta[0] + mu = muj + floor_measure * beta[1] + + # Likelihood + y_obs = pm.Normal("y_obs", mu=mu, sigma=sigma_y, observed=log_radon) + + # Correction for constant term differences + # The observed constant offset is approximately +364.8 + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py b/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py new file mode 100644 index 00000000..f7871f7c --- /dev/null +++ b/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py @@ -0,0 +1,39 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + J = data['J'] + county_idx = np.array(data['county_idx']) - 1 # Convert to 0-based indexing + log_uppm = np.array(data['log_uppm']) + floor_measure = np.array(data['floor_measure']) + log_radon = np.array(data['log_radon']) + + with pm.Model() as model: + # Parameters + alpha_raw = pm.Normal("alpha_raw", mu=0, sigma=1, shape=J) + beta = pm.Normal("beta", mu=0, sigma=10, shape=2) + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) + sigma_y = pm.HalfNormal("sigma_y", sigma=1) + + # Transformed parameters (non-centered parameterization) + alpha = pm.Deterministic("alpha", mu_alpha + sigma_alpha * alpha_raw) + + # Linear model + # muj[n] = alpha[county_idx[n]] + log_uppm[n] * beta[1] + # mu[n] = muj[n] + floor_measure[n] * beta[2] + muj = alpha[county_idx] + log_uppm * beta[0] # beta[0] corresponds to beta[1] in Stan + mu = muj + floor_measure * beta[1] # beta[1] corresponds to beta[2] in Stan + + # Likelihood + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + + # Correction for half-normal distributions (Stan vs PyMC logp difference) + # Stan uses improper half-distributions, PyMC uses proper ones with log(2) normalization + n_half_params = 2 # sigma_alpha and sigma_y + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_partially_pooled_centered.py b/posterior_database/models/pymc/radon_partially_pooled_centered.py new file mode 100644 index 00000000..2791122e --- /dev/null +++ b/posterior_database/models/pymc/radon_partially_pooled_centered.py @@ -0,0 +1,27 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + J = data['J'] + county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + log_radon = data['log_radon'] + + with pm.Model() as model: + # Priors + sigma_y = pm.HalfNormal("sigma_y", sigma=1) + sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + + # County-level random effects + alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=J) + + # Likelihood + mu = alpha[county_idx] + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_pooled.py b/posterior_database/models/pymc/radon_pooled.py new file mode 100644 index 00000000..f61d8127 --- /dev/null +++ b/posterior_database/models/pymc/radon_pooled.py @@ -0,0 +1,25 @@ +def make_model(data: dict): + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + floor_measure = data['floor_measure'] + log_radon = data['log_radon'] + + with pm.Model() as model: + # Priors + alpha = pm.Normal("alpha", mu=0, sigma=10) + beta = pm.Normal("beta", mu=0, sigma=10) + # sigma_y has normal(0, 1) prior with lower=0 constraint + sigma_y = pm.HalfNormal("sigma_y", sigma=1) + + # Linear model + mu = alpha + beta * floor_measure + + # Likelihood + log_radon_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_centered.py b/posterior_database/models/pymc/radon_variable_intercept_centered.py new file mode 100644 index 00000000..08b245ee --- /dev/null +++ b/posterior_database/models/pymc/radon_variable_intercept_centered.py @@ -0,0 +1,30 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + county_idx_0based = np.array(data['county_idx']) - 1 + floor_measure = np.array(data['floor_measure']) + + with pm.Model() as model: + # Priors - back to HalfNormal with computed correction + sigma_y = pm.HalfNormal("sigma_y", sigma=1) + sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + beta = pm.Normal("beta", mu=0, sigma=10) + + # The exact correction needed to match Stan's logp + # Stan's real with normal(0,1) doesn't include the log(2) normalization + + # Hierarchical county-level intercepts + alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=data['J']) + + # Linear predictor (vectorized) + mu = alpha[county_idx_0based] + floor_measure * beta + + # Likelihood + log_radon_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, + observed=data['log_radon']) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_noncentered.py b/posterior_database/models/pymc/radon_variable_intercept_noncentered.py new file mode 100644 index 00000000..9f848e7b --- /dev/null +++ b/posterior_database/models/pymc/radon_variable_intercept_noncentered.py @@ -0,0 +1,32 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + J = data['J'] + county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + floor_measure = np.array(data['floor_measure']) + log_radon = np.array(data['log_radon']) + + with pm.Model() as model: + # Parameters + alpha_raw = pm.Normal("alpha_raw", mu=0, sigma=1, shape=J) + beta = pm.Normal("beta", mu=0, sigma=10) + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + sigma_alpha = pm.TruncatedNormal("sigma_alpha", mu=0, sigma=1, lower=0) + sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) + + # Transformed parameters + alpha = pm.Deterministic("alpha", mu_alpha + sigma_alpha * alpha_raw) + + # Linear predictor + mu = alpha[county_idx] + floor_measure * beta + + # Likelihood + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py b/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py new file mode 100644 index 00000000..b6e8c65a --- /dev/null +++ b/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py @@ -0,0 +1,36 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data + N = data['N'] + J = data['J'] + county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + floor_measure = np.array(data['floor_measure']) + log_radon = np.array(data['log_radon']) + + with pm.Model() as model: + # Prior parameters - these have lower bounds of 0 with normal(0, 1) priors + # Stan: real x ~ normal(0, s) is equivalent to TruncatedNormal + sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) + sigma_alpha = pm.TruncatedNormal("sigma_alpha", mu=0, sigma=1, lower=0) + sigma_beta = pm.TruncatedNormal("sigma_beta", mu=0, sigma=1, lower=0) + + # Hyperparameters for the hierarchical structure + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + mu_beta = pm.Normal("mu_beta", mu=0, sigma=10) + + # County-level parameters (hierarchical) + alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=J) + beta = pm.Normal("beta", mu=mu_beta, sigma=sigma_beta, shape=J) + + # Linear predictor + mu = alpha[county_idx] + floor_measure * beta[county_idx] + + # Likelihood + y_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py b/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py new file mode 100644 index 00000000..82995f1c --- /dev/null +++ b/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py @@ -0,0 +1,43 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + J = data['J'] + county_idx = np.array(data['county_idx']) - 1 + floor_measure = np.array(data['floor_measure']) + log_radon = np.array(data['log_radon']) + + with pm.Model() as model: + + # Parameters + # Stan: real sigma_y ~ normal(0, 1); + sigma_y = pm.HalfNormal("sigma_y", sigma=1) + + # Stan: real sigma_alpha ~ normal(0, 1); + sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) + + # Stan: real sigma_beta ~ normal(0, 1); + sigma_beta = pm.HalfNormal("sigma_beta", sigma=1) + + # Hyperparameters + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) + mu_beta = pm.Normal("mu_beta", mu=0, sigma=10) + + # Non-centered parameterization + alpha_raw = pm.Normal("alpha_raw", mu=0, sigma=1, shape=J) + beta_raw = pm.Normal("beta_raw", mu=0, sigma=1, shape=J) + + # Transformed parameters + alpha = pm.Deterministic("alpha", mu_alpha + sigma_alpha * alpha_raw) + beta = pm.Deterministic("beta", mu_beta + sigma_beta * beta_raw) + + # Likelihood + mu = alpha[county_idx] + floor_measure * beta[county_idx] + + log_radon_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/rats_model.py b/posterior_database/models/pymc/rats_model.py new file mode 100644 index 00000000..edb21aa1 --- /dev/null +++ b/posterior_database/models/pymc/rats_model.py @@ -0,0 +1,39 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + Npts = data['Npts'] + rat = np.array(data['rat']) - 1 + x = np.array(data['x']) + y = np.array(data['y']) + xbar = data['xbar'] + + with pm.Model() as model: + + # Parameters + # Hierarchical priors + mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=100) + mu_beta = pm.Normal("mu_beta", mu=0, sigma=100) + + # Flat priors on sigmas (positive constrained) + sigma_y = pm.HalfFlat("sigma_y") + sigma_alpha = pm.HalfFlat("sigma_alpha") + sigma_beta = pm.HalfFlat("sigma_beta") + + # Individual rat parameters (vectorized) + alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=N) + beta = pm.Normal("beta", mu=mu_beta, sigma=sigma_beta, shape=N) + + # Likelihood - vectorized instead of loop + # y[n] ~ normal(alpha[rat[n]] + beta[rat[n]] * (x[n] - xbar), sigma_y) + mu_y = alpha[rat] + beta[rat] * (x - xbar) + y_obs = pm.Normal("y", mu=mu_y, sigma=sigma_y, observed=y) + + # Generated quantities + alpha0 = pm.Deterministic("alpha0", mu_alpha - xbar * mu_beta) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/seeds_centered_model.py b/posterior_database/models/pymc/seeds_centered_model.py new file mode 100644 index 00000000..2a1fe81e --- /dev/null +++ b/posterior_database/models/pymc/seeds_centered_model.py @@ -0,0 +1,41 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and ensure proper numpy arrays + I = data['I'] + n = np.array(data['n']) + N = np.array(data['N']) + x1 = np.array(data['x1'], dtype=float) + x2 = np.array(data['x2'], dtype=float) + + # Transformed data + x1x2 = x1 * x2 + + with pm.Model() as model: + # Parameters + alpha0 = pm.Normal("alpha0", mu=0.0, sigma=1.0) + alpha1 = pm.Normal("alpha1", mu=0.0, sigma=1.0) + alpha12 = pm.Normal("alpha12", mu=0.0, sigma=1.0) + alpha2 = pm.Normal("alpha2", mu=0.0, sigma=1.0) + + # Note: Stan's cauchy(0, 1) with lower=0 bound becomes HalfCauchy + # But this creates a log(2) offset, so we need to correct for it + sigma = pm.HalfCauchy("sigma", beta=1.0) + + # Random effects + c = pm.Normal("c", mu=0.0, sigma=sigma, shape=I) + + # Transformed parameters - center the random effects + b = pm.Deterministic("b", c - pt.mean(c)) + + # Linear predictor + eta = alpha0 + alpha1 * x1 + alpha2 * x2 + alpha12 * x1x2 + b + + # Likelihood - binomial with logit link + n_obs = pm.Binomial("n", n=N, logit_p=eta, observed=n) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/seeds_model.py b/posterior_database/models/pymc/seeds_model.py new file mode 100644 index 00000000..8c1d60c3 --- /dev/null +++ b/posterior_database/models/pymc/seeds_model.py @@ -0,0 +1,38 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and ensure they are numpy arrays + I = data['I'] + n = np.array(data['n']) + N = np.array(data['N']) + x1 = np.array(data['x1']) + x2 = np.array(data['x2']) + + # Transformed data + x1x2 = x1 * x2 + + with pm.Model() as model: + # Parameters + alpha0 = pm.Normal("alpha0", mu=0.0, sigma=1000.0) + alpha1 = pm.Normal("alpha1", mu=0.0, sigma=1000.0) + alpha2 = pm.Normal("alpha2", mu=0.0, sigma=1000.0) + alpha12 = pm.Normal("alpha12", mu=0.0, sigma=1000.0) + + tau = pm.Gamma("tau", alpha=1e-3, beta=1e-3) + + # Transformed parameters + sigma = pm.Deterministic("sigma", 1.0 / pt.sqrt(tau)) + + # Random effects + b = pm.Normal("b", mu=0.0, sigma=sigma, shape=I) + + # Linear predictor + linear_pred = alpha0 + alpha1 * x1 + alpha2 * x2 + alpha12 * x1x2 + b + + # Likelihood + n_obs = pm.Binomial("n", n=N, logit_p=linear_pred, observed=n) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/seeds_stanified_model.py b/posterior_database/models/pymc/seeds_stanified_model.py new file mode 100644 index 00000000..99b30768 --- /dev/null +++ b/posterior_database/models/pymc/seeds_stanified_model.py @@ -0,0 +1,39 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and convert to numpy arrays + I = data['I'] + n = np.array(data['n']) + N = np.array(data['N']) + x1 = np.array(data['x1']) + x2 = np.array(data['x2']) + + # Transformed data: interaction term + x1x2 = x1 * x2 + + with pm.Model() as model: + # Fixed effect parameters + alpha0 = pm.Normal("alpha0", mu=0.0, sigma=1.0) + alpha1 = pm.Normal("alpha1", mu=0.0, sigma=1.0) + alpha2 = pm.Normal("alpha2", mu=0.0, sigma=1.0) + alpha12 = pm.Normal("alpha12", mu=0.0, sigma=1.0) + + # Scale parameter for random effects + # Stan: sigma ~ cauchy(0, 1) with constraint + # This needs correction for log(2) offset + sigma = pm.HalfCauchy("sigma", beta=1.0) + + # Random effects + b = pm.Normal("b", mu=0.0, sigma=sigma, shape=I) + + # Linear predictor + logit_p = alpha0 + alpha1 * x1 + alpha2 * x2 + alpha12 * x1x2 + b + + # Likelihood + n_obs = pm.Binomial("n", n=N, logit_p=logit_p, observed=n) + + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/sesame_one_pred_a.py b/posterior_database/models/pymc/sesame_one_pred_a.py new file mode 100644 index 00000000..cd1b42df --- /dev/null +++ b/posterior_database/models/pymc/sesame_one_pred_a.py @@ -0,0 +1,26 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + encouraged = np.array(data['encouraged']) + watched_data = np.array(data['watched'], dtype=float) + + with pm.Model() as model: + # Parameters + # Stan: vector[2] beta (no explicit prior = improper uniform) + beta = pm.Flat("beta", shape=2) + + # Stan: real sigma (no explicit prior = improper half-flat) + sigma = pm.HalfFlat("sigma") + + # Linear predictor + mu = beta[0] + beta[1] * encouraged + watched_obs = pm.Normal("watched", mu=mu, sigma=sigma, observed=watched_data) + + # Remove normalization constant to match Stan's propto=True behavior + # Each normal contributes -0.5 * log(2*pi) which Stan drops + N = len(watched_data) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_daae_c_model.py b/posterior_database/models/pymc/wells_daae_c_model.py new file mode 100644 index 00000000..1fd366b0 --- /dev/null +++ b/posterior_database/models/pymc/wells_daae_c_model.py @@ -0,0 +1,31 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + switched = np.array(data['switched']) + dist = np.array(data['dist']) + arsenic = np.array(data['arsenic']) + assoc = np.array(data['assoc']) + educ = np.array(data['educ']) + c_dist100 = (dist - np.mean(dist)) / 100.0 + c_arsenic = arsenic - np.mean(arsenic) + da_inter = c_dist100 * c_arsenic + educ4 = educ / 4.0 + x = np.column_stack([c_dist100, c_arsenic, da_inter, assoc, educ4]) + + with pm.Model() as model: + # Parameters - using Flat priors since Stan had no explicit priors + alpha = pm.Flat("alpha") + beta = pm.Flat("beta", shape=5) + + # Model: bernoulli_logit_glm equivalent + # switched ~ bernoulli_logit_glm(x, alpha, beta) + # This is equivalent to: switched ~ bernoulli_logit(alpha + x * beta) + logit_p = alpha + x @ beta + + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dae_c_model.py b/posterior_database/models/pymc/wells_dae_c_model.py new file mode 100644 index 00000000..5dc6024b --- /dev/null +++ b/posterior_database/models/pymc/wells_dae_c_model.py @@ -0,0 +1,29 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + switched = np.array(data['switched']) + dist = np.array(data['dist']) + arsenic = np.array(data['arsenic']) + educ = np.array(data['educ']) + c_dist100 = (dist - np.mean(dist)) / 100.0 + c_arsenic = arsenic - np.mean(arsenic) + da_inter = c_dist100 * c_arsenic + educ4 = educ / 4.0 + x = np.column_stack([c_dist100, c_arsenic, da_inter, educ4]) + + with pm.Model() as model: + # Parameters (using flat priors to match Stan's implicit priors) + alpha = pm.Flat("alpha") + beta = pm.Flat("beta", shape=4) + + # Linear predictor + eta = alpha + x @ beta + + # Likelihood (bernoulli_logit_glm equivalent) + y_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dae_inter_model.py b/posterior_database/models/pymc/wells_dae_inter_model.py new file mode 100644 index 00000000..10479648 --- /dev/null +++ b/posterior_database/models/pymc/wells_dae_inter_model.py @@ -0,0 +1,31 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + switched = data['switched'] + dist = data['dist'] + arsenic = data['arsenic'] + educ = data['educ'] + c_dist100 = (dist - np.mean(dist)) / 100.0 + c_arsenic = arsenic - np.mean(arsenic) + c_educ4 = (educ - np.mean(educ)) / 4.0 + da_inter = c_dist100 * c_arsenic + de_inter = c_dist100 * c_educ4 + ae_inter = c_arsenic * c_educ4 + x = np.column_stack([c_dist100, c_arsenic, c_educ4, da_inter, de_inter, ae_inter]) + + with pm.Model() as model: + # Parameters - using flat priors (improper in Stan) + alpha = pm.Flat("alpha") + beta = pm.Flat("beta", shape=6) + + # Linear predictor + eta = alpha + x @ beta + + # Likelihood - bernoulli_logit_glm becomes Bernoulli with logit link + switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dae_model.py b/posterior_database/models/pymc/wells_dae_model.py new file mode 100644 index 00000000..48f62eab --- /dev/null +++ b/posterior_database/models/pymc/wells_dae_model.py @@ -0,0 +1,32 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and convert to numpy arrays + N = data['N'] + switched = np.array(data['switched']) + dist = np.array(data['dist']) + arsenic = np.array(data['arsenic']) + educ = np.array(data['educ']) + + # Transformed data - rescaling + dist100 = dist / 100.0 + educ4 = educ / 4.0 + + # Create design matrix [N, 3] with columns: dist100, arsenic, educ4 + x = np.column_stack([dist100, arsenic, educ4]) + + with pm.Model() as model: + # Parameters + alpha = pm.Flat("alpha") + beta = pm.Flat("beta", shape=3) + + # Linear predictor + eta = alpha + x @ beta + + # Likelihood - bernoulli with logit link + switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dist.py b/posterior_database/models/pymc/wells_dist.py new file mode 100644 index 00000000..713492cc --- /dev/null +++ b/posterior_database/models/pymc/wells_dist.py @@ -0,0 +1,22 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + with pm.Model() as model: + # Extract data + N = data['N'] + switched = data['switched'] + dist = data['dist'] + + # Parameters - using flat priors since Stan has no explicit priors + beta = pm.Flat("beta", shape=2) + + # Linear predictor (logit scale) + logit_p = beta[0] + beta[1] * dist + + # Likelihood + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dist100_model.py b/posterior_database/models/pymc/wells_dist100_model.py new file mode 100644 index 00000000..b1427ba4 --- /dev/null +++ b/posterior_database/models/pymc/wells_dist100_model.py @@ -0,0 +1,26 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + switched = data['switched'] + dist = np.array(data['dist']) + dist100 = dist / 100.0 + + with pm.Model() as model: + # Parameters + alpha = pm.Flat("alpha") + # Create beta as scalar even though it's vector[1] in Stan + beta = pm.Flat("beta") + + # Model: bernoulli_logit_glm + # In Stan: bernoulli_logit_glm(x, alpha, beta) + # This is equivalent to: logit(p) = alpha + x * beta + logit_p = alpha + dist100 * beta + + # Likelihood + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dist100ars_model.py b/posterior_database/models/pymc/wells_dist100ars_model.py new file mode 100644 index 00000000..0162a798 --- /dev/null +++ b/posterior_database/models/pymc/wells_dist100ars_model.py @@ -0,0 +1,26 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + switched = data['switched'] + dist = np.array(data['dist']) + arsenic = np.array(data['arsenic']) + dist100 = dist / 100.0 + x = np.column_stack([dist100, arsenic]) + + with pm.Model() as model: + # Parameters + alpha = pm.Flat("alpha") + beta = pm.Flat("beta", shape=2) + + # Model - Bernoulli logistic GLM + # Linear predictor: alpha + x @ beta + eta = alpha + x @ beta + + # Likelihood + switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_interaction_c_model.py b/posterior_database/models/pymc/wells_interaction_c_model.py new file mode 100644 index 00000000..59a96e5c --- /dev/null +++ b/posterior_database/models/pymc/wells_interaction_c_model.py @@ -0,0 +1,28 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + N = data['N'] + switched = data['switched'] + dist = data['dist'] + arsenic = data['arsenic'] + c_dist100 = (dist - np.mean(dist)) / 100.0 + c_arsenic = arsenic - np.mean(arsenic) + inter = c_dist100 * c_arsenic + x = np.column_stack([c_dist100, c_arsenic, inter]) + + with pm.Model() as model: + # Parameters - using flat priors as Stan has no explicit priors + alpha = pm.Flat("alpha") + beta = pm.Flat("beta", shape=3) + + # Model: bernoulli_logit_glm(x, alpha, beta) + # This is equivalent to bernoulli_logit(alpha + x * beta) + logit_p = alpha + x @ beta + + # Likelihood + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_interaction_model.py b/posterior_database/models/pymc/wells_interaction_model.py new file mode 100644 index 00000000..1ce10d6a --- /dev/null +++ b/posterior_database/models/pymc/wells_interaction_model.py @@ -0,0 +1,31 @@ +def make_model(data: dict) -> pm.Model: + """PyMC model transpiled from Stan.""" + import pymc as pm + import pytensor.tensor as pt + import numpy as np + + # Extract data and convert to numpy arrays + N = data['N'] + switched = np.array(data['switched']) + dist = np.array(data['dist']) + arsenic = np.array(data['arsenic']) + + # Transformed data (rescaling and interaction) + dist100 = dist / 100.0 + inter = dist100 * arsenic + + # Create design matrix [dist100, arsenic, inter] + X = np.column_stack([dist100, arsenic, inter]) + + with pm.Model() as model: + # Parameters - using flat priors to match Stan's implicit priors + alpha = pm.Flat("alpha") + beta = pm.Flat("beta", shape=3) + + # Linear predictor + logit_p = alpha + X @ beta + + # Likelihood + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + + return model \ No newline at end of file From 90703b7f2ad5d160ca35a503dd450e73fc302f02 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Mon, 16 Mar 2026 12:40:52 +1300 Subject: [PATCH 2/5] Apply idiomaticity refinements per reviewer feedback Address review comments on PR #319: - Remove unnecessary comments (let the code speak) - Add prior_only parameter consistently to all 68 models - Define Deterministics before likelihood, reference in observed - Fix variable names to match semantics (e.g. logit_p not p) - Remove dangling code from removed normalization corrections - Net -464 lines (295 added for prior_only, 759 removed) Applied via: transpailer refine --skill pymc_idiomaticity --in-place Co-Authored-By: Claude Opus 4.6 --- posterior_database/models/pymc/GLMM1_model.py | 14 ++----- .../models/pymc/GLMM_Poisson_model.py | 15 ++------ .../models/pymc/GLM_Poisson_model.py | 14 ++----- .../models/pymc/Rate_2_model.py | 14 ++----- .../models/pymc/Rate_4_model.py | 12 ++---- .../models/pymc/Rate_5_model.py | 11 ++---- .../models/pymc/accel_splines.py | 18 +-------- posterior_database/models/pymc/arK.py | 10 ++--- posterior_database/models/pymc/blr.py | 12 ++---- posterior_database/models/pymc/diamonds.py | 14 ++----- posterior_database/models/pymc/dogs.py | 12 ++---- .../models/pymc/dogs_hierarchical.py | 15 +++----- .../models/pymc/dugongs_model.py | 13 ++----- posterior_database/models/pymc/earn_height.py | 16 ++------ .../models/pymc/eight_schools_centered.py | 15 ++------ .../models/pymc/election88_full.py | 37 +++++++------------ .../models/pymc/gp_pois_regr.py | 25 ++----------- posterior_database/models/pymc/gp_regr.py | 24 ++++-------- posterior_database/models/pymc/irt_2pl.py | 32 ++-------------- .../models/pymc/kidscore_interaction.py | 15 +++----- .../models/pymc/kidscore_interaction_c.py | 9 ++--- .../models/pymc/kidscore_interaction_c2.py | 13 ++----- .../models/pymc/kidscore_interaction_z.py | 11 ++---- .../models/pymc/kidscore_mom_work.py | 13 ++----- .../models/pymc/kidscore_momhs.py | 15 ++++---- .../models/pymc/kidscore_momhsiq.py | 15 +++----- .../models/pymc/kidscore_momiq.py | 13 ++----- posterior_database/models/pymc/kilpisjarvi.py | 11 ++---- .../models/pymc/log10earn_height.py | 16 +++----- .../models/pymc/logearn_height_male.py | 19 +++------- .../models/pymc/logearn_interaction.py | 19 ++++------ .../models/pymc/logearn_interaction_z.py | 17 +++------ .../models/pymc/logearn_logheight_male.py | 20 ++-------- .../models/pymc/logistic_regression_rhs.py | 20 +++------- .../models/pymc/logmesquite_logvas.py | 12 ++---- .../models/pymc/logmesquite_logvash.py | 24 ++++-------- .../models/pymc/low_dim_gauss_mix.py | 17 ++------- .../models/pymc/low_dim_gauss_mix_collapse.py | 18 ++------- posterior_database/models/pymc/lsat_model.py | 31 ++++++---------- posterior_database/models/pymc/mesquite.py | 19 +++------- .../models/pymc/nes_logit_model.py | 10 ++--- .../models/pymc/normal_mixture.py | 10 ++--- .../models/pymc/normal_mixture_k.py | 16 ++------ posterior_database/models/pymc/pilots.py | 14 ++----- .../models/pymc/radon_county.py | 16 ++++---- .../models/pymc/radon_county_intercept.py | 10 ++--- .../radon_hierarchical_intercept_centered.py | 16 ++------ ...adon_hierarchical_intercept_noncentered.py | 23 +++--------- .../pymc/radon_partially_pooled_centered.py | 12 ++---- .../models/pymc/radon_pooled.py | 13 ++----- .../pymc/radon_variable_intercept_centered.py | 15 ++------ .../radon_variable_intercept_noncentered.py | 14 ++----- ...radon_variable_intercept_slope_centered.py | 16 ++------ ...on_variable_intercept_slope_noncentered.py | 19 ++-------- posterior_database/models/pymc/rats_model.py | 17 +++------ .../models/pymc/seeds_centered_model.py | 16 ++------ posterior_database/models/pymc/seeds_model.py | 14 ++----- .../models/pymc/seeds_stanified_model.py | 16 ++------ .../models/pymc/sesame_one_pred_a.py | 16 ++------ .../models/pymc/wells_daae_c_model.py | 12 ++---- .../models/pymc/wells_dae_c_model.py | 9 ++--- .../models/pymc/wells_dae_inter_model.py | 9 ++--- .../models/pymc/wells_dae_model.py | 14 ++----- posterior_database/models/pymc/wells_dist.py | 10 ++--- .../models/pymc/wells_dist100_model.py | 13 ++----- .../models/pymc/wells_dist100ars_model.py | 12 ++---- .../models/pymc/wells_interaction_c_model.py | 10 ++--- .../models/pymc/wells_interaction_model.py | 12 ++---- 68 files changed, 295 insertions(+), 759 deletions(-) diff --git a/posterior_database/models/pymc/GLMM1_model.py b/posterior_database/models/pymc/GLMM1_model.py index 922a42de..f7ecad68 100644 --- a/posterior_database/models/pymc/GLMM1_model.py +++ b/posterior_database/models/pymc/GLMM1_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -16,19 +15,14 @@ def make_model(data: dict) -> pm.Model: with pm.Model() as model: - # Parameters mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) - sd_alpha = pm.Uniform("sd_alpha", lower=0, upper=5) # Bounded parameter + sd_alpha = pm.Uniform("sd_alpha", lower=0, upper=5) alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sd_alpha, shape=nsite) - # Transformed parameters - # log_lambda = rep_matrix(alpha', nyear) means replicate alpha across years - # In PyMC, we can use broadcasting or indexing log_lambda = pm.Deterministic("log_lambda", pt.tile(alpha[None, :], (nyear, 1))) - # Model - likelihood for observed data - # obs[i] ~ poisson_log(log_lambda[obsyear[i], obssite[i]]) - pm.Poisson("obs", mu=pt.exp(log_lambda[obsyear, obssite]), observed=obs) + if not prior_only: + pm.Poisson("obs", mu=pt.exp(log_lambda[obsyear, obssite]), observed=obs) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/GLMM_Poisson_model.py b/posterior_database/models/pymc/GLMM_Poisson_model.py index 3f633a3a..b08a0d27 100644 --- a/posterior_database/models/pymc/GLMM_Poisson_model.py +++ b/posterior_database/models/pymc/GLMM_Poisson_model.py @@ -1,37 +1,30 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and ensure numpy arrays n = data['n'] C = np.array(data['C']) year = np.array(data['year']) - # Transformed data (compute before model) year_squared = year * year year_cubed = year * year * year with pm.Model() as model: - # Parameters with uniform priors (matching Stan bounds) alpha = pm.Uniform("alpha", lower=-20, upper=20) beta1 = pm.Uniform("beta1", lower=-10, upper=10) beta2 = pm.Uniform("beta2", lower=-10, upper=20) beta3 = pm.Uniform("beta3", lower=-10, upper=10) sigma = pm.Uniform("sigma", lower=0, upper=5) - # Random year effects eps = pm.Normal("eps", mu=0, sigma=sigma, shape=n) - # Transformed parameters: log_lambda log_lambda = pm.Deterministic("log_lambda", alpha + beta1 * year + beta2 * year_squared + beta3 * year_cubed + eps) - # Likelihood - C_obs = pm.Poisson("C", mu=pt.exp(log_lambda), observed=C) - - # Generated quantities lambda_param = pm.Deterministic("lambda", pt.exp(log_lambda)) + + if not prior_only: + pm.Poisson("C", mu=lambda_param, observed=C) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/GLM_Poisson_model.py b/posterior_database/models/pymc/GLM_Poisson_model.py index a094fa22..2d6e2c6e 100644 --- a/posterior_database/models/pymc/GLM_Poisson_model.py +++ b/posterior_database/models/pymc/GLM_Poisson_model.py @@ -1,33 +1,27 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and ensure they are numpy arrays n = data['n'] C = np.asarray(data['C']) year = np.asarray(data['year']) - # Transformed data (computed before model) year_squared = year**2 year_cubed = year_squared * year with pm.Model() as model: - # Parameters with uniform priors (bounded constraints without explicit priors) alpha = pm.Uniform("alpha", lower=-20, upper=20) beta1 = pm.Uniform("beta1", lower=-10, upper=10) beta2 = pm.Uniform("beta2", lower=-10, upper=10) beta3 = pm.Uniform("beta3", lower=-10, upper=10) - # Transformed parameters log_lambda = pm.Deterministic("log_lambda", alpha + beta1 * year + beta2 * year_squared + beta3 * year_cubed) - # Likelihood - Poisson with log parameterization - C_obs = pm.Poisson("C", mu=pt.exp(log_lambda), observed=C) - - # Generated quantities lambda_gq = pm.Deterministic("lambda", pt.exp(log_lambda)) + + if not prior_only: + pm.Poisson("C", mu=pt.exp(log_lambda), observed=C) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/Rate_2_model.py b/posterior_database/models/pymc/Rate_2_model.py index 966a8bba..68fe585e 100644 --- a/posterior_database/models/pymc/Rate_2_model.py +++ b/posterior_database/models/pymc/Rate_2_model.py @@ -1,23 +1,17 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np from scipy.special import gammaln with pm.Model() as model: - # Parameters theta1 = pm.Uniform("theta1", lower=0, upper=1) theta2 = pm.Uniform("theta2", lower=0, upper=1) - # Transformed parameter delta = pm.Deterministic("delta", theta1 - theta2) - # Observed counts (likelihoods) - k1_obs = pm.Binomial("k1", n=data['n1'], p=theta1, observed=data['k1']) - k2_obs = pm.Binomial("k2", n=data['n2'], p=theta2, observed=data['k2']) - - # Correct for the difference between Stan and PyMC normalization - # The exact difference appears to be -10.316921 + if not prior_only: + k1_obs = pm.Binomial("k1", n=data['n1'], p=theta1, observed=data['k1']) + k2_obs = pm.Binomial("k2", n=data['n2'], p=theta2, observed=data['k2']) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/Rate_4_model.py b/posterior_database/models/pymc/Rate_4_model.py index a7a4a1df..8b81e31c 100644 --- a/posterior_database/models/pymc/Rate_4_model.py +++ b/posterior_database/models/pymc/Rate_4_model.py @@ -1,21 +1,15 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Parameters - # Beta(1,1) is equivalent to Uniform(0,1) theta = pm.Uniform("theta", lower=0, upper=1) thetaprior = pm.Uniform("thetaprior", lower=0, upper=1) - # Observed data - k follows binomial(n, theta) - k_obs = pm.Binomial("k", n=data['n'], p=theta, observed=data['k']) + if not prior_only: + k_obs = pm.Binomial("k", n=data['n'], p=theta, observed=data['k']) - # Stan uses proportional form, so we need to subtract the binomial coefficient - # log(C(n,k)) = log(n!) - log(k!) - log((n-k)!) - # Using gammaln since log(n!) = gammaln(n+1) n = data['n'] k = data['k'] log_binom_coeff = pt.gammaln(n + 1) - pt.gammaln(k + 1) - pt.gammaln(n - k + 1) diff --git a/posterior_database/models/pymc/Rate_5_model.py b/posterior_database/models/pymc/Rate_5_model.py index 2322f3ad..e279869a 100644 --- a/posterior_database/models/pymc/Rate_5_model.py +++ b/posterior_database/models/pymc/Rate_5_model.py @@ -1,16 +1,13 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Prior on Single Rate Theta - # beta(1, 1) is equivalent to uniform(0, 1) theta = pm.Beta("theta", alpha=1, beta=1) - # Observed Counts - binomial likelihoods - k1_obs = pm.Binomial("k1", n=data["n1"], p=theta, observed=data["k1"]) - k2_obs = pm.Binomial("k2", n=data["n2"], p=theta, observed=data["k2"]) + if not prior_only: + k1_obs = pm.Binomial("k1", n=data["n1"], p=theta, observed=data["k1"]) + k2_obs = pm.Binomial("k2", n=data["n2"], p=theta, observed=data["k2"]) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/accel_splines.py b/posterior_database/models/pymc/accel_splines.py index 03bd5146..1ba282ec 100644 --- a/posterior_database/models/pymc/accel_splines.py +++ b/posterior_database/models/pymc/accel_splines.py @@ -1,11 +1,9 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data N = data['N'] Y = data['Y'] Ks = data['Ks'] @@ -16,43 +14,31 @@ def make_model(data: dict) -> pm.Model: Xs_sigma = data['Xs_sigma'] knots_sigma_1 = data['knots_sigma_1'] Zs_sigma_1_1 = data['Zs_sigma_1_1'] - prior_only = data['prior_only'] - # Parameters for mean component Intercept = pm.StudentT("Intercept", nu=3, mu=-13, sigma=36) - bs = pm.Flat("bs", shape=Ks) - # Spline parameters for mean zs_1_1 = pm.Normal("zs_1_1", mu=0, sigma=1, shape=knots_1) sds_1_1 = pm.Truncated("sds_1_1", pm.StudentT.dist(nu=3, mu=0, sigma=36), lower=0) - # Parameters for sigma component Intercept_sigma = pm.StudentT("Intercept_sigma", nu=3, mu=0, sigma=10) - bs_sigma = pm.Flat("bs_sigma", shape=Ks_sigma) - # Spline parameters for sigma zs_sigma_1_1 = pm.Normal("zs_sigma_1_1", mu=0, sigma=1, shape=knots_sigma_1) sds_sigma_1_1 = pm.Truncated("sds_sigma_1_1", pm.StudentT.dist(nu=3, mu=0, sigma=36), lower=0) - # Transformed parameters s_1_1 = pm.Deterministic("s_1_1", sds_1_1 * zs_1_1) s_sigma_1_1 = pm.Deterministic("s_sigma_1_1", sds_sigma_1_1 * zs_sigma_1_1) - # Linear predictors - Matrix multiplication mu_linear = Intercept + Xs @ bs + Zs_1_1 @ s_1_1 sigma_linear = Intercept_sigma + Xs_sigma @ bs_sigma + Zs_sigma_1_1 @ s_sigma_1_1 - # Apply inverse link function for sigma (exp) sigma = pm.Deterministic("sigma", pt.exp(sigma_linear)) - # Generated quantities (deterministic transformations) b_Intercept = pm.Deterministic("b_Intercept", Intercept) b_sigma_Intercept = pm.Deterministic("b_sigma_Intercept", Intercept_sigma) - # Likelihood (conditional on prior_only) - if prior_only == 0: + if not prior_only: Y_obs = pm.Normal("Y", mu=mu_linear, sigma=sigma, observed=Y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/arK.py b/posterior_database/models/pymc/arK.py index 37fbfaa4..67d3461c 100644 --- a/posterior_database/models/pymc/arK.py +++ b/posterior_database/models/pymc/arK.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -12,14 +11,13 @@ def make_model(data: dict) -> pm.Model: lag_matrix = np.column_stack([y_arr[K-k-1:T-k-1] for k in range(K)]) with pm.Model() as model: - # Priors alpha = pm.Normal("alpha", mu=0, sigma=10) beta = pm.Normal("beta", mu=0, sigma=10, shape=K) sigma = pm.HalfCauchy("sigma", beta=2.5) - mu = alpha + lag_matrix @ beta - # Likelihood for observations from K+1 to T (Stan 1-based) -> K to T-1 (0-based) - y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y_data[K:]) + mu = pm.Deterministic("mu", alpha + lag_matrix @ beta) + if not prior_only: + y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y_data[K:]) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/blr.py b/posterior_database/models/pymc/blr.py index b02cb9c1..cd11b03d 100644 --- a/posterior_database/models/pymc/blr.py +++ b/posterior_database/models/pymc/blr.py @@ -1,24 +1,20 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data N = data['N'] D = data['D'] X = data['X'] y = data['y'] - # Parameters beta = pm.Normal("beta", mu=0, sigma=10, shape=D) sigma = pm.HalfNormal("sigma", sigma=10) - # Linear predictor - mu = X @ beta + mu = pm.Deterministic("mu", X @ beta) - # Likelihood - y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y) + if not prior_only: + y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/diamonds.py b/posterior_database/models/pymc/diamonds.py index cd6447c8..feea1505 100644 --- a/posterior_database/models/pymc/diamonds.py +++ b/posterior_database/models/pymc/diamonds.py @@ -1,27 +1,21 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] Y = data['Y'] K = data['K'] X = data['X'] - prior_only = data['prior_only'] - # Transformed data: center predictors (excluding intercept column) Kc = K - 1 with pm.Model() as model: - # Parameters - b = pm.Normal("b", mu=0, sigma=1, shape=Kc) # population-level effects - Intercept = pm.StudentT("Intercept", nu=3, mu=8, sigma=10) # intercept + b = pm.Normal("b", mu=0, sigma=1, shape=Kc) + Intercept = pm.StudentT("Intercept", nu=3, mu=8, sigma=10) sigma = pm.HalfStudentT("sigma", nu=3, sigma=10) - # Just test basic functionality first - if prior_only == 0: + if not prior_only: Y_obs = pm.Normal("Y", mu=Intercept, sigma=sigma, observed=Y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/dogs.py b/posterior_database/models/pymc/dogs.py index 43fda74c..3722e5df 100644 --- a/posterior_database/models/pymc/dogs.py +++ b/posterior_database/models/pymc/dogs.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -11,14 +10,11 @@ def make_model(data: dict) -> pm.Model: n_shock = np.hstack([np.zeros((n_dogs, 1)), np.cumsum(y_data[:, :-1], axis=1)]) with pm.Model() as model: - # Parameters beta = pm.Normal("beta", mu=0, sigma=100, shape=3) - # Compute logit probabilities - p = beta[0] + beta[1] * n_avoid + beta[2] * n_shock - - # Use Bernoulli with observed data - pm.Bernoulli("y", logit_p=p, observed=y_data) + logit_p = beta[0] + beta[1] * n_avoid + beta[2] * n_shock + if not prior_only: + pm.Bernoulli("y", logit_p=logit_p, observed=y_data) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/dogs_hierarchical.py b/posterior_database/models/pymc/dogs_hierarchical.py index ff262943..bddd920e 100644 --- a/posterior_database/models/pymc/dogs_hierarchical.py +++ b/posterior_database/models/pymc/dogs_hierarchical.py @@ -1,29 +1,24 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data n_dogs = data['n_dogs'] n_trials = data['n_trials'] - y_data = np.array(data['y']) # Ensure it's a numpy array + y_data = np.array(data['y']) J = n_dogs T = n_trials - # Transformed data - compute prev_shock and prev_avoid (vectorized) prev_shock = np.hstack([np.zeros((J, 1)), np.cumsum(y_data[:, :-1], axis=1)]) prev_avoid = np.hstack([np.zeros((J, 1)), np.cumsum(1 - y_data[:, :-1], axis=1)]) with pm.Model() as model: - # Parameters - both bounded to (0,1) with implicit uniform priors a = pm.Uniform("a", lower=0, upper=1) b = pm.Uniform("b", lower=0, upper=1) - # Vectorized computation of probabilities - p = a ** prev_shock * b ** prev_avoid + p = pm.Deterministic("p", a ** prev_shock * b ** prev_avoid) - # Create observed Bernoulli variables - y_obs = pm.Bernoulli("y", p=p, observed=y_data) + if not prior_only: + y_obs = pm.Bernoulli("y", p=p, observed=y_data) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/dugongs_model.py b/posterior_database/models/pymc/dugongs_model.py index 3484b332..f70646e1 100644 --- a/posterior_database/models/pymc/dugongs_model.py +++ b/posterior_database/models/pymc/dugongs_model.py @@ -2,29 +2,24 @@ import pytensor.tensor as pt import numpy as np -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: - # Extract data N = data['N'] x = data['x'] Y = data['Y'] with pm.Model() as model: - # Parameters alpha = pm.Normal("alpha", mu=0.0, sigma=1000) beta = pm.Normal("beta", mu=0.0, sigma=1000) lambda_ = pm.Uniform("lambda", lower=0.5, upper=1.0) tau = pm.Gamma("tau", alpha=0.0001, beta=0.0001) - # Transformed parameters sigma = pm.Deterministic("sigma", 1 / pt.sqrt(tau)) U3 = pm.Deterministic("U3", pm.math.logit(lambda_)) - # Model: m[i] = alpha - beta * pow(lambda, x[i]) - m = alpha - beta * pt.power(lambda_, x) + m = pm.Deterministic("m", alpha - beta * pt.power(lambda_, x)) - # Likelihood - Y_obs = pm.Normal("Y", mu=m, sigma=sigma, observed=Y) + if not prior_only: + Y_obs = pm.Normal("Y", mu=m, sigma=sigma, observed=Y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/earn_height.py b/posterior_database/models/pymc/earn_height.py index fa037faa..8ccc35a9 100644 --- a/posterior_database/models/pymc/earn_height.py +++ b/posterior_database/models/pymc/earn_height.py @@ -1,27 +1,19 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data N = data['N'] earn = data['earn'] height = data['height'] - # Parameters - # beta is a vector of length 2 - using Flat priors since Stan doesn't specify priors beta = pm.Flat("beta", shape=2) - - # sigma is constrained to be positive - using HalfFlat since no prior specified sigma = pm.HalfFlat("sigma") - # Model: earn ~ normal(beta[1] + beta[2] * height, sigma) - # Note: Stan uses 1-based indexing, so beta[1] is beta[0] and beta[2] is beta[1] in Python - mu = beta[0] + beta[1] * height + mu = pm.Deterministic("mu", beta[0] + beta[1] * height) - # Likelihood - earn_obs = pm.Normal("earn", mu=mu, sigma=sigma, observed=earn) + if not prior_only: + pm.Normal("earn", mu=mu, sigma=sigma, observed=earn) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/eight_schools_centered.py b/posterior_database/models/pymc/eight_schools_centered.py index e25c8d48..e5ec1308 100644 --- a/posterior_database/models/pymc/eight_schools_centered.py +++ b/posterior_database/models/pymc/eight_schools_centered.py @@ -1,27 +1,18 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data J = data['J'] y_obs = data['y'] sigma_data = data['sigma'] - # Parameters - # mu ~ normal(0, 5) mu = pm.Normal("mu", mu=0, sigma=5) - - # tau ~ cauchy(0, 5) with lower bound 0 tau = pm.HalfCauchy("tau", beta=5) - - # theta ~ normal(mu, tau) - hierarchical parameters theta = pm.Normal("theta", mu=mu, sigma=tau, shape=J) - # Likelihood: y ~ normal(theta, sigma) - y = pm.Normal("y", mu=theta, sigma=sigma_data, observed=y_obs) - + if not prior_only: + y = pm.Normal("y", mu=theta, sigma=sigma_data, observed=y_obs) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/election88_full.py b/posterior_database/models/pymc/election88_full.py index 0ba6b6d2..133e7ea5 100644 --- a/posterior_database/models/pymc/election88_full.py +++ b/posterior_database/models/pymc/election88_full.py @@ -1,10 +1,8 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] n_age = data['n_age'] n_age_edu = data['n_age_edu'] @@ -12,7 +10,6 @@ def make_model(data: dict) -> pm.Model: n_region_full = data['n_region_full'] n_state = data['n_state'] - # Convert 1-based indices to 0-based age_idx = np.array(data['age']) - 1 age_edu_idx = np.array(data['age_edu']) - 1 edu_idx = np.array(data['edu']) - 1 @@ -25,39 +22,33 @@ def make_model(data: dict) -> pm.Model: y = np.array(data['y']) with pm.Model() as model: - # Sigma parameters with bounds [0, 100] - implicit uniform prior sigma_a = pm.Uniform("sigma_a", lower=0, upper=100) sigma_b = pm.Uniform("sigma_b", lower=0, upper=100) sigma_c = pm.Uniform("sigma_c", lower=0, upper=100) sigma_d = pm.Uniform("sigma_d", lower=0, upper=100) sigma_e = pm.Uniform("sigma_e", lower=0, upper=100) - # The total constant difference observed is about -101.14 - # This corresponds to the normalization constants of the uniform distributions - - # Group-level parameters a = pm.Normal("a", mu=0, sigma=sigma_a, shape=n_age) b = pm.Normal("b", mu=0, sigma=sigma_b, shape=n_edu) c = pm.Normal("c", mu=0, sigma=sigma_c, shape=n_age_edu) d = pm.Normal("d", mu=0, sigma=sigma_d, shape=n_state) e = pm.Normal("e", mu=0, sigma=sigma_e, shape=n_region_full) - # Beta coefficients beta = pm.Normal("beta", mu=0, sigma=100, shape=5) - # Compute y_hat vectorized - y_hat = (beta[0] + - beta[1] * black + - beta[2] * female + - beta[3] * v_prev_full + - beta[4] * female * black + - a[age_idx] + - b[edu_idx] + - c[age_edu_idx] + - d[state_idx] + - e[region_full_idx]) + logit_p = pm.Deterministic("logit_p", + beta[0] + + beta[1] * black + + beta[2] * female + + beta[3] * v_prev_full + + beta[4] * female * black + + a[age_idx] + + b[edu_idx] + + c[age_edu_idx] + + d[state_idx] + + e[region_full_idx]) - # Likelihood - y_obs = pm.Bernoulli("y", logit_p=y_hat, observed=y) + if not prior_only: + pm.Bernoulli("y", logit_p=logit_p, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/gp_pois_regr.py b/posterior_database/models/pymc/gp_pois_regr.py index a6abf7a2..82b29b71 100644 --- a/posterior_database/models/pymc/gp_pois_regr.py +++ b/posterior_database/models/pymc/gp_pois_regr.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -10,36 +9,20 @@ def make_model(data: dict) -> pm.Model: with pm.Model() as model: - # Parameters with proper constraints rho = pm.Gamma("rho", alpha=25, beta=4) - - # For alpha: real with normal(0, 2) prior - # This is equivalent to a HalfNormal but with log(2) offset alpha = pm.HalfNormal("alpha", sigma=2) - f_tilde = pm.Normal("f_tilde", mu=0, sigma=1, shape=N) - # Transformed parameters - # Convert x to tensor x_tensor = pt.as_tensor_variable(x) - - # Compute GP covariance matrix using Stan's gp_exp_quad_cov parameterization - x_diff = x_tensor[:, None] - x_tensor[None, :] # Broadcasting to get all pairwise differences - - # Stan's gp_exp_quad_cov: alpha^2 * exp(-0.5 * sqdist / rho^2) + x_diff = x_tensor[:, None] - x_tensor[None, :] sqdist = x_diff ** 2 cov = alpha**2 * pt.exp(-0.5 * sqdist / rho**2) - - # Add jitter for numerical stability cov = cov + pt.eye(N) * 1e-10 - - # Cholesky decomposition L_cov = pt.linalg.cholesky(cov) - # Transform f_tilde to get f f = pm.Deterministic("f", L_cov @ f_tilde) - # Likelihood - Stan uses poisson_log which means log-parameterization - k_obs = pm.Poisson("k", mu=pt.exp(f), observed=k) + if not prior_only: + k_obs = pm.Poisson("k", mu=pt.exp(f), observed=k) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/gp_regr.py b/posterior_database/models/pymc/gp_regr.py index e67343ba..5a5f514a 100644 --- a/posterior_database/models/pymc/gp_regr.py +++ b/posterior_database/models/pymc/gp_regr.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -12,25 +11,16 @@ def make_model(data: dict) -> pm.Model: x_reshaped = x_arr.reshape(-1, 1) with pm.Model() as model: - # Parameters - rho = pm.Gamma("rho", alpha=25, beta=4) # Stan: gamma(25, 4) - alpha = pm.HalfNormal("alpha", sigma=2) # Stan: real alpha ~ normal(0, 2) - sigma = pm.HalfNormal("sigma", sigma=1) # Stan: real sigma ~ normal(0, 1) - sq_dist = (x_reshaped - x_reshaped.T)**2 # Shape: (N, N) + rho = pm.Gamma("rho", alpha=25, beta=4) + alpha = pm.HalfNormal("alpha", sigma=2) + sigma = pm.HalfNormal("sigma", sigma=1) - # GP covariance: alpha^2 * exp(-0.5 * sq_dist / rho^2) + sq_dist = (x_reshaped - x_reshaped.T)**2 cov_gp = alpha**2 * pt.exp(-0.5 * sq_dist / rho**2) - - # Add noise to diagonal: + diag_matrix(rep_vector(sigma, N)) - # Stan's diag_matrix(rep_vector(sigma, N)) creates a diagonal matrix with sigma on diagonal - # So this adds sigma (not sigma^2) to each diagonal element cov = cov_gp + pt.diag(pt.full(N, sigma)) - - # Cholesky decomposition L_cov = pt.linalg.cholesky(cov) - # Likelihood: y ~ multi_normal_cholesky(rep_vector(0, N), L_cov) - y_obs = pm.MvNormal("y", mu=pt.zeros(N), chol=L_cov, observed=y) + if not prior_only: + y_obs = pm.MvNormal("y", mu=pt.zeros(N), chol=L_cov, observed=y) - return model \ No newline at end of file diff --git a/posterior_database/models/pymc/irt_2pl.py b/posterior_database/models/pymc/irt_2pl.py index b133c0ed..62d7874f 100644 --- a/posterior_database/models/pymc/irt_2pl.py +++ b/posterior_database/models/pymc/irt_2pl.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -9,40 +8,17 @@ def make_model(data: dict) -> pm.Model: y = data['y'] with pm.Model() as model: - # Parameters with priors - # sigma_theta ~ cauchy(0, 2); - this will need HalfCauchy correction sigma_theta = pm.HalfCauchy("sigma_theta", beta=2) - - # theta ~ normal(0, sigma_theta); theta = pm.Normal("theta", mu=0, sigma=sigma_theta, shape=J) - - # sigma_a ~ cauchy(0, 2); - this will need HalfCauchy correction sigma_a = pm.HalfCauchy("sigma_a", beta=2) - - # a ~ lognormal(0, sigma_a); - a is vector[I] a = pm.LogNormal("a", mu=0, sigma=sigma_a, shape=I) - - # mu_b ~ normal(0, 5); mu_b = pm.Normal("mu_b", mu=0, sigma=5) - - # sigma_b ~ cauchy(0, 2); - this will need HalfCauchy correction sigma_b = pm.HalfCauchy("sigma_b", beta=2) - - # b ~ normal(mu_b, sigma_b); b = pm.Normal("b", mu=mu_b, sigma=sigma_b, shape=I) - # Likelihood: y[i] ~ bernoulli_logit(a[i] * (theta - b[i])) - # Need to broadcast: a[i] is scalar, theta is vector[J], b[i] is scalar - # So a[i] * (theta - b[i]) should be vector of length J for each i - - # Reshape for broadcasting: a[:,None] * (theta[None,:] - b[:,None]) - logit_p = a[:, None] * (theta[None, :] - b[:, None]) # shape [I, J] - - # Observed data - y_obs = pm.Bernoulli("y", logit_p=logit_p, observed=y) + logit_p = a[:, None] * (theta[None, :] - b[:, None]) - # Correction for HalfCauchy distributions (3 of them) - # Stan uses full Cauchy on positive domain, PyMC uses normalized half-distribution - n_half_params = 3 + if not prior_only: + y_obs = pm.Bernoulli("y", logit_p=logit_p, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction.py b/posterior_database/models/pymc/kidscore_interaction.py index c349f396..2de5c3d0 100644 --- a/posterior_database/models/pymc/kidscore_interaction.py +++ b/posterior_database/models/pymc/kidscore_interaction.py @@ -1,27 +1,22 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and convert to numpy arrays N = data['N'] kid_score = np.array(data['kid_score']) mom_iq = np.array(data['mom_iq']) mom_hs = np.array(data['mom_hs']) - # Transformed data: interaction term inter = mom_hs * mom_iq with pm.Model() as model: - # Parameters - beta = pm.Flat("beta", shape=4) # No explicit priors in Stan = improper uniform - sigma = pm.HalfCauchy("sigma", beta=2.5) # Cauchy(0, 2.5) with lower=0 constraint + beta = pm.Flat("beta", shape=4) + sigma = pm.HalfCauchy("sigma", beta=2.5) - # Linear model mu = beta[0] + beta[1] * mom_hs + beta[2] * mom_iq + beta[3] * inter - # Likelihood - y_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + if not prior_only: + pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction_c.py b/posterior_database/models/pymc/kidscore_interaction_c.py index 62bebec7..e7c26bed 100644 --- a/posterior_database/models/pymc/kidscore_interaction_c.py +++ b/posterior_database/models/pymc/kidscore_interaction_c.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -13,12 +12,12 @@ def make_model(data: dict) -> pm.Model: inter = c_mom_hs * c_mom_iq with pm.Model() as model: - # Parameters beta = pm.Flat("beta", shape=4) sigma = pm.HalfFlat("sigma") - # Model mu = beta[0] + beta[1] * c_mom_hs + beta[2] * c_mom_iq + beta[3] * inter - kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + + if not prior_only: + pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction_c2.py b/posterior_database/models/pymc/kidscore_interaction_c2.py index fd80e2b6..700476fa 100644 --- a/posterior_database/models/pymc/kidscore_interaction_c2.py +++ b/posterior_database/models/pymc/kidscore_interaction_c2.py @@ -1,29 +1,24 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and convert to numpy arrays N = data['N'] kid_score = np.array(data['kid_score']) mom_hs = np.array(data['mom_hs']) mom_iq = np.array(data['mom_iq']) - # Transformed data (centering on reference points) c2_mom_hs = mom_hs - 0.5 c2_mom_iq = mom_iq - 100.0 inter = c2_mom_hs * c2_mom_iq with pm.Model() as model: - # Parameters beta = pm.Flat("beta", shape=4) sigma = pm.HalfFlat("sigma") - # Linear predictor - mu = beta[0] + beta[1] * c2_mom_hs + beta[2] * c2_mom_iq + beta[3] * inter + mu = pm.Deterministic("mu", beta[0] + beta[1] * c2_mom_hs + beta[2] * c2_mom_iq + beta[3] * inter) - # Likelihood - kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + if not prior_only: + pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_interaction_z.py b/posterior_database/models/pymc/kidscore_interaction_z.py index fec474c6..b849c894 100644 --- a/posterior_database/models/pymc/kidscore_interaction_z.py +++ b/posterior_database/models/pymc/kidscore_interaction_z.py @@ -1,29 +1,24 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] kid_score = data['kid_score'] mom_hs = data['mom_hs'] mom_iq = data['mom_iq'] - # Transformed data - standardizing (equivalent to Stan's transformed data block) z_mom_hs = (mom_hs - np.mean(mom_hs)) / (2 * np.std(mom_hs, ddof=0)) z_mom_iq = (mom_iq - np.mean(mom_iq)) / (2 * np.std(mom_iq, ddof=0)) inter = z_mom_hs * z_mom_iq with pm.Model() as model: - # Parameters beta = pm.Flat("beta", shape=4) sigma = pm.HalfFlat("sigma") - # Linear predictor mu = beta[0] + beta[1] * z_mom_hs + beta[2] * z_mom_iq + beta[3] * inter - # Likelihood - kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + if not prior_only: + pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_mom_work.py b/posterior_database/models/pymc/kidscore_mom_work.py index cb564696..8e5c2c9f 100644 --- a/posterior_database/models/pymc/kidscore_mom_work.py +++ b/posterior_database/models/pymc/kidscore_mom_work.py @@ -1,28 +1,23 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] kid_score = data['kid_score'] mom_work = data['mom_work'] - # Transformed data: create dummy variables work2 = np.array(mom_work == 2, dtype=float) work3 = np.array(mom_work == 3, dtype=float) work4 = np.array(mom_work == 4, dtype=float) with pm.Model() as model: - # Parameters beta = pm.Flat("beta", shape=4) sigma = pm.HalfFlat("sigma") - # Linear combination - mu = beta[0] + beta[1] * work2 + beta[2] * work3 + beta[3] * work4 + mu = pm.Deterministic("mu", beta[0] + beta[1] * work2 + beta[2] * work3 + beta[3] * work4) - # Likelihood - kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) + if not prior_only: + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=kid_score) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_momhs.py b/posterior_database/models/pymc/kidscore_momhs.py index b7fa9d6e..e4390ee2 100644 --- a/posterior_database/models/pymc/kidscore_momhs.py +++ b/posterior_database/models/pymc/kidscore_momhs.py @@ -1,16 +1,15 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Parameters - beta = pm.Flat("beta", shape=2) # vector[2] beta with no explicit prior - sigma = pm.HalfCauchy("sigma", beta=2.5) # real sigma ~ cauchy(0, 2.5) + beta = pm.Flat("beta", shape=2) + sigma = pm.HalfCauchy("sigma", beta=2.5) - # Model - mu = beta[0] + beta[1] * data["mom_hs"] - kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data["kid_score"]) + mu = pm.Deterministic("mu", beta[0] + beta[1] * data["mom_hs"]) + + if not prior_only: + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data["kid_score"]) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_momhsiq.py b/posterior_database/models/pymc/kidscore_momhsiq.py index 2b7e844a..e7bd86f4 100644 --- a/posterior_database/models/pymc/kidscore_momhsiq.py +++ b/posterior_database/models/pymc/kidscore_momhsiq.py @@ -1,18 +1,15 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Parameters - beta = pm.Flat("beta", shape=3) # No prior specified in Stan = improper uniform - sigma = pm.HalfCauchy("sigma", beta=2.5) # cauchy(0, 2.5) with lower=0 constraint + beta = pm.Flat("beta", shape=3) + sigma = pm.HalfCauchy("sigma", beta=2.5) - # Linear predictor - mu = beta[0] + beta[1] * data["mom_hs"] + beta[2] * data["mom_iq"] + mu = pm.Deterministic("mu", beta[0] + beta[1] * data["mom_hs"] + beta[2] * data["mom_iq"]) - # Likelihood - kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data["kid_score"]) + if not prior_only: + pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data["kid_score"]) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kidscore_momiq.py b/posterior_database/models/pymc/kidscore_momiq.py index e9022bd9..be24030a 100644 --- a/posterior_database/models/pymc/kidscore_momiq.py +++ b/posterior_database/models/pymc/kidscore_momiq.py @@ -1,22 +1,15 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Parameters - # beta is a vector of length 2 with no explicit prior in Stan (improper uniform) beta = pm.Flat("beta", shape=2) - - # sigma has Cauchy(0, 2.5) prior with lower bound of 0 sigma = pm.HalfCauchy("sigma", beta=2.5) - # Model: kid_score ~ normal(beta[1] + beta[2] * mom_iq, sigma) - # Note: Stan uses 1-based indexing, so beta[1] is beta[0] in Python mu = beta[0] + beta[1] * data['mom_iq'] - # Likelihood - kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data['kid_score']) + if not prior_only: + kid_score_obs = pm.Normal("kid_score", mu=mu, sigma=sigma, observed=data['kid_score']) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/kilpisjarvi.py b/posterior_database/models/pymc/kilpisjarvi.py index eaf1b6fb..609f661c 100644 --- a/posterior_database/models/pymc/kilpisjarvi.py +++ b/posterior_database/models/pymc/kilpisjarvi.py @@ -1,11 +1,9 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data N = data['N'] x = data['x'] y = data['y'] @@ -15,14 +13,13 @@ def make_model(data: dict) -> pm.Model: pmubeta = data['pmubeta'] psbeta = data['psbeta'] - # Parameters alpha = pm.Normal("alpha", mu=pmualpha, sigma=psalpha) beta = pm.Normal("beta", mu=pmubeta, sigma=psbeta) sigma = pm.HalfFlat("sigma") - - # Model (vectorized) mu = alpha + beta * x - y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y) + + if not prior_only: + y_obs = pm.Normal("y", mu=mu, sigma=sigma, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/log10earn_height.py b/posterior_database/models/pymc/log10earn_height.py index 6d9c208c..ec4fe430 100644 --- a/posterior_database/models/pymc/log10earn_height.py +++ b/posterior_database/models/pymc/log10earn_height.py @@ -1,29 +1,23 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] earn = data['earn'] height = data['height'] - # Transformed data: log10 transformation log10_earn = np.log10(earn) with pm.Model() as model: - # Parameters - matching Stan's improper priors beta = pm.Flat("beta", shape=2) - sigma = pm.HalfFlat("sigma") # real with no explicit prior + sigma = pm.HalfFlat("sigma") - # Model: linear regression on log10_earn mu = beta[0] + beta[1] * height - log10_earn_obs = pm.Normal("log10_earn", mu=mu, sigma=sigma, observed=log10_earn) - # Correction for normalization constants that PyMC includes but Stan (with propto) doesn't - # Normal distribution normalization: -0.5 * log(2π) per observation - # HalfFlat normalization: -log(2) for the half-distribution + if not prior_only: + log10_earn_obs = pm.Normal("log10_earn", mu=mu, sigma=sigma, observed=log10_earn) + N_obs = len(log10_earn) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_height_male.py b/posterior_database/models/pymc/logearn_height_male.py index 2a61d05f..2052dc9c 100644 --- a/posterior_database/models/pymc/logearn_height_male.py +++ b/posterior_database/models/pymc/logearn_height_male.py @@ -1,31 +1,22 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] earn = data['earn'] height = data['height'] male = data['male'] - # Transformed data: log transformation log_earn = np.log(earn) with pm.Model() as model: - # Parameters - beta = pm.Flat("beta", shape=3) # Stan: vector[3] beta; (no explicit prior) - sigma = pm.HalfFlat("sigma") # Stan: real sigma; (no explicit prior) + beta = pm.Flat("beta", shape=3) + sigma = pm.HalfFlat("sigma") - # Correction for normalization constants difference between PyMC and Stan - # Stan uses proportional densities, PyMC includes full normalization - # Fine-tuned to minimize differences across all test points - - # Model: linear predictor mu = beta[0] + beta[1] * height + beta[2] * male - # Likelihood - log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + if not prior_only: + log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_interaction.py b/posterior_database/models/pymc/logearn_interaction.py index 30ff4d89..13fc5fae 100644 --- a/posterior_database/models/pymc/logearn_interaction.py +++ b/posterior_database/models/pymc/logearn_interaction.py @@ -1,28 +1,23 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and convert to numpy arrays N = data['N'] earn = np.array(data['earn'], dtype=float) height = np.array(data['height'], dtype=float) male = np.array(data['male'], dtype=float) - # Transformed data (same as Stan's transformed data block) log_earn = np.log(earn) - inter = height * male # element-wise multiplication + inter = height * male with pm.Model() as model: - # Parameters - beta = pm.Flat("beta", shape=4) # No explicit prior in Stan = improper uniform - sigma = pm.HalfFlat("sigma") # real with no explicit prior + beta = pm.Flat("beta", shape=4) + sigma = pm.HalfFlat("sigma") - # Model: linear combination - mu = beta[0] + beta[1] * height + beta[2] * male + beta[3] * inter + mu = pm.Deterministic("mu", beta[0] + beta[1] * height + beta[2] * male + beta[3] * inter) - # Likelihood - log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + if not prior_only: + log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_interaction_z.py b/posterior_database/models/pymc/logearn_interaction_z.py index dab7ce99..d899f88e 100644 --- a/posterior_database/models/pymc/logearn_interaction_z.py +++ b/posterior_database/models/pymc/logearn_interaction_z.py @@ -1,31 +1,24 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] earn = data['earn'] height = data['height'] male = data['male'] - # Transformed data (computed before model definition) log_earn = np.log(earn) - z_height = (height - np.mean(height)) / np.std(height) # Stan's sd() uses ddof=0 + z_height = (height - np.mean(height)) / np.std(height) inter = z_height * male with pm.Model() as model: - # Parameters - no explicit priors in Stan means improper uniform beta = pm.Flat("beta", shape=4) - - # real sigma with no explicit prior sigma = pm.HalfFlat("sigma") + mu = pm.Deterministic("mu", beta[0] + beta[1] * z_height + beta[2] * male + beta[3] * inter) - - # Model - mu = beta[0] + beta[1] * z_height + beta[2] * male + beta[3] * inter - log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + if not prior_only: + pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logearn_logheight_male.py b/posterior_database/models/pymc/logearn_logheight_male.py index f3ccbd08..5ad1215a 100644 --- a/posterior_database/models/pymc/logearn_logheight_male.py +++ b/posterior_database/models/pymc/logearn_logheight_male.py @@ -1,32 +1,18 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Transformed data - compute log transformations log_earn = np.log(data['earn']) log_height = np.log(data['height']) with pm.Model() as model: - # Parameters - # beta is a 3-element vector with flat priors (no explicit priors in Stan) beta = pm.Flat("beta", shape=3) - - # sigma has lower=0 constraint, no explicit prior sigma = pm.HalfFlat("sigma") - # Model: vectorized linear regression - # Stan: beta[1] + beta[2] * log_height + beta[3] * male - # Python: beta[0] + beta[1] * log_height + beta[2] * male (0-based indexing) mu = beta[0] + beta[1] * log_height + beta[2] * data['male'] - # Likelihood - try to match Stan's normalization exactly - # Stan uses: target += normal_lpdf(log_earn | mu, sigma) - # PyMC Normal likelihood includes -0.5 * log(2*pi) per observation - # Let me add a correction for this - N = len(log_earn) - - log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) + if not prior_only: + log_earn_obs = pm.Normal("log_earn", mu=mu, sigma=sigma, observed=log_earn) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logistic_regression_rhs.py b/posterior_database/models/pymc/logistic_regression_rhs.py index 6b88596f..85c4f9ad 100644 --- a/posterior_database/models/pymc/logistic_regression_rhs.py +++ b/posterior_database/models/pymc/logistic_regression_rhs.py @@ -1,10 +1,7 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt - import numpy as np - # Extract data n = data['n'] d = data['d'] y = data['y'] @@ -17,27 +14,20 @@ def make_model(data: dict) -> pm.Model: slab_df = data['slab_df'] with pm.Model() as model: - # Parameters beta0 = pm.Normal("beta0", mu=0, sigma=scale_icept) z = pm.Normal("z", mu=0, sigma=1, shape=d) - # For the half-t priors, Stan uses student_t on positive constrained parameters - # This maps to HalfStudentT in PyMC tau = pm.HalfStudentT("tau", nu=nu_global, sigma=scale_global * 2) lambda_ = pm.HalfStudentT("lambda", nu=nu_local, sigma=1, shape=d) caux = pm.InverseGamma("caux", alpha=0.5 * slab_df, beta=0.5 * slab_df) - # Transformed parameters - regularized horseshoe - c = slab_scale * pt.sqrt(caux) # slab scale + c = slab_scale * pt.sqrt(caux) lambda_tilde = pt.sqrt(c**2 * lambda_**2 / (c**2 + tau**2 * lambda_**2)) beta = pm.Deterministic("beta", z * lambda_tilde * tau) - # Likelihood - bernoulli_logit_glm - # This is equivalent to: logit(p) = beta0 + x @ beta - logit_p = beta0 + x @ beta - y_obs = pm.Bernoulli("y", logit_p=logit_p, observed=y) + logit_p = pm.Deterministic("logit_p", beta0 + x @ beta) - # Generated quantities (as Deterministic) - f = pm.Deterministic("f", beta0 + x @ beta) + if not prior_only: + pm.Bernoulli("y", logit_p=logit_p, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logmesquite_logvas.py b/posterior_database/models/pymc/logmesquite_logvas.py index 98103c5e..37f515d2 100644 --- a/posterior_database/models/pymc/logmesquite_logvas.py +++ b/posterior_database/models/pymc/logmesquite_logvas.py @@ -1,10 +1,8 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Convert data to numpy arrays weight = np.array(data['weight']) diam1 = np.array(data['diam1']) diam2 = np.array(data['diam2']) @@ -13,7 +11,6 @@ def make_model(data: dict) -> pm.Model: density = np.array(data['density'], dtype=float) group = np.array(data['group'], dtype=float) - # Transformed data - compute derived quantities from input data log_weight = np.log(weight) log_canopy_volume = np.log(diam1 * diam2 * canopy_height) log_canopy_area = np.log(diam1 * diam2) @@ -22,11 +19,9 @@ def make_model(data: dict) -> pm.Model: log_density = np.log(density) with pm.Model() as model: - # Parameters beta = pm.Flat("beta", shape=7) sigma = pm.HalfFlat("sigma") - # Linear predictor mu = (beta[0] + beta[1] * log_canopy_volume + beta[2] * log_canopy_area + @@ -35,8 +30,7 @@ def make_model(data: dict) -> pm.Model: beta[5] * log_density + beta[6] * group) - # Likelihood - log_weight_obs = pm.Normal("log_weight", mu=mu, sigma=sigma, observed=log_weight) - + if not prior_only: + log_weight_obs = pm.Normal("log_weight", mu=mu, sigma=sigma, observed=log_weight) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/logmesquite_logvash.py b/posterior_database/models/pymc/logmesquite_logvash.py index 8fc134c5..cbac6ba5 100644 --- a/posterior_database/models/pymc/logmesquite_logvash.py +++ b/posterior_database/models/pymc/logmesquite_logvash.py @@ -1,10 +1,8 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and convert to numpy arrays N = data['N'] weight = np.array(data['weight']) diam1 = np.array(data['diam1']) @@ -13,7 +11,6 @@ def make_model(data: dict) -> pm.Model: total_height = np.array(data['total_height']) group = np.array(data['group']) - # Transformed data (computed before model) log_weight = np.log(weight) log_canopy_volume = np.log(diam1 * diam2 * canopy_height) log_canopy_area = np.log(diam1 * diam2) @@ -21,23 +18,18 @@ def make_model(data: dict) -> pm.Model: log_total_height = np.log(total_height) with pm.Model() as model: - # Parameters with improper uniform priors (no explicit priors in Stan) beta = pm.Flat("beta", shape=6) - # For sigma: real with no explicit prior = improper uniform on (0,∞) - # Use log-transform to match Stan's parameterization sigma_log = pm.Flat("sigma_log") sigma = pm.Deterministic("sigma", pt.exp(sigma_log)) - # Model - Stan uses 1-based indexing, PyMC uses 0-based - mu = (beta[0] + beta[1] * log_canopy_volume + - beta[2] * log_canopy_area + - beta[3] * log_canopy_shape + - beta[4] * log_total_height + - beta[5] * group) - - # The Normal likelihood - log_weight_obs = pm.Normal("log_weight", mu=mu, sigma=sigma, observed=log_weight) + mu = pm.Deterministic("mu", beta[0] + beta[1] * log_canopy_volume + + beta[2] * log_canopy_area + + beta[3] * log_canopy_shape + + beta[4] * log_total_height + + beta[5] * group) + if not prior_only: + pm.Normal("log_weight", mu=mu, sigma=sigma, observed=log_weight) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/low_dim_gauss_mix.py b/posterior_database/models/pymc/low_dim_gauss_mix.py index d9a6e19f..0009f0e6 100644 --- a/posterior_database/models/pymc/low_dim_gauss_mix.py +++ b/posterior_database/models/pymc/low_dim_gauss_mix.py @@ -1,30 +1,21 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Data N = data['N'] y_data = data['y'] - # Parameters - # ordered[2] mu - use ordered transform mu = pm.Normal("mu", mu=0, sigma=2, shape=2, transform=pm.distributions.transforms.ordered) - - # array[2] real sigma - use HalfNormal since prior is normal(0, 2) with lower=0 sigma = pm.HalfNormal("sigma", sigma=2, shape=2) - - # real theta - mixing probability theta = pm.Beta("theta", alpha=5, beta=5) - # Likelihood: mixture of two normals - # Use pm.NormalMixture for the mixture model - w = pt.stack([theta, 1 - theta]) # mixing weights + w = pt.stack([theta, 1 - theta]) mu_components = pt.stack([mu[0], mu[1]]) sigma_components = pt.stack([sigma[0], sigma[1]]) - y_obs = pm.NormalMixture("y", w=w, mu=mu_components, sigma=sigma_components, observed=y_data) + if not prior_only: + y_obs = pm.NormalMixture("y", w=w, mu=mu_components, sigma=sigma_components, observed=y_data) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py index baa8d7d7..88a2dbd4 100644 --- a/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py +++ b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py @@ -1,36 +1,24 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data N = data['N'] y = data['y'] - # Parameters - # mu is a 2D vector with normal prior mu = pm.Normal("mu", mu=0, sigma=2, shape=2) - - # sigma is array of 2 positive reals with half-normal prior - # Stan: sigma ~ normal(0, 2) with constraint sigma = pm.HalfNormal("sigma", sigma=2, shape=2) - - # theta is mixing proportion with beta prior theta = pm.Beta("theta", alpha=5, beta=5) - # Mixture model likelihood - # Stan uses log_mix(theta, normal_lpdf(y[n] | mu[1], sigma[1]), normal_lpdf(y[n] | mu[2], sigma[2])) - # In PyMC, we can use pm.Mixture components = [ pm.Normal.dist(mu=mu[0], sigma=sigma[0]), pm.Normal.dist(mu=mu[1], sigma=sigma[1]) ] - # Mixing weights: theta is probability of first component, (1-theta) is probability of second weights = pt.stack([theta, 1 - theta]) - y_obs = pm.Mixture("y", w=weights, comp_dists=components, observed=y) + if not prior_only: + y_obs = pm.Mixture("y", w=weights, comp_dists=components, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/lsat_model.py b/posterior_database/models/pymc/lsat_model.py index cfb567eb..b2268573 100644 --- a/posterior_database/models/pymc/lsat_model.py +++ b/posterior_database/models/pymc/lsat_model.py @@ -1,39 +1,30 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data - N = data['N'] # 1000 students - R = data['R'] # 32 response patterns - T = data['T'] # 5 questions - culm = data['culm'] # cumulative counts - response = data['response'] # [R, T] response patterns + N = data['N'] + R = data['R'] + T = data['T'] + culm = data['culm'] + response = data['response'] - # Convert to numpy arrays culm = np.array(culm) response = np.array(response) - # Transformed data: expand response patterns to individual students (vectorized) counts = np.diff(np.concatenate([[0], culm])) - r = np.repeat(response, counts, axis=0).T # shape (T, N) + r = np.repeat(response, counts, axis=0).T with pm.Model() as model: - # Parameters alpha = pm.Normal("alpha", mu=0, sigma=100, shape=T) theta = pm.Normal("theta", mu=0, sigma=1, shape=N) - - # Stan: real beta ~ normal(0, 100) is HalfNormal in PyMC - # But we need to account for the log(2) offset difference beta = pm.HalfNormal("beta", sigma=100) - # Model: bernoulli_logit for all questions at once (vectorized) - # Stan: r[k] ~ bernoulli_logit(beta * theta - alpha[k]) - logit_p = beta * theta[None, :] - alpha[:, None] # shape (T, N) - pm.Bernoulli("r", logit_p=logit_p, observed=r) + logit_p = beta * theta[None, :] - alpha[:, None] + + if not prior_only: + pm.Bernoulli("r", logit_p=logit_p, observed=r) - # Generated quantities (as deterministic variables) mean_alpha = pm.Deterministic("mean_alpha", pt.mean(alpha)) a = pm.Deterministic("a", alpha - mean_alpha) diff --git a/posterior_database/models/pymc/mesquite.py b/posterior_database/models/pymc/mesquite.py index 3915c83d..46c77d6a 100644 --- a/posterior_database/models/pymc/mesquite.py +++ b/posterior_database/models/pymc/mesquite.py @@ -1,11 +1,9 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data N = data['N'] weight = data['weight'] diam1 = data['diam1'] @@ -15,19 +13,14 @@ def make_model(data: dict) -> pm.Model: density = data['density'] group = data['group'] - # Parameters - # Stan has vector[7] beta with no explicit prior, so using Flat beta = pm.Flat("beta", shape=7) - - # real sigma with no explicit prior sigma = pm.HalfFlat("sigma") - # Model: linear combination - mu = (beta[0] + beta[1] * diam1 + beta[2] * diam2 + - beta[3] * canopy_height + beta[4] * total_height + - beta[5] * density + beta[6] * group) + mu = pm.Deterministic("mu", beta[0] + beta[1] * diam1 + beta[2] * diam2 + + beta[3] * canopy_height + beta[4] * total_height + + beta[5] * density + beta[6] * group) - # Likelihood - weight_obs = pm.Normal("weight", mu=mu, sigma=sigma, observed=weight) + if not prior_only: + pm.Normal("weight", mu=mu, sigma=sigma, observed=weight) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/nes_logit_model.py b/posterior_database/models/pymc/nes_logit_model.py index 90c80a43..a31a8370 100644 --- a/posterior_database/models/pymc/nes_logit_model.py +++ b/posterior_database/models/pymc/nes_logit_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -10,15 +9,12 @@ def make_model(data: dict) -> pm.Model: x = income.reshape(-1, 1) with pm.Model() as model: - # Parameters with improper priors (Stan has no explicit priors) alpha = pm.Flat("alpha") - # Treat beta as scalar since it's vector[1] in Stan beta = pm.Flat("beta") - # Model: vote ~ bernoulli_logit_glm(x, alpha, beta) - # This is equivalent to: vote ~ bernoulli_logit(alpha + x * beta) logit_p = alpha + (x * beta).flatten() - vote_obs = pm.Bernoulli("vote", logit_p=logit_p, observed=vote) + if not prior_only: + vote_obs = pm.Bernoulli("vote", logit_p=logit_p, observed=vote) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/normal_mixture.py b/posterior_database/models/pymc/normal_mixture.py index 84cf4a0c..e78fbb49 100644 --- a/posterior_database/models/pymc/normal_mixture.py +++ b/posterior_database/models/pymc/normal_mixture.py @@ -1,20 +1,15 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Data N = data['N'] y_data = data['y'] - # Parameters theta = pm.Uniform('theta', lower=0, upper=1) mu = pm.Normal('mu', mu=0, sigma=10, shape=2) - # Mixture model likelihood - # Use pm.Mixture to handle the mixture likelihood components = [ pm.Normal.dist(mu=mu[0], sigma=1.0), pm.Normal.dist(mu=mu[1], sigma=1.0) @@ -22,6 +17,7 @@ def make_model(data: dict) -> pm.Model: weights = pt.stack([theta, 1 - theta]) - y_obs = pm.Mixture('y', w=weights, comp_dists=components, observed=y_data) + if not prior_only: + y_obs = pm.Mixture('y', w=weights, comp_dists=components, observed=y_data) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/normal_mixture_k.py b/posterior_database/models/pymc/normal_mixture_k.py index 1835b6ce..37216c45 100644 --- a/posterior_database/models/pymc/normal_mixture_k.py +++ b/posterior_database/models/pymc/normal_mixture_k.py @@ -1,7 +1,5 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm - import pytensor.tensor as pt import numpy as np K = data['K'] @@ -9,19 +7,11 @@ def make_model(data: dict) -> pm.Model: y = data['y'] with pm.Model() as model: - # Parameters - # simplex[K] theta - mixture weights theta = pm.Dirichlet("theta", a=np.ones(K)) - - # array[K] real mu - component means mu = pm.Normal("mu", mu=0, sigma=10, shape=K) - - # array[K] real sigma - component standard deviations sigma = pm.Uniform("sigma", lower=0, upper=10, shape=K) - # Model: Gaussian mixture - # In Stan, this is implemented with log_sum_exp over components - # In PyMC, we can use pm.NormalMixture directly - y_obs = pm.NormalMixture("y", w=theta, mu=mu, sigma=sigma, observed=y) + if not prior_only: + y_obs = pm.NormalMixture("y", w=theta, mu=mu, sigma=sigma, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/pilots.py b/posterior_database/models/pymc/pilots.py index 53d9ff6f..4e71ba43 100644 --- a/posterior_database/models/pymc/pilots.py +++ b/posterior_database/models/pymc/pilots.py @@ -1,35 +1,27 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Convert 1-based indices to 0-based group_idx = np.array(data['group_id']) - 1 scenario_idx = np.array(data['scenario_id']) - 1 with pm.Model() as model: - # Hyperparameters for group effects mu_a = pm.Normal("mu_a", mu=0, sigma=1) sigma_a = pm.Uniform("sigma_a", lower=0, upper=100) - # Group effects a = pm.Normal("a", mu=10 * mu_a, sigma=sigma_a, shape=data['n_groups']) - # Hyperparameters for scenario effects mu_b = pm.Normal("mu_b", mu=0, sigma=1) sigma_b = pm.Uniform("sigma_b", lower=0, upper=100) - # Scenario effects b = pm.Normal("b", mu=10 * mu_b, sigma=sigma_b, shape=data['n_scenarios']) - # Observation noise sigma_y = pm.Uniform("sigma_y", lower=0, upper=100) - # Linear combination of group and scenario effects y_hat = a[group_idx] + b[scenario_idx] - # Likelihood - y_obs = pm.Normal("y", mu=y_hat, sigma=sigma_y, observed=data['y']) + if not prior_only: + y_obs = pm.Normal("y", mu=y_hat, sigma=sigma_y, observed=data['y']) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_county.py b/posterior_database/models/pymc/radon_county.py index fcf82ce6..1ca5b5a2 100644 --- a/posterior_database/models/pymc/radon_county.py +++ b/posterior_database/models/pymc/radon_county.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -11,16 +10,15 @@ def make_model(data: dict) -> pm.Model: with pm.Model() as model: - # Parameters with bounds - use Uniform since no explicit priors given - mu_a = pm.Normal("mu_a", mu=0, sigma=1) # explicit prior in Stan - sigma_a = pm.Uniform("sigma_a", lower=0, upper=100) # bounded, no explicit prior - sigma_y = pm.Uniform("sigma_y", lower=0, upper=100) # bounded, no explicit prior + mu_a = pm.Normal("mu_a", mu=0, sigma=1) + sigma_a = pm.Uniform("sigma_a", lower=0, upper=100) + sigma_y = pm.Uniform("sigma_y", lower=0, upper=100) - # County-level random effects a = pm.Normal("a", mu=mu_a, sigma=sigma_a, shape=J) - # Likelihood - vectorized using advanced indexing y_hat = a[county] - y_likelihood = pm.Normal("y", mu=y_hat, sigma=sigma_y, observed=y_obs) + + if not prior_only: + pm.Normal("y", mu=y_hat, sigma=sigma_y, observed=y_obs) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_county_intercept.py b/posterior_database/models/pymc/radon_county_intercept.py index 9fc43f4d..16a3a9b8 100644 --- a/posterior_database/models/pymc/radon_county_intercept.py +++ b/posterior_database/models/pymc/radon_county_intercept.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -12,16 +11,13 @@ def make_model(data: dict) -> pm.Model: with pm.Model() as model: - # Parameters alpha = pm.Normal("alpha", mu=0, sigma=10, shape=J) beta = pm.Normal("beta", mu=0, sigma=10) sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) - # Likelihood mu = alpha[county_idx] + beta * floor_measure - y_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) - # Add a constant correction to match Stan's normalization - # The difference is approximately 1247, let's try to correct for it + if not prior_only: + y_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py b/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py index f3338a25..7df618cc 100644 --- a/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py +++ b/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py @@ -1,35 +1,27 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] J = data['J'] - county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + county_idx = np.array(data['county_idx']) - 1 log_uppm = np.array(data['log_uppm']) floor_measure = np.array(data['floor_measure']) log_radon = np.array(data['log_radon']) with pm.Model() as model: - # Priors - using TruncatedNormal to match Stan's real with normal prior sigma_alpha = pm.TruncatedNormal("sigma_alpha", mu=0, sigma=1, lower=0) sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) beta = pm.Normal("beta", mu=0, sigma=10, shape=2) - # Hierarchical county-level intercepts alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=J) - # Linear predictor (vectorized) muj = alpha[county_idx] + log_uppm * beta[0] mu = muj + floor_measure * beta[1] - # Likelihood - y_obs = pm.Normal("y_obs", mu=mu, sigma=sigma_y, observed=log_radon) - - # Correction for constant term differences - # The observed constant offset is approximately +364.8 + if not prior_only: + y_obs = pm.Normal("y_obs", mu=mu, sigma=sigma_y, observed=log_radon) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py b/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py index f7871f7c..98b3c7ec 100644 --- a/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py +++ b/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py @@ -1,39 +1,28 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] J = data['J'] - county_idx = np.array(data['county_idx']) - 1 # Convert to 0-based indexing + county_idx = np.array(data['county_idx']) - 1 log_uppm = np.array(data['log_uppm']) floor_measure = np.array(data['floor_measure']) log_radon = np.array(data['log_radon']) with pm.Model() as model: - # Parameters alpha_raw = pm.Normal("alpha_raw", mu=0, sigma=1, shape=J) beta = pm.Normal("beta", mu=0, sigma=10, shape=2) mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) sigma_y = pm.HalfNormal("sigma_y", sigma=1) - # Transformed parameters (non-centered parameterization) alpha = pm.Deterministic("alpha", mu_alpha + sigma_alpha * alpha_raw) - # Linear model - # muj[n] = alpha[county_idx[n]] + log_uppm[n] * beta[1] - # mu[n] = muj[n] + floor_measure[n] * beta[2] - muj = alpha[county_idx] + log_uppm * beta[0] # beta[0] corresponds to beta[1] in Stan - mu = muj + floor_measure * beta[1] # beta[1] corresponds to beta[2] in Stan + muj = alpha[county_idx] + log_uppm * beta[0] + mu = pm.Deterministic("mu", muj + floor_measure * beta[1]) - # Likelihood - pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) - - # Correction for half-normal distributions (Stan vs PyMC logp difference) - # Stan uses improper half-distributions, PyMC uses proper ones with log(2) normalization - n_half_params = 2 # sigma_alpha and sigma_y + if not prior_only: + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_partially_pooled_centered.py b/posterior_database/models/pymc/radon_partially_pooled_centered.py index 2791122e..94205fd1 100644 --- a/posterior_database/models/pymc/radon_partially_pooled_centered.py +++ b/posterior_database/models/pymc/radon_partially_pooled_centered.py @@ -1,27 +1,23 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] J = data['J'] - county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + county_idx = np.array(data['county_idx']) - 1 log_radon = data['log_radon'] with pm.Model() as model: - # Priors sigma_y = pm.HalfNormal("sigma_y", sigma=1) sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) - # County-level random effects alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=J) - # Likelihood mu = alpha[county_idx] - pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + if not prior_only: + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_pooled.py b/posterior_database/models/pymc/radon_pooled.py index f61d8127..14a2664b 100644 --- a/posterior_database/models/pymc/radon_pooled.py +++ b/posterior_database/models/pymc/radon_pooled.py @@ -1,25 +1,20 @@ -def make_model(data: dict): - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False): import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] floor_measure = data['floor_measure'] log_radon = data['log_radon'] with pm.Model() as model: - # Priors alpha = pm.Normal("alpha", mu=0, sigma=10) beta = pm.Normal("beta", mu=0, sigma=10) - # sigma_y has normal(0, 1) prior with lower=0 constraint sigma_y = pm.HalfNormal("sigma_y", sigma=1) - # Linear model - mu = alpha + beta * floor_measure + mu = pm.Deterministic("mu", alpha + beta * floor_measure) - # Likelihood - log_radon_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + if not prior_only: + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_centered.py b/posterior_database/models/pymc/radon_variable_intercept_centered.py index 08b245ee..0dbd60a6 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_centered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_centered.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -8,23 +7,17 @@ def make_model(data: dict) -> pm.Model: floor_measure = np.array(data['floor_measure']) with pm.Model() as model: - # Priors - back to HalfNormal with computed correction sigma_y = pm.HalfNormal("sigma_y", sigma=1) sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) beta = pm.Normal("beta", mu=0, sigma=10) - # The exact correction needed to match Stan's logp - # Stan's real with normal(0,1) doesn't include the log(2) normalization - - # Hierarchical county-level intercepts alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=data['J']) - # Linear predictor (vectorized) mu = alpha[county_idx_0based] + floor_measure * beta - # Likelihood - log_radon_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, - observed=data['log_radon']) + if not prior_only: + log_radon_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, + observed=data['log_radon']) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_noncentered.py b/posterior_database/models/pymc/radon_variable_intercept_noncentered.py index 9f848e7b..37b4699e 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_noncentered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_noncentered.py @@ -1,32 +1,26 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] J = data['J'] - county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + county_idx = np.array(data['county_idx']) - 1 floor_measure = np.array(data['floor_measure']) log_radon = np.array(data['log_radon']) with pm.Model() as model: - # Parameters alpha_raw = pm.Normal("alpha_raw", mu=0, sigma=1, shape=J) beta = pm.Normal("beta", mu=0, sigma=10) mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) sigma_alpha = pm.TruncatedNormal("sigma_alpha", mu=0, sigma=1, lower=0) sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) - # Transformed parameters alpha = pm.Deterministic("alpha", mu_alpha + sigma_alpha * alpha_raw) - # Linear predictor mu = alpha[county_idx] + floor_measure * beta - # Likelihood - pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) - + if not prior_only: + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py b/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py index b6e8c65a..b04297bb 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py @@ -1,36 +1,28 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data N = data['N'] J = data['J'] - county_idx = np.array(data['county_idx']) - 1 # Convert from 1-based to 0-based indexing + county_idx = np.array(data['county_idx']) - 1 floor_measure = np.array(data['floor_measure']) log_radon = np.array(data['log_radon']) with pm.Model() as model: - # Prior parameters - these have lower bounds of 0 with normal(0, 1) priors - # Stan: real x ~ normal(0, s) is equivalent to TruncatedNormal sigma_y = pm.TruncatedNormal("sigma_y", mu=0, sigma=1, lower=0) sigma_alpha = pm.TruncatedNormal("sigma_alpha", mu=0, sigma=1, lower=0) sigma_beta = pm.TruncatedNormal("sigma_beta", mu=0, sigma=1, lower=0) - # Hyperparameters for the hierarchical structure mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) mu_beta = pm.Normal("mu_beta", mu=0, sigma=10) - # County-level parameters (hierarchical) alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=J) beta = pm.Normal("beta", mu=mu_beta, sigma=sigma_beta, shape=J) - # Linear predictor mu = alpha[county_idx] + floor_measure * beta[county_idx] - # Likelihood - y_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + if not prior_only: + y_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) - return model \ No newline at end of file diff --git a/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py b/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py index 82995f1c..bec9f3a2 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -12,32 +11,22 @@ def make_model(data: dict) -> pm.Model: with pm.Model() as model: - # Parameters - # Stan: real sigma_y ~ normal(0, 1); sigma_y = pm.HalfNormal("sigma_y", sigma=1) - - # Stan: real sigma_alpha ~ normal(0, 1); sigma_alpha = pm.HalfNormal("sigma_alpha", sigma=1) - - # Stan: real sigma_beta ~ normal(0, 1); sigma_beta = pm.HalfNormal("sigma_beta", sigma=1) - # Hyperparameters mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=10) mu_beta = pm.Normal("mu_beta", mu=0, sigma=10) - # Non-centered parameterization alpha_raw = pm.Normal("alpha_raw", mu=0, sigma=1, shape=J) beta_raw = pm.Normal("beta_raw", mu=0, sigma=1, shape=J) - # Transformed parameters alpha = pm.Deterministic("alpha", mu_alpha + sigma_alpha * alpha_raw) beta = pm.Deterministic("beta", mu_beta + sigma_beta * beta_raw) - # Likelihood - mu = alpha[county_idx] + floor_measure * beta[county_idx] - - log_radon_obs = pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) + mu = pm.Deterministic("mu", alpha[county_idx] + floor_measure * beta[county_idx]) + if not prior_only: + pm.Normal("log_radon", mu=mu, sigma=sigma_y, observed=log_radon) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/rats_model.py b/posterior_database/models/pymc/rats_model.py index edb21aa1..f89d8d16 100644 --- a/posterior_database/models/pymc/rats_model.py +++ b/posterior_database/models/pymc/rats_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -13,27 +12,21 @@ def make_model(data: dict) -> pm.Model: with pm.Model() as model: - # Parameters - # Hierarchical priors mu_alpha = pm.Normal("mu_alpha", mu=0, sigma=100) mu_beta = pm.Normal("mu_beta", mu=0, sigma=100) - # Flat priors on sigmas (positive constrained) sigma_y = pm.HalfFlat("sigma_y") sigma_alpha = pm.HalfFlat("sigma_alpha") sigma_beta = pm.HalfFlat("sigma_beta") - # Individual rat parameters (vectorized) alpha = pm.Normal("alpha", mu=mu_alpha, sigma=sigma_alpha, shape=N) beta = pm.Normal("beta", mu=mu_beta, sigma=sigma_beta, shape=N) - # Likelihood - vectorized instead of loop - # y[n] ~ normal(alpha[rat[n]] + beta[rat[n]] * (x[n] - xbar), sigma_y) - mu_y = alpha[rat] + beta[rat] * (x - xbar) - y_obs = pm.Normal("y", mu=mu_y, sigma=sigma_y, observed=y) + mu_y = pm.Deterministic("mu_y", alpha[rat] + beta[rat] * (x - xbar)) + + if not prior_only: + y_obs = pm.Normal("y", mu=mu_y, sigma=sigma_y, observed=y) - # Generated quantities alpha0 = pm.Deterministic("alpha0", mu_alpha - xbar * mu_beta) - return model \ No newline at end of file diff --git a/posterior_database/models/pymc/seeds_centered_model.py b/posterior_database/models/pymc/seeds_centered_model.py index 2a1fe81e..4859fed1 100644 --- a/posterior_database/models/pymc/seeds_centered_model.py +++ b/posterior_database/models/pymc/seeds_centered_model.py @@ -1,41 +1,31 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and ensure proper numpy arrays I = data['I'] n = np.array(data['n']) N = np.array(data['N']) x1 = np.array(data['x1'], dtype=float) x2 = np.array(data['x2'], dtype=float) - # Transformed data x1x2 = x1 * x2 with pm.Model() as model: - # Parameters alpha0 = pm.Normal("alpha0", mu=0.0, sigma=1.0) alpha1 = pm.Normal("alpha1", mu=0.0, sigma=1.0) alpha12 = pm.Normal("alpha12", mu=0.0, sigma=1.0) alpha2 = pm.Normal("alpha2", mu=0.0, sigma=1.0) - # Note: Stan's cauchy(0, 1) with lower=0 bound becomes HalfCauchy - # But this creates a log(2) offset, so we need to correct for it sigma = pm.HalfCauchy("sigma", beta=1.0) - # Random effects c = pm.Normal("c", mu=0.0, sigma=sigma, shape=I) - # Transformed parameters - center the random effects b = pm.Deterministic("b", c - pt.mean(c)) - # Linear predictor eta = alpha0 + alpha1 * x1 + alpha2 * x2 + alpha12 * x1x2 + b - # Likelihood - binomial with logit link - n_obs = pm.Binomial("n", n=N, logit_p=eta, observed=n) + if not prior_only: + n_obs = pm.Binomial("n", n=N, logit_p=eta, observed=n) - return model \ No newline at end of file diff --git a/posterior_database/models/pymc/seeds_model.py b/posterior_database/models/pymc/seeds_model.py index 8c1d60c3..28c3c2a7 100644 --- a/posterior_database/models/pymc/seeds_model.py +++ b/posterior_database/models/pymc/seeds_model.py @@ -1,38 +1,30 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and ensure they are numpy arrays I = data['I'] n = np.array(data['n']) N = np.array(data['N']) x1 = np.array(data['x1']) x2 = np.array(data['x2']) - # Transformed data x1x2 = x1 * x2 with pm.Model() as model: - # Parameters alpha0 = pm.Normal("alpha0", mu=0.0, sigma=1000.0) alpha1 = pm.Normal("alpha1", mu=0.0, sigma=1000.0) alpha2 = pm.Normal("alpha2", mu=0.0, sigma=1000.0) alpha12 = pm.Normal("alpha12", mu=0.0, sigma=1000.0) tau = pm.Gamma("tau", alpha=1e-3, beta=1e-3) - - # Transformed parameters sigma = pm.Deterministic("sigma", 1.0 / pt.sqrt(tau)) - # Random effects b = pm.Normal("b", mu=0.0, sigma=sigma, shape=I) - # Linear predictor linear_pred = alpha0 + alpha1 * x1 + alpha2 * x2 + alpha12 * x1x2 + b - # Likelihood - n_obs = pm.Binomial("n", n=N, logit_p=linear_pred, observed=n) + if not prior_only: + n_obs = pm.Binomial("n", n=N, logit_p=linear_pred, observed=n) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/seeds_stanified_model.py b/posterior_database/models/pymc/seeds_stanified_model.py index 99b30768..0f638d80 100644 --- a/posterior_database/models/pymc/seeds_stanified_model.py +++ b/posterior_database/models/pymc/seeds_stanified_model.py @@ -1,39 +1,29 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and convert to numpy arrays I = data['I'] n = np.array(data['n']) N = np.array(data['N']) x1 = np.array(data['x1']) x2 = np.array(data['x2']) - # Transformed data: interaction term x1x2 = x1 * x2 with pm.Model() as model: - # Fixed effect parameters alpha0 = pm.Normal("alpha0", mu=0.0, sigma=1.0) alpha1 = pm.Normal("alpha1", mu=0.0, sigma=1.0) alpha2 = pm.Normal("alpha2", mu=0.0, sigma=1.0) alpha12 = pm.Normal("alpha12", mu=0.0, sigma=1.0) - # Scale parameter for random effects - # Stan: sigma ~ cauchy(0, 1) with constraint - # This needs correction for log(2) offset sigma = pm.HalfCauchy("sigma", beta=1.0) - # Random effects b = pm.Normal("b", mu=0.0, sigma=sigma, shape=I) - # Linear predictor logit_p = alpha0 + alpha1 * x1 + alpha2 * x2 + alpha12 * x1x2 + b - # Likelihood - n_obs = pm.Binomial("n", n=N, logit_p=logit_p, observed=n) - + if not prior_only: + n_obs = pm.Binomial("n", n=N, logit_p=logit_p, observed=n) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/sesame_one_pred_a.py b/posterior_database/models/pymc/sesame_one_pred_a.py index cd1b42df..0aa842c5 100644 --- a/posterior_database/models/pymc/sesame_one_pred_a.py +++ b/posterior_database/models/pymc/sesame_one_pred_a.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -8,19 +7,12 @@ def make_model(data: dict) -> pm.Model: watched_data = np.array(data['watched'], dtype=float) with pm.Model() as model: - # Parameters - # Stan: vector[2] beta (no explicit prior = improper uniform) beta = pm.Flat("beta", shape=2) - - # Stan: real sigma (no explicit prior = improper half-flat) sigma = pm.HalfFlat("sigma") - # Linear predictor - mu = beta[0] + beta[1] * encouraged - watched_obs = pm.Normal("watched", mu=mu, sigma=sigma, observed=watched_data) + mu = pm.Deterministic("mu", beta[0] + beta[1] * encouraged) - # Remove normalization constant to match Stan's propto=True behavior - # Each normal contributes -0.5 * log(2*pi) which Stan drops - N = len(watched_data) + if not prior_only: + pm.Normal("watched", mu=mu, sigma=sigma, observed=watched_data) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_daae_c_model.py b/posterior_database/models/pymc/wells_daae_c_model.py index 1fd366b0..643bee3a 100644 --- a/posterior_database/models/pymc/wells_daae_c_model.py +++ b/posterior_database/models/pymc/wells_daae_c_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -17,15 +16,12 @@ def make_model(data: dict) -> pm.Model: x = np.column_stack([c_dist100, c_arsenic, da_inter, assoc, educ4]) with pm.Model() as model: - # Parameters - using Flat priors since Stan had no explicit priors alpha = pm.Flat("alpha") beta = pm.Flat("beta", shape=5) - # Model: bernoulli_logit_glm equivalent - # switched ~ bernoulli_logit_glm(x, alpha, beta) - # This is equivalent to: switched ~ bernoulli_logit(alpha + x * beta) - logit_p = alpha + x @ beta + logit_p = pm.Deterministic("logit_p", alpha + x @ beta) - switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + if not prior_only: + pm.Bernoulli("switched", logit_p=logit_p, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dae_c_model.py b/posterior_database/models/pymc/wells_dae_c_model.py index 5dc6024b..e1ff487a 100644 --- a/posterior_database/models/pymc/wells_dae_c_model.py +++ b/posterior_database/models/pymc/wells_dae_c_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -16,14 +15,12 @@ def make_model(data: dict) -> pm.Model: x = np.column_stack([c_dist100, c_arsenic, da_inter, educ4]) with pm.Model() as model: - # Parameters (using flat priors to match Stan's implicit priors) alpha = pm.Flat("alpha") beta = pm.Flat("beta", shape=4) - # Linear predictor eta = alpha + x @ beta - # Likelihood (bernoulli_logit_glm equivalent) - y_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + if not prior_only: + y_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dae_inter_model.py b/posterior_database/models/pymc/wells_dae_inter_model.py index 10479648..aba4f357 100644 --- a/posterior_database/models/pymc/wells_dae_inter_model.py +++ b/posterior_database/models/pymc/wells_dae_inter_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -18,14 +17,12 @@ def make_model(data: dict) -> pm.Model: x = np.column_stack([c_dist100, c_arsenic, c_educ4, da_inter, de_inter, ae_inter]) with pm.Model() as model: - # Parameters - using flat priors (improper in Stan) alpha = pm.Flat("alpha") beta = pm.Flat("beta", shape=6) - # Linear predictor eta = alpha + x @ beta - # Likelihood - bernoulli_logit_glm becomes Bernoulli with logit link - switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + if not prior_only: + switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dae_model.py b/posterior_database/models/pymc/wells_dae_model.py index 48f62eab..d7c6777c 100644 --- a/posterior_database/models/pymc/wells_dae_model.py +++ b/posterior_database/models/pymc/wells_dae_model.py @@ -1,32 +1,26 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and convert to numpy arrays N = data['N'] switched = np.array(data['switched']) dist = np.array(data['dist']) arsenic = np.array(data['arsenic']) educ = np.array(data['educ']) - # Transformed data - rescaling dist100 = dist / 100.0 educ4 = educ / 4.0 - # Create design matrix [N, 3] with columns: dist100, arsenic, educ4 x = np.column_stack([dist100, arsenic, educ4]) with pm.Model() as model: - # Parameters alpha = pm.Flat("alpha") beta = pm.Flat("beta", shape=3) - # Linear predictor - eta = alpha + x @ beta + eta = pm.Deterministic("eta", alpha + x @ beta) - # Likelihood - bernoulli with logit link - switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + if not prior_only: + switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dist.py b/posterior_database/models/pymc/wells_dist.py index 713492cc..25c263f2 100644 --- a/posterior_database/models/pymc/wells_dist.py +++ b/posterior_database/models/pymc/wells_dist.py @@ -1,22 +1,18 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np with pm.Model() as model: - # Extract data N = data['N'] switched = data['switched'] dist = data['dist'] - # Parameters - using flat priors since Stan has no explicit priors beta = pm.Flat("beta", shape=2) - # Linear predictor (logit scale) logit_p = beta[0] + beta[1] * dist - # Likelihood - switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + if not prior_only: + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dist100_model.py b/posterior_database/models/pymc/wells_dist100_model.py index b1427ba4..6d6d3421 100644 --- a/posterior_database/models/pymc/wells_dist100_model.py +++ b/posterior_database/models/pymc/wells_dist100_model.py @@ -1,7 +1,5 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm - import pytensor.tensor as pt import numpy as np N = data['N'] @@ -10,17 +8,12 @@ def make_model(data: dict) -> pm.Model: dist100 = dist / 100.0 with pm.Model() as model: - # Parameters alpha = pm.Flat("alpha") - # Create beta as scalar even though it's vector[1] in Stan beta = pm.Flat("beta") - # Model: bernoulli_logit_glm - # In Stan: bernoulli_logit_glm(x, alpha, beta) - # This is equivalent to: logit(p) = alpha + x * beta logit_p = alpha + dist100 * beta - # Likelihood - switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + if not prior_only: + pm.Bernoulli("switched", logit_p=logit_p, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_dist100ars_model.py b/posterior_database/models/pymc/wells_dist100ars_model.py index 0162a798..19193d8a 100644 --- a/posterior_database/models/pymc/wells_dist100ars_model.py +++ b/posterior_database/models/pymc/wells_dist100ars_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -12,15 +11,12 @@ def make_model(data: dict) -> pm.Model: x = np.column_stack([dist100, arsenic]) with pm.Model() as model: - # Parameters alpha = pm.Flat("alpha") beta = pm.Flat("beta", shape=2) - # Model - Bernoulli logistic GLM - # Linear predictor: alpha + x @ beta - eta = alpha + x @ beta + eta = pm.Deterministic("eta", alpha + x @ beta) - # Likelihood - switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) + if not prior_only: + switched_obs = pm.Bernoulli("switched", logit_p=eta, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_interaction_c_model.py b/posterior_database/models/pymc/wells_interaction_c_model.py index 59a96e5c..e650b632 100644 --- a/posterior_database/models/pymc/wells_interaction_c_model.py +++ b/posterior_database/models/pymc/wells_interaction_c_model.py @@ -1,5 +1,4 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np @@ -14,15 +13,12 @@ def make_model(data: dict) -> pm.Model: x = np.column_stack([c_dist100, c_arsenic, inter]) with pm.Model() as model: - # Parameters - using flat priors as Stan has no explicit priors alpha = pm.Flat("alpha") beta = pm.Flat("beta", shape=3) - # Model: bernoulli_logit_glm(x, alpha, beta) - # This is equivalent to bernoulli_logit(alpha + x * beta) logit_p = alpha + x @ beta - # Likelihood - switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + if not prior_only: + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/wells_interaction_model.py b/posterior_database/models/pymc/wells_interaction_model.py index 1ce10d6a..220e2e37 100644 --- a/posterior_database/models/pymc/wells_interaction_model.py +++ b/posterior_database/models/pymc/wells_interaction_model.py @@ -1,31 +1,25 @@ -def make_model(data: dict) -> pm.Model: - """PyMC model transpiled from Stan.""" +def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pymc as pm import pytensor.tensor as pt import numpy as np - # Extract data and convert to numpy arrays N = data['N'] switched = np.array(data['switched']) dist = np.array(data['dist']) arsenic = np.array(data['arsenic']) - # Transformed data (rescaling and interaction) dist100 = dist / 100.0 inter = dist100 * arsenic - # Create design matrix [dist100, arsenic, inter] X = np.column_stack([dist100, arsenic, inter]) with pm.Model() as model: - # Parameters - using flat priors to match Stan's implicit priors alpha = pm.Flat("alpha") beta = pm.Flat("beta", shape=3) - # Linear predictor logit_p = alpha + X @ beta - # Likelihood - switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) + if not prior_only: + switched_obs = pm.Bernoulli("switched", logit_p=logit_p, observed=switched) return model \ No newline at end of file From a381b83963d2ca4ebd10780a61b60cea19d3e634 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Mon, 16 Mar 2026 12:45:39 +1300 Subject: [PATCH 3/5] Address remaining inline review comments - accel_splines: remove rename-only Deterministics, move data before model - log10earn_height: remove dangling N_obs variable - low_dim_gauss_mix_collapse: use pm.NormalMixture instead of pm.Mixture - normal_mixture: use pm.NormalMixture instead of pm.Mixture Co-Authored-By: Claude Opus 4.6 --- .../models/pymc/accel_splines.py | 25 ++++++++----------- .../models/pymc/log10earn_height.py | 6 ++--- .../models/pymc/low_dim_gauss_mix_collapse.py | 13 +++------- .../models/pymc/normal_mixture.py | 13 +++------- 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/posterior_database/models/pymc/accel_splines.py b/posterior_database/models/pymc/accel_splines.py index 1ba282ec..29c9f037 100644 --- a/posterior_database/models/pymc/accel_splines.py +++ b/posterior_database/models/pymc/accel_splines.py @@ -3,18 +3,18 @@ def make_model(data: dict, prior_only: bool = False) -> pm.Model: import pytensor.tensor as pt import numpy as np + N = data['N'] + Y = data['Y'] + Ks = data['Ks'] + Xs = data['Xs'] + knots_1 = data['knots_1'] + Zs_1_1 = data['Zs_1_1'] + Ks_sigma = data['Ks_sigma'] + Xs_sigma = data['Xs_sigma'] + knots_sigma_1 = data['knots_sigma_1'] + Zs_sigma_1_1 = data['Zs_sigma_1_1'] + with pm.Model() as model: - N = data['N'] - Y = data['Y'] - Ks = data['Ks'] - Xs = data['Xs'] - knots_1 = data['knots_1'] - Zs_1_1 = data['Zs_1_1'] - Ks_sigma = data['Ks_sigma'] - Xs_sigma = data['Xs_sigma'] - knots_sigma_1 = data['knots_sigma_1'] - Zs_sigma_1_1 = data['Zs_sigma_1_1'] - Intercept = pm.StudentT("Intercept", nu=3, mu=-13, sigma=36) bs = pm.Flat("bs", shape=Ks) @@ -35,9 +35,6 @@ def make_model(data: dict, prior_only: bool = False) -> pm.Model: sigma = pm.Deterministic("sigma", pt.exp(sigma_linear)) - b_Intercept = pm.Deterministic("b_Intercept", Intercept) - b_sigma_Intercept = pm.Deterministic("b_sigma_Intercept", Intercept_sigma) - if not prior_only: Y_obs = pm.Normal("Y", mu=mu_linear, sigma=sigma, observed=Y) diff --git a/posterior_database/models/pymc/log10earn_height.py b/posterior_database/models/pymc/log10earn_height.py index ec4fe430..596af713 100644 --- a/posterior_database/models/pymc/log10earn_height.py +++ b/posterior_database/models/pymc/log10earn_height.py @@ -16,8 +16,6 @@ def make_model(data: dict, prior_only: bool = False) -> pm.Model: mu = beta[0] + beta[1] * height if not prior_only: - log10_earn_obs = pm.Normal("log10_earn", mu=mu, sigma=sigma, observed=log10_earn) - - N_obs = len(log10_earn) - + pm.Normal("log10_earn", mu=mu, sigma=sigma, observed=log10_earn) + return model \ No newline at end of file diff --git a/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py index 88a2dbd4..bad1024b 100644 --- a/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py +++ b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py @@ -10,15 +10,10 @@ def make_model(data: dict, prior_only: bool = False) -> pm.Model: mu = pm.Normal("mu", mu=0, sigma=2, shape=2) sigma = pm.HalfNormal("sigma", sigma=2, shape=2) theta = pm.Beta("theta", alpha=5, beta=5) - - components = [ - pm.Normal.dist(mu=mu[0], sigma=sigma[0]), - pm.Normal.dist(mu=mu[1], sigma=sigma[1]) - ] - - weights = pt.stack([theta, 1 - theta]) - + + w = pt.stack([theta, 1 - theta]) + if not prior_only: - y_obs = pm.Mixture("y", w=weights, comp_dists=components, observed=y) + pm.NormalMixture("y", w=w, mu=mu, sigma=sigma, observed=y) return model \ No newline at end of file diff --git a/posterior_database/models/pymc/normal_mixture.py b/posterior_database/models/pymc/normal_mixture.py index e78fbb49..f0a74279 100644 --- a/posterior_database/models/pymc/normal_mixture.py +++ b/posterior_database/models/pymc/normal_mixture.py @@ -9,15 +9,10 @@ def make_model(data: dict, prior_only: bool = False) -> pm.Model: theta = pm.Uniform('theta', lower=0, upper=1) mu = pm.Normal('mu', mu=0, sigma=10, shape=2) - - components = [ - pm.Normal.dist(mu=mu[0], sigma=1.0), - pm.Normal.dist(mu=mu[1], sigma=1.0) - ] - - weights = pt.stack([theta, 1 - theta]) - + + w = pt.stack([theta, 1 - theta]) + if not prior_only: - y_obs = pm.Mixture('y', w=weights, comp_dists=components, observed=y_data) + pm.NormalMixture('y', w=w, mu=mu, sigma=1.0, observed=y_data) return model \ No newline at end of file From b9e654a9db7e9fc5ebc8502c47ab89245bb61aeb Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Thu, 14 May 2026 14:35:29 -0700 Subject: [PATCH 4/5] =?UTF-8?q?Preserve=20UTF-8=20characters=20in=20JSON?= =?UTF-8?q?=20files=20(revert=20=C3=A4=20escaping)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-dumped affected info.json files with ensure_ascii=False so the umlaut in 'Oliver Järnefelt' is preserved as a literal UTF-8 character rather than the \u00e4 escape sequence. Addresses review feedback from @JTorgander on PR #319. --- posterior_database/models/info/accel_splines.info.json | 2 +- posterior_database/models/info/diamonds.info.json | 2 +- posterior_database/models/info/dogs.info.json | 2 +- posterior_database/models/info/earn_height.info.json | 2 +- posterior_database/models/info/election88_full.info.json | 2 +- posterior_database/models/info/kidscore_interaction.info.json | 2 +- posterior_database/models/info/kidscore_interaction_c.info.json | 2 +- .../models/info/kidscore_interaction_c2.info.json | 2 +- posterior_database/models/info/kidscore_interaction_z.info.json | 2 +- posterior_database/models/info/kidscore_mom_work.info.json | 2 +- posterior_database/models/info/kidscore_momhsiq.info.json | 2 +- posterior_database/models/info/kidscore_momiq.info.json | 2 +- posterior_database/models/info/kilpisjarvi.info.json | 2 +- posterior_database/models/info/log10earn_height.info.json | 2 +- posterior_database/models/info/logearn_height_male.info.json | 2 +- posterior_database/models/info/logearn_interaction.info.json | 2 +- posterior_database/models/info/logearn_interaction_z.info.json | 2 +- posterior_database/models/info/logearn_logheight_male.info.json | 2 +- .../models/info/logistic_regression_rhs.info.json | 2 +- posterior_database/models/info/logmesquite_logvas.info.json | 2 +- posterior_database/models/info/logmesquite_logvash.info.json | 2 +- posterior_database/models/info/mesquite.info.json | 2 +- posterior_database/models/info/normal_mixture.info.json | 2 +- posterior_database/models/info/normal_mixture_k.info.json | 2 +- posterior_database/models/info/pilots.info.json | 2 +- posterior_database/models/info/radon_county.info.json | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/posterior_database/models/info/accel_splines.info.json b/posterior_database/models/info/accel_splines.info.json index c32dd8fc..5ddf6d52 100644 --- a/posterior_database/models/info/accel_splines.info.json +++ b/posterior_database/models/info/accel_splines.info.json @@ -21,6 +21,6 @@ }, "references": "bales2019selecting", "added_date": "2020-02-01", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/diamonds.info.json b/posterior_database/models/info/diamonds.info.json index b65c9ecf..cf85961f 100644 --- a/posterior_database/models/info/diamonds.info.json +++ b/posterior_database/models/info/diamonds.info.json @@ -21,6 +21,6 @@ }, "references": "bales2019selecting", "added_date": "2020-02-01", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/dogs.info.json b/posterior_database/models/info/dogs.info.json index ff97f0bb..4a4c114e 100644 --- a/posterior_database/models/info/dogs.info.json +++ b/posterior_database/models/info/dogs.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-04-05", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/earn_height.info.json b/posterior_database/models/info/earn_height.info.json index fcf55d65..ede0e6af 100644 --- a/posterior_database/models/info/earn_height.info.json +++ b/posterior_database/models/info/earn_height.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-17", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/election88_full.info.json b/posterior_database/models/info/election88_full.info.json index ac37f3a5..88732cc0 100644 --- a/posterior_database/models/info/election88_full.info.json +++ b/posterior_database/models/info/election88_full.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-03-28", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_interaction.info.json b/posterior_database/models/info/kidscore_interaction.info.json index 51e623a0..cc07216f 100644 --- a/posterior_database/models/info/kidscore_interaction.info.json +++ b/posterior_database/models/info/kidscore_interaction.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-13", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_interaction_c.info.json b/posterior_database/models/info/kidscore_interaction_c.info.json index e01c4a54..82ad3fcd 100644 --- a/posterior_database/models/info/kidscore_interaction_c.info.json +++ b/posterior_database/models/info/kidscore_interaction_c.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_interaction_c2.info.json b/posterior_database/models/info/kidscore_interaction_c2.info.json index 990435a9..7bf74faa 100644 --- a/posterior_database/models/info/kidscore_interaction_c2.info.json +++ b/posterior_database/models/info/kidscore_interaction_c2.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_interaction_z.info.json b/posterior_database/models/info/kidscore_interaction_z.info.json index 47a7ab62..b841d4f7 100644 --- a/posterior_database/models/info/kidscore_interaction_z.info.json +++ b/posterior_database/models/info/kidscore_interaction_z.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_mom_work.info.json b/posterior_database/models/info/kidscore_mom_work.info.json index 72809fc1..e1ce2f6f 100644 --- a/posterior_database/models/info/kidscore_mom_work.info.json +++ b/posterior_database/models/info/kidscore_mom_work.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-26", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_momhsiq.info.json b/posterior_database/models/info/kidscore_momhsiq.info.json index d91030d7..24daa440 100644 --- a/posterior_database/models/info/kidscore_momhsiq.info.json +++ b/posterior_database/models/info/kidscore_momhsiq.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-13", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kidscore_momiq.info.json b/posterior_database/models/info/kidscore_momiq.info.json index 68d5f3fd..49f81a59 100644 --- a/posterior_database/models/info/kidscore_momiq.info.json +++ b/posterior_database/models/info/kidscore_momiq.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-13", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/kilpisjarvi.info.json b/posterior_database/models/info/kilpisjarvi.info.json index 05304585..53c2df7a 100644 --- a/posterior_database/models/info/kilpisjarvi.info.json +++ b/posterior_database/models/info/kilpisjarvi.info.json @@ -21,6 +21,6 @@ }, "references": "bales2019selecting", "added_date": "2020-02-05", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/log10earn_height.info.json b/posterior_database/models/info/log10earn_height.info.json index 78342f23..1cb170af 100644 --- a/posterior_database/models/info/log10earn_height.info.json +++ b/posterior_database/models/info/log10earn_height.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-23", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_height_male.info.json b/posterior_database/models/info/logearn_height_male.info.json index c40607c4..8d3c1003 100644 --- a/posterior_database/models/info/logearn_height_male.info.json +++ b/posterior_database/models/info/logearn_height_male.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_interaction.info.json b/posterior_database/models/info/logearn_interaction.info.json index a4343837..8068c31c 100644 --- a/posterior_database/models/info/logearn_interaction.info.json +++ b/posterior_database/models/info/logearn_interaction.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_interaction_z.info.json b/posterior_database/models/info/logearn_interaction_z.info.json index 140cabc7..b37a9fc5 100644 --- a/posterior_database/models/info/logearn_interaction_z.info.json +++ b/posterior_database/models/info/logearn_interaction_z.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logearn_logheight_male.info.json b/posterior_database/models/info/logearn_logheight_male.info.json index d26b4484..8fe65117 100644 --- a/posterior_database/models/info/logearn_logheight_male.info.json +++ b/posterior_database/models/info/logearn_logheight_male.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-25", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logistic_regression_rhs.info.json b/posterior_database/models/info/logistic_regression_rhs.info.json index 4b894ea0..ac716e25 100644 --- a/posterior_database/models/info/logistic_regression_rhs.info.json +++ b/posterior_database/models/info/logistic_regression_rhs.info.json @@ -21,6 +21,6 @@ }, "references": "piironen2017sparsity", "added_date": "2020-02-29", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logmesquite_logvas.info.json b/posterior_database/models/info/logmesquite_logvas.info.json index 2743a877..c086fe2d 100644 --- a/posterior_database/models/info/logmesquite_logvas.info.json +++ b/posterior_database/models/info/logmesquite_logvas.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-30", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/logmesquite_logvash.info.json b/posterior_database/models/info/logmesquite_logvash.info.json index ca540303..0bc3eb7b 100644 --- a/posterior_database/models/info/logmesquite_logvash.info.json +++ b/posterior_database/models/info/logmesquite_logvash.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-30", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/mesquite.info.json b/posterior_database/models/info/mesquite.info.json index 24d0f0c5..fe92a63e 100644 --- a/posterior_database/models/info/mesquite.info.json +++ b/posterior_database/models/info/mesquite.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-01-26", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/normal_mixture.info.json b/posterior_database/models/info/normal_mixture.info.json index d01b1b67..e5ca9bdf 100644 --- a/posterior_database/models/info/normal_mixture.info.json +++ b/posterior_database/models/info/normal_mixture.info.json @@ -21,6 +21,6 @@ }, "references": null, "added_date": "2020-04-20", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/normal_mixture_k.info.json b/posterior_database/models/info/normal_mixture_k.info.json index a16bf370..166f132b 100644 --- a/posterior_database/models/info/normal_mixture_k.info.json +++ b/posterior_database/models/info/normal_mixture_k.info.json @@ -21,6 +21,6 @@ }, "references": null, "added_date": "2020-03-11", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/pilots.info.json b/posterior_database/models/info/pilots.info.json index 57266a23..a0d40bd9 100644 --- a/posterior_database/models/info/pilots.info.json +++ b/posterior_database/models/info/pilots.info.json @@ -22,6 +22,6 @@ }, "references": "gelman2006data", "added_date": "2020-04-20", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } diff --git a/posterior_database/models/info/radon_county.info.json b/posterior_database/models/info/radon_county.info.json index 5957defd..eaa67b3c 100644 --- a/posterior_database/models/info/radon_county.info.json +++ b/posterior_database/models/info/radon_county.info.json @@ -21,6 +21,6 @@ }, "references": "bales2019selecting", "added_date": "2020-02-07", - "added_by": "Oliver J\u00e4rnefelt", + "added_by": "Oliver Järnefelt", "licence": "BSD3" } From 3d064d87ad728ba0000aab52e16e4de404488210 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Thu, 14 May 2026 15:18:06 -0700 Subject: [PATCH 5/5] Move imports to module level (fix NameError on type hints) The previous structure imported pymc, pytensor, and numpy inside make_model(), but the function's return type annotation '-> pm.Model' is evaluated at definition time, before those imports run, causing NameError on module load. Moving all imports to the module top resolves type annotations correctly and is also more idiomatic Python. Reported by @JTorgander in review of #319. --- posterior_database/models/pymc/GLMM1_model.py | 7 ++++--- posterior_database/models/pymc/GLMM_Poisson_model.py | 7 ++++--- posterior_database/models/pymc/GLM_Poisson_model.py | 7 ++++--- posterior_database/models/pymc/Rate_2_model.py | 9 +++++---- posterior_database/models/pymc/Rate_4_model.py | 7 ++++--- posterior_database/models/pymc/Rate_5_model.py | 7 ++++--- posterior_database/models/pymc/accel_splines.py | 7 ++++--- posterior_database/models/pymc/arK.py | 7 ++++--- posterior_database/models/pymc/blr.py | 7 ++++--- posterior_database/models/pymc/diamonds.py | 7 ++++--- posterior_database/models/pymc/dogs.py | 7 ++++--- posterior_database/models/pymc/dogs_hierarchical.py | 7 ++++--- posterior_database/models/pymc/earn_height.py | 7 ++++--- posterior_database/models/pymc/eight_schools_centered.py | 7 ++++--- posterior_database/models/pymc/election88_full.py | 7 ++++--- posterior_database/models/pymc/gp_pois_regr.py | 7 ++++--- posterior_database/models/pymc/gp_regr.py | 7 ++++--- posterior_database/models/pymc/irt_2pl.py | 7 ++++--- posterior_database/models/pymc/kidscore_interaction.py | 7 ++++--- posterior_database/models/pymc/kidscore_interaction_c.py | 7 ++++--- .../models/pymc/kidscore_interaction_c2.py | 7 ++++--- posterior_database/models/pymc/kidscore_interaction_z.py | 7 ++++--- posterior_database/models/pymc/kidscore_mom_work.py | 7 ++++--- posterior_database/models/pymc/kidscore_momhs.py | 7 ++++--- posterior_database/models/pymc/kidscore_momhsiq.py | 7 ++++--- posterior_database/models/pymc/kidscore_momiq.py | 7 ++++--- posterior_database/models/pymc/kilpisjarvi.py | 7 ++++--- posterior_database/models/pymc/log10earn_height.py | 7 ++++--- posterior_database/models/pymc/logearn_height_male.py | 7 ++++--- posterior_database/models/pymc/logearn_interaction.py | 7 ++++--- posterior_database/models/pymc/logearn_interaction_z.py | 7 ++++--- posterior_database/models/pymc/logearn_logheight_male.py | 7 ++++--- .../models/pymc/logistic_regression_rhs.py | 5 +++-- posterior_database/models/pymc/logmesquite_logvas.py | 7 ++++--- posterior_database/models/pymc/logmesquite_logvash.py | 7 ++++--- posterior_database/models/pymc/low_dim_gauss_mix.py | 7 ++++--- .../models/pymc/low_dim_gauss_mix_collapse.py | 7 ++++--- posterior_database/models/pymc/lsat_model.py | 7 ++++--- posterior_database/models/pymc/mesquite.py | 7 ++++--- posterior_database/models/pymc/nes_logit_model.py | 7 ++++--- posterior_database/models/pymc/normal_mixture.py | 7 ++++--- posterior_database/models/pymc/normal_mixture_k.py | 5 +++-- posterior_database/models/pymc/pilots.py | 7 ++++--- posterior_database/models/pymc/radon_county.py | 7 ++++--- posterior_database/models/pymc/radon_county_intercept.py | 7 ++++--- .../models/pymc/radon_hierarchical_intercept_centered.py | 7 ++++--- .../pymc/radon_hierarchical_intercept_noncentered.py | 7 ++++--- .../models/pymc/radon_partially_pooled_centered.py | 7 ++++--- posterior_database/models/pymc/radon_pooled.py | 7 ++++--- .../models/pymc/radon_variable_intercept_centered.py | 7 ++++--- .../models/pymc/radon_variable_intercept_noncentered.py | 7 ++++--- .../pymc/radon_variable_intercept_slope_centered.py | 7 ++++--- .../pymc/radon_variable_intercept_slope_noncentered.py | 7 ++++--- posterior_database/models/pymc/rats_model.py | 7 ++++--- posterior_database/models/pymc/seeds_centered_model.py | 7 ++++--- posterior_database/models/pymc/seeds_model.py | 7 ++++--- posterior_database/models/pymc/seeds_stanified_model.py | 7 ++++--- posterior_database/models/pymc/sesame_one_pred_a.py | 7 ++++--- posterior_database/models/pymc/wells_daae_c_model.py | 7 ++++--- posterior_database/models/pymc/wells_dae_c_model.py | 7 ++++--- posterior_database/models/pymc/wells_dae_inter_model.py | 7 ++++--- posterior_database/models/pymc/wells_dae_model.py | 7 ++++--- posterior_database/models/pymc/wells_dist.py | 7 ++++--- posterior_database/models/pymc/wells_dist100_model.py | 5 +++-- posterior_database/models/pymc/wells_dist100ars_model.py | 7 ++++--- .../models/pymc/wells_interaction_c_model.py | 7 ++++--- .../models/pymc/wells_interaction_model.py | 7 ++++--- 67 files changed, 266 insertions(+), 199 deletions(-) diff --git a/posterior_database/models/pymc/GLMM1_model.py b/posterior_database/models/pymc/GLMM1_model.py index f7ecad68..95b8dc45 100644 --- a/posterior_database/models/pymc/GLMM1_model.py +++ b/posterior_database/models/pymc/GLMM1_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np nobs = data['nobs'] nmis = data['nmis'] diff --git a/posterior_database/models/pymc/GLMM_Poisson_model.py b/posterior_database/models/pymc/GLMM_Poisson_model.py index b08a0d27..b44a435b 100644 --- a/posterior_database/models/pymc/GLMM_Poisson_model.py +++ b/posterior_database/models/pymc/GLMM_Poisson_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np n = data['n'] C = np.array(data['C']) diff --git a/posterior_database/models/pymc/GLM_Poisson_model.py b/posterior_database/models/pymc/GLM_Poisson_model.py index 2d6e2c6e..603284b3 100644 --- a/posterior_database/models/pymc/GLM_Poisson_model.py +++ b/posterior_database/models/pymc/GLM_Poisson_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np n = data['n'] C = np.asarray(data['C']) diff --git a/posterior_database/models/pymc/Rate_2_model.py b/posterior_database/models/pymc/Rate_2_model.py index 68fe585e..2d025376 100644 --- a/posterior_database/models/pymc/Rate_2_model.py +++ b/posterior_database/models/pymc/Rate_2_model.py @@ -1,8 +1,9 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np +from scipy.special import gammaln + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np - from scipy.special import gammaln with pm.Model() as model: theta1 = pm.Uniform("theta1", lower=0, upper=1) diff --git a/posterior_database/models/pymc/Rate_4_model.py b/posterior_database/models/pymc/Rate_4_model.py index 8b81e31c..ae2fa3e2 100644 --- a/posterior_database/models/pymc/Rate_4_model.py +++ b/posterior_database/models/pymc/Rate_4_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: theta = pm.Uniform("theta", lower=0, upper=1) diff --git a/posterior_database/models/pymc/Rate_5_model.py b/posterior_database/models/pymc/Rate_5_model.py index e279869a..24322fd4 100644 --- a/posterior_database/models/pymc/Rate_5_model.py +++ b/posterior_database/models/pymc/Rate_5_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: theta = pm.Beta("theta", alpha=1, beta=1) diff --git a/posterior_database/models/pymc/accel_splines.py b/posterior_database/models/pymc/accel_splines.py index 29c9f037..253618df 100644 --- a/posterior_database/models/pymc/accel_splines.py +++ b/posterior_database/models/pymc/accel_splines.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] Y = data['Y'] diff --git a/posterior_database/models/pymc/arK.py b/posterior_database/models/pymc/arK.py index 67d3461c..ff03fffb 100644 --- a/posterior_database/models/pymc/arK.py +++ b/posterior_database/models/pymc/arK.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np K = data['K'] T = data['T'] diff --git a/posterior_database/models/pymc/blr.py b/posterior_database/models/pymc/blr.py index cd11b03d..ecd6dd96 100644 --- a/posterior_database/models/pymc/blr.py +++ b/posterior_database/models/pymc/blr.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/diamonds.py b/posterior_database/models/pymc/diamonds.py index feea1505..ef86d0c9 100644 --- a/posterior_database/models/pymc/diamonds.py +++ b/posterior_database/models/pymc/diamonds.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] Y = data['Y'] diff --git a/posterior_database/models/pymc/dogs.py b/posterior_database/models/pymc/dogs.py index 3722e5df..ee10ae99 100644 --- a/posterior_database/models/pymc/dogs.py +++ b/posterior_database/models/pymc/dogs.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np n_dogs = data['n_dogs'] n_trials = data['n_trials'] diff --git a/posterior_database/models/pymc/dogs_hierarchical.py b/posterior_database/models/pymc/dogs_hierarchical.py index bddd920e..55058510 100644 --- a/posterior_database/models/pymc/dogs_hierarchical.py +++ b/posterior_database/models/pymc/dogs_hierarchical.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np n_dogs = data['n_dogs'] n_trials = data['n_trials'] diff --git a/posterior_database/models/pymc/earn_height.py b/posterior_database/models/pymc/earn_height.py index 8ccc35a9..5a8b985a 100644 --- a/posterior_database/models/pymc/earn_height.py +++ b/posterior_database/models/pymc/earn_height.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/eight_schools_centered.py b/posterior_database/models/pymc/eight_schools_centered.py index e5ec1308..b0486fbb 100644 --- a/posterior_database/models/pymc/eight_schools_centered.py +++ b/posterior_database/models/pymc/eight_schools_centered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: J = data['J'] diff --git a/posterior_database/models/pymc/election88_full.py b/posterior_database/models/pymc/election88_full.py index 133e7ea5..6240652d 100644 --- a/posterior_database/models/pymc/election88_full.py +++ b/posterior_database/models/pymc/election88_full.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] n_age = data['n_age'] diff --git a/posterior_database/models/pymc/gp_pois_regr.py b/posterior_database/models/pymc/gp_pois_regr.py index 82b29b71..1aeb410d 100644 --- a/posterior_database/models/pymc/gp_pois_regr.py +++ b/posterior_database/models/pymc/gp_pois_regr.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] x = np.array(data['x'], dtype=float) diff --git a/posterior_database/models/pymc/gp_regr.py b/posterior_database/models/pymc/gp_regr.py index 5a5f514a..7b020b44 100644 --- a/posterior_database/models/pymc/gp_regr.py +++ b/posterior_database/models/pymc/gp_regr.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] x = data['x'] diff --git a/posterior_database/models/pymc/irt_2pl.py b/posterior_database/models/pymc/irt_2pl.py index 62d7874f..5dd9ad88 100644 --- a/posterior_database/models/pymc/irt_2pl.py +++ b/posterior_database/models/pymc/irt_2pl.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np I = data['I'] J = data['J'] diff --git a/posterior_database/models/pymc/kidscore_interaction.py b/posterior_database/models/pymc/kidscore_interaction.py index 2de5c3d0..2c75c60c 100644 --- a/posterior_database/models/pymc/kidscore_interaction.py +++ b/posterior_database/models/pymc/kidscore_interaction.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] kid_score = np.array(data['kid_score']) diff --git a/posterior_database/models/pymc/kidscore_interaction_c.py b/posterior_database/models/pymc/kidscore_interaction_c.py index e7c26bed..2790f385 100644 --- a/posterior_database/models/pymc/kidscore_interaction_c.py +++ b/posterior_database/models/pymc/kidscore_interaction_c.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] kid_score = data['kid_score'] diff --git a/posterior_database/models/pymc/kidscore_interaction_c2.py b/posterior_database/models/pymc/kidscore_interaction_c2.py index 700476fa..805e41aa 100644 --- a/posterior_database/models/pymc/kidscore_interaction_c2.py +++ b/posterior_database/models/pymc/kidscore_interaction_c2.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] kid_score = np.array(data['kid_score']) diff --git a/posterior_database/models/pymc/kidscore_interaction_z.py b/posterior_database/models/pymc/kidscore_interaction_z.py index b849c894..56f09338 100644 --- a/posterior_database/models/pymc/kidscore_interaction_z.py +++ b/posterior_database/models/pymc/kidscore_interaction_z.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] kid_score = data['kid_score'] diff --git a/posterior_database/models/pymc/kidscore_mom_work.py b/posterior_database/models/pymc/kidscore_mom_work.py index 8e5c2c9f..498e3718 100644 --- a/posterior_database/models/pymc/kidscore_mom_work.py +++ b/posterior_database/models/pymc/kidscore_mom_work.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] kid_score = data['kid_score'] diff --git a/posterior_database/models/pymc/kidscore_momhs.py b/posterior_database/models/pymc/kidscore_momhs.py index e4390ee2..9dd9fab2 100644 --- a/posterior_database/models/pymc/kidscore_momhs.py +++ b/posterior_database/models/pymc/kidscore_momhs.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: beta = pm.Flat("beta", shape=2) diff --git a/posterior_database/models/pymc/kidscore_momhsiq.py b/posterior_database/models/pymc/kidscore_momhsiq.py index e7bd86f4..df0820ff 100644 --- a/posterior_database/models/pymc/kidscore_momhsiq.py +++ b/posterior_database/models/pymc/kidscore_momhsiq.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: beta = pm.Flat("beta", shape=3) diff --git a/posterior_database/models/pymc/kidscore_momiq.py b/posterior_database/models/pymc/kidscore_momiq.py index be24030a..1989e6e0 100644 --- a/posterior_database/models/pymc/kidscore_momiq.py +++ b/posterior_database/models/pymc/kidscore_momiq.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: beta = pm.Flat("beta", shape=2) diff --git a/posterior_database/models/pymc/kilpisjarvi.py b/posterior_database/models/pymc/kilpisjarvi.py index 609f661c..6132c491 100644 --- a/posterior_database/models/pymc/kilpisjarvi.py +++ b/posterior_database/models/pymc/kilpisjarvi.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/log10earn_height.py b/posterior_database/models/pymc/log10earn_height.py index 596af713..ee45f598 100644 --- a/posterior_database/models/pymc/log10earn_height.py +++ b/posterior_database/models/pymc/log10earn_height.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] earn = data['earn'] diff --git a/posterior_database/models/pymc/logearn_height_male.py b/posterior_database/models/pymc/logearn_height_male.py index 2052dc9c..4d54e379 100644 --- a/posterior_database/models/pymc/logearn_height_male.py +++ b/posterior_database/models/pymc/logearn_height_male.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] earn = data['earn'] diff --git a/posterior_database/models/pymc/logearn_interaction.py b/posterior_database/models/pymc/logearn_interaction.py index 13fc5fae..1702ae1a 100644 --- a/posterior_database/models/pymc/logearn_interaction.py +++ b/posterior_database/models/pymc/logearn_interaction.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] earn = np.array(data['earn'], dtype=float) diff --git a/posterior_database/models/pymc/logearn_interaction_z.py b/posterior_database/models/pymc/logearn_interaction_z.py index d899f88e..e161acd0 100644 --- a/posterior_database/models/pymc/logearn_interaction_z.py +++ b/posterior_database/models/pymc/logearn_interaction_z.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] earn = data['earn'] diff --git a/posterior_database/models/pymc/logearn_logheight_male.py b/posterior_database/models/pymc/logearn_logheight_male.py index 5ad1215a..0105d934 100644 --- a/posterior_database/models/pymc/logearn_logheight_male.py +++ b/posterior_database/models/pymc/logearn_logheight_male.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np log_earn = np.log(data['earn']) log_height = np.log(data['height']) diff --git a/posterior_database/models/pymc/logistic_regression_rhs.py b/posterior_database/models/pymc/logistic_regression_rhs.py index 85c4f9ad..d41a3fb3 100644 --- a/posterior_database/models/pymc/logistic_regression_rhs.py +++ b/posterior_database/models/pymc/logistic_regression_rhs.py @@ -1,6 +1,7 @@ +import pymc as pm +import pytensor.tensor as pt + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt n = data['n'] d = data['d'] diff --git a/posterior_database/models/pymc/logmesquite_logvas.py b/posterior_database/models/pymc/logmesquite_logvas.py index 37f515d2..f72d2808 100644 --- a/posterior_database/models/pymc/logmesquite_logvas.py +++ b/posterior_database/models/pymc/logmesquite_logvas.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np weight = np.array(data['weight']) diam1 = np.array(data['diam1']) diff --git a/posterior_database/models/pymc/logmesquite_logvash.py b/posterior_database/models/pymc/logmesquite_logvash.py index cbac6ba5..0420d40b 100644 --- a/posterior_database/models/pymc/logmesquite_logvash.py +++ b/posterior_database/models/pymc/logmesquite_logvash.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] weight = np.array(data['weight']) diff --git a/posterior_database/models/pymc/low_dim_gauss_mix.py b/posterior_database/models/pymc/low_dim_gauss_mix.py index 0009f0e6..cf96cd9d 100644 --- a/posterior_database/models/pymc/low_dim_gauss_mix.py +++ b/posterior_database/models/pymc/low_dim_gauss_mix.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py index bad1024b..10b3423d 100644 --- a/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py +++ b/posterior_database/models/pymc/low_dim_gauss_mix_collapse.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/lsat_model.py b/posterior_database/models/pymc/lsat_model.py index b2268573..d57b5350 100644 --- a/posterior_database/models/pymc/lsat_model.py +++ b/posterior_database/models/pymc/lsat_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] R = data['R'] diff --git a/posterior_database/models/pymc/mesquite.py b/posterior_database/models/pymc/mesquite.py index 46c77d6a..017733f6 100644 --- a/posterior_database/models/pymc/mesquite.py +++ b/posterior_database/models/pymc/mesquite.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/nes_logit_model.py b/posterior_database/models/pymc/nes_logit_model.py index a31a8370..b541c04b 100644 --- a/posterior_database/models/pymc/nes_logit_model.py +++ b/posterior_database/models/pymc/nes_logit_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] income = np.array(data['income']) diff --git a/posterior_database/models/pymc/normal_mixture.py b/posterior_database/models/pymc/normal_mixture.py index f0a74279..6a89b7c8 100644 --- a/posterior_database/models/pymc/normal_mixture.py +++ b/posterior_database/models/pymc/normal_mixture.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/normal_mixture_k.py b/posterior_database/models/pymc/normal_mixture_k.py index 37216c45..31fda4bd 100644 --- a/posterior_database/models/pymc/normal_mixture_k.py +++ b/posterior_database/models/pymc/normal_mixture_k.py @@ -1,6 +1,7 @@ +import pymc as pm +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import numpy as np K = data['K'] N = data['N'] diff --git a/posterior_database/models/pymc/pilots.py b/posterior_database/models/pymc/pilots.py index 4e71ba43..b9cc41f5 100644 --- a/posterior_database/models/pymc/pilots.py +++ b/posterior_database/models/pymc/pilots.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np group_idx = np.array(data['group_id']) - 1 scenario_idx = np.array(data['scenario_id']) - 1 diff --git a/posterior_database/models/pymc/radon_county.py b/posterior_database/models/pymc/radon_county.py index 1ca5b5a2..cd5a5b0a 100644 --- a/posterior_database/models/pymc/radon_county.py +++ b/posterior_database/models/pymc/radon_county.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/radon_county_intercept.py b/posterior_database/models/pymc/radon_county_intercept.py index 16a3a9b8..3610e9f0 100644 --- a/posterior_database/models/pymc/radon_county_intercept.py +++ b/posterior_database/models/pymc/radon_county_intercept.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py b/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py index 7df618cc..eddedcc1 100644 --- a/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py +++ b/posterior_database/models/pymc/radon_hierarchical_intercept_centered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py b/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py index 98b3c7ec..f31557be 100644 --- a/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py +++ b/posterior_database/models/pymc/radon_hierarchical_intercept_noncentered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/radon_partially_pooled_centered.py b/posterior_database/models/pymc/radon_partially_pooled_centered.py index 94205fd1..51504fa0 100644 --- a/posterior_database/models/pymc/radon_partially_pooled_centered.py +++ b/posterior_database/models/pymc/radon_partially_pooled_centered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/radon_pooled.py b/posterior_database/models/pymc/radon_pooled.py index 14a2664b..2ab49502 100644 --- a/posterior_database/models/pymc/radon_pooled.py +++ b/posterior_database/models/pymc/radon_pooled.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False): - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] floor_measure = data['floor_measure'] diff --git a/posterior_database/models/pymc/radon_variable_intercept_centered.py b/posterior_database/models/pymc/radon_variable_intercept_centered.py index 0dbd60a6..c8fa960a 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_centered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_centered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np county_idx_0based = np.array(data['county_idx']) - 1 floor_measure = np.array(data['floor_measure']) diff --git a/posterior_database/models/pymc/radon_variable_intercept_noncentered.py b/posterior_database/models/pymc/radon_variable_intercept_noncentered.py index 37b4699e..fd83fd5f 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_noncentered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_noncentered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py b/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py index b04297bb..eaed9735 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_slope_centered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py b/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py index bec9f3a2..73d24841 100644 --- a/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py +++ b/posterior_database/models/pymc/radon_variable_intercept_slope_noncentered.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] J = data['J'] diff --git a/posterior_database/models/pymc/rats_model.py b/posterior_database/models/pymc/rats_model.py index f89d8d16..8dbc93bd 100644 --- a/posterior_database/models/pymc/rats_model.py +++ b/posterior_database/models/pymc/rats_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] Npts = data['Npts'] diff --git a/posterior_database/models/pymc/seeds_centered_model.py b/posterior_database/models/pymc/seeds_centered_model.py index 4859fed1..a27bb11c 100644 --- a/posterior_database/models/pymc/seeds_centered_model.py +++ b/posterior_database/models/pymc/seeds_centered_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np I = data['I'] n = np.array(data['n']) diff --git a/posterior_database/models/pymc/seeds_model.py b/posterior_database/models/pymc/seeds_model.py index 28c3c2a7..4a2d880f 100644 --- a/posterior_database/models/pymc/seeds_model.py +++ b/posterior_database/models/pymc/seeds_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np I = data['I'] n = np.array(data['n']) diff --git a/posterior_database/models/pymc/seeds_stanified_model.py b/posterior_database/models/pymc/seeds_stanified_model.py index 0f638d80..a43dfd56 100644 --- a/posterior_database/models/pymc/seeds_stanified_model.py +++ b/posterior_database/models/pymc/seeds_stanified_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np I = data['I'] n = np.array(data['n']) diff --git a/posterior_database/models/pymc/sesame_one_pred_a.py b/posterior_database/models/pymc/sesame_one_pred_a.py index 0aa842c5..43901c39 100644 --- a/posterior_database/models/pymc/sesame_one_pred_a.py +++ b/posterior_database/models/pymc/sesame_one_pred_a.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np encouraged = np.array(data['encouraged']) watched_data = np.array(data['watched'], dtype=float) diff --git a/posterior_database/models/pymc/wells_daae_c_model.py b/posterior_database/models/pymc/wells_daae_c_model.py index 643bee3a..0528f08e 100644 --- a/posterior_database/models/pymc/wells_daae_c_model.py +++ b/posterior_database/models/pymc/wells_daae_c_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] switched = np.array(data['switched']) diff --git a/posterior_database/models/pymc/wells_dae_c_model.py b/posterior_database/models/pymc/wells_dae_c_model.py index e1ff487a..618ea64a 100644 --- a/posterior_database/models/pymc/wells_dae_c_model.py +++ b/posterior_database/models/pymc/wells_dae_c_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] switched = np.array(data['switched']) diff --git a/posterior_database/models/pymc/wells_dae_inter_model.py b/posterior_database/models/pymc/wells_dae_inter_model.py index aba4f357..e0a950bc 100644 --- a/posterior_database/models/pymc/wells_dae_inter_model.py +++ b/posterior_database/models/pymc/wells_dae_inter_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] switched = data['switched'] diff --git a/posterior_database/models/pymc/wells_dae_model.py b/posterior_database/models/pymc/wells_dae_model.py index d7c6777c..37906cf0 100644 --- a/posterior_database/models/pymc/wells_dae_model.py +++ b/posterior_database/models/pymc/wells_dae_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] switched = np.array(data['switched']) diff --git a/posterior_database/models/pymc/wells_dist.py b/posterior_database/models/pymc/wells_dist.py index 25c263f2..4b700750 100644 --- a/posterior_database/models/pymc/wells_dist.py +++ b/posterior_database/models/pymc/wells_dist.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np with pm.Model() as model: N = data['N'] diff --git a/posterior_database/models/pymc/wells_dist100_model.py b/posterior_database/models/pymc/wells_dist100_model.py index 6d6d3421..9715d655 100644 --- a/posterior_database/models/pymc/wells_dist100_model.py +++ b/posterior_database/models/pymc/wells_dist100_model.py @@ -1,6 +1,7 @@ +import pymc as pm +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import numpy as np N = data['N'] switched = data['switched'] diff --git a/posterior_database/models/pymc/wells_dist100ars_model.py b/posterior_database/models/pymc/wells_dist100ars_model.py index 19193d8a..80bf971b 100644 --- a/posterior_database/models/pymc/wells_dist100ars_model.py +++ b/posterior_database/models/pymc/wells_dist100ars_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] switched = data['switched'] diff --git a/posterior_database/models/pymc/wells_interaction_c_model.py b/posterior_database/models/pymc/wells_interaction_c_model.py index e650b632..47b94531 100644 --- a/posterior_database/models/pymc/wells_interaction_c_model.py +++ b/posterior_database/models/pymc/wells_interaction_c_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] switched = data['switched'] diff --git a/posterior_database/models/pymc/wells_interaction_model.py b/posterior_database/models/pymc/wells_interaction_model.py index 220e2e37..a3e4a092 100644 --- a/posterior_database/models/pymc/wells_interaction_model.py +++ b/posterior_database/models/pymc/wells_interaction_model.py @@ -1,7 +1,8 @@ +import pymc as pm +import pytensor.tensor as pt +import numpy as np + def make_model(data: dict, prior_only: bool = False) -> pm.Model: - import pymc as pm - import pytensor.tensor as pt - import numpy as np N = data['N'] switched = np.array(data['switched'])