# maxxu05/relcon architecture

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

- Interactive diagram: https://gitdiagram.com/maxxu05/relcon
- Repository: https://github.com/maxxu05/relcon

## Overview

##### Project Type and Purpose
- This is a self-supervised machine-learning pipeline for wearable accelerometry data.
- It comprises two sequential training stages (MotifDist distance measure, then RelCon foundation model) plus downstream evaluation on public benchmarks.

A. Orchestration Layer
– run_exp.py
– experiment configs (relcon/experiments/configs/*.py)
– setup.py, env.yml

B. Data Ingestion & Preprocessing
– relcon/data/process/
- process_dummydataset.py (synthetic pre-training dataset)
- process_comparepriorpt_datasets.py (Opportunity, PAMAP2)
- process_comparesslbench_datasets.py (HHAR, Motionsense)
– relcon/data/Base_Dataset.py
– relcon/utils/datasets.py

C. Distance-Measure Training (“MotifDist” stage)
– models/MotifDist/MotifDist_Model.py
– nets/CrossAttn/CrossAttn_Net.py (+ utils: DilatedConv, RevIN, functional_mod)
– experiments/configs/MotifDist_expconfigs.py

D. Foundation Model Training (“RelCon” stage)
– models/RelCon/RelCon_Model.py
– nets/ResNet1D/ResNet1D_Net.py (+ blocks)
– experiments/configs/RelCon_expconfigs.py

E. Evaluation Pipeline
– relcon/eval/Base_Eval.py
– relcon/eval/Classify/ (linear_probe.py, MLP_probe.py, MLP_finetune.py)

F. Utilities
– relcon/utils/{gpu.py, imports.py, utils.py}

##### Important Architectural Patterns
- Modular, config-driven pipeline: All experiment parameters live in Python dicts under experiments/configs/.
- Separation of concerns:
– Data layer (relcon/data/)
– Model definitions (relcon/models/)
– Network backbones (relcon/nets/)
– Evaluation (relcon/eval/)
- Class-based structure: Base classes provide common functionality (Base_Dataset, Base_Model, Base_Nets, Base_Eval).

##### Detail Level
- Shared utilities only once and connect to all modules that import them.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Orchestration Layer"
        OR1["run_exp.py"]:::orchestration
        OR2["setup.py"]:::orchestration
        OR3["env.yml"]:::orchestration
        OR4["MotifDist_expconfigs.py"]:::orchestration
        OR5["RelCon_expconfigs.py"]:::orchestration
    end

    subgraph "Data Ingestion & Preprocessing"
        EXTSRC["External Sources\n(Opportunity / PAMAP2 / HHAR / Motionsense)"]:::external
        D1["Base_Dataset.py"]:::data
        D2["process_dummydataset.py"]:::data
        D3["process_comparepriorpt_datasets.py"]:::data
        D4["process_comparesslbench_datasets.py"]:::data
        D5["datasets.py"]:::data
    end

    subgraph "MotifDist Stage (Distance Training)"
        M1["MotifDist_Model.py"]:::training
        M2["CrossAttn_Net.py"]:::training
        M3["DilatedConv.py"]:::training
        M4["RevIN.py"]:::training
        M5["functional_mod.py"]:::training
    end

    subgraph "RelCon Stage (Foundation Training)"
        R1["RelCon_Model.py"]:::training
        R2["ResNet1D_Net.py"]:::training
        R3["blocks.py"]:::training
    end

    subgraph "Evaluation Pipeline"
        E1["Base_Eval.py"]:::evaluation
        E2["linear_probe.py"]:::evaluation
        E3["MLP_probe.py"]:::evaluation
        E4["MLP_finetune.py"]:::evaluation
    end

    subgraph "Utilities"
        U1["gpu.py"]:::utility
        U2["imports.py"]:::utility
        U3["utils.py"]:::utility
        U4["figs/"]:::utility
    end

    %% Data flow and control flow
    OR1 -->|"triggers preprocessing"| D1
    OR1 --> D2
    OR1 --> D3
    OR1 --> D4
    EXTSRC -->|"raw data"| D2
    EXTSRC --> D3
    EXTSRC --> D4
    D1 -->|"cleaned datasets"| M1
    D2 --> M1
    D3 --> M1
    D4 --> M1

    OR4 -.->|"config"| M1
    M1 -->|"trained checkpoint"| R1
    OR5 -.->|"config"| R1
    D1 --> R1
    D2 --> R1
    D3 --> R1
    D4 --> R1
    M1 -->|"frozen distance model"| R1

    R1 -->|"trained embeddings"| E2
    D1 --> E2
    D2 --> E2
    D3 --> E2
    D4 --> E2
    OR1 -->|"launch evaluation"| E1
    E1 --> E2
    E1 --> E3
    E1 --> E4

    %% Utilities connections
    U1 --- M1
    U1 --- R1
    U1 --- E1
    U2 --- M1
    U2 --- R1
    U2 --- E1
    U3 --- M1
    U3 --- R1
    U3 --- E1

    %% Click events
    click OR1 "https://github.com/maxxu05/relcon/blob/main/run_exp.py"
    click OR2 "https://github.com/maxxu05/relcon/blob/main/setup.py"
    click OR3 "https://github.com/maxxu05/relcon/blob/main/env.yml"
    click OR4 "https://github.com/maxxu05/relcon/blob/main/relcon/experiments/configs/MotifDist_expconfigs.py"
    click OR5 "https://github.com/maxxu05/relcon/blob/main/relcon/experiments/configs/RelCon_expconfigs.py"
    click D1 "https://github.com/maxxu05/relcon/blob/main/relcon/data/Base_Dataset.py"
    click D2 "https://github.com/maxxu05/relcon/blob/main/relcon/data/process/process_dummydataset.py"
    click D3 "https://github.com/maxxu05/relcon/blob/main/relcon/data/process/process_comparepriorpt_datasets.py"
    click D4 "https://github.com/maxxu05/relcon/blob/main/relcon/data/process/process_comparesslbench_datasets.py"
    click D5 "https://github.com/maxxu05/relcon/blob/main/relcon/utils/datasets.py"
    click M1 "https://github.com/maxxu05/relcon/blob/main/relcon/models/MotifDist/MotifDist_Model.py"
    click M2 "https://github.com/maxxu05/relcon/blob/main/relcon/nets/CrossAttn/CrossAttn_Net.py"
    click M3 "https://github.com/maxxu05/relcon/blob/main/relcon/nets/CrossAttn/utils/DilatedConv.py"
    click M4 "https://github.com/maxxu05/relcon/blob/main/relcon/nets/CrossAttn/utils/RevIN.py"
    click M5 "https://github.com/maxxu05/relcon/blob/main/relcon/nets/CrossAttn/utils/functional_mod.py"
    click R1 "https://github.com/maxxu05/relcon/blob/main/relcon/models/RelCon/RelCon_Model.py"
    click R2 "https://github.com/maxxu05/relcon/blob/main/relcon/nets/ResNet1D/ResNet1D_Net.py"
    click R3 "https://github.com/maxxu05/relcon/blob/main/relcon/nets/ResNet1D/utils/blocks.py"
    click E1 "https://github.com/maxxu05/relcon/blob/main/relcon/eval/Base_Eval.py"
    click E2 "https://github.com/maxxu05/relcon/blob/main/relcon/eval/Classify/linear_probe.py"
    click E3 "https://github.com/maxxu05/relcon/blob/main/relcon/eval/Classify/MLP_probe.py"
    click E4 "https://github.com/maxxu05/relcon/blob/main/relcon/eval/Classify/MLP_finetune.py"
    click U1 "https://github.com/maxxu05/relcon/blob/main/relcon/utils/gpu.py"
    click U2 "https://github.com/maxxu05/relcon/blob/main/relcon/utils/imports.py"
    click U3 "https://github.com/maxxu05/relcon/blob/main/relcon/utils/utils.py"
    click U4 "https://github.com/maxxu05/relcon/tree/main/figs/"

    %% Styles
    classDef orchestration fill:#dddddd,stroke:#888888,stroke-width:1px
    classDef data fill:#cce5ff,stroke:#4da3ff,stroke-width:1px
    classDef training fill:#d4edda,stroke:#28a745,stroke-width:1px
    classDef evaluation fill:#fff3cd,stroke:#ffcd39,stroke-width:1px
    classDef utility fill:#f0f0f0,stroke:#aaaaaa,stroke-width:1px
    classDef external fill:#f8d7da,stroke:#e55353,stroke-width:1px,stroke-dasharray: 4 2
```
