Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CGM_Forecasting

Environment Setup

We recommend using Conda to create the base environment and pip to install project-specific dependencies.

Step 1: Create Conda environment

conda env create -f environment.yml
conda activate cgm-fusion

Step 2: Install Python packages via pip

pip install -r requirements.txt

Some experiments use the TimesFM model. Please follow the official installation instructions provided by the authors:

https://github.com/google-research/timesfm

Data Cleaning

Model Comparison Data

The datasets we used in this project are all publicly available. Below are the links to access them:

Please store the data as follows, then use ./Data/preprocessing.R to do the preprocessing. The processed data will be stored in ./Data/CleanedData/merged_5min.parquet and ./Data/CleanedData/merged_demo.csv.

RawData/
├── Anderson_2016/
│   ├── Case Report Forms/
│   ├── Data Tables/
│   ├── APP Outpt Pilot CTR Protocol.pdf
│   └── ReadMe.rtf
├── Brown_2019/
│   ├── Case Report Forms/
│   ├── Data Files/
│   ├── Participant Questionnaires/
│   ├── DCLP3_Clinical_Protocol_Pivotal_Study_v10.0_5_NOV_2018.pdf
│   └── ReadMe.rtf
├── CGMacros_2025/
│   ├── CGMacros-001/
│   ├── ...
│   ├── CGMacros-049/
│   ├── bio.xlsx
│   ├── gut_health_test.xlsx
│   └── microbes.xlsx
├── Colas_2019/
│   └── S1/
├── Hall_2018/
│   ├── pbio.2005143.s010
│   └── pbio.2005143.s014
├── Lynch_2022/
│   ├── CRFs/
│   ├── Data Tables/
│   ├── Data Tables in SAS/
│   ├── DataGlossary.rtf
│   ├── IOBP_PIVOTAL_PROTOCOL_V8.5_26JAN2021.pdf
│   └── IOBP2 Dataset ReadMe.rtf
└── Shah_2019/
    ├── NonDiabBaselineComp.xlsx
    ├── NonDiabDeviceBGM.xlsx
    ├── NonDiabDeviceCGM.xlsx
    ├── NonDiabDeviceIssue.xlsx
    ├── NonDiabDiabTannerStaging.xlsx
    ├── NonDiabFollowUpComp.xlsx
    ├── NonDiabMedication.xlsx
    ├── NonDiabParticipantLogs.xlsx
    ├── NonDiabPreExistingCondition.xlsx
    ├── NonDiabPtFinalStatus.xlsx
    ├── NonDiabPtRoster.xlsx
    ├── NonDiabSampleResults.xlsx
    ├── NonDiabScreening.xlsx
    ├── NonDiabVisitInfo.xlsx
    ├── ReadMe.rtf
    └── T1DX CRFs.pdf

CGMacros Data for Multimodal Experiment

conda activate cgm-fusion
python ./Data/CGMacros_preprocessing.py

CGMacros Multimodal Data

This repository contains a script CGMacros_GetAnalysisData.py, which is a fully reproducible, end-to-end data preparation pipeline for the CGMacros multimodal glucose forecasting experiments.

The script performs (in order):

  1. Download checkpoints from Hugging Face (ConvNeXT finetuned on Food101 + Chronos checkpoint).
  2. Compute image embeddings for CGMacros meal photos:
    • Category-supervised ConvNeXT embedding
    • Nutrition-aligned ConvNeXT embedding
  3. Optional UMAP reduction on image embeddings (1024 → 8 dims, in-place CSV update).
  4. Build wide analysis datasets (train/val + test) with sliding windows, and merge modalities.
  5. Extract Chronos-Bolt embeddings from CGM context windows and write final parquet files.

Data Layout

CGMacros_clean/
├── CGMacros-001/
│   ├── photos/
│   │   ├── *.jpg
│   │   ├── *.png
│   │   └── *.jpeg
│   └── CGMacros-001_images_only.csv
│
├── CGMacros-002/
│   ├── photos/
│   │   └── *.jpg
│   └── CGMacros-002_images_only.csv
│
├── ...
│
├── CGMacros-049/
│   ├── photos/
│   │   └── *.jpg
│   └── CGMacros-049_images_only.csv
│
├── CGMacros_gl_hr_5min_long.csv
└── bio.csv
  • photos/ contains meal images aligned to CGM timestamps.
  • {CGMacros-XXX}_images_only.csv contains per-image metadata, including meal type and macronutrients.
  • CGMacros_gl_hr_5min_long.csv contains the full longitudinal CGM time series with train/val/test split labels.
  • bio.csv contains subject-level demographic and clinical variables.

Quick Start

# Run with defaults
python ./Data/CGMacros_GetAnalysisData.py
# Override paths
python ./Data/CGMacros_GetAnalysisData.py \
  --cleaned-folder /path/to/CGMacros_clean \
  --output-folder  /path/to/output \
  --classes-txt    /path/to/classes.txt

Outputs

All outputs are written to --output-folder:

  • Image feature CSVs

    • Category_supervised.csv
    • Nutrition_aligned.csv
  • Multimodal datasets

    • CategoryLabel_dataset_train.parquet
    • CategoryLabel_dataset_test.parquet
    • NutritionAligned_dataset_train.parquet
    • NutritionAligned_dataset_test.parquet
  • Logs

    • CGMacros_GetAnalysisData.log

Model Comparison (CGM-only Forecasting)

FoundationModels folder contains code and results for the CGM-Only Forecasting Performance of Foundation Time-Series Models (and baseline methods).

The goal of this part is to provide a systematic and fair benchmarking of classical statistical models, deep learning baselines, and pretrained time-series foundation models under a unified evaluation framework.

All models are evaluated on the same preprocessed CGM datasets, sliding-window formulation, and train / validation / test splits.

Models Included

The following model families are implemented:

Classical and Statistical Baselines

  • LOCF (Last Observation Carried Forward)
  • ARIMA
  • Elastic Net regression (enet.qmd)

Deep Learning Baselines

  • LSTM (lstm.ipynb)
  • PatchTST (patchtst.ipynb)

Pretrained / Foundation Models

  • Chronos (chronos.ipynb: Bolt-Tiny, Bolt-Mini, and Chronos2 results are obtained by changing the model preset and hyperparameter file under FoundationModels/hyperparams/.)
  • TimesFM (timesfm.ipynb)

Each model operates on CGM-only inputs and predicts future glucose values over fixed forecasting horizons.


Directory Structure

FoundationModels/
├── Results/              # Saved evaluation results (metrics, summaries)
├── hyperparams/          # Model-specific hyperparameter configurations
│
├── sliding_window.py     # Sliding window construction and dataset utilities
├── evaluate.py           # Unified evaluation logic and metrics computation
│
├── locf_arima.ipynb      # LOCF and ARIMA baselines
├── enet.qmd              # Elastic Net regression
├── lstm.ipynb            # LSTM-based CGM encoder
├── patchtst.ipynb        # PatchTST implementation
├── chronos.ipynb         # Chronos pretrained foundation model
├── timesfm.ipynb         # TimesFM pretrained model

Multimodal Experiments

All multimodal results can be reproduced by running run_across_seeds.py, which loads model definitions from fusion_model.py and hyperparameters from multimodal_hp.json, and aggregates results across multiple random seeds.


Due to data use agreements associated with the public CGM datasets, we do not redistribute processed data; hyperparameter tuning was performed offline and is computationally intensive, and the reported results use fixed configurations, so tuning code is not included but are available upon request.

About

Evaluating Time-Series Foundation Models and Multimodal Dietary Context for CGM Forecasting

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages