Beyond AI¶
The KAIROS engine (null model, singularity detector, forecastability horizon, capability-against-capacity gap) fits any system that can run away. This page shows two pieces that ship with the library.
Pandemic growth against health-system capacity¶
kairos.beyond.pandemic treats hospital occupancy as C(t) and beds as
H(t). The gap G = ln C − ln H reaches 0 on the day the system is
overwhelmed. The lead time uses the upper end of the recent growth
interval, the Jonas rule applied to an epidemic.
from kairos.beyond.pandemic import capacity_gap, simulate_sir
free = simulate_sir(45)
gap = capacity_gap(free, capacity=50_000)
print(f"dG/dt = {gap.velocity:.3f}/day, lead time = {gap.lead_time_days:.0f} days")
locked = simulate_sir(120, lockdown_day=40) # an intervention event bends the curve
COVID-19 in early 2020 is the historical test (K-9.05).
Critical slowing down: an optional fifth dial¶
Near a tipping point, systems recover from small shocks more slowly (Scheffer
et al., 2009). kairos.beyond.csd.csd_dial detrends a series, computes rolling
lag-1 autocorrelation and variance, and is in danger when both trend upward
(Kendall's tau above the configured threshold).
from kairos.beyond.csd import CSDConfig, csd_dial
dial = csd_dial(series, CSDConfig(window=0.5, bandwidth=0.1, tau_threshold=0.5))
print(dial.state, dial.tau_ar1, dial.tau_variance)
The fifth dial is off by default. It is not part of the AI tripwire levels; it is offered for climate, ecological and financial applications where the four AI dials have no direct analogue.
API¶
kairos.beyond.pandemic ¶
Pandemic growth against health-system capacity.
The epidemic analogue of the Jonas Gap: C(t) is hospital demand and
H(t) is the number of beds. G = ln C − ln H; G = 0 is the date the
system is overwhelmed. Lead time is how long until the upper growth scenario
reaches G = 0, which is the Collingridge window for a lockdown decision.
CapacityGap
dataclass
¶
Gap between hospital demand and capacity.
Attributes:
| Name | Type | Description |
|---|---|---|
gap |
FloatArray
|
|
velocity |
float
|
|
growth_low |
float
|
Lower bound of the recent log growth rate per day. |
growth_high |
float
|
Upper bound of the recent log growth rate per day. |
lead_time_days |
float
|
Days until |
simulate_sir ¶
simulate_sir(
days: int,
*,
population: float = 10000000.0,
beta: float = 0.3,
gamma: float = 0.1,
initial_infected: float = 10.0,
lockdown_day: int | None = None,
lockdown_factor: float = 0.4,
) -> FloatArray
Daily new infections from a discrete-time SIR model.
lockdown_day multiplies beta by lockdown_factor from that day on,
which is how an intervention event bends the curve.
capacity_gap ¶
capacity_gap(
infections: ArrayLike,
capacity: ArrayLike | float,
*,
hospital_rate: float = 0.05,
length_of_stay: int = 10,
window: int = 14,
z: float = 1.645,
) -> CapacityGap
Compare hospital occupancy implied by infections with capacity.
Occupancy is hospital_rate times the trailing length_of_stay-day sum
of infections. The growth interval is z standard errors around the slope
of ln occupancy over the last window days (z = 1.645 gives 90%).
kairos.beyond.csd ¶
Critical slowing down (Scheffer et al. 2009) as an optional fifth dial.
Near a tipping point a system recovers from small shocks more slowly. In a time series this shows up as rising lag-1 autocorrelation and rising variance of the detrended residuals. The dial computes both in a rolling window and tests for an upward trend with Kendall's tau.
The thresholds are parameters of :class:CSDConfig. Deployments read them from
versioned YAML, like every other KAIROS threshold.
CSDConfig
dataclass
¶
Settings for the critical-slowing-down dial.
Attributes:
| Name | Type | Description |
|---|---|---|
window |
float
|
Rolling window as a fraction of the series length. |
bandwidth |
float
|
Gaussian smoothing bandwidth for detrending, as a fraction of the series length. |
tau_threshold |
float
|
Kendall's tau above which an indicator counts as rising. |
CSDDial
dataclass
¶
Result of the dial: indicator series, their trends and the state.
detrend ¶
detrend(x: ArrayLike, bandwidth: float) -> FloatArray
Subtract a Gaussian kernel smooth with bandwidth given in samples.
rolling_indicators ¶
rolling_indicators(
resid: ArrayLike, window: int
) -> tuple[FloatArray, FloatArray]
Rolling lag-1 autocorrelation and variance; the first window - 1 are NaN.
csd_dial ¶
csd_dial(
x: ArrayLike, config: CSDConfig | None = None
) -> CSDDial
Compute the critical-slowing-down dial for one series.
The state is danger when both lag-1 autocorrelation and variance have a
Kendall's tau above config.tau_threshold.