# zlhe0/transfusion architecture

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

- Interactive diagram: https://gitdiagram.com/zlhe0/transfusion
- Repository: https://github.com/zlhe0/transfusion

## Overview

Step 1: Identify the Project Type and Purpose
- R-based research code for high-dimensional regression under covariate shift.
- Implements TransFusion (centralized) and D-TransFusion (distributed) algorithms plus baseline methods.
- Generates synthetic data, runs experiments, and produces publication figures.

Step 2: Analyze the File Structure
- src/
– data_generation.R (creates simulated datasets)
– transfusion_algorithm.R (TransFusion & D-TransFusion implementations)
– baseline_algorithm.R (baseline methods)
– utils.R (shared helper functions)
- run_transfusion_exp.R (driver for centralized experiments, Figure 1)
- run_dtransfusion_exp.R (driver for distributed experiments, Figure 2)
- README.md, .DS_Store

Step 3: Main Components and Relationships
##### Orchestrator Scripts
- Source modules, configure parameters, coordinate the pipeline.
##### Data Generation Module
- Produces synthetic covariate-shifted datasets.
##### Algorithm Engine
- TransFusion & D-TransFusion implementations.
- Baseline methods implementation.
##### Utility Library
- Data splitting, metric computations, logging.
##### Visualization
- ggplot2 for generating figures.
##### External Dependencies
- glmnet, MASS, parallel for model fitting and distributed execution.

Data Flow:
Orchestrator → DataGen → synthetic data → Algorithm Engine (↔ Utils) → results → Orchestrator → ggplot2 → figures.
D-TransFusion branch: Orchestrator ↔ parallel workers (one-round communication) → aggregated estimates.

Step 4: Architectural Patterns & Technologies
- Pipeline Pattern: linear flow from data generation to visualization.
- Modular Separation: clear boundaries between data, algorithms, utils, and orchestrator.
- Master-Worker Pattern: for D-TransFusion using the parallel package.
- R Packages: highlight where glmnet (model fitting), MASS (data), ggplot2 (plotting), parallel (distributed) are loaded.

Step 5: Diagramming Guidelines
– Light blue: Data Generation
– Green: Algorithms (TransFusion & Baselines)
– Teal: Utility Library
– Orange: Orchestrator Scripts
– Gray: External Libraries & Packages

Step 6: Tailoring to This Codebase
- That this is a batch-processing research pipeline, not a web or service-oriented system.
- Which R packages each module loads to clarify dependencies.

Step 7: Detail and Clarity
- Number the flow steps (①→②→③…) to guide the reader.
- Keep labels concise but include file names for traceability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Orchestrator Scripts"
        O1[/run_transfusion_exp.R/]:::orchestrator
        O2[/run_dtransfusion_exp.R/]:::orchestrator
    end

    DataGen["Data Generation\nsrc/data_generation.R"]:::datagen

    subgraph "Algorithm Engine"
        Alg1["TransFusion & D-TransFusion\nsrc/transfusion_algorithm.R"]:::algo
        Alg2["Baseline Methods\nsrc/baseline_algorithm.R"]:::algo
    end

    Utils["Utility Library\nsrc/utils.R"]:::utils

    Results[(Results Data)]:::data

    Visualization[/ggplot2: Figures/]:::visual

    subgraph "D-TransFusion Master-Worker"
        MW1[Master]:::algo
        subgraph Workers
            W1[Worker1]:::algo
            W2[WorkerN]:::algo
        end
    end

    External["External Packages:\nglmnet, MASS, ggplot2, parallel"]:::external

    %% Data Flow
    O1 -->|"① generate_data()"| DataGen
    O2 -->|"① generate_data()"| DataGen

    DataGen -->|"② simulated data"| Alg1
    DataGen -->|"② simulated data"| Alg2

    Alg1 <-->|"uses"| Utils
    Alg2 <-->|"uses"| Utils

    O2 --> MW1
    MW1 -->|"one-round sync"| Alg1
    MW1 -->|"gathers estimates"| Results

    Alg1 -->|"results"| Results
    Alg2 -->|"results"| Results

    Results -->|"③ collate & plot"| Visualization

    %% External Dependencies
    External -.-> DataGen
    External -.-> Alg1
    External -.-> Alg2
    External -.-> Visualization
    External -.-> MW1

    %% Click Events
    click O1 "https://github.com/zlhe0/transfusion/blob/main/run_transfusion_exp.R"
    click O2 "https://github.com/zlhe0/transfusion/blob/main/run_dtransfusion_exp.R"
    click DataGen "https://github.com/zlhe0/transfusion/blob/main/src/data_generation.R"
    click Alg1 "https://github.com/zlhe0/transfusion/blob/main/src/transfusion_algorithm.R"
    click Alg2 "https://github.com/zlhe0/transfusion/blob/main/src/baseline_algorithm.R"
    click Utils "https://github.com/zlhe0/transfusion/blob/main/src/utils.R"

    %% Styles
    classDef orchestrator fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef datagen fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef algo fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef utils fill:#20B2AA,stroke:#333,stroke-width:1px;
    classDef data fill:#ffffff,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef visual fill:#ffffff,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
