# eakeweje/gpmix architecture

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

- Interactive diagram: https://gitdiagram.com/eakeweje/gpmix
- Repository: https://github.com/eakeweje/gpmix

## Overview

##### Project type and purpose
- This is a Python-based open-source library and CLI tool for clustering functional data via mixtures of Gaussian processes.
- Core focus: load raw data, smooth into continuous curves, project onto random bases, learn univariate GMMs on each projection, then extract an ensemble consensus clustering.
- It also ships simulation scripts and YAML configuration for reproducing experiments.

##### File structure
- Top-level directories/files:
- CBF/                    ← example dataset (CBF_TRAIN.txt, CBF_TEST.txt)
- data_configs/           ← YAML files for simulation scenarios A–L
- GPmix/                  ← core Python package
– __init__.py
– smoother.py
– projector.py
– unigmm.py
– misc.py
- GPmix_Clustering.py    ← CLI entry point that reads a config and runs a pipeline
- simulations.py         ← orchestration script for all scenarios
- requirements.txt, LICENSE, README.md

##### Extract architectural insights from README
- Four sequential pipeline steps:
1. Smoothing (GPmix.Smoother)
2. Projection (GPmix.Projector)
3. GMM learning & ensemble (GPmix.UniGaussianMixtureEnsemble)
4. Consensus clustering & validation (misc.estimate_nclusters + plot/score methods)
- CLI uses data_configs/*.yml to parameterize scenario runs.
- Depends on NumPy, scikit-fda, pywt, scikit-learn, joblib, seaborn, PyYAML.

##### Main components
A. Data Ingestion & Configuration
- Raw data files (TXT, CSV)
- YAML config loader (PyYAML)
- CLI scripts (GPmix_Clustering.py, simulations.py)
B. Core Library Modules (GPmix package)
- Smoother: inputs raw array → outputs FDataGrid
- Projector: inputs FDataGrid → outputs projection coefficients
- UniGaussianMixtureEnsemble: inputs coefficients → outputs cluster labels
- misc.estimate_nclusters: inputs FDataGrid → outputs optimal k
C. External Dependencies
- Numeric & scientific libs (NumPy, SciPy, scikit-learn, scikit-fda, pywt, joblib)
D. Visualization & Validation
- Plot methods in Smoother, Projector, UniGaussianMixtureEnsemble
- Scoring methods: AMI, ARI, silhouette, Davis–Bouldin
E. Output Artifacts
- Clustered functional plots (PNG)
- Experiment logs & metrics
- Saved models or intermediate data (optional)

##### Relationships and data flow
1. CLI Script ← reads YAML config & selects dataset (CBF/ or simulation generator)
2. Smoother.fit ← raw data → FDataGrid
3. Projector.fit ← FDataGrid → projection coefficients (array)
4. UniGaussianMixtureEnsemble.fit_gmms ← coefficients → list of GMMs
5. get_clustering ← GMMs → final cluster labels
6. plot_clustering, plot_gmms, plot_projection_coeffs ← visual outputs
7. misc.estimate_nclusters can be invoked at step 4 to search k

##### Architectural patterns & design principles
- Modular pipeline: each step encapsulated in a class with fit/transform APIs
- “Estimator” pattern similar to scikit-learn (fit, transform, plot)
- Functional separation: data ingestion, processing, learning, ensemble, evaluation
- Config-driven experiments for reproducibility (YAML + CLI)
- Parallelization of GMM fitting via joblib

- [ ] All components drawn and labeled
- [ ] Data formats annotated on edges
- [ ] Clear separation between “Core Library” and “Orchestration Layer”
- [ ] Visual grouping of config files and datasets
- [ ] Notes on parallel GMM fitting and validation metrics

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Orchestration Layer
    subgraph "Orchestration Layer"
        CLI["GPmix_Clustering.py"]:::cli
        SIM["simulations.py"]:::cli
    end

    %% Data Ingestion & Configuration
    subgraph "Data Ingestion & Configuration"
        DB1[(CBF Dataset)]:::io
        TRAIN["CBF_TRAIN.txt"]:::io
        TEST["CBF_TEST.txt"]:::io
        DB2[(YAML Configs)]:::io
    end

    %% Core Library Modules
    subgraph "GPmix Package"
        INIT["__init__.py"]:::core
        SMO["Smoother.fit(X)"]:::core
        PROJ["Projector.fit(FDataGrid)"]:::core
        GMM["UniGaussianMixtureEnsemble.fit_gmms(coeffs)"]:::core
        MISC["misc.estimate_nclusters(FDataGrid)"]:::core
    end

    %% External Dependencies
    subgraph "External Dependencies"
        NP["NumPy"]:::ext
        SKF["scikit-fda"]:::ext
        SKL["scikit-learn"]:::ext
        PYWT["pywt"]:::ext
        JB["joblib"]:::ext
        YA["PyYAML"]:::ext
    end

    %% Outputs
    subgraph "Output Artifacts"
        PLOTS["Cluster Plots (PNG)"]:::output
        LOGS["Logs & Metrics"]:::output
        MODELS["Saved Models"]:::output
    end

    %% Data & Control Flow
    CLI -->|"reads config"| DB2
    CLI -->|"selects dataset"| DB1
    DB1 -->|"raw array (n×m)"| SMO
    CLI -->|"invokes pipeline"| SMO
    SMO -->|"FDataGrid"| PROJ
    PROJ -->|"coeffs (n_proj×n_samples)"| GMM
    PROJ -->|"FDataGrid"| MISC
    MISC -->|"optimal k"| GMM
    GMM -->|"cluster labels"| PLOTS
    GMM -->|"models"| MODELS
    PLOTS -->|"metrics"| LOGS
    SIM -->|"batch runs"| CLI

    %% Dependencies to Modules
    NP --> SMO
    SKF --> SMO
    SKL --> GMM
    SKL --> PROJ
    PYWT --> PROJ
    JB --> GMM
    YA --> CLI

    %% Click Events
    click DB1 "https://github.com/eakeweje/gpmix/tree/main/CBF/"
    click TRAIN "https://github.com/eakeweje/gpmix/blob/main/CBF/CBF_TRAIN.txt"
    click TEST "https://github.com/eakeweje/gpmix/blob/main/CBF/CBF_TEST.txt"
    click DB2 "https://github.com/eakeweje/gpmix/tree/main/data_configs/"
    click CLI "https://github.com/eakeweje/gpmix/blob/main/GPmix_Clustering.py"
    click SIM "https://github.com/eakeweje/gpmix/blob/main/simulations.py"
    click INIT "https://github.com/eakeweje/gpmix/blob/main/GPmix/__init__.py"
    click SMO "https://github.com/eakeweje/gpmix/blob/main/GPmix/smoother.py"
    click PROJ "https://github.com/eakeweje/gpmix/blob/main/GPmix/projector.py"
    click GMM "https://github.com/eakeweje/gpmix/blob/main/GPmix/unigmm.py"
    click MISC "https://github.com/eakeweje/gpmix/blob/main/GPmix/misc.py"
    click README "https://github.com/eakeweje/gpmix/blob/main/README.md"
    click LICENSE "https://github.com/eakeweje/gpmix/tree/main/LICENSE"
    click REQ "https://github.com/eakeweje/gpmix/blob/main/requirements.txt"

    %% Styles
    classDef core fill:#d0e1ff,stroke:#333,stroke-width:1px
    classDef io fill:#d1ffd1,stroke:#333,stroke-width:1px
    classDef cli fill:#ffe0b3,stroke:#333,stroke-width:1px
    classDef ext fill:#f3d1ff,stroke:#333,stroke-width:1px
    classDef output fill:#f2f2f2,stroke:#333,stroke-width:1px
```
