# cardio-ai/funavg architecture

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

- Interactive diagram: https://gitdiagram.com/cardio-ai/funavg
- Repository: https://github.com/cardio-ai/funavg

## Overview

##### Project Type Analysis
This is a machine learning research project, specifically a federated learning implementation with a focus on handling diverse label distributions across different clients. The project appears to be implemented in Python, with several key computational and visualization components.

##### Main Components

a) Client-Side Components:
- Individual Data Repositories
- Local Segmentation Heads
- Uncertainty Estimation Module
- Local Training Process

b) Federation Components:
- Backbone Model (shared)
- Federated Averaging Mechanism
- Uncertainty-Weighted Averaging System

c) Evaluation and Visualization Components:
- Calibration System
- Uncertainty Visualization
- Method Visualization

##### Key Files Integration
How the following files contribute to the architecture:
- fed_trainer.py → Federation control
- condistfl.py → Conditional distribution handling
- transforms.py → Data transformation pipeline
- utils.py → Utility functions
- train.py → Training orchestration

##### Specific Elements to Highlight
- Uncertainty calculation flow
- Weighted averaging mechanism
- Bayesian techniques implementation
- Multi-label segmentation process

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style Definitions
    classDef client fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef federation fill:#90EE90,stroke:#333,stroke-width:2px
    classDef evaluation fill:#FFB366,stroke:#333,stroke-width:2px
    classDef data fill:#FFE5CC,stroke:#333,stroke-width:2px
    classDef process fill:#E6E6FA,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Client Components]:::client
        L2[Federation Components]:::federation
        L3[Evaluation Components]:::evaluation
        L4[Data Components]:::data
        L5[Process Components]:::process
    end

    %% Client Layer
    subgraph "Distributed Clients"
        Client1 --- ClientComponents1
        Client2 --- ClientComponents2
        Client3 --- ClientComponents3

        subgraph ClientComponents1
            D1[Local Dataset]:::data
            SH1[Local Segmentation Head]:::client
            U1[Uncertainty Estimation]:::client
            LT1[Local Training]:::process
        end

        subgraph ClientComponents2
            D2[Local Dataset]:::data
            SH2[Local Segmentation Head]:::client
            U2[Uncertainty Estimation]:::client
            LT2[Local Training]:::process
        end

        subgraph ClientComponents3
            D3[Local Dataset]:::data
            SH3[Local Segmentation Head]:::client
            U3[Uncertainty Estimation]:::client
            LT3[Local Training]:::process
        end
    end

    %% Federation Layer
    subgraph "Federation Layer"
        BB[Shared Backbone Model]:::federation
        FTC[Federated Training Controller]:::federation
        FAM[Federated Averaging Mechanism]:::federation
        CDH[Conditional Distribution Handler]:::federation
        DTP[Data Transform Pipeline]:::federation
    end

    %% Evaluation Layer
    subgraph "Evaluation Layer"
        CS[Calibration System]:::evaluation
        LDV[Label Distribution Visualizer]:::evaluation
        UV[Uncertainty Visualization]:::evaluation
        MV[Method Visualization]:::evaluation
        ES[Evaluation System]:::evaluation
        TF[Testing Framework]:::evaluation
    end

    %% Connections
    ClientComponents1 --> BB
    ClientComponents2 --> BB
    ClientComponents3 --> BB
    BB --> FTC
    FTC --> FAM
    FAM --> CDH
    CDH --> DTP

    FTC --> CS
    CS --> LDV
    CS --> UV
    UV --> MV
    MV --> ES
    ES --> TF

    %% Click Events
    click LT1 "https://github.com/Cardio-AI/FUNAvg/blob/main/train.py"
    click FTC "https://github.com/Cardio-AI/FUNAvg/blob/main/fed_trainer.py"
    click FAM "https://github.com/Cardio-AI/FUNAvg/blob/main/aggregate.py"
    click CDH "https://github.com/Cardio-AI/FUNAvg/blob/main/condistfl.py"
    click DTP "https://github.com/Cardio-AI/FUNAvg/blob/main/transforms.py"
    click U1,U2,U3 "https://github.com/Cardio-AI/FUNAvg/blob/main/utils.py"
    click CS "https://github.com/Cardio-AI/FUNAvg/blob/main/calibration.ipynb"
    click LDV "https://github.com/Cardio-AI/FUNAvg/blob/main/visualize_label_distribution.ipynb"
    click UV "https://github.com/Cardio-AI/FUNAvg/blob/main/visualize_uncertainty.ipynb"
    click MV "https://github.com/Cardio-AI/FUNAvg/blob/main/visualize_method.ipynb"
    click ES "https://github.com/Cardio-AI/FUNAvg/blob/main/eval.ipynb"
    click TF "https://github.com/Cardio-AI/FUNAvg/blob/main/test.py"
```
