# limsr12/nn architecture

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

- Interactive diagram: https://gitdiagram.com/limsr12/nn
- Repository: https://github.com/limsr12/nn

## Overview

##### Project type and purpose
- This is a small neural‐network classification project with two implementations:
- A C implementation (`train_model.c` / `test_model.c`) that reads raw MNIST image data, trains an MLP, saves weights, and evaluates accuracy.
- A Python implementation (`python/mnist_mlp.py`, `python/mnist_mlp_image.py`) for experimentation and image‐based inference.
- The goal is to recognize handwritten digits (0–9) using a multi‐layer perceptron (MLP).

##### File structure
Top level
- README.md – project overview (in Korean)
- .gitignore
- `python/` – Python scripts for training/inference
- `src/` – C source code, raw data archive, metadata files
Inside `src/`
- `mnist_raw.zip` – zipped training/testing folders with per‐digit images
- `train_model.c` – C training program
- `test_model.c` – C testing program
- `meta_h1.txt`, `meta_h2.txt`, `meta_h3.txt` – learned weight files for 1/2/3 hidden‐layer configurations

##### README for additional insights
- Architecture: Input layer (784 nodes), 1–3 hidden layers, output layer (10 nodes)
- Activation: Sigmoid / Softmax; Loss: Cross‐entropy or MSE; Optimizer: gradient descent + backprop
- Hyperparams: 40 epochs, batch size=1, learning rate fixed, random weight init in [–0.5,+0.5]

##### Main components
a. Data Sources
- Raw MNIST images (training / testing folders)
b. C‐based Training Module
- `train_model.c`
- Reads raw data → forward/backprop → outputs weight files (`meta_h*.txt`)
c. Weight Repository
- Persistent storage of `meta_h1.txt`, `meta_h2.txt`, `meta_h3.txt`
d. C‐based Testing Module
- `test_model.c`
- Loads weight files + testing images → computes accuracy metrics
e. Python MLP Modules (parallel path)
- `mnist_mlp.py` – pure‐Python training/inference loop using NumPy
- `mnist_mlp_image.py` – loads user‐provided images for classification
f. CLI / User Interface
- Command‐line invocation of C programs or Python scripts
g. Configuration
- Hyperparameter settings hard‐coded in source or passed as args

##### Relationships and data flows
- Parallel path: Raw MNIST Data → Python Training Module → Python‐based weight objects (in memory or disk) → Python Inference Module
- That both C and Python share the same data source but produce/use distinct weight outputs

##### Architectural patterns and principles
- Pipeline pattern: Data ingestion → Processing (train/test) → Storage → Reporting
- Separation of concerns: training vs. inference, C vs. Python implementations
- Configurability: different hidden‐layer depths via separate metadata files

##### Relevant technologies & frameworks
- C standard library for file I/O, math routines
- Python 3 + NumPy (assumed) for matrix ops / visualization
- No external services; purely local compute & disk storage

## Diagram (Mermaid)

```mermaid
graph TB
    %% Data Source
    Raw["Raw MNIST Data"]:::data

    %% C Implementation
    subgraph "C Implementation"
        CTrain["C Training Module\n(train_model.c)"]:::ccomp
        WeightRepo["Weight Repository\n(meta_h1.txt,\nmeta_h2.txt,\nmeta_h3.txt)"]:::data
        CTest["C Testing Module\n(test_model.c)"]:::ccomp
    end

    %% Python Implementation
    subgraph "Python Implementation"
        PyTrain["Python Training Module\n(mnist_mlp.py)"]:::pycomp
        PyInfer["Python Inference Module\n(mnist_mlp_image.py)"]:::pycomp
    end

    %% CLI / Documentation
    subgraph "CLI / Documentation"
        CLI["CLI Interface\n(Commands)"]:::cli
        README_Top["README.md"]:::cli
        README_Src["src/README.md"]:::cli
        README_Py["python/README.md"]:::cli
    end

    %% Data Flows - C
    Raw -->|"read images"| CTrain
    CTrain -->|"forward/backprop"| WeightRepo
    Raw -->|"read test images"| CTest
    WeightRepo -->|"load weights"| CTest
    CTest -->|"output accuracy"| CLI

    %% Data Flows - Python
    Raw -->|"read images"| PyTrain
    PyTrain -->|"in-memory weights"| PyInfer

    %% Click Events
    click Raw "https://github.com/limsr12/nn/blob/main/src/mnist_raw.zip"
    click CTrain "https://github.com/limsr12/nn/blob/main/src/train_model.c"
    click CTest "https://github.com/limsr12/nn/blob/main/src/test_model.c"
    click WeightRepo "https://github.com/limsr12/nn/blob/main/src/meta_h1.txt"
    click meta_h2 "https://github.com/limsr12/nn/blob/main/src/meta_h2.txt"
    click meta_h3 "https://github.com/limsr12/nn/blob/main/src/meta_h3.txt"
    click PyTrain "https://github.com/limsr12/nn/blob/main/python/mnist_mlp.py"
    click PyInfer "https://github.com/limsr12/nn/blob/main/python/mnist_mlp_image.py"
    click README_Top "https://github.com/limsr12/nn/blob/main/README.md"
    click README_Src "https://github.com/limsr12/nn/blob/main/src/README.md"
    click README_Py "https://github.com/limsr12/nn/blob/main/python/README.md"

    %% Styles
    classDef ccomp fill:#ADD8E6,stroke:#000,color:#000
    classDef pycomp fill:#90EE90,stroke:#000,color:#000
    classDef data fill:#FFA500,stroke:#000,color:#000
    classDef cli fill:#FFD700,stroke:#000,color:#000
```
