# tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery architecture

> Architecture diagram of the GitHub repository tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery
- Repository: https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery

## Overview

##### Project Type and Purpose
- This is a research-oriented machine learning pipeline for sleep stage classification using non-invasive signals (thermal imagery, flow, ribcage) as an alternative to EEG/EOG/EMG.

##### File Structure Analysis
- Top-level:
- BetterModels/ – the main Python package
– dataprocessor/ (dataloader.py, dataset.py, preprocessor.py, featurizer.py)
– models/ (implementations: InceptionTime, RandomForests, XGboost, biLSTM_CNN, transformer)
– utils/ (crossvalidation.py, metrics.py, traintest.py)
– visualizations/ (plots.py)
- dataset/files/ – raw input files (REC, EDF, stage annotations)
- ConvTran.py, Transformer architecture/transformer.py, boosting.ipynb, model*.ipynb – experiment drivers and notebooks
- requirements.txt – dependencies
- Architectural pattern: a staged, modular ML pipeline (ingest → preprocess → feature extraction → modeling → evaluation → visualization).

##### README Insights
- Methodology sections confirm the pipeline stages:
a. Preprocessing (normalization, smoothing)
b. Feature Extraction (TSFEL, CNN embeddings, handcrafted)
c. Modeling (Random Forests, XGBoost, BiLSTM, Transformer)
d. Evaluation (accuracy, specificity across class counts)
- Dependencies implied: Python scientific stack (pandas, numpy, scipy, TSFEL), ML frameworks (scikit-learn, xgboost, PyTorch or TensorFlow), plotting (matplotlib, seaborn).

a. Main Components
- Raw Data Store (dataset/files)
- Data Ingestion Layer (dataloader.py, dataset.py)
- Preprocessing Module (preprocessor.py: normalization, smoothing)
- Feature Engineering Module (featurizer.py: TSFEL, handcrafted, CNN-based)
- Model Training & Inference Layer (models/: RandomForests, XGBoost, biLSTM_CNN, Transformer)
- Evaluation & Validation Module (utils: traintest.py, crossvalidation.py, metrics.py)
- Visualization Layer (visualizations/plots.py, notebooks, Result images/)
b. Relationships and Data Flow
- Branching: Feature Engineering outputs feed into multiple model types in parallel.
- Feedback loop: Evaluation metrics may influence hyperparameter tuning in preprocessing or feature stages.
c. Architectural Patterns & Principles
- Modularity: each pipeline stage is its own package/submodule
- Pluggability: models and feature extractors can be swapped without rewiring the pipeline
- Separation of concerns: data, logic, visualization, and experiments are isolated
d. Key Technologies & Frameworks
- Python, pandas, NumPy, SciPy, TSFEL
- scikit-learn, xgboost
- PyTorch or TensorFlow (for BiLSTM, Transformer, CNN)
- Matplotlib/Seaborn for plots

##### Key Advice
- Pipeline stage as a separate node.
- How modules plug into one another without over-collapsing components.
- Both batch training and interactive notebook-driven experimentation.
- Artifacts (Result images folder) as the final output node.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    RawData(("Raw Data Store")):::dataLayers
    click RawData "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/tree/master/dataset/files/"

    subgraph "Data Ingestion Layer"
        direction TB
        Dataloader["dataloader.py"]:::dataLayers
        DatasetModule["dataset.py"]:::dataLayers
    end
    click Dataloader "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/dataprocessor/dataloader.py"
    click DatasetModule "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/dataprocessor/dataset.py"

    Preprocessor["preprocessor.py"]:::dataLayers
    click Preprocessor "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/dataprocessor/preprocessor.py"

    FeatureEng["featurizer.py"]:::feature
    click FeatureEng "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/dataprocessor/featurizer.py"

    %% Modeling Layer
    subgraph "Model Training & Inference" 
        direction TB
        subgraph "Random Forests" 
            RFMain["RandomForests.py"]:::model
            RFEEG["RF_EEG.py"]:::model
            RFSpO2["RF_SpO2.py"]:::model
        end
        subgraph "XGBoost"
            XGMain["XGboost.py"]:::model
            XGFeatures["XG_boost_features.py"]:::model
            XGEEG["XGboost_EEG.py"]:::model
            XGSpO2["XGboost_SpO2.py"]:::model
        end
        biLSTM["biLSTM_CNN.py"]:::model
        Inception["InceptionTime.py"]:::model
        subgraph "Transformer"
            TransformerMain["transformer.py"]:::model
            TransformerArch["Transformer architecture"]:::model
        end
    end
    click RFMain "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/RandomForests.py"
    click RFEEG "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/RandomForests/RF_EEG.py"
    click RFSpO2 "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/RandomForests/RF_SpO2.py"
    click XGMain "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/XGboost.py"
    click XGFeatures "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/XGboost/XG_boost_features.py"
    click XGEEG "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/XGboost/XGboost_EEG.py"
    click XGSpO2 "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/XGboost/XGboost_SpO2.py"
    click biLSTM "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/biLSTM_CNN.py"
    click Inception "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/InceptionTime.py"
    click TransformerMain "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/transformer.py"
    click TransformerArch "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/Transformer architecture/transformer.py"

    %% Evaluation & Visualization
    subgraph "Evaluation & Validation" 
        direction TB
        CrossVal["crossvalidation.py"]:::evalviz
        Metrics["metrics.py"]:::evalviz
        TrainTest["traintest.py"]:::evalviz
    end
    click CrossVal "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/utils/crossvalidation.py"
    click Metrics "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/utils/metrics.py"
    click TrainTest "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/utils/traintest.py"

    subgraph "Visualization Layer"
        direction TB
        Plots["plots.py"]:::evalviz
        ResultImages(("Result Images")):::evalviz
    end
    click Plots "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/visualizations/plots.py"
    click ResultImages "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/tree/master/Result images/"

    %% Orchestration
    subgraph "Experiment Orchestration & Notebooks"
        direction TB
        ConvScript["ConvTran.py"]:::orchestration
        ConvNB["ConvTran.ipynb"]:::orchestration
        BoostNB["boosting.ipynb"]:::orchestration
        ModelNB1["model.ipynb"]:::orchestration
        ModelNB2["model2.ipynb"]:::orchestration
        ModelCopyNB["model copy.ipynb"]:::orchestration
    end
    click ConvScript "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/ConvTran.py"
    click ConvNB "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/ConvTran.ipynb"
    click BoostNB "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/boosting.ipynb"
    click ModelNB1 "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/model.ipynb"
    click ModelNB2 "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/model2.ipynb"
    click ModelCopyNB "https://github.com/tanishy7777/sleep-stage-classification-using-non-invasive-signals-from-thermal-imagery/blob/master/BetterModels/models/model copy.ipynb"

    %% Data Flow
    RawData --> Dataloader --> DatasetModule --> Preprocessor --> FeatureEng
    FeatureEng --> RFMain
    FeatureEng --> XGMain
    FeatureEng --> biLSTM
    FeatureEng --> Inception
    FeatureEng --> TransformerMain

    RFMain --> CrossVal
    XGMain --> CrossVal
    biLSTM --> CrossVal
    Inception --> CrossVal
    TransformerMain --> CrossVal

    CrossVal --> Metrics --> TrainTest --> Plots --> ResultImages

    %% Orchestration flows
    ConvScript --> Dataloader
    ConvNB --> FeatureEng
    BoostNB --> XGMain
    ModelNB1 --> biLSTM
    ModelNB2 --> TransformerMain
    ModelCopyNB --> RFMain

    %% Styles
    classDef dataLayers fill:#ADD8E6,stroke:#000,color:#000
    classDef feature fill:#90EE90,stroke:#000,color:#000
    classDef model fill:#FFA500,stroke:#000,color:#000
    classDef evalviz fill:#DDA0DD,stroke:#000,color:#000
    classDef orchestration fill:#D3D3D3,stroke:#000,color:#000
```
