# decisionintelligence/pathformer architecture

> Architecture diagram of the GitHub repository decisionintelligence/pathformer, 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/decisionintelligence/pathformer
- Repository: https://github.com/decisionintelligence/pathformer

## Overview

##### Main Components
- Data Input & Preprocessing:
- “data_provider” directory which includes modules (data_factory.py, data_loader.py) responsible for loading and preparing datasets.
- That the README mentions placing pre-processed datasets under a ./dataset folder (even though it isn’t in the file tree, it is an essential external component).

- Model Architecture & Core Layers:
- The “layers” directory includes key modules (AMS, Embedding, Layer, RevIN) that make up various components of the multi-scale transformer blocks.
- The “models” directory hosts the implementation of the primary model (PathFormer). This sits atop the layered components and constitutes the core computation engine.

- Experimentation:
- The “exp” folder holds experiment scripts (exp_basic.py, exp_main.py) which define how the model is trained, evaluated, and experimented with.
- The “scripts” directory (with its multivariate bash scripts) shows how different experiment configurations are run, each targeting specific datasets (e.g., ETTh, traffic, weather).

- Utility Functions & Tools:
- The “utils” directory includes functions for decomposition, masking, metrics, time features, and other tools to support the main processing pipeline.

- Entry Point & Configuration:
- “run.py” serves as the starting point to launch the application or experiments, and “requirements.txt” lists the external Python dependencies needed by the system.

- Experiment Results & Visuals:

##### Relationships and Data Flow
- Data flows from external sources (datasets placed under ./dataset) to the Data Provider modules which load and pre-process the input.
- Pre-processed data is then passed into the model—where the “layers” modules implement the transformer’s multi-scale characteristics—and processed by the “models” implementation (PathFormer).
- The output from the model is utilized by the experiment scripts in “exp” or triggered via “run.py” for training/inference.
- Utility modules support every stage, providing essential functions for data transformation, metrics calculation, and evaluation.
- Bash scripts in “scripts/multivariate” automate experiments on different datasets, thereby interfacing with “run.py” and configuration files.

##### Key Architectural Patterns and Technologies
- Modular Design: Each functional part (layers, models, utils) is organized into its own directory ensuring easy extensibility and isolated development.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Entry & Configuration
    subgraph "Entry & Config"
        entry_run("run.py"):::entry
        entry_req("requirements.txt"):::entry
    end

    %% External Data Source
    external_data("External Dataset"):::external

    %% Data Input & Preprocessing
    subgraph "Data Input & Preprocessing"
        dp("Data Provider"):::data
        dp_factory("Data Factory"):::data
        dp_loader("Data Loader"):::data
    end

    %% Model Architecture & Core Layers
    subgraph "Model Architecture & Core Layers"
        subgraph "Transformer Layers"
            layers_AMS("AMS"):::layers
            layers_Embedding("Embedding"):::layers
            layers_Layer("Layer"):::layers
            layers_RevIN("RevIN"):::layers
        end
        model_PathFormer("PathFormer"):::model
    end

    %% Experimentation
    subgraph "Experimentation"
        exp_basic("exp_basic"):::experiment
        exp_main("exp_main"):::experiment
        scripts_multi("Multivariate Scripts"):::experiment
    end

    %% Utility Functions & Tools
    subgraph "Utility Functions & Tools"
        utils_decomp("Decomposition"):::utility
        utils_mask("Masking"):::utility
        utils_metrics("Metrics"):::utility
        utils_time("Time Features"):::utility
        utils_tools("Tools"):::utility
        utils_other("Other"):::utility
    end

    %% Experiment Results & Visuals
    figs("Figures"):::figs

    %% Connections
    entry_run --> dp
    entry_req --> entry_run
    external_data --> dp

    dp --> dp_factory
    dp --> dp_loader

    dp -->|"sends data"| layers_AMS
    dp -->|"sends data"| layers_Embedding
    dp -->|"sends data"| layers_Layer
    dp -->|"sends data"| layers_RevIN

    layers_AMS --> model_PathFormer
    layers_Embedding --> model_PathFormer
    layers_Layer --> model_PathFormer
    layers_RevIN --> model_PathFormer

    model_PathFormer --> exp_basic
    model_PathFormer --> exp_main
    model_PathFormer --> scripts_multi

    exp_basic --> figs
    exp_main --> figs
    scripts_multi --> figs

    entry_run --> exp_basic
    entry_run --> exp_main
    entry_run --> scripts_multi

    %% Dotted support from Utilities
    dp --- utils_decomp
    dp --- utils_mask
    dp --- utils_metrics
    dp --- utils_time
    dp --- utils_tools
    dp --- utils_other

    model_PathFormer --- utils_decomp
    model_PathFormer --- utils_mask
    model_PathFormer --- utils_metrics
    model_PathFormer --- utils_time
    model_PathFormer --- utils_tools
    model_PathFormer --- utils_other

    exp_basic --- utils_decomp
    exp_basic --- utils_mask
    exp_basic --- utils_metrics
    exp_basic --- utils_time
    exp_basic --- utils_tools
    exp_basic --- utils_other

    %% Click Events
    click dp "https://github.com/decisionintelligence/pathformer/tree/main/data_provider/"
    click dp_factory "https://github.com/decisionintelligence/pathformer/blob/main/data_provider/data_factory.py"
    click dp_loader "https://github.com/decisionintelligence/pathformer/blob/main/data_provider/data_loader.py"
    click layers_AMS "https://github.com/decisionintelligence/pathformer/blob/main/layers/AMS.py"
    click layers_Embedding "https://github.com/decisionintelligence/pathformer/blob/main/layers/Embedding.py"
    click layers_Layer "https://github.com/decisionintelligence/pathformer/blob/main/layers/Layer.py"
    click layers_RevIN "https://github.com/decisionintelligence/pathformer/blob/main/layers/RevIN.py"
    click model_PathFormer "https://github.com/decisionintelligence/pathformer/blob/main/models/PathFormer.py"
    click exp_basic "https://github.com/decisionintelligence/pathformer/blob/main/exp/exp_basic.py"
    click exp_main "https://github.com/decisionintelligence/pathformer/blob/main/exp/exp_main.py"
    click scripts_multi "https://github.com/decisionintelligence/pathformer/tree/main/scripts/multivariate/"
    click utils_decomp "https://github.com/decisionintelligence/pathformer/blob/main/utils/decomposition.py"
    click utils_mask "https://github.com/decisionintelligence/pathformer/blob/main/utils/masking.py"
    click utils_metrics "https://github.com/decisionintelligence/pathformer/blob/main/utils/metrics.py"
    click utils_time "https://github.com/decisionintelligence/pathformer/blob/main/utils/timefeatures.py"
    click utils_tools "https://github.com/decisionintelligence/pathformer/blob/main/utils/tools.py"
    click utils_other "https://github.com/decisionintelligence/pathformer/blob/main/utils/Other.py"
    click entry_run "https://github.com/decisionintelligence/pathformer/blob/main/run.py"
    click entry_req "https://github.com/decisionintelligence/pathformer/blob/main/requirements.txt"
    click figs "https://github.com/decisionintelligence/pathformer/tree/main/figs/"

    %% Styles
    classDef external fill:#ffcccb,stroke:#333,stroke-width:2px
    classDef data fill:#add8e6,stroke:#333,stroke-width:2px
    classDef layers fill:#90ee90,stroke:#333,stroke-width:2px
    classDef model fill:#98fb98,stroke:#333,stroke-width:2px
    classDef experiment fill:#ffa500,stroke:#333,stroke-width:2px
    classDef utility fill:#d3d3d3,stroke:#333,stroke-width:2px
    classDef entry fill:#f0e68c,stroke:#333,stroke-width:2px
    classDef figs fill:#ffdead,stroke:#333,stroke-width:2px
```
