# mrassell/homemade-neural-network architecture

> Architecture diagram of the GitHub repository mrassell/homemade-neural-network, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrassell/homemade-neural-network
- Repository: https://github.com/mrassell/homemade-neural-network

## Overview

##### Project type and purpose
- This is an educational, from-scratch neural-network implementation in a single Python script (`NeuralNetwork.py`) that trains and evaluates a two-layer neural network on the MNIST dataset.
- There are no separate frontend/backend or microservices; it’s a standalone data-processing and ML pipeline.

##### File structure
- Top-level file: `NeuralNetwork.py`
- No subdirectories—everything lives in one script.
- External dependencies are defined in the README: NumPy, pandas, matplotlib.

##### README for architecture clues
- Describes stages: data loading/preprocessing, parameter initialization, forward propagation, backward propagation (gradient computation), parameter updates (gradient descent), and testing/visualization.
- Key functions map directly to pipeline steps.

##### Main components
a. Data Layer
- MNIST CSV file (`train.csv`)
- pandas for data loading
- preprocessing to normalize pixel values and split into train/dev sets
b. Model Component
- Parameter storage: W1, b1, W2, b2
- Activation functions: ReLU (hidden), Softmax (output)
- Forward propagation module
- Backward propagation module
c. Training Engine
- Loss calculation (cross-entropy)
- Gradient descent loop (iterations + learning rate α)
- Logging training accuracy every N steps
d. Evaluation & Visualization
- Test predictions on sample images
- matplotlib for displaying images and predicted labels
e. External Libraries
- NumPy (numerical computation)
- pandas (data I/O)
- matplotlib (plotting)

##### Relationships and interactions
- From Data Loader to Preprocessor
- Preprocessed data flows into Training Engine
- Training Engine repeatedly invokes Model’s Forward → Loss → Backward → Parameter Update
- After training, final parameters go into Evaluation module
- Evaluation module outputs images + predicted labels via matplotlib

##### Architectural patterns/design principles
- Pipeline pattern: data → model → training loop → evaluation
- Clear separation of concerns even in one file: data I/O vs. core model vs. training logic vs. visualization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    DDB["MNIST CSV (train.csv)"]:::data
    DataLoader["Data Loader"]:::data
    Preprocessor["Preprocessor"]:::data

    %% Model Component
    subgraph "Model Component"
        ParamStore["Parameter Storage (W1, b1; W2, b2)"]:::model
        Forward["Forward Propagation"]:::model
        Backward["Backward Propagation"]:::model
    end

    %% Training Logic
    Loss["Loss Calculation (Cross-Entropy)"]:::train
    GradientDescent["Gradient Descent Loop"]:::train

    %% Evaluation
    Eval["Evaluation & Visualization"]:::train

    %% External Libraries
    subgraph "External Libraries"
        NP["NumPy"]:::ext
        Pandas["pandas"]:::ext
        MPL["matplotlib"]:::ext
    end

    %% Data Flow
    DDB --> DataLoader
    DataLoader -->|"raw pixels"| Preprocessor
    Preprocessor -->|"normalized pixels"| Forward
    Forward -->|"predictions"| Loss
    Loss -->|"gradients"| Backward
    Backward -->|"gradients"| GradientDescent
    GradientDescent -->|"updated parameters"| ParamStore
    GradientDescent -->|"iterate"| Forward
    ParamStore -->|"final model"| Eval
    Eval -->|"plots"| MPL

    %% External library usage
    Pandas --> DataLoader
    NP --> Preprocessor
    NP --> Forward
    NP --> Backward
    NP --> GradientDescent

    %% Click Events
    click DataLoader "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click Preprocessor "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click ParamStore "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click Forward "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click Backward "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click Loss "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click GradientDescent "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click Eval "https://github.com/mrassell/homemade-neural-network/blob/main/NeuralNetwork.py"
    click NP "https://github.com/mrassell/homemade-neural-network/blob/main/README.md"
    click Pandas "https://github.com/mrassell/homemade-neural-network/blob/main/README.md"
    click MPL "https://github.com/mrassell/homemade-neural-network/blob/main/README.md"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef model fill:#90EE90,stroke:#333,stroke-width:1px
    classDef train fill:#FFD580,stroke:#333,stroke-width:1px
    classDef ext fill:#D3D3D3,stroke:#333,stroke-width:1px
```
