convergence¶
tissue_simulator.convergence ¶
Convergence diagnostics for agent-based-model trajectories.
This module provides stationarity testing and convergence-detection utilities intended for evaluating how quickly an ABM trajectory reaches steady state. It combines the Augmented Dickey-Fuller test, the Mann-Kendall trend test, and a rolling coefficient-of-variation criterion.
MultiMetricConvergence ¶
MultiMetricConvergence(metrics: Dict[str, ArrayLike], window: int = 20, cv_threshold: float = 0.05, require_stationary: bool = True)
Aggregate convergence diagnostics across multiple ABM metrics.
Parameters¶
metrics : dict Mapping from metric name to a 1D series (array or list). window : int, optional Window length used for each metric. Default 20. cv_threshold : float, optional Rolling CV threshold. Default 0.05. require_stationary : bool, optional Whether each metric must also pass ADF. Default True.
Attributes¶
convergence_times : dict Per-metric convergence index (or None). global_convergence_time : int or None Maximum convergence index across all metrics, or None if any metric never converged.
Source code in tissue_simulator/convergence.py
global_convergence_time
property
¶
Maximum convergence time across metrics, or None if any failed.
summary ¶
Build a formatted multi-metric convergence report.
Returns¶
str Human-readable summary suitable for logging.
Source code in tissue_simulator/convergence.py
adf_test ¶
Run the Augmented Dickey-Fuller test for unit-root non-stationarity.
Parameters¶
series : array_like
1D numeric time series.
regression : str, optional
Trend/constant specification passed through to adfuller
("c", "ct", "ctt" or "n"). Default "c".
Returns¶
dict
Dictionary with keys statistic, pvalue, is_stationary,
critical_values and lags_used. is_stationary is True
when pvalue < 0.05 (null of unit root rejected).
Raises¶
ImportError If statsmodels is not installed.
Source code in tissue_simulator/convergence.py
mann_kendall_test ¶
Two-sided Mann-Kendall trend test with tie correction.
Computes the S statistic as the sum of signs of all pairwise differences, applies the standard tie-adjusted variance, and converts to a z-score using the continuity correction. The two-sided p-value is obtained from the standard normal distribution.
Parameters¶
series : array_like 1D numeric time series. alpha : float, optional Significance level. Default 0.05.
Returns¶
dict
Dictionary with keys trend ("increasing", "decreasing"
or "no trend"), S, z, pvalue and is_significant.
Source code in tissue_simulator/convergence.py
rolling_cv ¶
Rolling coefficient of variation (std / |mean|).
Parameters¶
series : array_like 1D numeric time series. window : int Window length (must be >= 2).
Returns¶
numpy.ndarray
Array of the same length as series. The first window - 1
entries are NaN. Windows whose mean is zero produce NaN.
Source code in tissue_simulator/convergence.py
find_convergence_time ¶
find_convergence_time(series: ArrayLike, window: int = 20, cv_threshold: float = 0.05, require_stationary: bool = True) -> Optional[int]
Find the first timestep at which the trajectory has converged.
A timestep t is declared converged when (a) the rolling CV computed
over series[t - window + 1 : t + 1] is below cv_threshold and
(b) if require_stationary is True, the ADF test on the same window
rejects the unit-root null.
Parameters¶
series : array_like 1D numeric time series. window : int, optional Window length used for both CV and ADF. Default 20. cv_threshold : float, optional Maximum allowable rolling CV. Default 0.05. require_stationary : bool, optional If True, also require the ADF test to flag the window as stationary. Default True.
Returns¶
int or None Index of the first converged timestep, or None if never converged.