# lin956/sttns architecture

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

- Interactive diagram: https://gitdiagram.com/lin956/sttns
- Repository: https://github.com/lin956/sttns

## Overview

##### Main Components
- Data Input & Preprocessing:
- The PEMSD7 folder contains the dataset (including CSV files like V_25.csv and W_25.csv) and data description.
- One_hot_encoder.py is likely used to transform categorical or discrete data features into a machine-readable format.
- Model Components:
- GCN_models.py defines graph convolutional modules that capture spatial relationships in traffic data.
- STTNS.py is the core module implementing the Spatial-Temporal Transformer Networks for forecasting.
- layers.py contains reusable neural network layers and components that build up the network architecture.
- Entry Point & Training:
- main.py serves as the central pipeline for loading data, setting up the model, training, and evaluation.
- Additional Utility Components:
- Any other utility modules embedded in the codebase help glue the components together (though not separate directories, the file separation itself indicates modular design).

##### Interactions & Flow
- Data then flows to the network components where spatial dependencies (captured by GCN models) and temporal features (handled by transformer layers in STTNS) are processed.
- The layers defined in layers.py support both the GCN and transformer modules.
- main.py orchestrates the entire process, managing data flow, model instantiation, training loops, and evaluation.
- There’s clear data dependency: raw data → preprocessing → feature extraction → model inference/training → forecasting output.

##### Architectural Patterns & Design Principles
- Modularity: Each key function (data preprocessing, spatial modeling, temporal modeling) is encapsulated in its own module.
- Separation of Concerns: Data handling, model definition, and training processes are clearly separated into different files.
- Deep Learning Pipeline Structure: The data flows sequentially from ingestion to preprocessing to model evaluation.

##### Relevant Technologies/Frameworks
- Graph Neural Networks (GCN) and Transformer architectures are important aspects that should be highlighted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Preprocessing Layer
    subgraph "Data & Preprocessing"
        D1["Data Input (PEMS7 Dataset)"]:::data
        D2["Preprocessing (One_hot_encoder)"]:::data
    end

    %% Modeling Components Layer
    subgraph "Modeling Components"
        M1["Spatial Component (GCN_models)"]:::model
        M2["Temporal Component (STTNS)"]:::model
        M3["Reusable Layers (layers)"]:::model
    end

    %% Pipeline Layer
    subgraph "Pipeline"
        P1["Training & Evaluation (main.py)"]:::entry
        P2["Forecasting Output"]:::output
    end

    %% Connections
    D1 --> D2
    D2 --> M1
    D2 --> M2
    M3 --> M2
    M1 --> P1
    M2 --> P1
    P1 --> P2

    %% Click Events
    click D1 "https://github.com/lin956/sttns/tree/main/PEMS7"
    click D2 "https://github.com/lin956/sttns/blob/main/One_hot_encoder.py"
    click M1 "https://github.com/lin956/sttns/blob/main/GCN_models.py"
    click M2 "https://github.com/lin956/sttns/blob/main/STTNS.py"
    click M3 "https://github.com/lin956/sttns/blob/main/layers.py"
    click P1 "https://github.com/lin956/sttns/blob/main/main.py"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef model fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef entry fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef output fill:#FFA07A,stroke:#000,stroke-width:1px;
```
