diff --git a/Python/multilevel_elasticities_single_sku_2.ipynb b/Python/multilevel_elasticities_single_sku_2.ipynb index 41597e15..a763305b 100644 --- a/Python/multilevel_elasticities_single_sku_2.ipynb +++ b/Python/multilevel_elasticities_single_sku_2.ipynb @@ -165,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -181,16 +181,6 @@ " viewBox=\"0.00 0.00 1046.60 893.27\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", "\n", "\n", - "\n", - "clustereffect (2) x region (9)\n", - "\n", - "effect (2) x region (9)\n", - "\n", - "\n", - "clusterregion (9) x effect (2)\n", - "\n", - "region (9) x effect (2)\n", - "\n", "\n", "clusterobs (2379)\n", "\n", @@ -216,6 +206,16 @@ "\n", "2\n", "\n", + "\n", + "clustereffect (2) x region (9)\n", + "\n", + "effect (2) x region (9)\n", + "\n", + "\n", + "clusterregion (9) x effect (2)\n", + "\n", + "region (9) x effect (2)\n", + "\n", "\n", "\n", "likelihood\n", @@ -512,24 +512,25 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 15, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coords = {\n", - " \"region\": region,\n", - " \"obs\": obs,\n", " \"effect\": [\"intercept\", \"slope\"],\n", "}\n", "\n", "with pm.Model(coords=coords) as model_cov:\n", " # --- Data Containers ---\n", "\n", + " model_cov.add_coord(name=\"region\", values=region, mutable=True)\n", + " model_cov.add_coord(name=\"obs\", values=obs, mutable=True)\n", + "\n", " region_idx_data = pm.Data(\n", " name=\"region_idx_data\", value=region_idx, mutable=True, dims=\"obs\"\n", " )\n", @@ -596,7 +597,27 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2379" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "region_idx.size" + ] + }, + { + "cell_type": "code", + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -604,14 +625,14 @@ "output_type": "stream", "text": [ "Compiling...\n", - "Compilation time = 0:00:12.731440\n", + "Compilation time = 0:00:03.184377\n", "Sampling...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "5d6bbf8879f042d892777c138416ed5f", + "model_id": "72f6b0befc5a4d3d86d4c290c216320e", "version_major": 2, "version_minor": 0 }, @@ -625,7 +646,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "a3765e1ed7b949fca5fa78be5e366f07", + "model_id": "e5875fd80cf94035ac440cca57f7cd3f", "version_major": 2, "version_minor": 0 }, @@ -639,7 +660,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "8b2da7985c22416780e6de0bee17720a", + "model_id": "9edd919a9d2a445e8f83705bd0408575", "version_major": 2, "version_minor": 0 }, @@ -653,7 +674,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "67e90549e40a4ed1b2c14f81b628cbc7", + "model_id": "0612450d2704491fb9588b4354e6e916", "version_major": 2, "version_minor": 0 }, @@ -668,9 +689,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "Sampling time = 0:00:23.272978\n", + "Sampling time = 0:00:28.715495\n", "Transforming variables...\n", - "Transformation time = 0:00:02.480620\n", + "Transformation time = 0:00:01.841283\n", "Sampling: [likelihood]\n" ] }, @@ -707,7 +728,7 @@ "\n", "
\n", " \n", - " 100.00% [16000/16000 00:02<00:00]\n", + " 100.00% [16000/16000 00:03<00:00]\n", "
\n", " " ], @@ -733,6 +754,2486 @@ " )" ] }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + "
\n", + "
arviz.InferenceData
\n", + "
\n", + "
    \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + "
    \n", + "
      \n", + "
      \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
      <xarray.Dataset>\n",
      +       "Dimensions:              (chain: 4, draw: 4000, effect: 2, region: 9,\n",
      +       "                          chol_cov_dim_0: 3, chol_cov_corr_dim_0: 2,\n",
      +       "                          chol_cov_corr_dim_1: 2, chol_cov_stds_dim_0: 2,\n",
      +       "                          obs: 2379)\n",
      +       "Coordinates:\n",
      +       "  * chain                (chain) int64 0 1 2 3\n",
      +       "  * draw                 (draw) int64 0 1 2 3 4 5 ... 3995 3996 3997 3998 3999\n",
      +       "  * effect               (effect) <U9 'intercept' 'slope'\n",
      +       "  * region               (region) int64 0 1 2 3 4 5 6 7 8\n",
      +       "  * chol_cov_dim_0       (chol_cov_dim_0) int64 0 1 2\n",
      +       "  * chol_cov_corr_dim_0  (chol_cov_corr_dim_0) int64 0 1\n",
      +       "  * chol_cov_corr_dim_1  (chol_cov_corr_dim_1) int64 0 1\n",
      +       "  * chol_cov_stds_dim_0  (chol_cov_stds_dim_0) int64 0 1\n",
      +       "  * obs                  (obs) int64 0 1 2 3 4 5 ... 2374 2375 2376 2377 2378\n",
      +       "Data variables: (12/15)\n",
      +       "    alpha_j_intercept    (chain, draw) float64 2.896 2.89 2.84 ... 2.78 2.904\n",
      +       "    beta_j_intercept     (chain, draw) float64 -3.802 -3.857 ... -3.621 -3.867\n",
      +       "    z_slopes             (chain, draw, effect, region) float64 -1.106 ... 0.2569\n",
      +       "    chol_cov             (chain, draw, chol_cov_dim_0) float64 0.03247 ... 0....\n",
      +       "    sigma                (chain, draw) float64 0.2875 0.2909 ... 0.2899 0.2916\n",
      +       "    chol_cov_corr        (chain, draw, chol_cov_corr_dim_0, chol_cov_corr_dim_1) float64 ...\n",
      +       "    ...                   ...\n",
      +       "    beta_j_slope         (chain, draw, region) float64 0.06038 ... 0.07071\n",
      +       "    alpha_j              (chain, draw, region) float64 2.735 2.863 ... 2.547\n",
      +       "    beta_j               (chain, draw, region) float64 -3.531 -3.777 ... -3.23\n",
      +       "    alpha                (chain, draw, obs) float64 2.735 2.735 ... 2.547 2.547\n",
      +       "    beta                 (chain, draw, obs) float64 -3.531 -3.531 ... -3.23\n",
      +       "    mu                   (chain, draw, obs) float64 1.713 0.8551 ... 1.066 2.389\n",
      +       "Attributes:\n",
      +       "    created_at:     2023-11-10T21:22:19.834099\n",
      +       "    arviz_version:  0.16.1

      \n", + "
    \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + "
    \n", + "
      \n", + "
      \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
      <xarray.Dataset>\n",
      +       "Dimensions:          (chain: 4, draw: 4000)\n",
      +       "Coordinates:\n",
      +       "  * chain            (chain) int64 0 1 2 3\n",
      +       "  * draw             (draw) int64 0 1 2 3 4 5 ... 3994 3995 3996 3997 3998 3999\n",
      +       "Data variables:\n",
      +       "    acceptance_rate  (chain, draw) float64 0.9997 0.8327 0.6855 ... 0.969 0.9994\n",
      +       "    step_size        (chain, draw) float64 0.05968 0.05968 ... 0.05964 0.05964\n",
      +       "    diverging        (chain, draw) bool False False False ... False False False\n",
      +       "    energy           (chain, draw) float64 498.1 495.4 495.9 ... 494.9 495.3\n",
      +       "    n_steps          (chain, draw) int64 127 31 63 31 31 31 ... 127 63 127 63 63\n",
      +       "    tree_depth       (chain, draw) int64 7 5 6 5 5 5 5 7 6 ... 6 6 6 7 7 6 7 6 6\n",
      +       "    lp               (chain, draw) float64 488.1 483.2 481.4 ... 483.8 488.4\n",
      +       "Attributes:\n",
      +       "    created_at:     2023-11-10T21:22:19.844318\n",
      +       "    arviz_version:  0.16.1

      \n", + "
    \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + "
    \n", + "
      \n", + "
      \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
      <xarray.Dataset>\n",
      +       "Dimensions:     (obs: 2379)\n",
      +       "Coordinates:\n",
      +       "  * obs         (obs) int64 0 1 2 3 4 5 6 ... 2372 2373 2374 2375 2376 2377 2378\n",
      +       "Data variables:\n",
      +       "    likelihood  (obs) float64 1.82 1.312 1.191 1.741 ... 1.41 1.255 0.7018 2.545\n",
      +       "Attributes:\n",
      +       "    created_at:                 2023-11-10T21:22:19.848288\n",
      +       "    arviz_version:              0.16.1\n",
      +       "    inference_library:          numpyro\n",
      +       "    inference_library_version:  0.13.2\n",
      +       "    sampling_time:              28.715495

      \n", + "
    \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + "
    \n", + "
      \n", + "
      \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
      <xarray.Dataset>\n",
      +       "Dimensions:              (obs: 2379, region: 9)\n",
      +       "Coordinates:\n",
      +       "  * obs                  (obs) int64 0 1 2 3 4 5 ... 2374 2375 2376 2377 2378\n",
      +       "  * region               (region) int64 0 1 2 3 4 5 6 7 8\n",
      +       "Data variables:\n",
      +       "    region_idx_data      (obs) int32 0 0 0 0 0 0 0 0 0 0 ... 8 8 8 8 8 8 8 8 8 8\n",
      +       "    median_income_data   (region) float64 4.494 4.767 5.118 ... 6.722 7.15 9.005\n",
      +       "    log_price_data       (obs) float64 0.2893 0.5323 0.5305 ... 0.4585 0.04895\n",
      +       "    log_quantities_data  (obs) float64 1.82 1.312 1.191 ... 1.255 0.7018 2.545\n",
      +       "Attributes:\n",
      +       "    created_at:                 2023-11-10T21:22:19.849286\n",
      +       "    arviz_version:              0.16.1\n",
      +       "    inference_library:          numpyro\n",
      +       "    inference_library_version:  0.13.2\n",
      +       "    sampling_time:              28.715495

      \n", + "
    \n", + "
    \n", + "
  • \n", + " \n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "Inference data with groups:\n", + "\t> posterior\n", + "\t> sample_stats\n", + "\t> observed_data\n", + "\t> constant_data" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "idata_cov" + ] + }, { "cell_type": "code", "execution_count": null,