5D Library › Two-Process Sleep Architecture, Slow-Wave Glymphatic Clearance and Thermoregulatory Phase Control · 中文
Chapter 1. Sleep Pressure, the Clock, and What Caffeine Actually Does
Two processes
The two-process model is the simplest account of when we sleep that still makes quantitative predictions (Borbély 1982; Daan et al. 1984). A homeostatic Process S rises while we are awake and falls while we sleep; its best-known marker is the slow-wave activity of the electroencephalogram in non-REM sleep, which is high after long waking and decays across the night. A circadian Process C, generated by the suprachiasmatic nucleus, sets two thresholds that rise and fall over 24 hours. Sleep begins when S reaches the upper threshold and ends when it falls to the lower one. Forty years of work have refined the model without overturning its structure (Borbély et al. 2016).
Calculation
The equations used. Awake, approaches 1 exponentially with time constant : . Asleep, it decays toward 0 with : . The thresholds are and . The program uses the classical illustrative time constants, 18.2 h and 4.2 h; is dimensionless.
Calculation
# Chapter 1. Borbely's two-process model. Process S (sleep pressure) rises
# toward 1 while awake with time constant TAU_R and decays toward 0 while
# asleep with TAU_D. Process C sets two thresholds that oscillate over 24 h:
# sleep starts when S reaches the upper one, waking happens when S falls to
# the lower one. Parameters are the classical illustrative values (time
# constants 18.2 h and 4.2 h); S is dimensionless. Time step 1 minute; t = 0
# is midnight.
import math
TAU_R, TAU_D = 18.2, 4.2
# thresholds and their peak hour
H0, L0, AMP, PHASE = 0.67, 0.17, 0.10, 16.0
DT = 1.0 / 60
def thr(t, base):
return base + AMP * math.cos(2 * math.pi * (t - PHASE) / 24.0)
def run(days, no_sleep=None, s0=0.25, t0=7.0):
"""Simulate; returns list of (sleep_on, sleep_off, S_at_onset, area under
S asleep)."""
t, S, asleep = t0, s0, False
bouts, cur = [], None
while t < t0 + 24 * days:
if asleep:
S *= math.exp(-DT / TAU_D)
cur[3] += S * DT
if S <= thr(t, L0):
asleep = False
cur[1] = t
bouts.append(tuple(cur))
else:
S = 1 - (1 - S) * math.exp(-DT / TAU_R)
can_sleep = no_sleep is None or not (
no_sleep[0] <= t < no_sleep[1]
)
if S >= thr(t, H0) and can_sleep:
asleep = True
cur = [t, None, S, 0.0]
t += DT
return bouts
def clock(h):
h = h % 24
return "{:02d}:{:02d}".format(int(h), int(round((h - int(h)) * 60)) % 60)
if __name__ == "__main__":
b = run(10)
on, off, s_on, area = b[-1]
print("A. Entrained day (after 10 simulated days)")
print(
" sleep {} -> {} duration {:.2f} h\n S at onset {:.3f} S at"
" waking {:.3f}".format(
clock(on), clock(off), off - on, s_on, thr(off, L0)
)
)
base_dur, base_area = off - on, area
print("\nB. One night of total sleep deprivation, then recovery")
for extra in (0, 8, 16, 24):
bb = run(12, no_sleep=(on - 1, on + extra) if extra else None)
rec = [x for x in bb if x[0] >= on + extra - 0.5][0]
print(
" kept awake {:>2} h past usual bedtime: recovery sleep {} ->"
" {},\n {:.2f} h (x {:.2f} usual), S at onset {:.3f},"
" slow-wave proxy x {:.2f}".format(
extra,
clock(rec[0]),
clock(rec[1]),
rec[1] - rec[0],
(rec[1] - rec[0]) / base_dur,
rec[2],
rec[3] / base_area,
)
)
print(
"\nReading: hours of sleep lost are not repaid hour for hour."
" Recovery sleep"
)
print(
"is longer only modestly; most of the repayment is in intensity"
" (higher S at"
)
print(
"onset, more slow-wave activity), and the clock (Process C) ends it"
" on time."
)
# A. Entrained day (after 10 simulated days)
# sleep 23:27 -> 07:08 duration 7.68 h
# S at onset 0.633 S at waking 0.102
#
# B. One night of total sleep deprivation, then recovery
# kept awake 0 h past usual bedtime: recovery sleep 23:27 -> 07:08,
# 7.68 h (x 1.00 usual), S at onset 0.633, slow-wave proxy x 1.00
# kept awake 8 h past usual bedtime: recovery sleep 07:27 -> 12:29,
# 5.03 h (x 0.66 usual), S at onset 0.764, slow-wave proxy x 1.00
# kept awake 16 h past usual bedtime: recovery sleep 15:27 -> 22:37,
# 7.17 h (x 0.93 usual), S at onset 0.848, slow-wave proxy x 1.30
# kept awake 24 h past usual bedtime: recovery sleep 23:27 -> 07:58,
# 8.52 h (x 1.11 usual), S at onset 0.902, slow-wave proxy x 1.47
#
# Reading: hours of sleep lost are not repaid hour for hour. Recovery sleep
# is longer only modestly; most of the repayment is in intensity (higher S at
# onset, more slow-wave activity), and the clock (Process C) ends it on time.Section A shows the entrained day: sleep from 23:27 to 07:08, 7.68 hours, beginning when pressure reaches 0.633. Section B is the result most people get wrong. Keep the sleeper awake past the usual bedtime and the lost hours are not repaid hour for hour. Kept awake 8 hours, the recovery sleep falls in the morning and is shorter than usual — 5.03 hours, 0.66 of normal — because the circadian threshold ends it. Kept awake a full extra day, recovery sleep is only 1.11 times as long as usual, but the pressure at onset is 0.902 instead of 0.633 and the slow-wave proxy is 1.47 times normal. The repayment is mostly in intensity, not duration.
Evidence
What is known about recovery. The finding that sleep after deprivation is deeper rather than proportionally longer, with slow-wave activity rising with prior waking, is the empirical core of the model (Borbély 1982; Daan et al. 1984; Borbély et al. 2016). The program’s numbers are the model’s, not measurements of any person.
Adenosine and caffeine
What carries Process S in the brain is not settled, but adenosine is the leading candidate: in cats, extracellular adenosine in the basal forebrain rose during prolonged waking and fell during recovery sleep (Porkka-Heiskanen et al. 1997). Caffeine blocks adenosine receptors. It is a non-selective antagonist at A1 and A2A receptors (Fredholm et al. 1999), and in mice its wake-promoting effect depends on A2A rather than A1 receptors (Huang et al. 2005).
A competitive antagonist does not remove the agonist; it occupies some of the receptors the agonist would have used. So the model writes the share of receptors occupied by adenosine as and takes felt sleepiness to follow that share. Caffeine is expressed in units of its own dissociation constant; no doses are implied anywhere in this book.
Calculation
# Chapter 1. Caffeine as a competitive antagonist at adenosine receptors.
# Adenosine (proportional to Process S) and caffeine compete for the same
# receptor; the share of receptors occupied by adenosine is
# occ = A / (A + KA x (1 + C / KC)) (competitive binding)
# Felt sleepiness is taken to follow occ, not A. Caffeine follows
# one-compartment elimination with half-life 3 h ("fast") or 8 h ("slow");
# concentrations are expressed in units of KC, with a peak of 2.0 KC one hour
# after intake. No doses are implied. The two-process model of p01 supplies A;
# slow-wave activity in the first three hours of sleep is taken, as a working
# hypothesis, to scale with adenosine occupancy.
import math
TAU_R, TAU_D = 18.2, 4.2
KA = 0.5
PEAK = 2.0
def caffeine(t, intake, half):
if t < intake:
return 0.0
k = math.log(2) / half
ka = 3.0 # absorption rate per hour (fast)
# Bateman function scaled so the peak is about PEAK
raw = (math.exp(-k * (t - intake)) - math.exp(-ka * (t - intake)))
tmax = math.log(ka / k) / (ka - k)
rmax = math.exp(-k * tmax) - math.exp(-ka * tmax)
return PEAK * raw / rmax
def occ(A, C):
return A / (A + KA * (1 + C))
def S_awake(hours_awake, s_wake=0.10):
return 1 - (1 - s_wake) * math.exp(-hours_awake / TAU_R)
if __name__ == "__main__":
wake, bed = 7.0, 23.0
A_bed = S_awake(bed - wake)
print(
"A. Adenosine pressure at 23:00 is the same with or without caffeine:"
)
print(" S = {:.3f}".format(A_bed))
print(
" felt pressure (occupancy) at 23:00, by intake time and half-life"
)
print(
" intake half-life caffeine left at 23:00 (x KC) occupancy "
" vs none"
)
base = occ(A_bed, 0.0)
for intake in (8.0, 14.0, 17.0):
for half in (3.0, 8.0):
c = caffeine(bed, intake, half)
o = occ(A_bed, c)
print(
" {:02d}:00 {:3.0f} h {:6.3f} "
" {:.3f} {:5.1%}".format(
int(intake), half, c, o, o / base - 1
)
)
print(
" no caffeine {:.3f}"
.format(base)
)
print(
"\nB. Working hypothesis: slow-wave activity over the first 3 h of"
" sleep"
)
print(
" scales with adenosine occupancy. Predicted change vs no caffeine:"
)
for intake in (8.0, 14.0, 17.0):
row = []
for half in (3.0, 8.0):
tot = tot0 = 0.0
for i in range(180):
t = bed + i / 60
A = A_bed * math.exp(-(i / 60) / TAU_D)
tot += occ(A, caffeine(t, intake, half))
tot0 += occ(A, 0.0)
row.append(tot / tot0 - 1)
print(
" intake {:02d}:00 fast (3 h) {:+6.1%} slow (8 h) {:+6.1%}"
.format(int(intake), *row)
)
print(
"\nC. After an 08:00 intake (3 h half-life): felt pressure climbs"
" faster as"
)
print(
" caffeine clears, because the masked pressure is unmasked on"
" top of"
)
print(" the rise")
print(
" time adenosine S felt felt without rise of felt over 2 h"
)
print(" caffeine (with / without)")
prev = None
for h in (9, 11, 13, 15, 17, 19):
A = S_awake(h - wake)
f, f0 = occ(A, caffeine(h, 8.0, 3.0)), occ(A, 0.0)
rise = (
""
if prev is None
else "{:+.3f} / {:+.3f}".format(f - prev[0], f0 - prev[1])
)
print(
" {:02d}:00 {:.3f} {:.3f} {:.3f} {}"
.format(
h, A, f, f0, rise
).rstrip()
)
prev = (f, f0)
print(
"\nReading: caffeine lowers how much of the pressure is felt, not the"
" pressure."
)
print(
"As it clears, the full accumulated pressure is felt again; the"
" slower the"
)
print(
"clearance, the more of it is still masking adenosine when sleep"
" begins."
)
# A. Adenosine pressure at 23:00 is the same with or without caffeine:
# S = 0.626
# felt pressure (occupancy) at 23:00, by intake time and half-life
# intake half-life caffeine left at 23:00 (x KC) occupancy vs none
# 08:00 3 h 0.084 0.536 -3.6%
# 08:00 8 h 0.624 0.435 -21.7%
# 14:00 3 h 0.335 0.484 -13.0%
# 14:00 8 h 1.049 0.379 -31.8%
# 17:00 3 h 0.671 0.428 -22.9%
# 17:00 8 h 1.361 0.347 -37.7%
# no caffeine 0.556
#
# B. Working hypothesis: slow-wave activity over the first 3 h of sleep
# scales with adenosine occupancy. Predicted change vs no caffeine:
# intake 08:00 fast (3 h) -3.1% slow (8 h) -22.5%
# intake 14:00 fast (3 h) -11.3% slow (8 h) -32.8%
# intake 17:00 fast (3 h) -20.3% slow (8 h) -38.7%
#
# C. After an 08:00 intake (3 h half-life): felt pressure climbs faster as
# caffeine clears, because the masked pressure is unmasked on top of
# the rise
# time adenosine S felt felt without rise of felt over 2 h
# caffeine (with / without)
# 09:00 0.194 0.114 0.279
# 11:00 0.278 0.192 0.357 +0.077 / +0.078
# 13:00 0.353 0.277 0.414 +0.085 / +0.057
# 15:00 0.420 0.354 0.457 +0.078 / +0.043
# 17:00 0.480 0.418 0.490 +0.064 / +0.033
# 19:00 0.535 0.469 0.517 +0.050 / +0.027
#
# Reading: caffeine lowers how much of the pressure is felt, not the pressure.
# As it clears, the full accumulated pressure is felt again; the slower the
# clearance, the more of it is still masking adenosine when sleep begins.Section A states the point plainly: at 23:00 adenosine pressure is 0.626 whatever was drunk that day. What changes is how much of it is felt. With a three-hour half-life, a morning intake leaves almost nothing at bedtime (−3.6 % felt pressure). With an eight-hour half-life the same morning intake still masks −21.7 % of it, and an intake at 17:00 masks −37.7 %.
Section B turns this into a prediction about the first three hours of sleep, under the stated working hypothesis that slow-wave activity scales with adenosine occupancy: −3.1 % for a fast metaboliser after a morning intake, −22.5 % for a slow one; −20.3 % and −38.7 % after an intake at 17:00. Half-life matters more than timing alone: a slow metaboliser’s 08:00 intake does about as much as a fast metaboliser’s 17:00 intake.
Section C is the “crash”. Caffeine lowers felt pressure, but the pressure keeps accumulating underneath. As caffeine clears, the masked pressure is unmasked on top of the ongoing rise, so felt pressure climbs faster than it would have without caffeine: between 13:00 and 15:00, by +0.078 against +0.043.
Evidence
What is known about caffeine and sleep. The elimination half-life of caffeine varies several-fold between healthy adults; smoking shortens it, and pregnancy and some medicines, including oral contraceptives, lengthen it, with genetic variation in the liver enzyme CYP1A2 contributing (Nehlig 2018). Caffeine taken in the morning has been shown to affect that night’s sleep and its EEG spectrum (Landolt et al. 1995), and in a controlled study caffeine taken even six hours before bedtime measurably reduced sleep (Drake et al. 2013).
Hypothesis · not established
The author’s hypothesis (not established): among adults with the same habitual intake time, the reduction in slow-wave activity over the first sleep cycle after an afternoon caffeine intake is larger in slower metabolisers, and the size of the reduction is predicted better by estimated residual caffeine at lights-out than by the clock time of intake. What would show it to be wrong: no relation between estimated residual caffeine and the change in slow-wave activity, or a relation explained by intake time alone.
Summary
In the two-process model, sleep pressure rises while awake and falls while asleep, and a circadian clock sets the levels at which sleep starts and stops. Lost sleep is repaid mainly in intensity: a full extra day awake lengthens recovery sleep by about a tenth but raises the pressure at onset and the slow-wave proxy by about half, and sleeping in the morning after a missed night gives a short sleep because the clock ends it. Caffeine, a competitive antagonist, does not remove adenosine; it lowers the share that is felt, and that share returns — faster than it would have — as caffeine clears. How much is still masked at bedtime depends on the half-life at least as much as on the time of the last cup.
References
Fan, Y. (2026). Two-Process Sleep Architecture, Slow-Wave Glymphatic Clearance and Thermoregulatory Phase Control: Adenosine Homeostasis, Flip-Flop Switch Bistability, Core-Distal Heat Flux and Sleep-Stage Markov Chains [双过程睡眠架构、慢波胶质淋巴清除与体温节律相位控制] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090162 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).