Abstract
Stochastic processes underpin dynamics across biology, physics, epidemiology, and finance, yet accurately simulating them remains a major challenge. Classical approaches such as the Gillespie algorithm are exact for Markovian, time-independent systems, where propensities depend only on the current state and agents of a given type are statistically identical. While efficient, this framework misses a defining feature of many real systems: heterogeneity and memory at the level of individual agents. Cells may divide or differentiate on distinct intrinsic timescales, individuals may preferentially interact with specific partners, and inter-event-time distributions can deviate strongly from the exponential. We introduce MOSAIC (Modeling of Stochastic Agents with Individual Complexity), a general and scalable framework that embeds agent-specific properties directly into the dynamics. MOSAIC unifies heterogeneous rates, dynamic interaction preferences, and both Markovian and non-Markovian waiting-time distributions within a single stochastic formalism, while retaining Gillespie-like computational cost. Applications to delayed biochemical reactions, competitive immune-cell dynamics, and temporal social networks show that MOSAIC reproduces empirical features that existing methods either miss or capture only at prohibitive computational cost, establishing it as a practical tool for simulating heterogeneous stochastic systems.
Similar content being viewed by others
Data availability
This study used previously published datasets on germinal center B-cell maturation39 and conference interactions58. These data are available from the original publications and their associated repositories. All simulation data required to reproduce the findings are generated from the model definitions and parameters reported in the Methods.
Code availability
The MOSAIC and DelaySSA Python implementations, together with the code and data needed to reproduce all figures, have been deposited on Zenodo at https://doi.org/10.5281/zenodo.18346965.
References
Ross, S. M. et al. Stochastic processes, vol. 2 (Wiley New York, 1996).
Van Kampen, N. G.Stochastic processes in physics and chemistry, vol. 1 (Elsevier, 1992).
Cao, Y. & Samuels, D. C. Discrete stochastic simulation methods for chemically reacting systems. Methods Enzymol. 454, 115–140 (2009).
Yan, P. Distribution theory, stochastic processes and infectious disease modelling. In Mathematical epidemiology, 229–293 (Springer, 2008).
Kijima, M. Stochastic processes with applications to finance (Chapman and Hall/CRC, 2002).
Tseng, Y.-T., Kawashima, S., Kobayashi, S., Takeuchi, S. & Nakamura, K. Forecasting the seasonal pollen index by using a hidden markov model combining meteorological and biological factors. Sci. Total Environ. 698, 134246 (2020).
Gillespie, D. T. A general method for numerically simulating the stochastic time evolution of coupled chemical reactions. J. Comput. Phys. 22, 403–434 (1976).
Gillespie, D. T. Exact stochastic simulation of coupled chemical reactions. J. Phys. Chem. 81, 2340–2361 (1977).
Arkin, A., Ross, J. & McAdams, H. H. Stochastic kinetic analysis of developmental pathway bifurcation in phage λ-infected Escherichia coli cells. Genetics 149, 1633–1648 (1998).
Thomas, M. J., Klein, U., Lygeros, J. & Rodríguez Martínez, M. A probabilistic model of the germinal center reaction. Front. Immunol. 10, 689 (2019).
Pélissier, A. et al. Computational model reveals a stochastic mechanism behind germinal center clonal bursts. Cells 9, 1448 (2020).
Hoops, S. et al. Copasi-a complex pathway simulator. Bioinformatics 22, 3067–3074 (2006).
Barabasi, A.-L. The origin of bursts and heavy tails in human dynamics. Nature 435, 207–211 (2005).
Bratsun, D., Volfson, D., Tsimring, L. S. & Hasty, J. Delay-induced stochastic oscillations in gene regulation. Proc. Natl. Acad. Sci. USA 102, 14593–14598 (2005).
Stumpf, P. S. et al. Stem cell differentiation as a non-Markov stochastic process. Cell Syst. 5, 268–282 (2017).
Corral, A. Long-term clustering, scaling, and universality in the temporal occurrence of earthquakes. Phys. Rev. Lett. 92, 108501 (2004).
Zhang, J. & Zhou, T. Markovian approaches to modeling intracellular reaction processes with molecular memory. Proc. Natl. Acad. Sci. USA 116, 23542–23550 (2019).
Gregg, R. W., Shabnam, F. & Shoemaker, J. E. Agent-based modeling reveals benefits of heterogeneous and stochastic cell populations during CGAS-mediated ifnβ production. Bioinformatics 37, 1428–1434 (2021).
Großmann, G., Backenköhler, M. & Wolf, V. Heterogeneity matters: Contact structure and individual variation shape epidemic dynamics. PLoS One 16, e0250050 (2021).
Le Bail, D., Génois, M. & Barrat, A. Modeling framework unifying contact and social networks. Phys. Rev. E 107, 024301 (2023).
Rabiner, L. & Juang, B. An introduction to hidden markov models. ieee assp Mag. 3, 4–16 (1986).
Bracken, C., Rajagopalan, B. & Zagona, E. A hidden Markov model combined with climate indices for multidecadal streamflow simulation. Water Resour. Res. 50, 7836–7846 (2014).
Nguyen, N. & Nguyen, D. Hidden Markov model for stock selection. Risks 3, 455–473 (2015).
Anderson, D. F. A modified next reaction method for simulating chemical systems with time dependent propensities and delays. J. Chem. Phys. 127 (2007).
Boguná, M., Lafuerza, L. F., Toral, R. & Serrano, M. Á Simulating non-markovian stochastic processes. Phys. Rev. E 90, 042108 (2014).
Masuda, N. & Rocha, L. E. A Gillespie algorithm for non-Markovian stochastic processes. SIAM Rev. 60, 95–115 (2018).
Sheng, A., Su, Q., Li, A., Wang, L. & Plotkin, J. B. Constructing temporal networks with bursty activity patterns. Nat. Commun. 14, 7311 (2023).
Ubaldi, E., Vezzani, A., Karsai, M., Perra, N. & Burioni, R. Burstiness and tie activation strategies in time-varying social networks. Sci. Rep. 7, 46225 (2017).
Figueredo, G. P., Siebers, P.-O., Owen, M. R., Reps, J. & Aickelin, U. Comparing stochastic differential equations and agent-based modelling and simulation for early-stage cancer. PloS one 9, e95150 (2014).
Garcia-Valiente, R. et al. Understanding repertoire sequencing data through a multiscale computational model of the germinal center. npj Syst. Biol. Appl. 9, 8 (2023).
Sahneh, F. D., Vajdi, A., Shakeri, H., Fan, F. & Scoglio, C. Gemfsim: A stochastic simulator for the generalized epidemic modeling framework. J. Comput. Sci. 22, 36–44 (2017).
Bisset, K. R., Chen, J., Feng, X., Kumar, V. A. & Marathe, M. V. Epifast: a fast algorithm for large scale realistic epidemic simulations on distributed memory systems. In Proceedings of the 23rd International Conference on Supercomputing, 430–439 (2009).
Barrett, C. L., Bisset, K. R., Eubank, S. G., Feng, X. & Marathe, M. V. Episimdemics: an efficient algorithm for simulating the spread of infectious disease over large realistic social networks. In SC’08: Proceedings of the 2008 ACM/IEEE Conference on Supercomputing, 1–12 (IEEE, 2008).
Chen, J. et al. Epihiper-a high performance computational modeling framework to support epidemic science. PNAS Nexus 4, pgae557 (2025).
Perra, N., Gonçalves, B., Pastor-Satorras, R. & Vespignani, A. Activity driven modeling of time varying networks. Sci. Rep. 2, 469 (2012).
Thanh, V. H., Priami, C. & Zunino, R. Efficient rejection-based simulation of biochemical reactions with stochastic noise and delays. J. Chem. Phys. 141, 10B602_1 (2014).
St-Onge, G., Young, J.-G., Hébert-Dufresne, L. & Dubé, L. J. Efficient sampling of spreading processes on complex networks using a composition and rejection algorithm. Comput. Phys. Commun. 240, 30–37 (2019).
Rubner, Y., Tomasi, C. & Guibas, L. J. A metric for distributions with applications to image databases. In Sixth International Conference on Computer Vision (IEEE Cat. No. 98CH36271), 59–66 (IEEE, 1998).
Tas, J. M. et al. Visualizing antibody affinity maturation in germinal centers. Science 351, 1048–1054 (2016).
Gibson, M. A. & Bruck, J. Efficient exact stochastic simulation of chemical systems with many species and many channels. J. Phys. Chem. A 104, 1876–1889 (2000).
Fu, X., Zhou, X., Gu, D., Cao, Z. & Grima, R. Delayssatoolkit. jl: stochastic simulation of reaction systems with time delays in Julia. Bioinformatics 38, 4243–4245 (2022).
Hirata, H. et al. Oscillatory expression of the bhlh factor hes1 regulated by a negative feedback loop. Science 298, 840–843 (2002).
Monk, N. A. Oscillatory expression of hes1, p53, and nf-κb driven by transcriptional time delays. Curr. Biol. 13, 1409–1413 (2003).
Barrio, M., Burrage, K., Leier, A. & Tian, T. Oscillatory regulation of hes1: discrete stochastic delay modelling and simulation. PLoS Comput. Biol. 2, e117 (2006).
Rajala, T., Häkkinen, A., Healy, S., Yli-Harja, O. & Ribeiro, A. S. Effects of transcriptional pausing on gene expression dynamics. PLoS Comput. Biol. 6, e1000704 (2010).
Qian, J., Dunlap, D. & Finzi, L. Basic mechanisms and kinetics of pause-interspersed transcript elongation. Nucleic Acids Res. 49, 15–24 (2021).
Li, P.-P., Zheng, D.-F. & Hui, P. M. Dynamics of opinion formation in a small-world network. Phys. Rev. E 73, 056128 (2006).
Wang, X., Sirianni, A. D., Tang, S., Zheng, Z. & Fu, F. Public discourse and social network echo chambers driven by socio-cognitive biases. Phys. Rev. X 10, 041042 (2020).
Holme, P. Temporal network structures controlling disease spreading. Phys. Rev. E 94, 022305 (2016).
Keeling, M. The implications of network structure for epidemic dynamics. Theor. Popul. Biol. 67, 1–8 (2005).
Lynn, C. W. & Bassett, D. S. The physics of brain network structure, function and control. Nat. Rev. Phys. 1, 318–332 (2019).
Iacopini, I., Milojević, S. & Latora, V. Network dynamics of innovation processes. Phys. Rev. Lett. 120, 048301 (2018).
Scholtes, I. et al. Causality-driven slow-down and speed-up of diffusion in non-Markovian temporal networks. Nat. Commun. 5, 5024 (2014).
Han, L. et al. Non-Markovian epidemic spreading on temporal networks. Chaos, Solitons Fractals 173, 113664 (2023).
Williams, O. E., Lillo, F. & Latora, V. Effects of memory on spreading processes in non-Markovian temporal networks. N. J. Phys. 21, 043028 (2019).
Vestergaard, C. L. & Génois, M. Temporal Gillespie algorithm: Fast simulation of contagion processes on time-varying networks. PLoS Comput. Biol. 11, e1007190 (2015).
Unicomb, S., Iñiguez, G., Gleeson, J. P. & Karsai, M. Dynamics of cascades on burstiness-controlled temporal networks. Nat. Commun. 12, 133 (2021).
Génois, M. et al. Combining sensors and surveys to study social contexts: Case of scientific conferences. Personality Science. 4, e9957 (2023).
Kelly, R. C. & Kass, R. E. A framework for evaluating pairwise and multiway synchrony among stimulus-driven neurons. Neural Comput. 24, 2007–2032 (2012).
Guevara-Salazar, J. A., Quintana-Zavala, D., Jiménez-Vázquez, H. A. & Trujillo-Ferrara, J. Use of the harmonic mean to the determination of dissociation constants of stereoisomeric mixtures of biologically active compounds. J. Enzym. Inhibition Med. Chem. 29, 884–894 (2014).
Karsai, M., Kaski, K., Barabási, A.-L. & Kertész, J. Universal features of correlated bursty behaviour. Sci. Rep. 2, 397 (2012).
Le Bail, D., Génois, M. & Barrat, A. Flow of temporal network properties under local aggregation and time shuffling: a tool for characterizing, comparing and classifying temporal networks. J. Phys. A: Math. Theor. 57, 435002 (2024).
Bail, D. L. Generalizing egocentric temporal neighborhoods to probe for spatial correlations in temporal networks and infer their topology. J. Phys. A Math. Theoretical (2025).
Han, Z. et al. Probabilistic activity driven model of temporal simplicial networks and its application on higher-order dynamics. Chaos Interdiscip. J. Nonlinear Sci. 34 (2024).
Lin, Z., Han, L., Feng, M., Liu, Y. & Tang, M. Higher-order non-Markovian social contagions in simplicial complexes. Commun. Phys. 7, 175 (2024).
Sheng, A., Su, Q., Wang, L. & Plotkin, J. B. Strategy evolution on higher-order networks. Nat. Comput. Sci. 4, 274–284 (2024).
Majhi, S., Perc, M. & Ghosh, D. Dynamics on higher-order networks: a review. J. R. Soc. Interface 19, 20220043 (2022).
Iacopini, I., Karsai, M. & Barrat, A. The temporal dynamics of group interactions in higher-order social networks. Nat. Commun. 15, 7391 (2024).
Aquino, T. & Dentz, M. Chemical continuous time random walks. Phys. Rev. Lett. 119, 230601 (2017).
Jiang, Q. et al. Neural network aided approximation and parameter inference of non-Markovian models of gene expression. Nat. Commun. 12, 1–12 (2021).
Herbach, U., Bonnaffoux, A., Espinasse, T. & Gandrillon, O. Inferring gene regulatory networks from single-cell data: a mechanistic approach. BMC Syst. Biol. 11, 1–15 (2017).
Boxma, O., Kaspi, H., Kella, O. & Perry, D. On/off storage systems with state-dependent input, output, and switching rates. Probab. Eng. Informational Sci. 19, 1–14 (2005).
Pakdaman, K., Thieullen, M. & Wainrib, G. Fluid limit theorems for stochastic hybrid systems with application to neuron models. Adv. Appl. Probab. 42, 761–794 (2010).
Koshkin, A., Herbach, U., Martínez, M. R., Gandrillon, O. & Crauste, F. Stochastic modeling of a gene regulatory network driving b cell development in germinal centers. PLoS ONE 19, e0301022 (2024).
Koher, A., Lentz, H. H., Gleeson, J. P. & Hövel, P. Contact-based model for epidemic spreading on temporal networks. Phys. Rev. X 9, 031017 (2019).
Valdano, E., Ferreri, L., Poletto, C. & Colizza, V. Analytical computation of the epidemic threshold on temporal networks. Phys. Rev. X 5, 021005 (2015).
Cure, S., Pflug, F. G. & Pigolotti, S. Fast and exact stochastic simulations of epidemics on static and temporal networks. PLOS Comput. Biol. 21, e1013490 (2025).
Mesin, L., Ersching, J. & Victora, G. D. Germinal center B cell dynamics. Immunity 45, 471–482 (2016).
Cao, Z. & Grima, R. Analytical distributions for detailed models of stochastic gene expression in eukaryotic cells. Proc. Natl. Acad. Sci. USA 117, 4682–4692 (2020).
Park, S. J. et al. The chemical fluctuation theorem governing gene expression. Nat. Commun. 9, 297 (2018).
Wang, Y. et al. Precision and functional specificity in mRNA decay. Proc. Natl. Acad. Sci. USA 99, 5860–5865 (2002).
Watts, D. J. & Strogatz, S. H. Collective dynamics of ‘small-world’networks. Nature 393, 440–442 (1998).
Newman, M. E. Modularity and community structure in networks. Proc. Natl. Acad. Sci. USA 103, 8577–8582 (2006).
Newman, M. E. The structure and function of complex networks. SIAM Rev. 45, 167–256 (2003).
Pósfai, M. & Barabási, A.-L.Network Science (Citeseer, 2016).
Newman, M. E. Assortative mixing in networks. Phys. Rev. Lett. 89, 208701 (2002).
Blondel, V. D., Guillaume, J.-L., Lambiotte, R. & Lefebvre, E. Fast unfolding of communities in large networks. J. Stat. Mech. Theory Exp. 2008, P10008 (2008).
Albert, R. & Barabási, A.-L. Statistical mechanics of complex networks. Rev. Mod. Phys. 74, 47 (2002).
Acknowledgements
The authors thank Jonathan Karr, Farshid Jafarpour, Srividya Iyer-Biswas, and Peter Ashcroft for their valuable suggestions. This research was supported by the COSMIC European Training Network, funded by the European Union’s Horizon 2020 research and innovation program under grant agreement No 765158 and from the Swiss National Science Foundation (Sinergia grant CRSII5 193832).
Author information
Authors and Affiliations
Contributions
A.P. designed and implemented the MOSAIC and MOSAIC-TN frameworks, performed all simulations and benchmarks, and wrote the manuscript. N.B. and M.R.M. supervised the project and contributed to writing and editing the manuscript; M.R.M. additionally contributed to the design of MOSAIC. M.P. contributed to the implementation of MOSAIC and assisted with simulations. D.B. advised on dataset selection and the activity-driven modeling framework for social interactions and clarified terminology.
Corresponding author
Ethics declarations
Competing interests
The authors declare no competing interest
Peer review
Peer review information
Nature Communications thanks Tianshou Zhou, Madhav Marathe and the other anonymous reviewer(s) for their contribution to the peer review of this work. A peer review file is available.
Additional information
Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Supplementary information
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Pélissier, A., Phan, M., Le Bail, D. et al. Unifying non-Markovian dynamics and agent heterogeneity in scalable stochastic networks. Nat Commun (2026). https://doi.org/10.1038/s41467-026-69817-y
Received:
Accepted:
Published:
DOI: https://doi.org/10.1038/s41467-026-69817-y


