Text and code for the forthcoming second edition of Think Bayes, by Allen Downey.

Overview

Think Bayes 2

by Allen B. Downey

The HTML version of this book is here.

Think Bayes is an introduction to Bayesian statistics using computational methods.

Think Bayes is a Free Book. It is available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0), which means that you are free to copy and modify it, as long as you attribute the work and don’t use it for commercial purposes.

Other Free Books by Allen Downey are available from Green Tea Press.

Run the notebooks

Download the notebooks as a Zip file

Or use these links to run the notebooks on Colab:

Comments
  • Chapter 1 download data code isn't working

    Chapter 1 download data code isn't working

    I found that the original code seems to be outdated since it seems to use a different repository name (BiteSizeBayes) and it uses a csv file whereas the current data is in a gss_bayes folder which I don't know how to read/use (normally I use csv files). Can anyone give guidance on how to read in this data (e.g. docs) or a pointer on where to find the original GSS data? Thanks in advance.

    Here's the original code for context:

    `# Load the data file

    from os.path import basename, exists

    def download(url): filename = basename(url) if not exists(filename): from urllib.request import urlretrieve local, _ = urlretrieve(url, filename) print('Downloaded ' + local)

    download('https://github.com/AllenDowney/BiteSizeBayes/raw/master/gss_bayes.csv')`

    opened by HelloWorld183L 5
  • Chapter 20 Counting Cells Measurement Error Specification

    Chapter 20 Counting Cells Measurement Error Specification

    I love your work and own a hard copy of Think Bayes 2! I know you got the cell counting example from another fantastic content creator. I have been pondering inferred vs. known error in my models and I think that the pymc cell counting model can be improved for posterity. Mainly, I think that there are a bunch of parameters that are inferred in pymc3 that should be fixed. For example:

    with pm.Model() as model:
        yeast_conc = pm.Normal("yeast conc", 
                               mu=2 * billion, sd=0.4 * billion)
    
        shaker1_vol = pm.Normal("shaker1 vol", 
                                   mu=9.0, sd=0.05)
        shaker2_vol = pm.Normal("shaker2 vol", 
                                   mu=9.0, sd=0.05)
        shaker3_vol = pm.Normal("shaker3 vol", 
                                   mu=9.0, sd=0.05)
    

    should be:

    import theano
    shaker_vol_mu = theano.shared(9.0)
    shaker_vol_sd = theano.shared(0.05)
    
    with pm.Model() as model:
        yeast_conc = pm.Normal("yeast conc", 
                               mu=2 * billion, sd=0.4 * billion)
    
        shaker1_vol = pm.Normal("shaker1 vol", 
                                   mu=shaker_vol_mu, sd=shaker_vol_sd)
        shaker2_vol = pm.Normal("shaker2 vol", 
                                   mu=shaker_vol_mu, sd=shaker_vol_sd)
        shaker3_vol = pm.Normal("shaker3 vol", 
                                   mu=shaker_vol_mu, sd=shaker_vol_sd)
    

    I'm interpreting the mean and sd of yeast conc as prior values to be inferred, and the mean and sd of shaker volumes as fixed values based on information from outside of the model inference (e.g., the values listed on the package of a pipette or something). I think this is also consistent with ABC portion of the analysis present just after. Other lines of code that would be added include the following:

    shaker_transfer_mu = theano.shared(1.0)
    shaker_transfer_sd = theano.shared(0.01)
    
    chamber_vol_mu = theano.shared(0.0001)
    chamber_vol_sd = theano.shared(0.0001/20)
    

    associated pm.Normal() calls would be updated.

    My motivation for writing is the amount of time it took for me to figure out how and when to specify fixed vs. inferred parameter values in my models. Thanks!

    opened by gbrunkhorst 5
  • TypeError: Series.__init__() got an unexpected keyword argument 'normalize'

    TypeError: Series.__init__() got an unexpected keyword argument 'normalize'

    Hi, Professor. I am facing this problem when I am practicing probability mass function in gss.hdf5. I am following exactly what have you teach in the slides. May I know why is this happening? Thank you.

    import pandas as pd
    import matplotlib.pyplot as plt
    from empiricaldist import Pmf
    
    gss = pd.read_hdf('gss.hdf5','gss')
    educ =gss['educ']
    pmf_educ = Pmf(educ normalize=False)
    

    Traceback (most recent call last): File "c:\Users\User\Desktop\Study\Data_Camp\courses\Exploratory Data Analysis in Python\Probability_mass_functions.py", line 30, in pmf_educ = Pmf(educ, normalize=False) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\empiricaldist\empiricaldist.py", line 45, in init super().init(*args, **kwargs) TypeError: Series.init() got an unexpected keyword argument 'normalize'``

    opened by Strigfox85 2
  • Update conda env

    Update conda env

    I really enjoyed reading Think Bayes, and I saw your tweet about conda being slow, so I wanted to help out. Please let me know if you'd like me to make any changes, and feel free to close if it isn't helpful.

    Background

    The biggest change I made was to ignore the defaults channel with nodefaults. At best searching the defaults channel will waste time, and at worst it will pull in defaults packages that are incompatible with conda-forge packages (they are built with different compilers). The only reason to keep defaults in the list is occasionally some packages required for Windows compatibility are only available from defaults (but I confirmed that this wasn't the case).

    By listing conda-forge first, this channel is always searched first. The fastai channel is then consulted whenever a package can't be found in the conda-forge channel.

    Demonstration

    I purposely tested on Windows since this is likely a big motivator for using conda in the first place. mamba installed the environment in under 5 minutes. And this is worst case scenario since it had to index the channels and download all the packages (ie nothing was cached). And I agree with you that conda is unuseable in this situation. I let it spin for ~15 minutes before I just killed it.

    # Cleaning up from my previous experiments
    conda env remove -n ThinkBayes2
    conda clean -ya
    
    mamba --version
    ## mamba 0.23.0
    ## conda 4.12.0
    
    # Run from the Anaconda prompt
    Time
    ## The current time is: 11:42:58.56
    mamba env create --file environment.yml
    Time
    ## The current time is: 11:47:21.52
    
    conda list -n ThinkBayes2
    conda list -n ThinkBayes2
    # Name                    Version                   Build  Channel
    alabaster                 0.7.12                     py_0    conda-forge
    anyio                     3.5.0           py310h5588dad_0    conda-forge
    argon2-cffi               21.3.0             pyhd8ed1ab_0    conda-forge
    argon2-cffi-bindings      21.2.0          py310he2412df_2    conda-forge
    arviz                     0.11.1             pyhd8ed1ab_0    conda-forge
    asttokens                 2.0.5              pyhd8ed1ab_0    conda-forge
    atomicwrites              1.4.0              pyh9f0ad1d_0    conda-forge
    attrs                     21.4.0             pyhd8ed1ab_0    conda-forge
    babel                     2.9.1              pyh44b312d_0    conda-forge
    backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
    backports                 1.0                        py_2    conda-forge
    backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
    beautifulsoup4            4.11.1             pyha770c72_0    conda-forge
    bleach                    5.0.0              pyhd8ed1ab_0    conda-forge
    blosc                     1.21.1               hcbbf2c4_0    conda-forge
    brotli                    1.0.9                h8ffe710_7    conda-forge
    brotli-bin                1.0.9                h8ffe710_7    conda-forge
    brotlipy                  0.7.0           py310he2412df_1004    conda-forge
    bzip2                     1.0.8                h8ffe710_4    conda-forge
    ca-certificates           2021.10.8            h5b45459_0    conda-forge
    cached-property           1.5.2                hd8ed1ab_1    conda-forge
    cached_property           1.5.2              pyha770c72_1    conda-forge
    cairo                     1.16.0            h15b3021_1010    conda-forge
    certifi                   2021.10.8       py310h5588dad_2    conda-forge
    cffi                      1.15.0          py310hcbf9ad4_0    conda-forge
    cftime                    1.6.0           py310h2873277_1    conda-forge
    charset-normalizer        2.0.12             pyhd8ed1ab_0    conda-forge
    click                     7.1.2              pyh9f0ad1d_0    conda-forge
    click-completion          0.5.2           py310h5588dad_3    conda-forge
    click-log                 0.3.2              pyh9f0ad1d_0    conda-forge
    colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
    cryptography              36.0.2          py310ha857299_1    conda-forge
    curl                      7.83.0               h789b8ee_0    conda-forge
    cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
    dataclasses               0.8                pyhc8e2a94_3    conda-forge
    debugpy                   1.6.0           py310h8a704f9_0    conda-forge
    decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
    defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
    docutils                  0.15.2          py310h5588dad_3    conda-forge
    empiricaldist             0.6.3                    pypi_0    pypi
    entrypoints               0.4                pyhd8ed1ab_0    conda-forge
    executing                 0.8.3              pyhd8ed1ab_0    conda-forge
    expat                     2.4.8                h39d44d4_0    conda-forge
    fastcore                  1.4.2              pyhd8ed1ab_0    conda-forge
    fastdoc                   0.0.2                      py_0    fastai
    fastprogress              1.0.2              pyhd8ed1ab_0    conda-forge
    fastrelease               0.1.16                     py_0    fastai
    flit-core                 3.7.1              pyhd8ed1ab_0    conda-forge
    font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
    font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
    font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
    font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
    fontconfig                2.14.0               hce3cb01_0    conda-forge
    fonts-conda-ecosystem     1                             0    conda-forge
    fonts-conda-forge         1                             0    conda-forge
    fonttools                 4.33.3          py310he2412df_0    conda-forge
    freetype                  2.10.4               h546665d_1    conda-forge
    fribidi                   1.0.10               h8d14728_0    conda-forge
    getopt-win32              0.1                  h8ffe710_0    conda-forge
    gettext                   0.19.8.1          ha2e2712_1008    conda-forge
    ghapi                     0.1.20             pyhd8ed1ab_0    conda-forge
    ghp-import                2.1.0              pyhd8ed1ab_0    conda-forge
    gitdb                     4.0.9              pyhd8ed1ab_0    conda-forge
    gitpython                 3.1.27             pyhd8ed1ab_0    conda-forge
    graphite2                 1.3.13                     1000    conda-forge
    graphviz                  3.0.0                had6c3a3_1    conda-forge
    greenlet                  1.1.2           py310h8a704f9_2    conda-forge
    gts                       0.7.6                h7c369d9_2    conda-forge
    h5py                      3.6.0           nompi_py310h00cbb18_100    conda-forge
    harfbuzz                  4.2.0                hc1763ed_0    conda-forge
    hdf4                      4.2.15               h0e5069d_3    conda-forge
    hdf5                      1.12.1          nompi_h2a0e4a3_104    conda-forge
    html5lib                  1.1                pyh9f0ad1d_0    conda-forge
    icu                       69.1                 h0e60522_0    conda-forge
    idna                      3.3                pyhd8ed1ab_0    conda-forge
    imagesize                 1.3.0              pyhd8ed1ab_0    conda-forge
    importlib-metadata        4.11.3          py310h5588dad_1    conda-forge
    importlib_metadata        4.11.3               hd8ed1ab_1    conda-forge
    importlib_resources       5.7.1              pyhd8ed1ab_0    conda-forge
    iniconfig                 1.1.1              pyh9f0ad1d_0    conda-forge
    intel-openmp              2022.0.0          h57928b3_3663    conda-forge
    ipykernel                 6.13.0          py310hbbfc1a7_0    conda-forge
    ipython                   8.3.0           py310h5588dad_0    conda-forge
    ipython_genutils          0.2.0                      py_1    conda-forge
    ipywidgets                7.7.0              pyhd8ed1ab_0    conda-forge
    jbig                      2.1               h8d14728_2003    conda-forge
    jedi                      0.18.1          py310h5588dad_1    conda-forge
    jinja2                    3.0.3              pyhd8ed1ab_0    conda-forge
    jpeg                      9e                   h8ffe710_1    conda-forge
    jsonschema                3.2.0              pyhd8ed1ab_3    conda-forge
    jupyter                   1.0.0           py310h5588dad_7    conda-forge
    jupyter-book              0.12.3             pyhd8ed1ab_0    conda-forge
    jupyter-cache             0.4.3              pyhd8ed1ab_0    conda-forge
    jupyter-server-mathjax    0.2.5              pyhc268e32_0    conda-forge
    jupyter-sphinx            0.3.2              pyhd8ed1ab_1    conda-forge
    jupyter_client            6.1.12             pyhd8ed1ab_0    conda-forge
    jupyter_console           6.4.2              pyhd8ed1ab_0    conda-forge
    jupyter_contrib_core      0.3.3                      py_2    conda-forge
    jupyter_core              4.9.2           py310h5588dad_0    conda-forge
    jupyter_nbextensions_configurator 0.4.1              pyhd8ed1ab_2    conda-forge
    jupyter_server            1.13.5             pyhd8ed1ab_0    conda-forge
    jupyterlab_widgets        1.1.0              pyhd8ed1ab_0    conda-forge
    kiwisolver                1.4.2           py310h476a331_1    conda-forge
    krb5                      1.19.3               h1176d77_0    conda-forge
    latexcodec                2.0.1              pyh9f0ad1d_0    conda-forge
    lcms2                     2.12                 h2a16943_0    conda-forge
    lerc                      3.0                  h0e60522_0    conda-forge
    libblas                   3.9.0              14_win64_mkl    conda-forge
    libbrotlicommon           1.0.9                h8ffe710_7    conda-forge
    libbrotlidec              1.0.9                h8ffe710_7    conda-forge
    libbrotlienc              1.0.9                h8ffe710_7    conda-forge
    libcblas                  3.9.0              14_win64_mkl    conda-forge
    libclang                  13.0.1          default_h81446c8_0    conda-forge
    libcurl                   7.83.0               h789b8ee_0    conda-forge
    libdeflate                1.10                 h8ffe710_0    conda-forge
    libffi                    3.4.2                h8ffe710_5    conda-forge
    libgd                     2.3.3                h217ff3b_2    conda-forge
    libglib                   2.70.2               h3be07f2_4    conda-forge
    libgpuarray               0.7.6             h8ffe710_1003    conda-forge
    libiconv                  1.16                 he774522_0    conda-forge
    liblapack                 3.9.0              14_win64_mkl    conda-forge
    libnetcdf                 4.8.1           nompi_h1cc8e9d_102    conda-forge
    libpng                    1.6.37               h1d00b33_2    conda-forge
    libsodium                 1.0.18               h8d14728_1    conda-forge
    libssh2                   1.10.0               h680486a_2    conda-forge
    libtiff                   4.3.0                hc4061b1_3    conda-forge
    libwebp                   1.2.2                h57928b3_0    conda-forge
    libwebp-base              1.2.2                h8ffe710_1    conda-forge
    libxcb                    1.13              hcd874cb_1004    conda-forge
    libxml2                   2.9.14               hf5bbc77_0    conda-forge
    libxslt                   1.1.33               h34f844d_4    conda-forge
    libzip                    1.8.0                hfed4ece_1    conda-forge
    libzlib                   1.2.11            h8ffe710_1014    conda-forge
    linkify-it-py             1.0.3              pyhd8ed1ab_0    conda-forge
    lxml                      4.8.0           py310he2412df_3    conda-forge
    lz4-c                     1.9.3                h8ffe710_1    conda-forge
    m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
    m2w64-gcc-libs            5.3.0                         7    conda-forge
    m2w64-gcc-libs-core       5.3.0                         7    conda-forge
    m2w64-gmp                 6.1.0                         2    conda-forge
    m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
    mako                      1.2.0              pyhd8ed1ab_1    conda-forge
    markdown-it-py            1.1.0              pyhd8ed1ab_0    conda-forge
    markupsafe                2.1.1           py310he2412df_1    conda-forge
    matplotlib                3.5.2           py310h5588dad_0    conda-forge
    matplotlib-base           3.5.2           py310h79a7439_0    conda-forge
    matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge
    mdit-py-plugins           0.2.8              pyhd8ed1ab_0    conda-forge
    mistune                   0.8.4           py310he2412df_1005    conda-forge
    mkl                       2022.0.0           h0e2418a_796    conda-forge
    mkl-service               2.4.0           py310h3d5ec83_0    conda-forge
    msys2-conda-epoch         20160418                      1    conda-forge
    munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
    myst-nb                   0.13.2             pyhd8ed1ab_0    conda-forge
    myst-parser               0.15.2             pyhd8ed1ab_0    conda-forge
    nbclient                  0.5.13             pyhd8ed1ab_0    conda-forge
    nbconvert                 5.6.1              pyhd8ed1ab_2    conda-forge
    nbdev                     1.1.23                     py_0    fastai
    nbdime                    3.1.1              pyhd8ed1ab_0    conda-forge
    nbformat                  5.4.0              pyhd8ed1ab_0    conda-forge
    nbmake                    1.3.0              pyhd8ed1ab_1    conda-forge
    nest-asyncio              1.5.5              pyhd8ed1ab_0    conda-forge
    netcdf4                   1.5.8           nompi_py310h5489b47_101    conda-forge
    notebook                  6.4.11             pyha770c72_0    conda-forge
    numexpr                   2.7.3           py310hf5e1058_2    conda-forge
    numpy                     1.22.3          py310hed7ac4c_2    conda-forge
    openjpeg                  2.4.0                hb211442_1    conda-forge
    openssl                   1.1.1o               h8ffe710_0    conda-forge
    packaging                 21.3               pyhd8ed1ab_0    conda-forge
    pandas                    1.4.2           py310hf5e1058_1    conda-forge
    pandoc                    2.2.2                hde52d81_1    conda-forge
    pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
    pango                     1.50.7               h66df5b2_0    conda-forge
    parso                     0.8.3              pyhd8ed1ab_0    conda-forge
    patsy                     0.5.2              pyhd8ed1ab_0    conda-forge
    pcre                      8.45                 h0e60522_0    conda-forge
    pickleshare               0.7.5                   py_1003    conda-forge
    pillow                    9.1.0           py310h767b3fd_2    conda-forge
    pip                       22.0.4             pyhd8ed1ab_0    conda-forge
    pixman                    0.40.0               h8ffe710_0    conda-forge
    pluggy                    1.0.0           py310h5588dad_3    conda-forge
    prometheus_client         0.14.1             pyhd8ed1ab_0    conda-forge
    prompt-toolkit            3.0.29             pyha770c72_0    conda-forge
    prompt_toolkit            3.0.29               hd8ed1ab_0    conda-forge
    psutil                    5.9.0           py310he2412df_1    conda-forge
    pthread-stubs             0.4               hcd874cb_1001    conda-forge
    pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
    py                        1.11.0             pyh6c4a22f_0    conda-forge
    pybtex                    0.24.0             pyhd8ed1ab_2    conda-forge
    pybtex-docutils           1.0.1           py310h5588dad_1    conda-forge
    pycparser                 2.21               pyhd8ed1ab_0    conda-forge
    pydantic                  1.9.0           py310he2412df_1    conda-forge
    pydata-sphinx-theme       0.7.2              pyhd8ed1ab_0    conda-forge
    pygments                  2.12.0             pyhd8ed1ab_0    conda-forge
    pygpu                     0.7.6           py310h2873277_1003    conda-forge
    pymc3                     3.9.3              pyhd8ed1ab_3    conda-forge
    pyopenssl                 22.0.0             pyhd8ed1ab_0    conda-forge
    pyparsing                 3.0.8              pyhd8ed1ab_0    conda-forge
    pyqt                      5.12.3          py310h5588dad_8    conda-forge
    pyqt-impl                 5.12.3          py310h8a704f9_8    conda-forge
    pyqt5-sip                 4.19.18         py310h8a704f9_8    conda-forge
    pyqtchart                 5.12            py310h8a704f9_8    conda-forge
    pyqtwebengine             5.12.1          py310h8a704f9_8    conda-forge
    pyrsistent                0.18.1          py310he2412df_1    conda-forge
    pysocks                   1.7.1           py310h5588dad_5    conda-forge
    pytables                  3.7.0           py310h5dd77a3_0    conda-forge
    pytest                    7.1.2           py310h5588dad_0    conda-forge
    python                    3.10.4          h9a09f29_0_cpython    conda-forge
    python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
    python-fastjsonschema     2.15.3             pyhd8ed1ab_0    conda-forge
    python-graphviz           0.20               pyhaef67bd_0    conda-forge
    python_abi                3.10                    2_cp310    conda-forge
    pytz                      2022.1             pyhd8ed1ab_0    conda-forge
    pywin32                   303             py310he2412df_0    conda-forge
    pywinpty                  2.0.5           py310h00ffb61_1    conda-forge
    pyyaml                    6.0             py310he2412df_4    conda-forge
    pyzmq                     22.3.0          py310h73ada01_2    conda-forge
    qt                        5.12.9               h556501e_6    conda-forge
    qtconsole                 5.3.0              pyhd8ed1ab_0    conda-forge
    qtconsole-base            5.3.0              pyhd8ed1ab_0    conda-forge
    qtpy                      2.1.0              pyhd8ed1ab_0    conda-forge
    requests                  2.27.1             pyhd8ed1ab_0    conda-forge
    scipy                     1.8.0           py310h33db832_1    conda-forge
    seaborn                   0.11.2               hd8ed1ab_0    conda-forge
    seaborn-base              0.11.2             pyhd8ed1ab_0    conda-forge
    send2trash                1.8.0              pyhd8ed1ab_0    conda-forge
    setuptools                62.1.0          py310h5588dad_0    conda-forge
    shellingham               1.4.0              pyh44b312d_0    conda-forge
    six                       1.16.0             pyh6c4a22f_0    conda-forge
    smmap                     3.0.5              pyh44b312d_0    conda-forge
    snappy                    1.1.8                ha925a31_3    conda-forge
    sniffio                   1.2.0           py310h5588dad_3    conda-forge
    snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
    soupsieve                 2.3.1              pyhd8ed1ab_0    conda-forge
    sphinx                    4.5.0              pyh6c4a22f_0    conda-forge
    sphinx-book-theme         0.1.9              pyhd8ed1ab_0    conda-forge
    sphinx-comments           0.0.3              pyh9f0ad1d_0    conda-forge
    sphinx-copybutton         0.5.0              pyhd8ed1ab_0    conda-forge
    sphinx-external-toc       0.2.3              pyhd8ed1ab_0    conda-forge
    sphinx-jupyterbook-latex  0.4.6              pyhd8ed1ab_0    conda-forge
    sphinx-multitoc-numbering 0.1.3              pyhd8ed1ab_0    conda-forge
    sphinx-panels             0.6.0              pyhd8ed1ab_0    conda-forge
    sphinx-thebe              0.1.2              pyhd8ed1ab_0    conda-forge
    sphinx-togglebutton       0.3.1              pyhd8ed1ab_0    conda-forge
    sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
    sphinxcontrib-bibtex      2.4.2              pyhd8ed1ab_0    conda-forge
    sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
    sphinxcontrib-htmlhelp    2.0.0              pyhd8ed1ab_0    conda-forge
    sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
    sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
    sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge
    sqlalchemy                1.4.36          py310he2412df_0    conda-forge
    sqlite                    3.38.3               h8ffe710_0    conda-forge
    stack_data                0.2.0              pyhd8ed1ab_0    conda-forge
    statsmodels               0.13.2          py310h2873277_0    conda-forge
    tbb                       2021.5.0             h2d74725_1    conda-forge
    terminado                 0.13.3          py310h5588dad_1    conda-forge
    testpath                  0.6.0              pyhd8ed1ab_0    conda-forge
    theano                    1.0.5           py310h8a704f9_3    conda-forge
    tk                        8.6.12               h8ffe710_0    conda-forge
    tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
    tornado                   6.1             py310he2412df_3    conda-forge
    tqdm                      4.64.0             pyhd8ed1ab_0    conda-forge
    traitlets                 5.1.1              pyhd8ed1ab_0    conda-forge
    typing-extensions         3.10.0.2             hd8ed1ab_0    conda-forge
    typing_extensions         3.10.0.2           pyha770c72_0    conda-forge
    tzdata                    2022a                h191b570_0    conda-forge
    uc-micro-py               1.0.1              pyhd8ed1ab_0    conda-forge
    ucrt                      10.0.20348.0         h57928b3_0    conda-forge
    unicodedata2              14.0.0          py310he2412df_1    conda-forge
    urllib3                   1.26.9             pyhd8ed1ab_0    conda-forge
    vc                        14.2                 hb210afc_6    conda-forge
    vs2015_runtime            14.29.30037          h902a5da_6    conda-forge
    vs2017_win-64             19.16.27033          hb90652a_6    conda-forge
    vswhere                   3.0.2                h57928b3_0    conda-forge
    wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
    webencodings              0.5.1                      py_1    conda-forge
    websocket-client          1.3.2              pyhd8ed1ab_0    conda-forge
    wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
    widgetsnbextension        3.6.0           py310h5588dad_0    conda-forge
    win_inet_pton             1.1.0           py310h5588dad_4    conda-forge
    winpty                    0.4.3                         4    conda-forge
    xarray                    2022.3.0           pyhd8ed1ab_0    conda-forge
    xlrd                      2.0.1              pyhd8ed1ab_3    conda-forge
    xorg-kbproto              1.0.7             hcd874cb_1002    conda-forge
    xorg-libice               1.0.10               hcd874cb_0    conda-forge
    xorg-libsm                1.2.3             hcd874cb_1000    conda-forge
    xorg-libx11               1.7.2                hcd874cb_0    conda-forge
    xorg-libxau               1.0.9                hcd874cb_0    conda-forge
    xorg-libxdmcp             1.1.3                hcd874cb_0    conda-forge
    xorg-libxext              1.3.4                hcd874cb_1    conda-forge
    xorg-libxpm               3.5.13               hcd874cb_0    conda-forge
    xorg-libxt                1.2.1                hcd874cb_2    conda-forge
    xorg-xextproto            7.3.0             hcd874cb_1002    conda-forge
    xorg-xproto               7.0.31            hcd874cb_1007    conda-forge
    xz                        5.2.5                h62dcd97_1    conda-forge
    yaml                      0.2.5                h8ffe710_2    conda-forge
    zeromq                    4.3.4                h0e60522_1    conda-forge
    zipp                      3.8.0              pyhd8ed1ab_0    conda-forge
    zlib                      1.2.11            h8ffe710_1014    conda-forge
    zstd                      1.5.2                h6255e5f_0    conda-forge
    
    

    Other ideas

    • Your environment file is quite large because it includes not only packages to run the example code but also packages to build the book. One idea would be to split this into 2 different files. This way readers of the book would have an easier time creating an environment to try out the code

    • I noticed that a previous version of your package is available from conda-forge: https://github.com/conda-forge/empyrical-dist-feedstock, but not the currrent version. I can add it to conda-forge if you like. That would save the time of installing from pip after the environment is solved

    opened by jdblischak 2
  • Chapter 6 Goblin Exercise

    Chapter 6 Goblin Exercise

    Hi,

    I'm working through the book atm, and I think I spotted a slight inaccuracy in the phrasing of the Goblin HP problem in Chapter 6 (Odds & Addends):

    The phrasing of the question is Suppose you are fighting a goblin and you have already inflicted 3 points of damage. What is your probability of defeating the goblin with your next successful attack?

    The solution subtracts a 1d6+3 distribution from a 2d6 distribution and looks at the likelihood of the remainder being < 0, which returns 0.5. However, given the phrasing you have already inflicted 3 points of damage and what is probability of defeating the goblin with your *next* successful attack?, am I right in assuming that the initial hit point distribution is necessarily greater than 3 (since the goblin is apparently still standing)?

    Assuming I'm correct, would the hp distribution be more accurately described by

    hp = make_die(6).add_dist(make_die(6))
    hypos = hp.qs
    impossible = hypos <= 3
    hp.ps[impossible] = 0
    hp.normalize()
    

    Alternatively, phrased as likelihood over the whole array of hypos:

    #prior hp
    hp = make_die(6).add_dist(make_die(6))
    hypos = hp.qs
    #likelihood of the goblin standing after 3 dmg:
    likelihood = [hypo > 3 for hypo in hypos]
    #updating prior given data:
    hp *= likelihood
    hp.normalize()
    

    This lead me to the following solution

    damage = make_die(6).add_dist(3)
    remainder = hp.sub_dist(damage)
    remainder.le_dist(0)
    

    which returns 0.45454545 (as opposed to 0.5 in the original phrasing of the solution)

    Please let me know if I'm barking up the wrong tree here! It's possible I overthought things, but figured I'd post this here.

    opened by cjungerius 2
  • Small typo in solutions to exercise 3 in ch2

    Small typo in solutions to exercise 3 in ch2

    Hi Allen,

    Thanks for this fantastic resource, it's helping me a lot!

    I noticed a small typo in the solutions to the 3rd exercise in chapter 2

    If the car is behind Door 1, Monty would have opened Door 2 If the car is behind Door 2, Monty would always Door 3 If the car is behind Door 3, Monty would have opened Door 3

    If the car is behind Door 1, Monty would have opened Door 2 If the car is behind Door 2, Monty would always open Door 3 If the car is behind Door 3, Monty would have opened Door 2

    If you agree with the suggestion I will be happy to open a PR fixing it.

    Have a nice day

    opened by nablabits 2
  • Typo in Theorem 1 from Laws of probability

    Typo in Theorem 1 from Laws of probability

    Thanks for your amazing books dear Allen. I found this typo by reading the early version at O'Reilly site (multiplying instead of dividing over P(B)): IMG_20210410_155600

    opened by GermanCM 2
  • The correctness of EvalExponentialPdf method in thinkbayes2.py

    The correctness of EvalExponentialPdf method in thinkbayes2.py

    Dear professor Downey,

    In chapter 7.6, you would like to compute the time between goals and the code in EvalExponentialPdf method is:

    return lam*math.exp(-lam*x)
    

    but I think the probability between two events is:

    return math.exp(-lam*x)
    

    The first term lam variable should be dropped.

    Here comes my justification: Assume T is the time interval between two goals. The Pr(T > x ) means the probability in a certain time interval x should not occur scoring. so we take the k=0 to the Poisson distribution, then we got math.exp(-lam*x).

    Although I know the EvalExponentialPdf only be called by MakeExponentialPmf, and the lam variable will be canceled out after Normalize function. so the result stays the same. But I still want to confirm with you the correctness of the method. Thanks in advance!

    opened by 18fanfan 2
  • fix Anaconda environment name

    fix Anaconda environment name

    The environment.yml file install the dependencies in the 'base' environment. However this environment already exists and is the Anaconda default. It causes an error when trying to follow the installation steps in the README.md file.

    The README offer to activate the environment with the name ThinkBayes2. Use this name instead in the yml file.

    opened by michaelmera 2
  • Is the solution for cookie problem without replacement (cookie3.py) incomplete?

    Is the solution for cookie problem without replacement (cookie3.py) incomplete?

    Hi!

    First, let me thank you for creating all this, it is really a nice resource for developers like me to learn how to solve problems with bayesian methods. Now the my question: I was surprised by the output of the code on cookie3.py. Am I right to think the code in that file is an incomplete solution to the "cookie problem without replacement"? If it were a complete solution I would have expected the code to construct a growing set of hypothesis as cookies go away, to consider the scenarios in which the cookie removal could be evening out between the bowls, which the current code is not doing.

    Say for example, that you eat 21 vanilla cookies ( no replacement ;-) )

        for x in range(0, 21):
             suite.Update('vanilla')
    

    Then the cookie3.py will printout:

    Hist({'vanilla': 9, 'chocolate': 10}) 1.0 Hist({'vanilla': 0, 'chocolate': 20}) 0.0

    Reaching the conclusion that there in no chance (0.0) the 21th cookie came from bowl2, when it could have been the case that 10 of those cookies came from "bow1" and 11 from "bowl2" making the probability of getting a 21th vanilla cookie from bowl2 non zero. Or maybe I missed some simplifying assumption in the text of the book?

    Thanks

    opened by luxspes 2
  • Install empiricaldist from conda-forge

    Install empiricaldist from conda-forge

    tl;dr Install empiricaldist with conda now that it is available from conda-forge

    Background

    A minimum of 0.6.7 is required because version 0.6.6 is broken (it doesn't import matplotlib, which it requires for its plotting methods)

    https://github.com/conda-forge/empiricaldist-feedstock/pull/1 https://anaconda.org/conda-forge/empiricaldist/files?version=0.6.7

    Testing

    I confirmed that I could build all the main chapter notebooks with this updated environment:

    mamba env create --file environment.yml
    conda activate ThinkBayes2
    
    for nb in chap*.ipynb
    do
      jupyter execute $nb
    done
    

    I also attempted to build the non-chapter notebook, but clustering.ipynb fails because the environment doesn't have scikit-learn installed:

    ModuleNotFoundError: No module named 'sklearn'
    

    Given how it already takes so long to solve and build the conda environment, and also that the clustering notebook is not included in the online version of the book, I decided to not add it in this PR.

    Other

    Also note that per our discussion in https://github.com/AllenDowney/ThinkBayes2/pull/56#issuecomment-1117536918, I took a stab at creating two separate environments: one for readers, and one for you to build the book. I loss motivation for now because:

    1. The reader-only env wasn't that light-weight anyways. The final few chapters ended up requiring a bunch of packages that I had hoped to remove
    2. I ran into the frustrating pymc3/arviz error that you had previously run into. Pinning to old versions of these dependencies limits the long-term usefulness of the book's code (eg it can't benefit from bug fixes in later releases). When I tried to force conda to install newer versions on macOS, the conflict was due to some low-level package (I can't remember which), which would be non-trivial to fix or workaround
    3. I got errors like missing scikit-learn in clustering.ipynb (as mentioned above). It's unclear to me which code is expected to be able to be executed using the conda env

    In case it could be useful to you, here's what I had when I stopped:

    https://github.com/jdblischak/ThinkBayes2/tree/more-conda-updates https://github.com/jdblischak/ThinkBayes2/blob/more-conda-updates/environment.yml https://github.com/jdblischak/ThinkBayes2/blob/more-conda-updates/environment-book.yml

    opened by jdblischak 1
  • Linda problem should use conditional probability when it comes to sex.

    Linda problem should use conditional probability when it comes to sex.

    One thing I feel the book misses multiple times in chapter I is the fact, that Linda's sex is given in the problem description (I picked an exercise as a sample):

    Linda is 31 years old, single, outspoken, and very bright. She majored in philosophy. As a student, she was deeply concerned with issues of discrimination and social justice, and also participated in anti-nuclear demonstrations. Which is more probable?

    Linda is a banker.
    
    Linda is a banker and considers herself a liberal Democrat
    

    According to sample solution to this exercise, we should answer "Linda is a banker" with P(female & banker). However, given it is clear from the description (from the usage of "she"), that Linda is a female, this fact should be considered given, and the solution should be P(banker | female).

    Of course, this fact doesn't change the answer (being a female banker is still more probable than being a liberal, democrat, female banker), however I feel like at least the answer to the above exercise needs to be changed, or the fact that multiple (In my humble opinion - valid) approaches are possible here.

    opened by Szustarol 0
  • Lincoln Index - Three parameter model

    Lincoln Index - Three parameter model

    I am receiving the following error when I attempt to compute the likelihood in the three parameter model: for N, p0, p1 in joint3_pmf.index:

    ValueError: not enough values to unpack (expected 3, got 2)

    I think the issue is that when I attempt to use make_joint using p1 and the joint2_pmf, I do not get the triplet, but rather only the pair, mean p1 is not attaching and thus the multi-index only has 2 items instead of three.

    Do you have any suggestions about how best to fix?

    Thank you

    opened by zjachc 17
  • Oliver Problem - Chapter 6 - General Question

    Oliver Problem - Chapter 6 - General Question

    Brief Background

    Working through this excellent book with a colleague and he noticed something interesting on the Oliver's Blood problem.

    Original solution, assuming 60% of local pop have type O and 1% have type AB:

    like1 = 0.01
    like2 = 2 * 0.6 * 0.01
    
    likelihood_ratio = like1 / like2
    post_odds = 1 * like1 / like2
    prob(post_odds) # 0.454545
    

    The interesting point mentioned by my colleague was this:

    • we could try the problem with a range of different values of % of local population having type AB and still get the same final probability:
    import numpy as np
    
    def prob(o):
        return o / (o+1)
      
      
    o = 0.6 # we fix type o proportion in local pop
    
    # iterate over various ab vals
    for ab in np.linspace(0.02, 0.40, 20):
      like1 = ab
      like2 = 2 * o * ab
    
      assert round(prob(like1 / like2),4) == 0.4545
    

    Clearly the ab cancel one another out in each likelihood calculation.

    Curiosity

    My interpretation of this is that the information on percent of local population with type AB does not matter for this problem. Is there additional insight or context you could add to this? My colleague & I were both a bit surprised, but the math is clear enough.

    Another thought: Perhaps we have to assume the possibility that the proportion of O would shift as AB changes, which would indeed change the final probabilities (even though there are more blood types than O and AB)

    • As AB becomes more likely, and O becomes less likely, then the evidence is increased that Oliver is one of the people that left blood (in this problem).

    Again, no bug found - just curious about any additional commentary on the above. We are very much enjoying the book and exercises.

    opened by davidwanner-8451 0
  • gss_bayes.csv

    gss_bayes.csv

    Should gss_bayes.csv (Chapter 1) be in /data ?

    (found it at https://raw.githubusercontent.com/AllenDowney/BiteSizeBayes/master/gss_bayes.csv after opening the notebook BTW)

    opened by rcsmit 0
  • What is considered to be the

    What is considered to be the "data" in the M&M solution? (Ch 2: Bayes's Theorem)

    The problem hint indicates the trick is defining the hypotheses and data carefully:

    Hint: The trick to this question is to define the hypotheses and the data carefully.

    The solution clearly states the "hypotheses":

    # Hypotheses:
    # A: yellow from 94, green from 96
    # B: yellow from 96, green from 94
    

    What is the "data" in this solution?


    My guess is the data is the color mixes in the bags (e.g. 1994 bag has 30% brown, etc. 1996 bag has 24% blue, etc.).

    With this data definition, the first likelihood would be represented by "the probability of the color mix given that yellow is from 94 and green is from 96". It's not clear to me why that probability would be represented by 0.2*0.2. Maybe I have to think more or maybe I've guessed wrong about the data definition.

    opened by rigdern 1
  • Example 6-8 number of Outperforming Portfolios

    Example 6-8 number of Outperforming Portfolios

    First of all thank you for writing this book. It's been an informative read and the examples are fun and challenging.

    That being said I believe there is a typo in Example 6-8: 312 outperforming portfolios must mean there are 430.5 honest members of congress. It is quite funny to say that there is a half-honest politician, but 313 outperforming portfolios does result in a whole number of honest and dishonest members of congress who add up to 538. So it makes more sense if the number of outperforming portfolios is 313.

    opened by Joe-Morgan-Code 1
Owner
Allen Downey
Professor at Olin College, author of Think Python, Think Bayes, Think Stats, and other books. Blog author of Probably Overthinking It.
Allen Downey
Clustering with variational Bayes and population Monte Carlo

pypmc pypmc is a python package focusing on adaptive importance sampling. It can be used for integration and sampling from a user-defined target densi

null 45 Feb 6, 2022
Predict Breast Cancer Wisconsin (Diagnostic) using Naive Bayes

Naive-Bayes Predict Breast Cancer Wisconsin (Diagnostic) using Naive Bayes Downloading Data Set Use our Breast Cancer Wisconsin Data Set Also you can

Faeze Habibi 0 Apr 6, 2022
Advanced Deep Learning with TensorFlow 2 and Keras (Updated for 2nd Edition)

Advanced Deep Learning with TensorFlow 2 and Keras (Updated for 2nd Edition)

Packt 1.5k Jan 3, 2023
The 7th edition of NTIRE: New Trends in Image Restoration and Enhancement workshop will be held on June 2022 in conjunction with CVPR 2022.

NTIRE 2022 - Image Inpainting Challenge Important dates 2022.02.01: Release of train data (input and output images) and validation data (only input) 2

Andrés Romero 37 Nov 27, 2022
Solutions of Reinforcement Learning 2nd Edition

Solutions of Reinforcement Learning, An Introduction

YIFAN WANG 1.4k Dec 30, 2022
MATLAB codes of the book "Digital Image Processing Fourth Edition" converted to Python

Digital Image Processing Python MATLAB codes of the book "Digital Image Processing Fourth Edition" converted to Python TO-DO: Refactor scripts, curren

Merve Noyan 24 Oct 16, 2022
Toontown House CT Edition

Toontown House: Classic Toontown House Classic source that should just work. ❓ W

Open Source Toontown Servers 5 Jan 9, 2022
This is the official implementation of 3D-CVF: Generating Joint Camera and LiDAR Features Using Cross-View Spatial Feature Fusion for 3D Object Detection, built on SECOND.

3D-CVF This is the official implementation of 3D-CVF: Generating Joint Camera and LiDAR Features Using Cross-View Spatial Feature Fusion for 3D Object

YecheolKim 97 Dec 20, 2022
Lowest memory consumption and second shortest runtime in NTIRE 2022 challenge on Efficient Super-Resolution

FMEN Lowest memory consumption and second shortest runtime in NTIRE 2022 on Efficient Super-Resolution. Our paper: Fast and Memory-Efficient Network T

null 33 Dec 1, 2022
Second Order Optimization and Curvature Estimation with K-FAC in JAX.

KFAC-JAX - Second Order Optimization with Approximate Curvature in JAX Installation | Quickstart | Documentation | Examples | Citing KFAC-JAX KFAC-JAX

DeepMind 90 Dec 22, 2022
aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probabilistic programming with a computation/understanding-first, mathematics-second point of view. All in pure Python ;)

Bayesian Methods for Hackers Using Python and PyMC The Bayesian method is the natural approach to inference, yet it is hidden from readers behind chap

Cameron Davidson-Pilon 25.1k Jan 2, 2023
The second project in Python course on FCC

Assignment Write a function named add_time that takes in two required parameters and one optional parameter: a start time in the 12-hour clock format

Denise T 1 Dec 13, 2021
ESGD-M - A stochastic non-convex second order optimizer, suitable for training deep learning models, for PyTorch

ESGD-M - A stochastic non-convex second order optimizer, suitable for training deep learning models, for PyTorch

Katherine Crowson 53 Dec 29, 2022
PyElecCL - Electron Monte Carlo Second Checks

PyElecCL Python program to perform second checks for electron Monte Carlo radiat

Reese Haywood 3 Feb 22, 2022
Deep Text Search is an AI-powered multilingual text search and recommendation engine with state-of-the-art transformer-based multilingual text embedding (50+ languages).

Deep Text Search - AI Based Text Search & Recommendation System Deep Text Search is an AI-powered multilingual text search and recommendation engine w

null 19 Sep 29, 2022
TAP: Text-Aware Pre-training for Text-VQA and Text-Caption, CVPR 2021 (Oral)

TAP: Text-Aware Pre-training TAP: Text-Aware Pre-training for Text-VQA and Text-Caption by Zhengyuan Yang, Yijuan Lu, Jianfeng Wang, Xi Yin, Dinei Flo

Microsoft 61 Nov 14, 2022
Pytorch re-implementation of Paper: SwinTextSpotter: Scene Text Spotting via Better Synergy between Text Detection and Text Recognition (CVPR 2022)

SwinTextSpotter This is the pytorch implementation of Paper: SwinTextSpotter: Scene Text Spotting via Better Synergy between Text Detection and Text R

mxin262 183 Jan 3, 2023
Code for EMNLP 2021 main conference paper "Text AutoAugment: Learning Compositional Augmentation Policy for Text Classification"

Text-AutoAugment (TAA) This repository contains the code for our paper Text AutoAugment: Learning Compositional Augmentation Policy for Text Classific

LancoPKU 105 Jan 3, 2023
[CVPR 2021] Rethinking Text Segmentation: A Novel Dataset and A Text-Specific Refinement Approach

Rethinking Text Segmentation: A Novel Dataset and A Text-Specific Refinement Approach This is the repo to host the dataset TextSeg and code for TexRNe

SHI Lab 174 Dec 19, 2022