# Requirements
1. Setup conda environment `conda env create -f environment.yml`
2. Activate environment `conda activate bridge`

# Repository structure
```
bridge_code
├── bash_scripts                              (bash scripts for reproducing experiments)
├── dataset_preprocessing                     (preprocessing code for WESAD and ISRUC)
├── ECG_Classification_anonymous              (source code from ECG traditional model ECG-DualNet)
├── ECG_FM_anonymous                          (source code from ECG foundation model ECG-FM)
├── HuBERT_ECG_anonymous                      (source code from ECG foundation model HuBERT-ECG)
├── LaBraM_anonymous                          (source code from EEG foundation model LaBraM)
├── papagei_anonymous                         (source code from PPG foundation model PaPaGei)
├── bridge_position_selector_utils.py         (helper tools for calculating CKA)
├── bridge_position_selector.py               (bridge position selection code)
├── environment.yml                           (configuration for building conda environment)
├── train_bridge.py                           (main code for training bridge, storing features, evaluating)
└── utils.py                                  (helper tools for main code)
```

# Data Preprocessing
1. Download WESAD https://ubi29.informatik.uni-siegen.de/usi/data_wesad.html
2. Download FOG https://data.mendeley.com/datasets/r8gmbtv7w2/3
3. Download ISRUC https://sleeptight.isr.uc.pt/?page_id=48
4. Go to data preprocessing directory `cd dataset_preprocessing`
5. Update `wesad_path` in `make_WESAD.py` and `fog_path` in `make_FOG.py` and `isruc_path` in `make_ISRUC.py`
6. Preprocess WESAD `python make_WESAD.py` and FOG `python make_FOG.py` and ISRUC `python make_ISRUC.py`

# Download foundation model checkpoints
1. Download `labram-base.pth` to `LaBraM_anonymous/checkpoints/` from https://github.com/935963004/LaBraM/tree/main/checkpoints
2. Download `hubert_ecg_small.pt` to `HuBERT_ECG_anonymous/code/checkpoint/` from https://huggingface.co/Edoardo-BS/HuBERT-ECG-SSL-Pretrained/tree/main
3. Download `papagei_s.pt` to `papagei_anonymous/weights/` from https://zenodo.org/records/13983110
4. Download `normwear_last_checkpoint-15470-correct.pth` to `NormWear_anonymous` from https://github.com/Mobile-Sensing-and-UbiComp-Laboratory/NormWear/releases/tag/v1.0.0-alpha

# Experiments
1. Linear probe `bash bash_scripts/linear_probe.sh`
2. Prepare for bridge position selection `bash bash_scripts/bridge_position_selection.sh`
3. Select bridge position `python bridge_position_selector.py`
4. Train bridge `bash bash_scripts/train_bridge.sh`

# Note
1. All logs will be stored under `/users/anonymous/bridge`
2. All checkpoints will be stored under `/data/anonymous/bridge/`
3. All source code folders from other models are cloned directly from their repository.