# mocherson/medgcn architecture

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

- Interactive diagram: https://gitdiagram.com/mocherson/medgcn
- Repository: https://github.com/mocherson/medgcn

## Overview

##### Project Type & Purpose
- This is a research/experimental deep learning project implementing a graph convolutional network (GCN) for medical applications.
- The main experiments include tasks such as node classification (via nodeclassify.py) and link prediction (via linkpredict.py). The repository is structured to both load and preprocess medical data and then use that processed data to train/test graph neural network models.

##### File Structure & Mapping to Components
- Data Layer:
- The "data" directory contains CSV files (e.g., enc_date.csv, inter_enc_lab.csv, inter_enc_med.csv, inter_enc_pat.csv) which serve as raw input data for the experiments.
- These files represent the medical data inputs which the system interacts with.

- Preprocessing/Utility Layer:
- The "preparedata.py" script, along with modules under the "utility" directory (iofile.py, preprocessing.py, rank_metrics.py), indicates that there is a dedicated data preprocessing and metrics evaluation stage.
- This layer handles data cleaning, formatting, and computes evaluation metrics.

- Model & Architecture Layer:
- Files such as model.py, layers.py, inductive.py, and inits.py contribute to the definition and initialization of the GCN architecture.
- These modules encapsulate core parts of the neural network, including layer definitions, model initialization, and possibly both forward and backward passes for training.

- Experiment/Task Layer:
- The main experiment runners nodeclassify.py and linkpredict.py are entry points for executing specific tasks – node classification and link prediction experiments respectively.
- These scripts combine the data layer, preprocessing utilities, and model components to run end-to-end training and evaluation processes.

a. Main Components:
- Data Source: CSV files in the "data" folder.
- Data Preprocessing Module: "preparedata.py" and utility functions from "utility" (preprocessing, iofile).
- GCN Model and Initialization: "model.py", "layers.py", "inits.py", "inductive.py".
- Experiment Runner: Node Classification (nodeclassify.py), Link Prediction (linkpredict.py).
- Evaluation Module: "utility/rank_metrics.py" for performance metrics.

b. Relationships and Data Flow:
- From Data Preprocessing, data is fed into the GCN Model block (composed of model definitions and layer architectures).

c. Architectural Patterns and Key Technologies:
- That the project leverages PyTorch for model implementation and training.
- That the design follows a modular and layered approach: separating data handling, model construction, and experiment execution.
- That clear abstraction boundaries exist (data preprocessing vs. model layers vs. experiment code), which aids extensibility and debugging.

d. Relevant Technologies, Frameworks, and Libraries:
- PyTorch as the core NN framework.
- CSV-based data handling (could be implemented via Pandas or built-in CSV libraries, as implied by the data files and iofile.py utility).
- Custom graph convolution layers and inductive modules defined in the code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    DS["Data Storage (CSV files)"]:::data

    %% Data Preprocessing Module
    subgraph "Data Preprocessing Module"
      direction TB
      Prep1["preparedata.py"]:::preprocessing
      Prep2["utility/iofile.py"]:::preprocessing
      Prep3["utility/preprocessing.py"]:::preprocessing
    end

    %% GCN Model & Architecture
    subgraph "GCN Model & Architecture"
      direction TB
      M1["model.py"]:::model
      M2["layers.py"]:::model
      M3["inductive.py"]:::model
      M4["inits.py"]:::model
    end

    %% Experiment Runner Layer
    subgraph "Experiment Runners"
      direction TB
      E1["Node Classification (nodeclassify.py)"]:::experiment
      E2["Link Prediction (linkpredict.py)"]:::experiment
    end

    %% Evaluation Module
    EVAL["Evaluation Module (utility/rank_metrics.py)"]:::evaluation

    %% Data Flow Arrows
    DS -->|"raw_data"| Prep1
    Prep1 -->|"cleaned_data"| M1
    M1 -->|"run_experiment"| E1
    M1 -->|"run_experiment"| E2
    E1 -->|"compute_metrics"| EVAL
    E2 -->|"compute_metrics"| EVAL

    %% Click Events
    click DS "https://github.com/mocherson/medgcn/tree/master/data/"
    click Prep1 "https://github.com/mocherson/medgcn/blob/master/preparedata.py"
    click Prep2 "https://github.com/mocherson/medgcn/blob/master/utility/iofile.py"
    click Prep3 "https://github.com/mocherson/medgcn/blob/master/utility/preprocessing.py"
    click M1 "https://github.com/mocherson/medgcn/blob/master/model.py"
    click M2 "https://github.com/mocherson/medgcn/blob/master/layers.py"
    click M3 "https://github.com/mocherson/medgcn/blob/master/inductive.py"
    click M4 "https://github.com/mocherson/medgcn/blob/master/inits.py"
    click E1 "https://github.com/mocherson/medgcn/blob/master/nodeclassify.py"
    click E2 "https://github.com/mocherson/medgcn/blob/master/linkpredict.py"
    click EVAL "https://github.com/mocherson/medgcn/blob/master/utility/rank_metrics.py"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef preprocessing fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef model fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef experiment fill:#F08080,stroke:#000,stroke-width:2px;
    classDef evaluation fill:#FFD700,stroke:#000,stroke-width:2px;
```
