# mulplue/mgf architecture

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

- Interactive diagram: https://gitdiagram.com/mulplue/mgf
- Repository: https://github.com/mulplue/mgf

## Overview

##### Project Overview and Purpose
- The project implements “MGF: Mixed Gaussian Flow for Diverse Trajectory Prediction,” a deep learning model (based on PyTorch) aimed at predicting diverse trajectories. The goal is to offer a robust inference and training pipeline for trajectory prediction across various scenes like eth, hotel, univ, zara1, zara2, and sdd.
- The README confirms this is a research implementation (accepted to Neurips’24) and notes its similarity or extension to the FlowChain codebase.

##### Main Components
a. Data Layer
- Raw Data Repository: Represent the various raw data folders under src/data/TP/raw_data corresponding to different scenes (eth, hotel, etc.). This includes test/train/val splits.
- Data Processing/Preprocessing: Include “process_data.py”, “preprocessing.py”, and components in the environment (e.g., data_structures.py, data_utils.py, map.py) that help structure and prepare the data.
- Data Loader: Show components like unified_loader.py and dataset-specific logic (e.g., trajectron_dataset.py) which transform raw files into input formats for models.

b. Configuration and Checkpoints
- Config Files: A “config” directory with separate YAML files for each scene. These files set the parameters for training and evaluation.
- Checkpoints: The “checkpoint” folder holds pre-trained clustering checkpoints (e.g., eth.ckpt, hotel.ckpt, etc.) that are likely used for the clustering portion of the architecture.

c. Model Components
- Core Trajectory Prediction Models: Represent “src/models/TP” with various architectures such as TFCondARFlow, Trajectron, fastpredNF, and mgcvae.
- Sub-components of the models: Under components, illustrate elements like additive_attention, discrete_latent, graph_attention, and map_encoder. Also include the dynamics components (linear, single_integrator, unicycle, etc.) which handle motion modeling.

d. Training and Evaluation
- Training Pipeline: Represent the training script (src/train.py) which connects configurations, model instantiation, and data processing, showing the training flow into the model.
- Inference/Evaluation: Show the evaluation script (src/test.py) for running inference, along with the metric components (in the src/metrics directory) that compute ADE, FDE, etc. Mark the directional flow from trained model outputs to metric calculation.

e. Utility and Supporting Components
- Utility Functions: Group “src/utils/common.py” and any other helper functions or miscellaneous modules that support training and model evaluation.
- External Dependencies: Mention that the project uses PyTorch (as indicated by the paper and overall implementation), and include references to other libraries from the requirements.txt.

##### Relationships and Interactions
- Inference: Show how trained models (along with applied clustering) generate predictions that are then evaluated by the “Metrics” component.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize the separation of concerns with distinct modules for data handling, model definitions, training utilities, and evaluation.
- Pipeline Pattern: The overall flow (from raw data → processing → training/inference → evaluation) is critical and should be highlighted.
- Integration of Clustering: The system cleverly integrates a clustering mechanism (via pre-trained KMeans models) as an intermediate processing step to aid in prediction diversity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        rData["Raw Data Repository"]:::storage
        subgraph "Data Preprocessing"
            pd["Process Data.py"]:::process
            pp["Preprocessing.py"]:::process
            ds["Data Structures.py"]:::process
            du["Data Utils.py"]:::process
            mp["Map.py"]:::process
            pd --> pp --> ds --> du --> mp
        end
        subgraph "Data Loader"
            ul["Unified Loader.py"]:::process
            td["Trajectron Dataset.py"]:::process
            ul --> td
        end
        rData --> pd
        mp --> ul
    end

    %% Configuration and Checkpoints
    subgraph "Configuration & Checkpoints"
        cfg["Config Files (YAML)"]:::storage
        ckpt["Checkpoints"]:::storage
    end

    %% Model Components
    subgraph "Model Components"
        cm["Core Trajectory Models"]:::process
        subgraph "Model Sub-components"
            comp["Components"]:::process
            dyn["Dynamics"]:::process
            comp --> dyn
        end
        clust["Clustering Components"]:::process
    end

    %% Training & Evaluation
    subgraph "Training & Evaluation"
        train["Training Pipeline"]:::process
        subgraph "Inference & Evaluation"
            test["Test Script.py"]:::process
            met["Metrics"]:::process
            test --> met
        end
    end

    %% Utilities
    subgraph "Utilities"
        util["Utility Functions"]:::utility
        pt["PyTorch"]:::external
    end

    %% Connections between major components
    td --> train
    cfg --> train
    train --> cm
    train --> comp
    train --> clust
    cm --> test
    comp --> test
    clust --> test
    cfg --> test
    ckpt --> test
    util -.-> train
    util -.-> test
    pt -.-> cm

    %% Click Events for Data Layer
    click rData "https://github.com/mulplue/mgf/tree/main/src/data/TP/raw_data"
    click pd "https://github.com/mulplue/mgf/blob/main/src/data/TP/process_data.py"
    click pp "https://github.com/mulplue/mgf/blob/main/src/data/TP/preprocessing.py"
    click ds "https://github.com/mulplue/mgf/blob/main/src/data/TP/environment/data_structures.py"
    click du "https://github.com/mulplue/mgf/blob/main/src/data/TP/environment/data_utils.py"
    click mp "https://github.com/mulplue/mgf/blob/main/src/data/TP/environment/map.py"
    click ul "https://github.com/mulplue/mgf/blob/main/src/data/unified_loader.py"
    click td "https://github.com/mulplue/mgf/blob/main/src/data/TP/trajectron_dataset.py"

    %% Click Events for Configuration and Checkpoints
    click cfg "https://github.com/mulplue/mgf/tree/main/config"
    click ckpt "https://github.com/mulplue/mgf/tree/main/checkpoint"

    %% Click Events for Model Components
    click cm "https://github.com/mulplue/mgf/tree/main/src/models/TP"
    click comp "https://github.com/mulplue/mgf/tree/main/src/models/TP/components"
    click dyn "https://github.com/mulplue/mgf/tree/main/src/models/TP/dynamics"
    click clust "https://github.com/mulplue/mgf/tree/main/src/clustering"

    %% Click Events for Training & Evaluation
    click train "https://github.com/mulplue/mgf/blob/main/src/train.py"
    click test "https://github.com/mulplue/mgf/blob/main/src/test.py"
    click met "https://github.com/mulplue/mgf/tree/main/src/metrics"

    %% Click Event for Utilities
    click util "https://github.com/mulplue/mgf/blob/main/src/utils/common.py"

    %% Styles
    classDef storage fill:#ffe0b2,stroke:#f57c00,stroke-width:2px;
    classDef process fill:#bbdefb,stroke:#1976d2,stroke-width:2px;
    classDef external fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef utility fill:#d1c4e9,stroke:#7b1fa2,stroke-width:2px;
```
