# tamu-esp/ring_bp_python architecture

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

- Interactive diagram: https://gitdiagram.com/tamu-esp/ring_bp_python
- Repository: https://github.com/tamu-esp/ring_bp_python

## Overview

##### Project type and purpose
- This is a data-science/ML pipeline in Python for building Bio-impedance (Bio-Z) to blood-pressure (BP) regression models.
- It ingests precomputed features and BP values (in a MATLAB .mat file), performs windowed averaging, and runs two modeling workflows: a subject-specific regression and a leave-one-subject-out regression.

##### File structure
Top-level files and scripts:
- Feature_and_BP_Subject_Data.mat – Input data store (features + BP labels)
- window_average.py – Preprocessing step (sliding-window averaging)
- subject_specific_regression.py – Workflow #1: Train/evaluate per-subject models
- leave_subjects_out_regression.py – Workflow #2: Cross-subject “leave‐one‐out” evaluation
- README.md – Project description, dependencies, usage instructions

##### README for additional insights
- Dependencies: numpy, pandas, tensorflow, scipy, matplotlib, seaborn, sklearn
- Usage commands show a linear pipeline: preprocessing + modeling + evaluation + plotting

A. Data Ingestion
B. Preprocessing Module
- window_average.py (rectangle)
- Takes raw data ➔ produces window-averaged features
C. Modeling Workflows (two parallel pipelines)
1. Subject-Specific Regression (rectangle)
- Reads preprocessed features
- Uses TensorFlow / scikit-learn to train per-subject models
- Outputs performance metrics & plots
2. Leave-Subjects-Out Regression (rectangle)
- Iteratively leaves one subject’s data out for testing
- Trains on remaining subjects
- Reports cross-validation metrics & plots
D. Visualization & Reporting
- matplotlib / seaborn modules embedded in each workflow
- Outputs: error distributions, scatter plots, summary tables

##### Relationships and data flow
1. Data Store ➔ Preprocessing
2. Preprocessing ➔ Subject-Specific Regression
3. Preprocessing ➔ Leave-Subjects-Out Regression
4. Each Regression Module ➔ Visualization & Reporting

##### Architectural patterns & design principles
- Single pipeline with two parallel experiment tracks
- ELT pattern: Extract (load .mat), Load (in memory), Transform (window_average)
- Modular scripts for separation of concerns (preprocessing vs. modeling vs. evaluation)
- Reproducibility: each script can be run independently with the same inputs

##### Technologies & frameworks
- Python 3.x
- Data handling: numpy, pandas, scipy (.mat file via scipy.io)
- Modeling: TensorFlow 2.7.0, scikit-learn 1.1.3
- Visualization: matplotlib 3.3.4, seaborn 0.11.1

##### Essential elements to capture
- Data source (.mat)
- Preprocessing step (window_average.py)
- Two modeling experiments (subject_specific_regression.py and leave_subjects_out_regression.py)
- Visualization/reporting step
- External library dependencies

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Ingestion
    DataStore["Feature_and_BP_Subject_Data.mat"]:::data

    %% Preprocessing Module
    Preprocess["window_average.py"]:::process

    %% Modeling Workflows
    subgraph "Modeling" 
        SS["subject_specific_regression.py"]:::process
        LO["leave_subjects_out_regression.py"]:::process
    end

    %% Visualization & Reporting Outputs
    SS_Out["Subject-Specific: metrics & plots"]:::output
    LO_Out["Leave-One-Out: metrics & plots"]:::output

    %% Data Flow
    DataStore -->|"raw features + BP labels"| Preprocess
    Preprocess -->|"window-averaged features + BP labels"| SS
    Preprocess -->|"window-averaged features + BP labels"| LO
    SS -->|"generate metrics & plots"| SS_Out
    LO -->|"generate metrics & plots"| LO_Out

    %% Click Events
    click DataStore "https://github.com/tamu-esp/ring_bp_python/blob/main/Feature_and_BP_Subject_Data.mat"
    click Preprocess "https://github.com/tamu-esp/ring_bp_python/blob/main/window_average.py"
    click SS "https://github.com/tamu-esp/ring_bp_python/blob/main/subject_specific_regression.py"
    click LO "https://github.com/tamu-esp/ring_bp_python/blob/main/leave_subjects_out_regression.py"

    %% Styles
    classDef data fill:#a6cee3,stroke:#1f78b4,color:#1f78b4;
    classDef process fill:#b2df8a,stroke:#33a02c,color:#33a02c;
    classDef output fill:#fb9a99,stroke:#e31a1c,color:#e31a1c;
```
