|
838 | 838 | },
|
839 | 839 | {
|
840 | 840 | "cell_type": "code",
|
841 |
| - "execution_count": 16, |
| 841 | + "execution_count": 6, |
842 | 842 | "id": "8f8459d1-648d-48d6-ab24-1ec030dea611",
|
843 | 843 | "metadata": {},
|
844 |
| - "outputs": [], |
| 844 | + "outputs": [ |
| 845 | + { |
| 846 | + "ename": "ModuleNotFoundError", |
| 847 | + "evalue": "No module named 'pymc'", |
| 848 | + "output_type": "error", |
| 849 | + "traceback": [ |
| 850 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 851 | + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", |
| 852 | + "Cell \u001b[1;32mIn[6], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpymc\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpm\u001b[39;00m \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;66;03m# Assuming BYM_model is the model you have defined\u001b[39;00m\n\u001b[0;32m 5\u001b[0m \n\u001b[0;32m 6\u001b[0m \u001b[38;5;66;03m# Wrapping mixture and mu in pm.Deterministic in the model definition\u001b[39;00m\n", |
| 853 | + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pymc'" |
| 854 | + ] |
| 855 | + } |
| 856 | + ], |
845 | 857 | "source": [
|
846 |
| - "phi_pred = idata.posterior.phi.mean((\"chain\", \"draw\")).values\n", |
847 |
| - "beta0_pred = idata.posterior.beta0.mean((\"chain\", \"draw\")).values\n", |
848 |
| - "sigma_pred = idata.posterior.sigma.mean((\"chain\", \"draw\")).values\n", |
849 |
| - "y_predict = np.exp(log_E + beta0_pred + sigma_pred * (1 / scaling_factor) * phi_pred)" |
| 858 | + "import pymc as pm\n", |
| 859 | + "import numpy as np\n", |
| 860 | + "# Wrapping mixture and mu in pm.Deterministic in the model definition\n", |
| 861 | + "with BYM_model:\n", |
| 862 | + " mixture = pm.Deterministic('mixture', some_mixture_expression)\n", |
| 863 | + " mu = pm.Deterministic('mu', some_mu_expression)\n", |
| 864 | + "\n", |
| 865 | + "# Use pm.do to condition on rho=1 and sample posterior predictive\n", |
| 866 | + "with pm.do(BYM_model, {'rho': 1.0}):\n", |
| 867 | + " y_predict_rho_1 = pm.sample_posterior_predictive(idata, var_names=['mixture', 'mu'], predictions=True, extend_inferencedata=False)\n", |
| 868 | + "\n", |
| 869 | + "# Compute the mean of the predictions\n", |
| 870 | + "y_predict = y_predict_rho_1.predictions.mu.mean(dim=['chain', 'draw'])\n" |
850 | 871 | ]
|
851 | 872 | },
|
852 | 873 | {
|
|
1265 | 1286 | "name": "python",
|
1266 | 1287 | "nbconvert_exporter": "python",
|
1267 | 1288 | "pygments_lexer": "ipython3",
|
1268 |
| - "version": "3.11.0" |
| 1289 | + "version": "3.12.0" |
1269 | 1290 | },
|
1270 | 1291 | "myst": {
|
1271 | 1292 | "substitutions": {
|
|
0 commit comments