Skip to content

PFun CMA Model

A physiofunctional chronometabolic model implementation (numerical inference for glucose, stress hormones, circadian time series).


What is PFun CMA?

The PFun CMA Model is a generative physiological model that functionally replicates neuroendocrine dynamics — specifically the interplay between cortisol, melatonin, and adiponectin — and their influence on glucose metabolism across the circadian cycle.

In simple terms

  • 🗜 Phase-based dimensionality reduction — Compress weeks or months of CGM time-series data into a compact phase vector (≥ 1024b in memory).
  • 🕮 Interpretable & Quantifiable — Translate between qualitative states ("mood", "stress") and biophysical neuroendocrine dynamics ("cortisol levels", "glucose variability").
  • 🕒 High-speed circadian mapping — Understand how circadian rhythm maps to glucose values in real time.

Generated CMA Decomposition

The model decomposes glucose time series data into underlying hormonal influences:

Generated Cortisol-Melatonin-Adiponectin decomposition from Glucose time series

The CMA model leverages physiological modeling principles to decompose glucose time series data into underlying hormonal influences — specifically cortisol, melatonin, and adiponectin.


Model Fitting

Fit the CMA model to real CGM data and extract clinically meaningful parameters:

24-hour fit result — blue is model, red is data

After fitting, visualize parameters with automatically generated qualitative descriptions:

Fit result with qualitative descriptions


Live Demos

LLM-Powered Scenario Generation

Generate realistic physiological scenarios using natural language prompts. The LLM translates qualitative descriptions into physiologically valid CMA parameters:

LLM Generate Scenario Demo

LLM Scenario with recommendations


Real-time WebSocket Streaming

Interactive parameter control with live chart updates via WebSocket:

WebSocket streaming demo

WebSocket demo with sliders


Parameter Grid Visualization

Explore the CMA parameter space with precomputed grids:

CMA parameter grid visualization


Quick Start

# Install
pip install pfun-cma-model
# — or with uv —
uv add pfun-cma-model

# Run a quick model fit
uv run pfun-cma-model fit-model --plot

# Generate a scenario via LLM
uv run pfun-cma-model generate-scenario \
  --query "a healthy individual who exercises before sunrise"

# Launch the full dev server
uv run fastapi dev pfun_cma_model/app.py --port 8001

→ Full installation guide


Project Architecture

pfun-cma-model/
├── pfun_cma_model/          # Core Python package
│   ├── engine/              # CMA model, fit, grid, plotting
│   ├── routes/              # FastAPI route handlers
│   ├── llm.py               # LLM prompting logic
│   ├── cli.py               # Click CLI commands
│   └── security.py          # Security middleware
├── examples/
│   ├── notebooks/           # Jupyter notebooks
│   ├── screenshots/         # Application screenshots
│   └── videos/              # Demo recordings
├── docs/                    # This documentation (Zensical)
├── tests/                   # Test suite
└── results/                 # Output artifacts & databases

Resource Link
:material-web: Homepage pfun.one
:material-play-circle: Live Demo PFun Health Tips
:material-github: Source Code pfun-health/pfun-cma-model