{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 9. Mixture models and label switching with MCMC\n", "\n", "[Data set download](https://s3.amazonaws.com/bebi103.caltech.edu/data/singer_transcript_counts.csv)\n", "\n", "
\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"<xarray.Dataset>\n", "Dimensions: (chain: 4, draw: 1000, alpha_dim_0: 2, b_dim_0: 2,\n", " beta__dim_0: 2)\n", "Coordinates:\n", " * chain (chain) int64 0 1 2 3\n", " * draw (draw) int64 0 1 2 3 4 5 6 7 ... 993 994 995 996 997 998 999\n", " * alpha_dim_0 (alpha_dim_0) int64 0 1\n", " * b_dim_0 (b_dim_0) int64 0 1\n", " * beta__dim_0 (beta__dim_0) int64 0 1\n", "Data variables:\n", " alpha (chain, draw, alpha_dim_0) float64 5.661 1.789 ... 5.441 3.164\n", " b (chain, draw, b_dim_0) float64 31.69 11.06 ... 30.25 4.162\n", " w (chain, draw) float64 0.8029 0.8019 0.7968 ... 0.8382 0.84\n", " beta_ (chain, draw, beta__dim_0) float64 0.03156 0.09042 ... 0.2402\n", "Attributes:\n", " created_at: 2024-01-07T07:49:38.905862\n", " arviz_version: 0.17.0\n", " inference_library: cmdstanpy\n", " inference_library_version: 1.2.0
<xarray.Dataset>\n", "Dimensions: (chain: 4, draw: 1000)\n", "Coordinates:\n", " * chain (chain) int64 0 1 2 3\n", " * draw (draw) int64 0 1 2 3 4 5 6 ... 993 994 995 996 997 998 999\n", "Data variables:\n", " lp (chain, draw) float64 -1.602e+03 -1.601e+03 ... -1.598e+03\n", " acceptance_rate (chain, draw) float64 0.4733 1.0 0.9368 ... 1.0 0.8343\n", " step_size (chain, draw) float64 0.1345 0.1345 ... 0.1206 0.1206\n", " tree_depth (chain, draw) int64 5 2 2 3 4 3 5 4 5 ... 3 3 5 4 3 3 3 5 2\n", " n_steps (chain, draw) int64 63 7 3 7 15 11 31 ... 15 15 7 15 35 7\n", " diverging (chain, draw) bool False False False ... False False False\n", " energy (chain, draw) float64 1.607e+03 1.603e+03 ... 1.601e+03\n", "Attributes:\n", " created_at: 2024-01-07T07:49:38.915960\n", " arviz_version: 0.17.0\n", " inference_library: cmdstanpy\n", " inference_library_version: 1.2.0
<xarray.Dataset>\n", "Dimensions: (alpha_dim_0: 2, b_dim_0: 2, beta__dim_0: 2)\n", "Coordinates:\n", " chain int64 2\n", " draw int64 478\n", " * alpha_dim_0 (alpha_dim_0) int64 0 1\n", " * b_dim_0 (b_dim_0) int64 0 1\n", " * beta__dim_0 (beta__dim_0) int64 0 1\n", "Data variables:\n", " alpha (alpha_dim_0) float64 6.893 1.426\n", " b (b_dim_0) float64 24.98 22.55\n", " w float64 0.7097\n", " beta_ (beta__dim_0) float64 0.04004 0.04435\n", "Attributes:\n", " created_at: 2024-01-07T07:49:38.905862\n", " arviz_version: 0.17.0\n", " inference_library: cmdstanpy\n", " inference_library_version: 1.2.0
<xarray.DataArray 'alpha' ()>\n", "array(1.42611)\n", "Coordinates:\n", " chain int64 2\n", " draw int64 478\n", " alpha_dim_0 int64 1
\n", " | \n", " | \n", " | \n", " | \n", " | alpha | \n", "b | \n", "w | \n", "beta_ | \n", "
---|---|---|---|---|---|---|---|---|
chain | \n", "draw | \n", "alpha_dim_0 | \n", "b_dim_0 | \n", "beta__dim_0 | \n", "\n", " | \n", " | \n", " | \n", " |
0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "5.66140 | \n", "31.6886 | \n", "0.802886 | \n", "0.031557 | \n", "
1 | \n", "5.66140 | \n", "31.6886 | \n", "0.802886 | \n", "0.090421 | \n", "||||
1 | \n", "0 | \n", "5.66140 | \n", "11.0593 | \n", "0.802886 | \n", "0.031557 | \n", "|||
1 | \n", "5.66140 | \n", "11.0593 | \n", "0.802886 | \n", "0.090421 | \n", "||||
1 | \n", "0 | \n", "0 | \n", "1.78864 | \n", "31.6886 | \n", "0.802886 | \n", "0.031557 | \n", "
\n", " | alpha[0] | \n", "alpha[1] | \n", "b[0] | \n", "b[1] | \n", "w | \n", "beta_[0] | \n", "beta_[1] | \n", "chain__ | \n", "draw__ | \n", "diverging__ | \n", "
---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "5.66140 | \n", "1.78864 | \n", "31.6886 | \n", "11.05930 | \n", "0.802886 | \n", "0.031557 | \n", "0.090421 | \n", "0 | \n", "0 | \n", "False | \n", "
1 | \n", "5.17734 | \n", "2.14482 | \n", "29.5825 | \n", "8.38260 | \n", "0.801894 | \n", "0.033804 | \n", "0.119295 | \n", "0 | \n", "1 | \n", "False | \n", "
2 | \n", "5.39749 | \n", "1.80403 | \n", "31.3802 | \n", "7.27724 | \n", "0.796794 | \n", "0.031867 | \n", "0.137415 | \n", "0 | \n", "2 | \n", "False | \n", "
3 | \n", "5.19167 | \n", "2.03671 | \n", "31.5290 | \n", "8.31763 | \n", "0.797783 | \n", "0.031717 | \n", "0.120226 | \n", "0 | \n", "3 | \n", "False | \n", "
4 | \n", "6.47852 | \n", "1.98396 | \n", "25.4453 | \n", "9.93925 | \n", "0.850177 | \n", "0.039300 | \n", "0.100611 | \n", "0 | \n", "4 | \n", "False | \n", "