# saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers architecture

> Architecture diagram of the GitHub repository saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers
- Repository: https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers

## Overview

##### Main Components
- Chapters – Each chapter folder (e.g., Chapter1_Introduction, Chapter2_MorePyMC, Chapter3_MCMC, etc.) acts as a “module” that contains content (Jupyter notebooks), code (Python scripts), data sets, and sometimes chapter-specific plots or visualizations.
- Prologue and Examples – The “Prologue” directory and “ExamplesFromChapters” directory provide supplementary content and runnable examples.
- Sandbox – The experimental directory (“sandbox”) is used for testing ideas and running exploratory notebooks.
- Supporting Files – This includes the top-level project files such as README.md, requirements.txt, and configuration files in .github and styles directories. These files handle deployment (e.g., funding, GitHub templates) and style customizations for Jupyter/Matplotlib outputs.

##### Relationships and Interactions
- Within each chapter, there is an interaction between code (notebooks, Python scripts) and local data resources stored in designated “data” subdirectories.
- The ExamplesFromChapters module serves as a support layer, showing how the concepts explained in the chapters can be applied in varied contexts.
- The Sandbox is connected as an “experimental” or “testing” area which may build upon ideas from the chapters.
- The README provides an overarching description of the project and is the entry point that guides how the chapters and supporting materials are used.

##### Architectural Patterns and Design Principles
- Modularity: The project is split into clear, modular units (each chapter is self-contained).
- Separation of concerns: Presentation (Jupyter notebooks), computation (Python scripts), data (data subdirectories), and configuration/styling (styles directory and top-level config files) are separated.
- Versioning/Multiplicity: There are parallel versions of notebooks for PyMC2 and PyMC3 (and even Pyro and TFP for some chapters), indicating a design that supports multiple hypotheses or implementations for the same concept.
- Self-containment: Each chapter is almost an independent “microservice” of content – a useful design that allows contributors to work on specific chapters without affecting others.

##### Relevant Technologies, Frameworks, and Libraries
- Python and Jupyter Notebook – for interactive examples and explorations.
- PyMC (PyMC2 and PyMC3) – the probabilistic programming libraries central to the book.
- NumPy, SciPy, and Matplotlib – as the underlying math and plotting libraries.
- Git and GitHub – for version control, pull requests, and collaborative contributions.
- Additionally, for some chapters, external tools (like nbviewer or nbconvert) are used for rendering notebooks, while style customizations are done via configuration files in the “styles” directory.

- Under “Chapters,” further break out into individual chapter blocks, each then showing internal items (Jupyter notebooks, Python scripts, data folders, and chapter README files).
- “external dependencies” and technologies (like Jupyter, PyMC libraries, etc.) as nodes that connect to every chapter, underscoring the project’s reliance on these technologies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Root("Bayesian Methods for Hackers"):::root
    Prologue("Prologue"):::chapterContent
    Chapters("Chapters"):::moduleGroup
    Examples("ExamplesFromChapters"):::example
    Sandbox("Sandbox"):::sandbox
    Support("Supporting Files"):::support
    Dependencies("Dependencies"):::external

    %% Top-level Connections
    Root --> Prologue
    Root --> Chapters
    Root --> Examples
    Root --> Sandbox
    Root --> Support
    Root --> Dependencies

    %% Chapters Subgraph with Chapter Nodes and Progression Flow
    subgraph "Chapters"
        C1("Chapter1_Introduction"):::chapter
        C2("Chapter2_MorePyMC"):::chapter
        C3("Chapter3_MCMC"):::chapter
        C4("Chapter4_TheGreatestTheoremNeverTold"):::chapter
        C5("Chapter5_LossFunctions"):::chapter
        C6("Chapter6_Priorities"):::chapter
        C7("Chapter7_BayesianMachineLearning"):::chapter
    end

    %% Progression Flow: Prologue --> Chapters in order
    Prologue -->|"start"| C1
    C1 -->|"next"| C2
    C2 -->|"next"| C3
    C3 -->|"next"| C4
    C4 -->|"next"| C5
    C5 -->|"next"| C6
    C6 -->|"next"| C7

    %% Internal Components for Chapter1_Introduction
    C1 --> C1_NB("Notebook"):::notebook
    C1 --> C1_Readme("README"):::doc
    C1 --> C1_Data("Data"):::data

    %% Internal Components for Chapter2_MorePyMC
    C2 --> C2_NB("Notebook"):::notebook
    C2 --> C2_Readme("README"):::doc
    C2 --> C2_Data("Data"):::data

    %% Internal Components for Chapter3_MCMC
    C3 --> C3_NB("Notebook"):::notebook
    C3 --> C3_Readme("README"):::doc
    C3 --> C3_Data("Data"):::data

    %% Internal Components for Chapter4_TheGreatestTheoremNeverTold
    C4 --> C4_NB("Notebook"):::notebook
    C4 --> C4_Readme("README"):::doc
    C4 --> C4_Data("Data"):::data

    %% Internal Components for Chapter5_LossFunctions (with extra script)
    C5 --> C5_NB("Notebook"):::notebook
    C5 --> C5_Readme("README"):::doc
    C5 --> C5_Data("Data"):::data
    C5 --> C5_Dark("DarkWorldsMetric.py"):::script

    %% Internal Components for Chapter6_Priorities
    C6 --> C6_NB("Notebook"):::notebook
    C6 --> C6_Readme("README"):::doc
    C6 --> C6_Data("Data"):::data

    %% Internal Components for Chapter7_BayesianMachineLearning
    C7 --> C7_NB("Notebook"):::notebook

    %% Supporting Files internal breakdown
    subgraph "Supporting Files"
        S_README("README"):::doc
        S_req("requirements.txt"):::doc
        S_book("book_layout.txt"):::doc
        S_LICENSE("LICENSE"):::doc
        S_toL("to_latex_pdf.sh"):::script
        S_GitHub(".github"):::config
        S_styles("styles"):::config
        S_gitignore(".gitignore"):::config
    end
    Support --> S_README
    Support --> S_req
    Support --> S_book
    Support --> S_LICENSE
    Support --> S_toL
    Support --> S_GitHub
    Support --> S_styles
    Support --> S_gitignore

    %% Dependencies Subgraph
    subgraph "Dependencies"
        Jupyter("Jupyter Notebook"):::external
        Python("Python"):::external
        PyMC2("PyMC2"):::external
        PyMC3("PyMC3"):::external
    end
    Dependencies --> Jupyter
    Dependencies --> Python
    Dependencies --> PyMC2
    Dependencies --> PyMC3

    %% Click Events for Chapter Components
    click C1 "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC2.ipynb"
    click C2 "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Chapter2_MorePyMC/Ch2_MorePyMC_PyMC2.ipynb"
    click C3 "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Chapter3_MCMC/Ch3_IntroMCMC_PyMC2.ipynb"
    click C4 "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Chapter4_TheGreatestTheoremNeverTold/Ch4_LawOfLargeNumbers_PyMC2.ipynb"
    click C5 "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Chapter5_LossFunctions/Ch5_LossFunctions_PyMC2.ipynb"
    click C6 "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Chapter6_Priorities/Ch6_Priors_PyMC2.ipynb"
    click C7 "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Chapter7_BayesianMachineLearning/DontOverfit.ipynb"
    click Prologue "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/Prologue/Prologue.ipynb"
    click Examples "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/tree/master/ExamplesFromChapters/"
    click Sandbox "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/tree/master/sandbox/"
    click S_README "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/README.md"
    click S_req "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/blob/master/requirements.txt"
    click S_GitHub "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/tree/master/.github/"
    click S_styles "https://github.com/saketjnu/probabilistic-programming-and-bayesian-methods-for-hackers/tree/master/styles/"

    %% Class Definitions for Styling
    classDef root fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef chapter fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef notebook fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef doc fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef data fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef script fill:#FAD7A0,stroke:#CA6F1E,stroke-width:2px;
    classDef moduleGroup fill:#D5F5E3,stroke:#239B56,stroke-width:2px;
    classDef external fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef config fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef chapterContent fill:#D6EAF8,stroke:#2E86C1,stroke-width:2px;
    classDef example fill:#FEF5E7,stroke:#D68910,stroke-width:2px;
    classDef sandbox fill:#F9EBEA,stroke:#C0392B,stroke-width:2px;
    classDef support fill:#EDF7EF,stroke:#28B463,stroke-width:2px;
```
