We recommend using Conda to create the base environment and pip to install project-specific dependencies.
conda env create -f environment.yml
conda activate cgm-fusionpip install -r requirements.txtSome experiments use the TimesFM model. Please follow the official installation instructions provided by the authors:
https://github.com/google-research/timesfm
The datasets we used in this project are all publicly available. Below are the links to access them:
- Anderson et al., Diabetes Care (2016). Multinational home use of closed-loop control is safe and effective. https://doi.org/10.2337/dc15-2468 (Link to data)
- Broll et al., PLOS ONE (2021). Interpreting blood GLUcose data with R package iglu. https://doi.org/10.1371/journal.pone.0248560 (Data is available in iglu package)
- Brown et al., NEJM (2019). Six-month randomized, multicenter trial of closed-loop control in type 1 diabetes. https://doi.org/10.1056/NEJMoa1907863 (Link to data)
- Colás et al., PLOS ONE (2019). Detrended Fluctuation Analysis in the prediction of type 2 diabetes mellitus in patients at risk: Model optimization and comparison with other metrics. https://doi.org/10.1371/journal.pone.0225817 (Link to data)
- Das et al., Scientific Data (2025). CGMacros: a pilot scientific dataset for personalized nutrition and diet monitoring. https://doi.org/10.1038/s41597-025-05851-7 (Link to data)
- Hall et al., PLOS Biology (2018). Glucotypes reveal new patterns of glucose dysregulation. https://doi.org/10.1371/journal.pbio.2005143 (Link to CGM data, Link to clinical variables)
- Lynch et al., Diabetes Technology & Therapeutics (2022). The insulin-only bionic pancreas pivotal trial extension study: A multi-center single-arm evaluation of the insulin-only configuration of the bionic pancreas in adults and youth with type 1 diabetes. https://doi.org/10.1089/dia.2022.0341 (Link to data)
- Shah et al., The Journal of Clinical Endocrinology & Metabolism (2019). Continuous glucose monitoring profiles in healthy nondiabetic participants: A multicenter prospective study. https://doi.org/10.1210/jc.2018-02763 (Link to data)
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
conda activate cgm-fusion
python ./Data/CGMacros_preprocessing.pyThis 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):
- Download checkpoints from Hugging Face (ConvNeXT finetuned on Food101 + Chronos checkpoint).
- Compute image embeddings for CGMacros meal photos:
- Category-supervised ConvNeXT embedding
- Nutrition-aligned ConvNeXT embedding
- Optional UMAP reduction on image embeddings (1024 → 8 dims, in-place CSV update).
- Build wide analysis datasets (train/val + test) with sliding windows, and merge modalities.
- Extract Chronos-Bolt embeddings from CGM context windows and write final parquet files.
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.csvcontains per-image metadata, including meal type and macronutrients.CGMacros_gl_hr_5min_long.csvcontains the full longitudinal CGM time series with train/val/test split labels.bio.csvcontains subject-level demographic and clinical variables.
# 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.txtAll 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
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.
The following model families are implemented:
- LOCF (Last Observation Carried Forward)
- ARIMA
- Elastic Net regression (
enet.qmd)
- LSTM (
lstm.ipynb) - PatchTST (
patchtst.ipynb)
- Chronos (
chronos.ipynb: Bolt-Tiny, Bolt-Mini, and Chronos2 results are obtained by changing the model preset and hyperparameter file underFoundationModels/hyperparams/.) - TimesFM (
timesfm.ipynb)
Each model operates on CGM-only inputs and predicts future glucose values over fixed forecasting horizons.
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
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.