# ontiyonke/reinforcement-learning architecture

> Architecture diagram of the GitHub repository ontiyonke/reinforcement-learning, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ontiyonke/reinforcement-learning
- Repository: https://github.com/ontiyonke/reinforcement-learning

## Overview

##### Main Components
- Learning Modules: Represent each major RL branch as separate “modules” corresponding to directories such as:
- DP (Dynamic Programming methods)
- MC (Monte Carlo methods)
- TD (Temporal Difference methods)
- FA (Function Approximation techniques)
- DQN (Deep Q-Learning variants)
- PolicyGradient (Policy gradient methods, including subcomponents like A3C)
- MDP and Introduction (Conceptual and introductory materials)
- Shared Libraries and Utilities: Illustrate the “lib” directory, which includes common helper functions for Atari environments, state processing, environment wrappers (e.g., for Blackjack, Gridworld, etc.), and plotting.
- External Dependencies & Frameworks: Indicate integration with external libraries like OpenAI Gym for environments and TensorFlow for deep learning in advanced methods.

##### Relationships and Interactions
- Modularity: Each algorithm category (DP, MC, TD, etc.) operates as an independent unit but generally follows a similar structure—a set of notebooks for playground and solution, often leveraging shared environment definitions.
- Notebooks as Execution Units: Highlight that many components are Jupyter notebooks, which encapsulate experiment code, solution walkthroughs, and demonstrations – they are entry points for experiment execution rather than full-blown deployment services.

##### Representing Architectural Patterns and Design Principles
- Educational Separation: Emphasize the educational “modularity” – each directory targets a specific RL concept from theory to practice, allowing one to navigate the learning progression.
- Hierarchical Layering: Illustrate higher-level “application logic” in the notebooks (i.e., algorithm implementations) that leverage lower-level “utility” modules from lib, mirroring a layered architecture.

##### Highlighting Relevant Technologies and Frameworks
- OpenAI Gym: Represent it as an external dependency that supplies environments.
- TensorFlow (in use for deep RL implementations such as DQN and some Policy Gradient methods): Include this as an external service that provides neural network functionality.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Algorithm Modules
    subgraph "Algorithm Modules"
        DP["DP - Dynamic Programming"]:::algo
        MC["MC - Monte Carlo Methods"]:::algo
        TD["TD - Temporal Difference"]:::algo
        FA["FA - Function Approximation"]:::algo
        DQN["DQN - Deep Q-Learning"]:::algo
        PG["PolicyGradient - Policy Gradient Methods"]:::algo
        MDP["MDP - Markov Decision Process"]:::algo
        Intro["Introduction"]:::algo

        %% A3C Components inside PolicyGradient
        PG -->|"uses_A3C"| A3C["A3C - Asynchronous Advantage Actor Critic"]:::algo
        A3C -->|"worker_to_trainer"| Worker["Worker"]:::algo
        A3C -->|"worker_to_monitor"| Trainer["Trainer"]:::algo
        A3C -->|"monitor_feedback"| PolicyMonitor["Policy Monitor"]:::algo
    end

    %% Shared Libraries and Utilities
    subgraph "Shared Libraries"
        LIB["lib"]:::utils
        Atari["Atari Utils"]:::utils
        Envs["Env Wrappers"]:::utils
        Plotting["Plotting Utilities"]:::utils
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Gym["OpenAI Gym"]:::external
        TF["TensorFlow"]:::external
    end

    %% Connections between Algorithm Modules and Shared Libraries
    DP -->|"utilizes"| LIB
    MC -->|"utilizes"| LIB
    TD -->|"utilizes"| LIB
    FA -->|"utilizes"| LIB
    DQN -->|"utilizes"| LIB
    PG -->|"utilizes"| LIB
    MDP -->|"utilizes"| LIB
    Intro -->|"utilizes"| LIB

    %% Connection between Shared Libraries and External Dependencies
    LIB -->|"fetch_env"| Gym

    %% Specific connections for deep learning integration
    DQN -->|"integrates"| TF
    PG -->|"integrates"| TF

    %% Internal A3C interactions
    Worker -->|"reports_to"| Trainer
    PolicyMonitor -->|"feedback_to"| Worker

    %% Styles for components
    classDef algo fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef utils fill:#D0ECE7,stroke:#1ABC9C,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;

    %% Click Events for Algorithm Modules
    click DP "https://github.com/ontiyonke/reinforcement-learning/tree/master/DP/"
    click MC "https://github.com/ontiyonke/reinforcement-learning/tree/master/MC/"
    click TD "https://github.com/ontiyonke/reinforcement-learning/tree/master/TD/"
    click FA "https://github.com/ontiyonke/reinforcement-learning/tree/master/FA/"
    click DQN "https://github.com/ontiyonke/reinforcement-learning/tree/master/DQN/"
    click PG "https://github.com/ontiyonke/reinforcement-learning/tree/master/PolicyGradient/"
    click A3C "https://github.com/ontiyonke/reinforcement-learning/tree/master/PolicyGradient/a3c/"
    click MDP "https://github.com/ontiyonke/reinforcement-learning/tree/master/MDP/"
    click Intro "https://github.com/ontiyonke/reinforcement-learning/tree/master/Introduction/"

    %% Click Events for Shared Libraries
    click LIB "https://github.com/ontiyonke/reinforcement-learning/tree/master/lib/"
    click Atari "https://github.com/ontiyonke/reinforcement-learning/tree/master/lib/atari"
    click Envs "https://github.com/ontiyonke/reinforcement-learning/tree/master/lib/envs"
    click Plotting "https://github.com/ontiyonke/reinforcement-learning/blob/master/lib/plotting.py"

    %% Click Events for A3C Components
    click Worker "https://github.com/ontiyonke/reinforcement-learning/blob/master/PolicyGradient/a3c/worker.py"
    click Trainer "https://github.com/ontiyonke/reinforcement-learning/blob/master/PolicyGradient/a3c/train.py"
    click PolicyMonitor "https://github.com/ontiyonke/reinforcement-learning/blob/master/PolicyGradient/a3c/policy_monitor.py"
```
