# yangwohenmai/lstm architecture

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

- Interactive diagram: https://gitdiagram.com/yangwohenmai/lstm
- Repository: https://github.com/yangwohenmai/lstm

## Overview

##### Project Type and Purpose
- This is a learning‐oriented code repository for LSTM time‐series forecasting. It contains:
- A series of tutorial scripts (“LSTM系列”, “长短期记忆(LSTM)”) demonstrating data preparation, single/multi-step univariate and multivariate forecasting with Keras/TensorFlow.
- A no-framework, from-scratch LSTM implementation (“LSTM无框架源码实现”) with its own mini-library (xDLbase) for activators, RNN cells, optimizers, sessions, etc.
- A small stock prediction example (“stock_predict”) that loads CSV data, trains Keras models, and saves checkpoints.

##### File Structure Analysis
- Top-level directories:
- LSTM系列 & 长短期记忆(LSTM): tutorial scripts + datasets (CSV).
- LSTM_Fly: quick LSTM regression examples on “airline-passengers.csv”.
- LSTM无框架源码实现: custom LSTM engine with src/config, src/xDLbase (core modules), src/xutils, plus example scenario.
- stock_predict: dedicated stock-forecasting pipeline with model checkpoints.
- README.md: project overview and curated links.
- Patterns:
- “Examples” layer: Python scripts that orchestrate data loading → preprocessing → model building → training → evaluation → prediction.
- “Framework” layer: two parallel stacks:
1) Keras/TensorFlow API
2) Custom “xDLbase” modules implementing core NN primitives.
- “Data” layer: CSV files under each example subfolder.
- “Artifacts” layer: model weights (HDF5, checkpoints), plots.

##### Insights from README
- Confirms focus on time-series forecasting using LSTM, with pipelines for data cleaning, feature extraction, modeling, and prediction.
- Emphasizes TensorFlow/Keras for most examples but also showcases a raw LSTM implementation.

##### Detail Level
- Every major folder as a component if it represents a distinct role (e.g., LSTM无框架源码实现/xDLbase vs LSTM系列).
- Similar example scripts under a “Tutorial Examples” cluster, annotated with sub-folders.
- Stock_predict pipeline as a standalone example branch.
- Flows for training vs inference phases.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources
    subgraph "Data Sources" 
        direction TB
        DS1["Airline Passengers CSV"]:::data
        DS2["LSTM系列 CSVs"]:::data
        DS3["Stock Predict CSVs"]:::data
        DS4["Long Short Term Memory CSVs"]:::data
    end

    %% Preprocessing Layer
    subgraph "Preprocessing & Feature Extraction" 
        direction TB
        PP1["时间序列转换成稳定数据"]:::process
        PP2["时间序列转监督学习数据"]:::process
        PP3["观测值缩放"]:::process
        PP4["多变量预处理 (LSTM多变量3)"]:::process
    end

    %% Framework Engines
    subgraph "Model Engines" 
        direction TB
        subgraph "Keras/TensorFlow Engine" 
            direction TB
            K1["tf.keras Models"]:::engine
        end
        subgraph "Custom xDLbase Engine" 
            direction TB
            X1["activators.py"]:::engine
            X2["rnn.py"]:::engine
            X3["optimizers.py"]:::engine
            X4["session.py"]:::engine
        end
    end

    %% Example Orchestration
    subgraph "Example Orchestration" 
        direction TB
        EX1["香皂销售预测.py"]:::script
        EX2["静态模型预测.py"]:::script
        EX3["scenario_seqCurve.py"]:::script
        EX4["stock_predict_1.py"]:::script
        EX5["stock_predict_2.py"]:::script
    end

    %% Config & Logging
    subgraph "Config & Utilities"
        direction TB
        CFG["logging.conf"]:::config
        GIT[".gitignore"]:::config
        README["README.md"]:::config
    end

    %% Artifacts & Outputs
    subgraph "Model Artifacts & Outputs"
        direction TB
        MA1["model.ckpt (stock_predict)"]:::output
        MA2["lstm_model.h5"]:::output
        PLT["Plots & Metrics"]:::output
    end

    %% Evaluation & Prediction
    subgraph "Evaluation & Prediction"
        direction TB
        EP1["LSTM性能测评.py"]:::eval
        EP2["保存模型并加载.py"]:::eval
        EP3["stock_predict_2.py"]:::eval
    end

    %% Data Flow Connections
    DS1 --> PP1
    DS2 --> PP1
    DS3 --> PP1
    DS4 --> PP1

    PP1 --> PP2
    PP2 --> PP3
    PP3 --> K1
    PP3 --> X1

    K1 --> MA2
    X4 --> MA1

    MA1 --> EP3
    MA2 --> EP2
    MA2 --> EP1

    EX1 --> PP1
    EX2 --> PP3
    EX3 --> X1
    EX4 --> K1
    EX5 --> K1

    EX1 --> CFG
    EX2 --> CFG
    EX3 --> CFG
    EX4 --> CFG
    EX5 --> CFG

    %% Click Events for Data Sources
    click DS1 "https://github.com/yangwohenmai/lstm/blob/master/LSTM_Fly/airline-passengers.csv"
    click DS2 "https://github.com/yangwohenmai/lstm/blob/master/LSTM系列/*/data_set/*.csv"
    click DS3 "https://github.com/yangwohenmai/lstm/blob/master/stock_predict/dataset_1.csv"
    click DS4 "https://github.com/yangwohenmai/lstm/blob/master/长短期记忆(LSTM)/***/shampoo-sales.csv"

    %% Click Events for Preprocessing
    click PP1 "https://github.com/yangwohenmai/lstm/blob/master/LSTM系列/LSTM单变量2/时间序列转换成稳定数据.py"
    click PP2 "https://github.com/yangwohenmai/lstm/blob/master/LSTM系列/LSTM单变量2/时间序列转监督学习数据.py"
    click PP3 "https://github.com/yangwohenmai/lstm/blob/master/LSTM系列/LSTM单变量2/观测值缩放.py"
    click PP4 "https://github.com/yangwohenmai/lstm/blob/master/LSTM系列/LSTM多变量3/数据预处理.py"

    %% Click Events for xDLbase Engine
    click X1 "https://github.com/yangwohenmai/lstm/blob/master/LSTM无框架源码实现/src/xDLbase/activators.py"
    click X2 "https://github.com/yangwohenmai/lstm/blob/master/LSTM无框架源码实现/src/xDLbase/rnn.py"
    click X3 "https://github.com/yangwohenmai/lstm/blob/master/LSTM无框架源码实现/src/xDLbase/optimizers.py"
    click X4 "https://github.com/yangwohenmai/lstm/blob/master/LSTM无框架源码实现/src/xDLbase/session.py"

    %% Click Events for Orchestration Scripts
    click EX1 "https://github.com/yangwohenmai/lstm/blob/master/LSTM系列/LSTM单变量1/香皂销售预测.py"
    click EX2 "https://github.com/yangwohenmai/lstm/blob/master/LSTM系列/Multi-Step LSTM预测1/静态模型预测.py"
    click EX3 "https://github.com/yangwohenmai/lstm/blob/master/LSTM无框架源码实现/src/scenario_seqCurve.py"
    click EX4 "https://github.com/yangwohenmai/lstm/blob/master/stock_predict/stock_predict_1.py"
    click EX5 "https://github.com/yangwohenmai/lstm/blob/master/stock_predict/stock_predict_2.py"

    %% Click Events for Config & Utilities
    click CFG "https://github.com/yangwohenmai/lstm/blob/master/LSTM无框架源码实现/src/config/logging.conf"
    click GIT "https://github.com/yangwohenmai/lstm/blob/master/.gitignore"
    click README "https://github.com/yangwohenmai/lstm/blob/master/README.md"

    %% Click Events for Artifacts
    click MA1 "https://github.com/yangwohenmai/lstm/blob/master/stock_predict/model_save1/modle.ckpt"
    click MA2 "https://github.com/yangwohenmai/lstm/blob/master/长短期记忆(LSTM)/使用LSTM建模/如何调用Keras中的长短期记忆模型/lstm_model.h5"
    click EP1 "https://github.com/yangwohenmai/lstm/blob/master/长短期记忆(LSTM)/LSTM实例/洗发水销量(单步预测)/7.LSTM模型性能测评.py"
    click EP2 "https://github.com/yangwohenmai/lstm/blob/master/长短期记忆(LSTM)/使用LSTM建模/如何调用Keras中的长短期记忆模型/保存模型并加载.py"
    click EP3 "https://github.com/yangwohenmai/lstm/blob/master/stock_predict/stock_predict_2.py"

    %% Styles
    classDef data fill:#D0E8FF,stroke:#0288D1,stroke-width:1px
    classDef process fill:#E0F2F1,stroke:#00695C,stroke-width:1px
    classDef engine fill:#FFE0B2,stroke:#EF6C00,stroke-width:1px
    classDef script fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef config fill:#F5F5F5,stroke:#9E9E9E,stroke-width:1px
    classDef output fill:#E1BEE7,stroke:#8E24AA,stroke-width:1px
    classDef eval fill:#E1BEE7,stroke:#6A1B9A,stroke-width:1px
```
