# riddhiraj/lunar-lander architecture

> Architecture diagram of the GitHub repository riddhiraj/lunar-lander, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riddhiraj/lunar-lander
- Repository: https://github.com/riddhiraj/lunar-lander

## Overview

##### Project Context and Purpose
- Project Type: This is a machine learning/reinforcement learning project that applies the NEAT (NeuroEvolution of Augmenting Topologies) algorithm to solve the classic Lunar Lander problem.

##### File Structure
- Top-level files and their roles:
- lunar_lander_neat.py: The main script that sets up the Lunar Lander environment, runs the NEAT algorithm, and handles the evolution process.
- config-feedforward.txt: A configuration file that holds the hyperparameters and setup details required by the NEAT algorithm.
- visualize_network.py: A utility script used to generate graphical representations of the best-evolved neural network.
- result.txt: A file containing training run results and possibly performance metrics.
- requirements.txt: Lists all Python dependencies, indicating the reliance on libraries such as NEAT-Python, Gymnasium, etc.
- .gitignore and README.md: Standard supporting files for repository management and documentation.

##### Main Components
a. Lunar Lander Environment:
- Represents the Gymnasium simulation providing state observations for the lander.
b. NEAT Algorithm Core:
- Implemented in lunar_lander_neat.py, this component orchestrates the neuroevolution process.
- Uses parameters specified in config-feedforward.txt.
- Evolves neural network controller candidates based on feedback from the simulation.
c. Neural Network Visualization:
- The visualize_network.py tool processes the output from the NEAT run and produces visual representations.
d. Outputs & Logs:
- result.txt as the output/log file where training performance and results are recorded.
e. Supporting Elements:
- External libraries and frameworks: the NEAT-Python library for algorithm implementation and Gymnasium for the simulation environment.

##### Relationships and Data Flow
- Data Flow Sequence:
1. The simulation environment (Gymnasium) sends state observations (input data) to the neural network controller.
2. The NEAT component receives this data and outputs control actions back to the environment.
3. Evolutionary feedback is processed to adjust and improve the network architecture over iterations.
4. Results during training are recorded and saved into result.txt.
- Dependencies:
- The main training loop (lunar_lander_neat.py) depends on both the configuration file and the Gymnasium environment.
- The visualization script is triggered after training to provide insights on the evolved network topology.

##### Final Recommendations

Happy diagramming!

## Diagram (Mermaid)

```mermaid
graph TD
    %% Output Layer (Top)
    subgraph "Output Layer"
        results["Results Logger"]:::output
        viz["Visualization Module"]:::output
    end

    %% Processing Layer (Middle)
    subgraph "Processing Layer"
        config["Configuration"]:::processing
        neat["NEAT Engine"]:::processing
    end

    %% Simulation Layer (Bottom)
    subgraph "Simulation Layer"
        env["Lunar Lander Environment"]:::simulation
    end

    %% Data Flow Connections
    env -->|"state observations"| neat
    neat -->|"control actions"| env
    config -->|"configuration parameters"| neat
    neat -->|"training results"| results
    neat -->|"network data"| viz

    %% Click Events
    click env "https://github.com/riddhiraj/lunar-lander/blob/main/lunar_lander_neat.py"
    click neat "https://github.com/riddhiraj/lunar-lander/blob/main/lunar_lander_neat.py"
    click config "https://github.com/riddhiraj/lunar-lander/blob/main/config-feedforward.txt"
    click viz "https://github.com/riddhiraj/lunar-lander/blob/main/visualize_network.py"
    click results "https://github.com/riddhiraj/lunar-lander/blob/main/result.txt"

    %% Styling
    classDef simulation fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef processing fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef output fill:#ADD8E6,stroke:#333,stroke-width:2px;
```
