{"id":13415550,"url":"https://github.com/ksachdeva/rethinking-tensorflow-probability","last_synced_at":"2025-04-10T01:14:18.485Z","repository":{"id":50472055,"uuid":"233911158","full_name":"ksachdeva/rethinking-tensorflow-probability","owner":"ksachdeva","description":"Statistical Rethinking (2nd Ed) with Tensorflow Probability","archived":false,"fork":false,"pushed_at":"2022-01-19T19:16:55.000Z","size":336452,"stargazers_count":273,"open_issues_count":3,"forks_count":50,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-10T01:14:11.242Z","etag":null,"topics":["bayesian-inference","bayesian-statistics","markov-chain-monte-carlo","statistical-rethinking","tensorflow","tensorflow-probability","tutorials","variational-inference"],"latest_commit_sha":null,"homepage":"https://ksachdeva.github.io/rethinking-tensorflow-probability/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ksachdeva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-14T18:44:28.000Z","updated_at":"2025-02-27T12:01:54.000Z","dependencies_parsed_at":"2022-08-05T13:00:43.590Z","dependency_job_id":null,"html_url":"https://github.com/ksachdeva/rethinking-tensorflow-probability","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksachdeva%2Frethinking-tensorflow-probability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksachdeva%2Frethinking-tensorflow-probability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksachdeva%2Frethinking-tensorflow-probability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksachdeva%2Frethinking-tensorflow-probability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksachdeva","download_url":"https://codeload.github.com/ksachdeva/rethinking-tensorflow-probability/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137891,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian-inference","bayesian-statistics","markov-chain-monte-carlo","statistical-rethinking","tensorflow","tensorflow-probability","tutorials","variational-inference"],"created_at":"2024-07-30T21:00:50.231Z","updated_at":"2025-04-10T01:14:18.465Z","avatar_url":"https://github.com/ksachdeva.png","language":"Jupyter Notebook","readme":"# Statistical Rethinking (2nd Edition) with Tensorflow Probability\n\nThis repository provides jupyter notebooks that port various R code fragments found in the\nchapters of [Statistical Rethinking 2nd Edition](https://xcelab.net/rm/statistical-rethinking/) by Professor Richard McElreath to python using tensorflow probability framework.\n\nNote - These notebooks are based on the 8th December 2019 draft. I will update the notebooks once the book is released.\n\n## Misc Notes\n\n* **Why Tensorflow Probability ?** There are many great probabilitic frameworks (PPLs) out there. I especially like `Numpyro` \u0026 `PyMC3`. There are 2 main reasons why I chose to do this exercise in tfp.\n    * First and main reason is to not use the magic of the libraries. Sometimes higher level libraries hide the details which are necessary for one to truly understand the subject. As a matter of fact, working with TFP has resulted in me becoming more appreciable of these high level libraries as indeed they not only provide great helpers but make the code easy to read and reuse.\n    * Second is that I have other investments in Tensorflow ecosystem so am not keen on switching to pyTorch even though I really like what Pyro team has done.\n\n  \u003e For production use, I strongly recommend that one must use these higher level libraries i.e. `Numpyro`, `PyMC3`\n\n* **What worked ?** Well of course this book is the best there is in this area. The community is also great. I got quick responses from tensorflow probability team whenever I asked questions on tfp google group.\n\n* **What was hard ?** It may be tad bit subjective because I am **challenged** when it comes to manipulating shapes (high dimensional arrays). I find numpy to be difficult and tensorflow is way more harder when it comes to working with multi-dimensional arrays. This is one of the main problems I have faced and continue to face. Another problem is that the stack trace generated by TFP can be really difficult to understand. This mostly is the side effect of graphs that make debugging difficult. Quite often as long as I used only 1 chain things would work but working with multiple chains require that you pay special attention to the shapes/batches of the various tensors/distributions.\n\n* **Visualization** I have made use of `arviz` and in order to do that I converted the output of various sampling procedures to the format/structure required by it. This made me learn and discover `xarray`. It was really worth doing it and made it easy to plot the graphs.\n\n## Chapters  \n\nIf you prefer the readonly view of notebooks (html pages) then use this link - [https://ksachdeva.github.io/rethinking-tensorflow-probability/](https://ksachdeva.github.io/rethinking-tensorflow-probability/)\n\nIf you want to run the notebooks locally -\n\n```bash\n# install the requirements\npip install -r requirements.txt\n# install jupyter in your virtual environment\npip install -r requirements-extra.txt\n# do the dev setup (as some common code resides in rethinking module)\npip install -e .\n```\n\nIf you prefer to run the notebooks in binder then click here [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ksachdeva/rethinking-tensorflow-probability/master)\n\n*Clicking on the links will open the notebooks in Google Colab \u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\"/\u003e*\n\n* [Preface](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/preface.ipynb)\n\n* [Chapter 1 - The Golem of Prague](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/01_the_golem_of_prague.ipynb)\n\n* [Chapter 2 - Small worlds \u0026 large worlds](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/02_small_worlds_and_large_worlds.ipynb)  \n\n* [Chapter 3 - Sampling the Imaginary](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/03_sampling_the_imaginary.ipynb)\n\n* [Chapter 4 - Geocentric Models](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/04_geocentric_models.ipynb)\n\n* [Chapter 5 - The Many Variables and The Spurious Waffles](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/05_the_many_variables_and_the_spurious_waffles.ipynb)\n\n* [Chapter 6 - The Haunted DAG \u0026 The Causal Terror](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/06_the_haunted_dag_and_the_causal_terror.ipynb)\n\n* [Chapter 7 - Ulysses' Compass](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/07_ulysses_compass.ipynb)\n\n* [Chapter 8 - Conditional Manatees](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/08_conditional_manatees.ipynb)\n\n* [Chapter 9 - Markov Chain Monte Carlo](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/09_markov_chain_monte_carlo.ipynb)\n\n* [Chapter 10 - Big Entropy and The Generalized Linear Model](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/10_big_entropy_and_the_generalized_linear_model.ipynb)\n\n* [Chapter 11 - God Spiked the Integers (WIP)](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/11_god_spiked_the_integers.ipynb)\n\n* [Chapter 12 - Monsters and Mixtures (WIP)](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/12_monsters_and_mixtures.ipynb)\n\n* [Chapter 13 - Models with Memory](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/13_models_with_memory.ipynb)\n\n* [Chapter 14 - Adventures in Covariance (WIP)](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/14_adventures_in_covariance.ipynb)\n\n* [Chapter 15 - Missing data \u0026 Other Opportunities (WIP)](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/15_missing_data_and_other_opportunities.ipynb)\n\n* [Chapter 16 - Generalized Linear Madness](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/16_generalized_linear_madness.ipynb)\n\n* [Chapter 17 - Horoscopes](https://colab.research.google.com/github/ksachdeva/rethinking-tensorflow-probability/blob/master/notebooks/17_horoscopes.ipynb)\n\n## Acknowledgements\n\nMy immense gratitude goes to Professor Richard McElreath for writing such a wonderful book. His method of teaching has made somewhat difficult subject of Bayesian Statistics approachable, interesting and to some extent fun as well. We need more educators like you Sir !.\n\nAnother person I want to thank is Du Phan (https://github.com/fehiepsi). He is the main author of [Numpyro](https://github.com/pyro-ppl/numpyro), a great framework to do Bayesian Analysis. He has ported Statsical Rethinking (2nd Ed) to Numpyro and his notebooks were not only insipirational but were also of great help to me in creating graphs. I borrowed most of his code fragments when it came to plotting the figures using matplotlib.\n","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksachdeva%2Frethinking-tensorflow-probability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksachdeva%2Frethinking-tensorflow-probability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksachdeva%2Frethinking-tensorflow-probability/lists"}