# haoxingl/stsan architecture

> Architecture diagram of the GitHub repository haoxingl/stsan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haoxingl/stsan
- Repository: https://github.com/haoxingl/stsan

## Overview

This repository implements a TensorFlow spatial-temporal traffic forecasting model. The main workflow configures a taxi or bike run, prepares historical spatial-temporal samples, trains and evaluates model streams, and records metrics/checkpoints. The model’s attention and convolutional layers are useful internal stages. README documentation is only a title, so additional product capabilities are inferred only where the supplied source supports them; unsampled training details are not expanded.

Main entry points: [`train.py`](https://github.com/haoxingl/stsan/blob/master/train.py) (Training and evaluation), [`utils/DataLoader.py`](https://github.com/haoxingl/stsan/blob/master/utils/DataLoader.py) (Spatial-temporal sampling), [`models.py`](https://github.com/haoxingl/stsan/blob/master/models.py) (Forecast networks), [`main.py`](https://github.com/haoxingl/stsan/blob/master/main.py) (Run configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_run["Run orchestration"]
  node_runner["Run configuration<br/>[main.py]"]
  node_trainer["Training and evaluation<br/>[train.py]"]
end

subgraph group_data["Data preparation"]
  node_dataset_config["Dataset parameters<br/>[data_parameters.py]"]
  node_traffic_data[("Traffic datasets")]
  node_sample_builder["Spatial-temporal sampling<br/>[DataLoader.py]"]
  node_dataset_pipeline["Batch pipeline<br/>[tools.py]"]
  node_masking["Attention masks<br/>[tools.py]"]
end

subgraph group_model["Forecast model"]
  node_network["Forecast networks<br/>[models.py]"]
  node_encoder["Spatial-temporal encoder<br/>[models.py]"]
  node_decoder["Forecast decoder<br/>[models.py]"]
  node_attention["Multi-head attention<br/>[models.py]"]
  node_convolution["Convolution fusion<br/>[models.py]"]
end

subgraph group_training["Training support"]
  node_optimizer_schedule["Learning-rate schedule<br/>[CustomSchedule.py]"]
  node_early_stopping["Early stopping<br/>[EarlystopHelper.py]"]
  node_metrics["Forecast metrics<br/>[Metrics.py]"]
  node_run_output[("Run records and checkpoints<br/>[train.py]")]
end

node_engineer(("Experiment operator"))

node_engineer -->|"configures run"| node_runner
node_runner -->|"starts training"| node_trainer
node_trainer -->|"builds datasets"| node_dataset_pipeline
node_dataset_pipeline -->|"loads samples"| node_sample_builder
node_sample_builder -->|"reads parameters"| node_dataset_config
node_sample_builder -.->|"loads arrays"| node_traffic_data
node_trainer -->|"generates masks"| node_masking
node_trainer -->|"trains models"| node_network
node_network -->|"encodes history"| node_encoder
node_network -->|"decodes forecast"| node_decoder
node_encoder -->|"applies attention"| node_attention
node_decoder -->|"applies attention"| node_attention
node_encoder -->|"extracts features"| node_convolution
node_decoder -->|"extracts features"| node_convolution
node_trainer -->|"sets learning rate"| node_optimizer_schedule
node_trainer -->|"checks progress"| node_early_stopping
node_trainer -->|"measures forecasts"| node_metrics
node_trainer -->|"saves run state"| node_run_output

click node_runner "https://github.com/haoxingl/stsan/blob/master/main.py"
click node_trainer "https://github.com/haoxingl/stsan/blob/master/train.py"
click node_dataset_config "https://github.com/haoxingl/stsan/blob/master/data_parameters.py"
click node_sample_builder "https://github.com/haoxingl/stsan/blob/master/utils/DataLoader.py"
click node_dataset_pipeline "https://github.com/haoxingl/stsan/blob/master/utils/tools.py"
click node_masking "https://github.com/haoxingl/stsan/blob/master/utils/tools.py"
click node_network "https://github.com/haoxingl/stsan/blob/master/models.py"
click node_encoder "https://github.com/haoxingl/stsan/blob/master/models.py"
click node_decoder "https://github.com/haoxingl/stsan/blob/master/models.py"
click node_attention "https://github.com/haoxingl/stsan/blob/master/models.py"
click node_convolution "https://github.com/haoxingl/stsan/blob/master/models.py"
click node_optimizer_schedule "https://github.com/haoxingl/stsan/blob/master/utils/CustomSchedule.py"
click node_early_stopping "https://github.com/haoxingl/stsan/blob/master/utils/EarlystopHelper.py"
click node_metrics "https://github.com/haoxingl/stsan/blob/master/utils/Metrics.py"
click node_run_output "https://github.com/haoxingl/stsan/blob/master/train.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runner,node_trainer toneBlue
class node_dataset_config,node_traffic_data,node_sample_builder,node_dataset_pipeline,node_masking toneAmber
class node_network,node_encoder,node_decoder,node_attention,node_convolution toneMint
class node_optimizer_schedule,node_early_stopping,node_metrics,node_run_output toneRose
class node_engineer toneIndigo
```

## Components

### Run orchestration

- [Run configuration](https://github.com/haoxingl/stsan/blob/master/main.py): `main.py`
- [Training and evaluation](https://github.com/haoxingl/stsan/blob/master/train.py): `train.py`

### Data preparation

- [Dataset parameters](https://github.com/haoxingl/stsan/blob/master/data_parameters.py): `data_parameters.py`
- **Traffic datasets**
- [Spatial-temporal sampling](https://github.com/haoxingl/stsan/blob/master/utils/DataLoader.py): `utils/DataLoader.py`
- [Batch pipeline](https://github.com/haoxingl/stsan/blob/master/utils/tools.py): `utils/tools.py`
- [Attention masks](https://github.com/haoxingl/stsan/blob/master/utils/tools.py): `utils/tools.py`

### Forecast model

- [Forecast networks](https://github.com/haoxingl/stsan/blob/master/models.py): `models.py`
- [Spatial-temporal encoder](https://github.com/haoxingl/stsan/blob/master/models.py): `models.py`
- [Forecast decoder](https://github.com/haoxingl/stsan/blob/master/models.py): `models.py`
- [Multi-head attention](https://github.com/haoxingl/stsan/blob/master/models.py): `models.py`
- [Convolution fusion](https://github.com/haoxingl/stsan/blob/master/models.py): `models.py`

### Training support

- [Learning-rate schedule](https://github.com/haoxingl/stsan/blob/master/utils/CustomSchedule.py): `utils/CustomSchedule.py`
- [Early stopping](https://github.com/haoxingl/stsan/blob/master/utils/EarlystopHelper.py): `utils/EarlystopHelper.py`
- [Forecast metrics](https://github.com/haoxingl/stsan/blob/master/utils/Metrics.py): `utils/Metrics.py`
- [Run records and checkpoints](https://github.com/haoxingl/stsan/blob/master/train.py): `train.py`

### Other components

- **Experiment operator**

## Connections

- Experiment operator → Run configuration: configures run (evidence: `main.py`)
- Run configuration → Training and evaluation: starts training (evidence: `main.py`)
- Training and evaluation → Batch pipeline: builds datasets (evidence: `train.py`)
- Batch pipeline → Spatial-temporal sampling: loads samples (evidence: `utils/tools.py`)
- Spatial-temporal sampling → Dataset parameters: reads parameters (evidence: `utils/DataLoader.py`)
- Spatial-temporal sampling → Traffic datasets: loads arrays
- Training and evaluation → Attention masks: generates masks (evidence: `train.py`)
- Training and evaluation → Forecast networks: trains models (evidence: `train.py`)
- Forecast networks → Spatial-temporal encoder: encodes history (evidence: `models.py`)
- Forecast networks → Forecast decoder: decodes forecast (evidence: `models.py`)
- Spatial-temporal encoder → Multi-head attention: applies attention (evidence: `models.py`)
- Forecast decoder → Multi-head attention: applies attention (evidence: `models.py`)
- Spatial-temporal encoder → Convolution fusion: extracts features (evidence: `models.py`)
- Forecast decoder → Convolution fusion: extracts features (evidence: `models.py`)
- Training and evaluation → Learning-rate schedule: sets learning rate (evidence: `train.py`)
- Training and evaluation → Early stopping: checks progress (evidence: `train.py`)
- Training and evaluation → Forecast metrics: measures forecasts (evidence: `train.py`)
- Training and evaluation → Run records and checkpoints: saves run state (evidence: `train.py`)
