Contact-tracing is an essential tool in order to mitigate the impact of pandemic such as the COVID-19. In order to achieve efficient and scalable contact-tracing in real time, digital devices can play an important role. While a lot of attention has been paid to analyzing the privacy and ethical risks of the associated mobile applications, so far much less research has been devoted to optimizing their performance and assessing their impact on the mitigation of the epidemic.
We develop Bayesian inference methods to estimate the risk that an individual is infected. This inference is based on the list of his recent contacts and their own risk levels, as well as personal information such as results of tests or presence of syndromes. We propose to use probabilistic risk estimation in order to optimize testing and quarantining strategies for the control of an epidemic. Our results show that in some range of epidemic spreading (typically when the manual tracing of all contacts of infected people becomes practically impossible, but before the fraction of infected people reaches the scale where a lock-down becomes unavoidable), this inference of individuals at risk could be an efficient way to mitigate the epidemic. Our approaches translate into fully distributed algorithms that only require communication between individuals who have recently been in contact. Such communication may be encrypted and anonymized and thus compatible with privacy preserving standards. We conclude that probabilistic risk estimation is capable to enhance performance of digital contact tracing and should be considered in the currently developed mobile applications.
Motivation One of the main tools public health authorities use to mitigate the spread of a pandemic, such as COVID-19, is the trace-test-isolate strategy. Identifying, calling, testing, and if needed quarantining the recent contacts of an individual who has just been tested positive is the standard route for limiting the transmission of a highly contagious virus. This standard strategy proves its efficacy at early stages of the epidemic, when the number of newly infected individuals is small enough to be manageable by reasonable-scale manual contact tracing infrastructures. However, it cannot be applied as such when the epidemic starts to spread faster, because the average number of contacts of a typical individual in the few days before he is tested positive can be large, not all contacts are with people known to the individual, and manual tracing incurs delays during which infected contacts keep on spreading the virus.
For these reasons, and taking into account the properties and parameters of the COVID-19 epidemic, digital contact tracing was convincingly argued to be a viable route to mitigation of COVID-19 and other similar epidemics [1] . Current mobile phone technology indeed enables automated, real-time proximity tracing between individuals and many works in this direction were initiated and deployed in past months [2, 3, 4, 5, 6, 6] . With currently developed mobile applications, the distance and duration of a contact between two individuals can be estimated. Furthermore, contextual or health information about individuals can be included as well. This tracing can be used while preserving the privacy of each individual's information, the level of privacy protection depending on the protocol. While many works have been devoted, justifiably, to the compatibility of privacy and tracing, see e.g. [2, 4, 6, 7, 8] , much less work is available concerning the assessment of the efficiency of tracing in mitigation of the pandemic. Most considered systems use the tracing data simply as a fast and scalable device to identify all recent contacts, in order to notify and perhaps isolate all of them.
In this paper we show that approximate Bayesian probabilistic inference techniques allow to use the data exchanged by the tracing applications in order to provide highly accurate estimates of the probability that any given individual is infected. This estimate can then be used in order to focus the tests and other interventions on the group of individuals who have the largest probabilities of being infected, even if they do not show symptoms. The contact-tracing protocols that we propose require individuals that have been in contact in the recent past to be able to exchange messages about their risk level. When two individuals meet, they exchange a small amount of information (typically through Bluetooth). Later on, these individuals exchange messages carrying information about their current status, e.g. an increased risk due to presence of syndromes associated with the illness or due to their history of past contacts. Probabilistic inference then concatenates this information from all past contacts locally on the individuals phone and sends updates of the status to their contacts.
We shall describe hereafter two concrete algorithms to perform the inference; one which is more accurate, based on Belief Propagation [9] , and a second one which is a simpler approximation based on the so-called Mean-Field method. The latter requires smaller communication bandwidth between devices and could be potentially more privacy-friendly. Both the algorithms are inspired by our previous work [10, 11, 12, 13, 14, 15, 16, 17] , and adapted to the present contact tracing problem. For a given testing capacity we show, through extensive simulation on realistic models for COVID-19 diffusion, that both methods allow to significantly reduce the impact of an outbreak and eventually contain the epidemics in many cases where standard tracing protocols fail to do so. We additionally evaluate robustness of the methods to presence of false negative tests as well as partial adoption of the contact-tracing mobile applications.
Related work While most considered systems use the tracing data simply as a fast and scalable device to identify all recent contacts, works aiming at estimating the risk of infection appeared recently. These include a machine learning based risk estimation proposed in [5] , that provides only limited validation of the approach even on data specific to the privacy preserving protocol, and is thus difficult to directly compare to our approach. Preliminary version of our work was first presented in Ellis COVID-19 workshop [18] . An approach similar to our MF algorithms was proposed by [19] using Monte Carlo sampling to estimate the corresponding probabilities. This work does not provide validation of the approach involving the control of the epidemic. Another recent work estimating the risks from the tracing data is [20] that is in the spirit similar to our work, it uses Monte Carlo sampling based estimations of the risks. The authors of [20] evaluate their approach only on data that come from the model that is assumed in the inference algorithm. A key aspect of our work is that we test on data coming from a much more complex model than assumed when designing the inference algorithm [21] . We believe that this is crucially important for eventual validation on real world contact data, which are not available to us at this point. We note that the authors of [20] evaluate their approach on networks up to 10k individuals, compared to 500k used in our simulations. As is common with Monte-Carlo schemes, convergence properties could significantly deteriorate with system size. The lack of separation between the epidemic generating model and the inference procedure in the implementation of [20] makes it difficult for us to compare directly to our approach, and we thus leave it for future work. The python code used for our simulations [22] is modular and comparisons with other inference procedures can be performed by adding new modules.
Scheme of propagation A convincing validation of any individual-level intervention policy requires extensive simulations by means of sufficiently detailed agent-based models. In such models, at each time, a given individual is in a state that belongs to a finite set of possible states, like for instance susceptible, exposed, infected-asymptomatic, infected-asymptomatic, in ICU, recovered, or dead. The most accurate mathematical descriptions of COVID-19 epidemic propagation are based on complex multi-state compartment models, in which infected individuals are not immediately contagious upon infection, may be asymptomatic or develop mild/severe symptoms with some delay, and the ages, households and workplaces are also taken into account. Even though the long-term effects of SARS-CoV-2 infection are still under study, it seems reasonable to assume that some level of immunity is developed with recovery, so that the individual progression through the epidemic compartments is not recurrent (a recovered person typically does not become infected again). The observation of non-trivial distributions of incubation and recovery times as well as that of time-dependent viral transmission capacity [23, 24, 25, 26, 26] indicate that the most realistic models for SARS-CoV-2 infection clearly depart from the simplest, and largely adopted, Markovian epidemic models. In addition, such models also provide representations of the time-varying contact network over which viral transmissions occur, some including real-world mobility data [27] or computer-generated synthetic surrogates [21, 28] .
In particular, the model in Ref. [21] simulates the spread of COVID-19 in urban age-stratified populations with a multi-layer contact network (see also Supplemental Material A for details).
Information regarding the status of tested or symptomatic individuals can be used in different ways within a contact tracing procedure. In the simplest situation, the observation of an infected individual involves tracing (a fraction of) his recent contacts in order to prevent/contain further transmissions of the infection. It is also possible to infer transmission chains and detect the parent cases which are the origin of the infection detected in an individual. In a Bayesian approach, this is made possible assuming as a prior a particular probabilistic model of epidemic propagation and using it to define a likelihood function conditioned on the evidences coming from observational data, i.e. tests (PCR and/or serology) and self-reported symptoms from a fraction of the individuals. As we shall show, the adopted prior inferential model provides the mathematical framework for developing risk assessment, but it does not need to reflect the real epidemic spread in all its details in order to allow for valuable inference. Indeed, for epidemic propagation generated with complex agent-based models along the lines described above, we show that the approximate computation of local probability marginals can be effectively obtained using as a prior much simpler inferential models. In practice in this paper we use a simple agent-based Susceptible-Infected-Recovered (SIR) model. We emphasize that, depending on the approximate inference technique used for computing such probability marginals, some of the ingredients of realistic epidemic propagation can be reintroduced, such as non-Markovian evolution between states, time-dependent infectiousness or more compartments.
Here we propose two distributed algorithms for risk estimation from contact tracing data, which are both derived within a Bayesian framework and based on a message-passing principle: Mean-Field (MF) algorithm and Belief Propagation (BP) algorithm. They both provide estimates of the time-dependent local probability marginals of being infected which can be used to estimate the risk level of each individual; this risk of being infected can in turn be used to implement a sanitary protocol, like suggesting higher risk individuals to be tested and/or quarantined. The main differences between these methods, which are presented in the next section, are in the accuracy of the approximation of the epidemic dynamics and in the way in which observational data are incorporated into the probabilistic model.
We use the Bayesian approach that is based on a prior description of the epidemic process, and a method to include the information from observations. We present here, and use in this paper, a prior description based on a discrete-time Markov chain corresponding to the SIR model. It can be generalized to non-Markovian, continuous-time, and other model settings.
Let x t i be the state of an individual at time t (it is convenient to think of t as a number of days), with x t i ∈ X and X a finite set of epidemic states. We use X = {S, I, R} for the case in which the susceptible (S), infected (I) and recovered (R) individual states are considered. The state of individual i at time t, x t i , depends on her state at the previous time, and on the states at time t − 1 of all the individuals j that she has met between times t − 1 and t. We denote by ∂i(t) this set of individuals, and by
is the probability of individual transitions for i occurring between time t − 1 and time t. For the SIR model, this probability depends on the following parameters:
• the recovery rate µ i , defining the daily probability that the infected individual i moves to the recovered state 'R';
• the transmission rates {λ k→i (t)} k∈∂i(t) , which are the probability of infection from an infected k to a susceptible i on day t.
,...,N be a collective time-trajectory generated by the epidemic. The prior probability associated with this trajectory is defined by
where we assumed a factorized probability of initial state
i . We can now include the effects of observations. Given a set O of observations O = {O r } r∈O , where each observation r provides some information on the state of an individual at a given time (as the result of tests, or of individual symptoms), and assuming that these observations are statistically independent, the posterior probability of the trajectory x can be expressed using Bayes theorem as
For the BP approach, we start from the posterior at (2) and remark that it can be written as:
Belief Propagation [9] can then be used to estimate marginal posterior probabilities from (3). However, a straightforward factor graph representation [29, 30] of (3) with {x i } as variable nodes and the compatibility functions {ψ i (x i , x ∂i )} as factor nodes, contains many short loops, so that the corresponding BP equations would not be exact even when the underlying contact network is acyclic. We instead construct a factor graph representation that closely reflects the topological structure of the contact network by associating the individual trajectories of a pair of individuals in contact, and involves BP messages m ij (x i , x j ) for pairs of trajectories. The corresponding BP fixed-point system for {m ij (x i , x j )} (ij)∈E is solved by iteration. This formalism has been employed for large-deviation analyses of a class of dynamical processes including applications to epidemics [12, 13, 15, 31, 32] , in particular regarding the patient zero problem and the inference of causality chains of infection. We extended here previous works to deal with non-Markovian processes and to make it computationally efficient through a limited time-window approximation (see Supplemental Material). Restricted to Markovian epidemic models, a simpler, Mean-Field approximation can be devised starting from (1) . It is based on assuming that
Thanks to this factorization, one can write closed equations for the evolution of the individual probabilities p(x t i ) for the simple prior model (1) along the same spirit as presented in [10, 11] , (see Supplemental Material).
For risk inference, we need to estimate the p(x t i |O) in the full model (2) that includes the observations. We show in the Supplemental Material a heuristic that incorporates the presence of observations done at a time t obs into the Mean-Field equations. The algorithm propagates the information on the population from t M F days before the current time and it simply takes into account the following facts:
• If an individual is tested 'S' at time t obs , it has been 'S' at all previous times
• If an individual is tested 'R' at time t obs , it will be 'R' at all following times
• If an individual is tested 'I' at time t obs , we assume that he has been 'I' at times [t obs −τ, t obs ], where τ , the typical time between infection and observation, is a parameter of the algorithm.
We test the inference of risk on two types of epidemic spreading and contact networks.
• SIR spreading model on proximity-based random network: This is a simple SIR-modelbased propagation in a population of N individuals, where the graph of contact is updated dynamically at each step as follows. The individuals are distributed uniformly in a square of side √ N , and at each time step a contact can be established between two individuals i and j with a probability e −d ij / , where d ij is the Euclidean distance between the points and is a parameter that controls the density of the contact graph. We shall call this the geometric contact model.
• Oxford OpenABM model: The second model is a much more realistic epidemic spread model [1] , which is aimed at capturing essential features of the contacts in real populations as well as the real epidemiology of COVID-19, we call it the OpenABM model. In the absence of sufficiently detailed real world data, we view the data from the OpenABM model as realistic and our main point is to demonstrate that even though the proposed inference procedures do not capture most of the details and complexity of this model, they still work and provide large improvement over competing current contact tracing methods.
For the OpenABM model, we use in MF inference an extremely simplified hypothesis of equal recovery rates, µ i = µ, and transmission probabilities only divided into two classes (interhousehold contacts, with λ k→i (t) = λ and intra-household contacts, with λ k→i (t) = 2λ). The values of parameters µ and λ are chosen on the basis of population averages; they could also be inferred from data. Note that arbitrarily heterogeneous parameters can be used if more information is available, such as the duration of a contact. It is important to notice that the MF algorithms that we derive from this simple model turn out to be very efficient at predicting the risk of an individual to be infected, even in sophisticated propagation models that involve individual and time-dependent rates µ i and λ k→i (t). The BP inference model is slightly more complex (see Section C.4 for details), although still much simpler than the original OpenABM propagation model.
In both models, we start the simulation at time 0 with everybody in the susceptible state S except a small number of infected individuals. The number of these "patients-zero" will be specified in the following for each case.
We apply the following testing protocol. We observe a fraction of symptomatic individuals at the day of symptoms. After a fixed number of days (t start ) the interventions start. Every day, we perform a fixed amount n r of tests to the top individuals ranked as having the largest probabilities of being infected, according to the different risk estimation strategies. We assume that the result of the test is available on the same time step (day) and is included in the observations used to adjust the probabilities of risk on the next time step (day).
Besides BP and MF risk estimation, the ranking strategies considered for comparison are:
• Random Guessing (RG): The n r individuals on which the tests are performed are randomly chosen among the individuals that were not previously tested positive.
• Contact Tracing (CT): One ranks the individuals who have not been tested positive previously according to the number of contacts with confirmed positive individuals during the time interval [t − τ, t[, and tests the n r individuals with the largest number of contacts. This is what would be possible to implement with the currently deployed mobile applications.
For BP and MF inference, the ranking is done as follows:
• Belief Propagation (BP) and Mean-Field (MF): One uses the algorithm (BP or MF) in order to estimate the probabilities q t i = p(x t i = I) of being infected at time t. Individuals who have not been tested positive previously are ranked according to their risk q t i , the n r individuals with largest risk are tested. For BP, the rank is computed as the probability of infection in the last δ rank days. Prioritizing recent infections can be more effective as it helps containing the "boundary" of an ongoing outbreak.
We compare test-guided containment strategies based on MF, BP, RG and CT in a scenario where quarantines are put in place when tested individuals result infected. We show that BP and MF-based methods are able to predict infections and control the epidemic considerably more successfully than the classic contact tracing strategy. Implementation of the MF and BP risk estimation algorithms and all the tests that follow can be found at [22] .
We evaluate the proposed framework in a pessimistic regime with 200 simultaneous independent outbreaks that are discovered after ten days. We start with a simulation of the proximity-based random network. Figure 1 shows the development of the epidemic over three months in a population of 500 000 individuals, starting from 200 patients-zero, and performing n r = 1500 tests per day. In spite of rather large fluctuations from run to run, one sees a very clear signal indicating that the proposed inference methods, MF and BP, largely improve upon the usual CT, which is itself better than RG. The best inference method is clearly BP, but the simpler MF, which is less demanding in terms of the amount of information exchanged between individuals, and therefore easier to protect for better privacy, is also quite successful. Even in this pessimistic regime both risk inference methods allow to slow down the epidemic spread by more than a month compared to classic contact tracing.
In this first test we assumed that the model used for BP and MF inference coincides exactly with underlying epidemic propagation model (SIR), which is overly optimistic. A much more stringent test has been performed on the more realistic OpenABM COVID-19 model. In this framework, each infected individual can either be asymptomatic or show symptoms of various degree (mild or severe). As in a realistic setting, we will consider an additional source of information: individuals that show severe symptoms are immediately quarantined when symptoms emerge (typically 5 days after infection) or hospitalized. In addition, half of the mildly symptomatic individuals is assumed to self-report and self-isolate as well. No direct information is available on asymptomatic (or pre-symptomatic) infected individuals, their detection is possible only through contact tracing. We mimic a post lock-down scenario where only a small fraction of individuals is initially infected, i.e. few tens of patients zero in a population of 500 thousand individuals that all employ a contact-tracing application. The epidemic dynamics freely evolves according to the OpenABM model [21] for ten days and then a number of individuals with the highest infection risk, assessed by RG, CT, MF, or BP, is tested on a daily basis. The MF algorithm assumes a Markovian SIR spreading with parameters λ = 0.02 and µ = 1/12, and has parameters τ = 5 and t MF = 10. See Section C.4 for details on the BP parameters. In these simulations, the result of the medical tests is assumed to be exact; errors in tests will be addressed below. The number of medical tests associated with the individuals detected by the mobile application is fixed while there is no limitation on those performed to the fraction of symptomatic people presented above. The original contact dynamics is then modified in agreement to two alternative strategies: tested positive are confined and can have contacts only with their cohabitants or, whenever one person results positive to the medical test, all the households are quarantined without being tested. Figure 2 shows the number of infected individuals in a time interval of 100 days when the number of initial infections is 50 and the intervention starts after 10 days. In the top panels, we show the results for three independent realizations of the epidemics in the case where tested positive individuals only are quarantined, while in the bottom panels we show the results for a more restrictive intervention scenario in which all the households are confined. The number of available tests per day increases from 625 to 5000 (from left to the right panels). The lines are colored according to the adopted ranking strategy and the thick lines show the mean number of infected individuals mediated on the three instances. The results suggest that for both the inference strategies the size of the epidemics is significantly reduced if compared to the random testing and also to the classic contact tracing, even when few tests are available. We remark the behavior of the BP-based strategy when 1000 (1250 when the confinement is not extended to the households) daily medical tests are performed: the confinement of the people inferred by this method suffices to stop the epidemic after 75 days. The MF-based strategy performs notably better than CT and it achieves similar performances to BP when the number of daily observations is large.
In Figure 5 of the Supplemental Material we show the number of infected individuals for a time window of 100 days in, to some extent, a different scenario, that is when the containment measures are applied earlier in time, after a week from the beginning of the epidemics, and the size of the epidemics at initial time is smaller than that examined in Figure 2 .
Robustness of the inference In the previous section we investigated how several intervention protocols (differing in the treatment of the households and the number of available tests) control realistic epidemics when paired to the considered risk assessment strategies (RG, CT, MF and BP). However, some of the conditions assumed in that section are not realistic. In reality, the sensitivity of medical tests is not 100% and it is to be expected that only a fraction of the population will adopt the app, so that not all contacts are detectable. In this section, we shall address these two issues, focusing on the more realistic OpenABM model.
We first consider the case in which the results of the medical tests are inaccurate and therefore there exists a fraction of the tested individuals incorrectly identified as uninfected or infected. Concerning the fraction of false positive tests this simply puts a small additional fraction of individual in isolation, but does not lead to deterioration of the epidemic control. We hence focus on the influence of false negatives and test how the performance depends on the false negative rate (FNR) of the medical tests. We remark that within the Bayesian framework it is possible to correctly include this information in a straight-forward way and we do so for the BP algorithm, but not for the MF as we want to keep it as simple as possible and test its robustness. In Figure  3 we show the results of several simulations (three different realizations of the dynamics), starting from the setting in Figure 2 with 2500 medical tests and the quarantine of the entire households, when the FNR spans the range [0.09, 0.40]. We see that all the control strategies present good robustness with respect to the false negative tests. The CT controls the spreading up to FNR 0.19, MF is robustly better than CT up about FNR 0.25. Remarkably the intervention based of BP predictions not only limits the number of the infected individuals in time, but its performance remains almost unchanged with respect to the noiseless case as it completely stops the epidemic spreading even for large values of the FNR, up to 0.31. Figure 6 of the Supplemental Material displays the results of the same experiment but starting from the initial setting of Figure 5 using 1000 medical tests, bottom panel. These results confirm the effectiveness of inference-based ranking and reveal the robustness in a realistic scenario of a fully Bayesian approach such as the proposed Belief Propagation in which the probabilistic evidence of tests can be consistently included as priors. We now turn to the study of partial adoption of the mobile application. This is done in the simulation by hiding the contacts of a fraction of individuals (which are unknown to the inference algorithm): these hidden contacts represent individuals without the application or without smartphone. Figure 4 shows the result of mitigation, in the OpenABM model, with AF (the fraction of individuals who have adopted the app) ranging between 0.6 and 0.9. It shows that the method is still effective in presence of partially detected contacts. Although performance is severely affected, one observes that even at AF equal to 0.6 the use of inference algorithms allows to delay the spreading of the epidemic and to flatten the peak of infected individuals, way more efficiently than the classical contact tracing strategy. Furthermore, it should be noted that application utilization may be positively correlated to the number of contacts of individuals. Including more detailed information about mobile application utilization e.g. in population age classes may greatly reduce the impact of low adoption. Similar results are presented in the Supplemental Material, Figure 7 for a smaller number of daily observations. Figure 4 : Effect of a poor adoption fraction of the mobile application to the number of infected individuals. We simulate the same intervention protocol as Figure 2 for 5000 daily observations. We assume here that only a fraction of the population, from 90 % to 60%, uses the mobile application for contact tracing.
The above results show that, in the regime where the epidemic is growing and exhaustive testing of all contacts is unfeasible, inference methods allow to contain the epidemics more efficiently than the classical tracing of contacts, which itself is better than random testing. Both inference schemes require exchange of information between individuals during a limited time window after they have been in contact, and could be implemented in contact-tracing smartphone applications in a distributed way. Additionally, numerical tests show that the approach is robust to false negatives in the test results as well as to partial adoption of the mobile tracing applications, although the adoption rate required for efficient control of the epidemic with the number of daily tests considered is large relative to the one of the currently deployed applications. The volume of daily exchanged messages per pair of individuals in the two proposed methods is constant with respect to both the population size and time (a total of about 1kB for MF, 1MB for BP per individual assuming ∼ 10 daily contacts). This volume is negligible when compared with normal data usage. A privacy-preserving implementation will require an additional overload, but the computational burden on the phone's CPU will remain negligible.
Having access to the estimated posterior probability of being infected in time, a series of threshold values could be put in place so as to suggest actions on individuals, including reduction of contacts, self-isolation and testing.
With regard to privacy, it is worth emphasizing that the proposed inference methods are in principle more protective than the usual (manual) tracing. On the one hand, both can be implemented in a fully distributed way using point to point cryptography without fully centralized processing and storage of information on infections or contacts. On the other hand, by identifying individuals who have the largest probability of being infected through a cumulative process by which information is integrated, the direct attribution of potential infection events to a given individual is made much harder. Details of such fully privacy preserving implementation, along the lines of [4] , are left for future work.
The OpenABM computational model by R. Hinch et al. [21] involves simulating epidemic propagation in an age-stratified population based on the UK national census data (see Table 1 in [21] ). Each individual is represented by a node of a multi-layered network and takes part in three different subnets describing different social contexts: two static subnets represent households and workplaces while a degree-heterogeneous random network, different every day, represents the occasional interactions which individuals have on a daily basis. Age stratification influences both the composition of households (the elderly tend to live with other elderly, children preferably live with young adults) and the social activity level of individuals (e.g. participation in the workplace network, average number of random daily interactions). The epidemic states considered by the model are those discussed above, apart from the exposed state, which is not explicitly modeled. Hospitalization and/or death is possible only for severely symptomatic patients, while the resistant state is eventually reached in case of no or mild symptoms. The epidemic dynamics is modeled as a discrete-time stochastic process, with a temporal resolution of one day, in which infected individuals can transmit the disease with a (daily) infection rate which depends mainly on the symptomatic state of the potential infector, the age of the potential infected and the time passed since the potential infector became infected. The latter dependence, modeled through a Gamma distribution, is an attempt to describe the temporal variation of the infectiousness level of SARS-CoV-2. In particular, the incubation period (usually represented by the E state), is here implicitly taken into account by assuming an infectiousness level which does not immediately grow from zero. Finally, the infection rate depends on an intrinsic infectiousness level of the virus and on the type of network on which the contact occurs. Although the notion of duration of contacts is not present, the infectiousness rate associated with contacts inside households is larger than for the other environments, to account for the typically longer duration of domestic interactions. With the exception of the viral transmission process just described, all other possible transitions between individual epidemic states (e.g. transition from mild symptomatic infected state to the resistant state) are independent of the state of the other individuals. These events are characterized by a (discrete) waiting time, also distributed according to a Gamma distribution or, in case of dichotomous support, according to a shifted Bernoulli distribution. The parameters of these distributions have been extracted from recent SARS-CoV-2 literature and are summarized in Tables 5-6-7 of Hinch et al. [21] .
The model provides the possibility of intervention in order to slow down and, if possible, contain the epidemic outbreak. In particular, it is possible to introduce interventions of increasing severity, from case-based measures (e.g. quarantine for individuals which are positive to swab tests and their housemates) to mobility restrictions for some categories of individuals and lockdown scenarios. In this respect, the OpenABM model is very appropriate for the implementation of contact tracing strategies. Finally, the OpenABM model also provides for the possibility of varying the adoption fraction of the contact tracing app within the population, possibly introducing different percentages of adoption in different age groups of individuals.
The mean field inference is based on a prior epidemic model which is an agent-based SIR model. At each time, an individual i is in either one of the three states: Susceptible, Infected, Removed, x i (t) ∈ {S, I, R} (where the "Removed" state means either dead, or recovered and having acquired immunity).
When going from time t to time t + 1, the following events can take place:
• If x i (t) = R: x i (t + 1) = R.
• If x i (t) = I: we call µ i the probability that an infected individual i recovers:
x i (t + 1) = I with probability 1 − µ i x i (t + 1) = R with probability µ i
• If x i (t) = S: One looks at all the individuals j which are infected and have been in contact with i at time t (in practice this means between day t and day t + 1). Define this set of individuals as ∂i(t). Each individual j in ∂i(t) infects i with a probability λ j→i (t). More precisely:
To resume, the parameters of the model are:
• µ i : The probability of removal of the infectious patient i.
• λ i→j (t): The transmission probability given that there was a contact between an infected i and susceptible j at time t. This depends on i, j and on t, depending on the duration and nature of contacts between i and j between day t and t + 1 transmission probability changes with contact time, as well as the sanitary measures, such as wearing masks.
From these rules one obtains the propagation of the epidemic p x t i |x t−1 ∂i , x t−1 i as defined in eq. (1).
In order to understand and monitor the propagation of the epidemic, and to develop mitigating strategies, it is important to evaluate the probabilities that individual j is in state S, I or R at a given time t. We denote these probabilities respectively by P j S (t), P j I (t), P j R (t). These marginal probabilities are in general difficult to evaluate. A straightforward strategy for this evaluation is to simulate a large number of instances of the propagation, and estimate P j S (t) as the fraction of instances where individual j is in state S at time t. However this requires a centralized system, and a large computing power. Here, instead, we use some approximate techniques from statistical physics, that allow for a good estimate of P j S (t) through a fully distributed method, using only simple exchange of information at each contact.
The Mean-Field (MF) method computes the marginal probabilities of (1) through an iterative process. The probability of individual j receiving the infection from her contact k at time t depends on their contact transmission λ k→j (t) and on the joint probability of j being S and k being I at time t. The mean field approximation estimates this joint probability by the product P j S (t)P k I (t). Using this approximation, one can write the probability that individual j is susceptible at time t + 1 as
The probability of being recovered is
and the probability of being infected is obtained using the fact that P S + P R + P I = 1. In practice, considering that the probability of transmission is small, our MF algorithm is based on the following linearized form for P S (and we have checked that this linearization is fine in the regimes of epidemic propagation that we explore):
P j R (t + 1) = P j R (t) + µ j P j I (t), P j I (t + 1) = P j I (t) + P j S (t)
The mean-field equations have an intuitive content which is easy to understand. They basically reproduce in an agent-dependent model the equations used for the global monitoring of the proportions of S,I,R states in a population. They can also be derived as a limiting case of the dynamical message passing equations from [10] , when the transmission probabilities are small. This approach offers several advantages. Every individual j can estimate her probabilities P j S (t), P j I (t), P j R (t) every day, by updating the equations (7). These probabilities can be stored in her phone. For the update, individual j needs to receive, during the contact with k, the information on λ k→j (t) and the information from k about his estimates of P k S (t), P k I (t), P k R (t). The value of λ k→j (t) is the standard contact-tracing information, which estimates the encounter duration within a certain distance, as used in all contact tracing applications that are being developed, for instance based on bluetooth signals between the phones of j and k. On top of this, the phone of individual k should send the values of P k S (t) and P k I (t) to individual j during the contact, and reciprocally. The information is fully distributed, there is no need for a central system that stores the full information, and the data exchange can be encrypted.
We suppose that, at time t obs an individual i is tested or presents illness-associated syndromes. Then the state of i is known: x obs i (t) ∈ {S, I, R} and P i q (t obs ) = δ q,q obs i (t) . In case of syndromes at time t obs the probability P i q (t obs ) is updated on the basis of external medical data, namely the probability to be infected among all people presenting the same set of syndromes.
A simple inference method that turns out to be quite efficient consists in adapting the mean-field equations (7) in order to take into account the results of tests and symptoms. The information about tests and syndroms must be propagated back in time and be used to update the risk levels of the contacts of person i in recent times. Assume that we are estimating the probabilities for each individual i to be in each of the three states q at a given time t, P i q (t). We run the mean-field equations (7) starting at time t − t M F with the whole population S, and imposing the constraints due to the tests done in the interval [t − t M F , t] as follows. If j is tested at a time t obs in this interval, then:
if x j (t obs ) = I : P j I (t ) = 1 for t obs − τ ≤ t ≤ t obs (9) if x j (t obs ) = R : P j R (t ) = 1 for t ≥ t obs
Our inference procedure depends on two parameters: τ is the typical time between the infection and the testing consecutive to the apparition of syndroms, and t M F is the integration time of the mean-field procedure.
Each pair i, j of individuals will be in mutual contact in a finite set of instants X ij ⊂ R ∞ = R ∪ {+∞}. For reasons that will become clear in the following, we will always assume ∞ ∈ X ij . As time advances, instantaneous contagion will happen with probability λ at time s ij ∈ X ij if i is infected and j is susceptible. We will assume λ = λ
to possibly depend both on the specific (absolute) contact time s ij , on the direction of the contact and on the time t i of infection of individual i. Individual i can thus become infected in one instant in the set X i = ∪ j∈∂i X ij . We will denote by t i ∈ X i , r i ∈ R respectively the times of infection and recovery of individual i, with t i = ∞ (resp. r i = ∞) if the individual did not become infected (resp. recovered) within the time-frame.
We will assume the recovery delay r i − t i of node i to be distributed with a continuous distribution with pdf p R,i (r i − t i ). We will assume a set of factorized, site-dependent observations p O,i (O i |t i , r i ). Model parameters will be hidden for the moment inside functions p R,i , λ s,t ij , and p O,i and we will include them only later to avoid cluttering the notation. The standard SIR model can be obtained by setting p R,i (r i − t i ) = µe −µ(r i −t i ) , λ s,t ij ≡ λ. In this setup, the model is memory-less (Markov) on the state of infection variables x t i ∈ {S, I, R}. In the following we will always assume that t i ∈ X i and s ij , s ji ∈ X ij . Given the times of infection and recovery t i and r i , the transmission delay s ij has "truncated" generalized geometric distribution
because i will be infectious in the open time interval (t i , r i ) and will possibly (i.e. if j is susceptible at the time) transmit the disease at some time s ij in that interval if he did not transmit it before. If time r i arrives and he did not transmit the disease, the individual will recover and never transmit the disease through that link; then transmission time on that link will be nominally s ij = ∞. Special attention must be taken for auto-infections (otherwise, no infection can enter into the closed system). By adding a contact with an additional extra always-infected virtual neighbor i t * to node i at time instant t ∈ X i with probability p t (s i t * i = t) = γ t i (typically small), 
We can now write the joint pdf of discrete variables t, s and continuous variables r as
so then as p (t, r, s|O) ∝ p (O|t, r) p (t, r, s), we get
A note about r i s: all terms in (14) except R i are constant as functions of r i in any interval (r i ,r i ) of consecutive times in X i . We will exploit this fact and write r i =r i + u i , wherê r i = max {r ∈ X i : r < r i }. Integrating away the u i variables in (14) , we obtain an all-discrete model for variables t, s,r, with an identical expression to (14) but in which r i has been replaced byr i and
du. For simplicity of notation, we will drop theˆsymbols in the following.
A naive interpretation of (14) as a graphical model would introduces many unneeded short cycles that were not present in the original contact network. For example, pairs (t i , s ji ) , (t i , s ij ) , (t j , s ij ) , (t j , s ji ) share respectively factors with indices i, (ij) , j, (ji) , effectively forming a small cycle. A simple solution consists in regrouping factors as in (15) and considering (s ij , s ji ) as a single variable:
1 A particularly interesting case is with γ 0 i = γ → 0 and γ t i = 0 for t > 0: in this case individuals can be self-infected only at time 0, representing a closed system with a single unknown seed at time t = 0. which results in a factor graph for (14) in which variables (s ij , s ji ) have degree two and live in the middle of the original edges, and vars t i , r i have degree 1, i.e. a topology that closely follows the one of the original contact network:
The corresponding BP equations for Ψ i are
and marginals for t i are
and similarly for r i . A more efficient computation of the equations can be achieved by defining:
and substituting the extra neighbor message
Note that products k∈∂i\j G k can be computed simultaneously for j ∈ ∂i in time O (|∂i|)
(either by computing it as the fraction G −1 j k∈∂i G k , or by first recursively computing =1 G k and |∂i| = G k for = 1, . . . , |∂i| and then = G k = −1 =1 G k |∂i| = +1 G k , a method that does not involve divisions and is thus numerically more stable). The resulting implementation of the update of all messages in factor Ψ i has complexity O |X i | j∈∂i |X i | + |X ij | 2 .
In the BP-based epidemic tracing scheme, exchanged messages between two individuals grow quadratically with the number of temporal contacts occurred between them. However, only recent contacts are important to determine marginal probabilities at present time, therefore keeping only a short time window (about two or three weeks) is sufficient to obtain quasi-optimal results. For better accuracy, information about contacts and observations at the dropped times is included approximately as simple factorized priors applied at the start of the window. This prior contains the posterior probability at the first non-dropped time computed only using contacts and observations at the dropped time (and the prior computed in the previous step). All simulations have been performed using a 21 days time window.
For the OpenABM model, we chose to use Gamma distributions for the recovery density p R.i = p R and a rescaled Gamma for the infection transmissivity λ s ij ,t i ij = p I (s ij − t i ). The five parameters were fitted from experimental data produced by the model (parameters could in principle be also learned or adjusted online during the process through an approximate maximum likelihood procedure [13] , but we leave this for future work). Note that the model used for inference with BP is still much simplified with respect to OpenABM itself, in particular having only three states (against 11 in OpenABM). As a consequence, results are only weakly sensitive to the parameters. The used values were Gamma(k = 10, µ = 0.57) for p R and Gamma(k=5.76, µ = 0.96), with a scale of 0.25 (multiplied by 2 for intra-household contacts as with MF inference) for λ. The self-infection probability was chosen to be p seed = 1/N at time t = 0 (k/N where k is the number of patient zeros would bring slightly better results, but would use inaccessible information) and 0 for t > 0 except for the case with partial adoption, in which we allowed a small probability of self-infections at times t > 0 to avoid plain incompatibility between the inference model and observations due to undetected transmissions). The parameter δ rank for the computation of the ranking was chosen to be 10 days.
In this section, we present additional results to stress how the containment measures associated with the inference-based methods proposed in the main text, are effective in limiting the epidemics. We consider a realistic spreading dynamics given by the OpenABM model [21] and, unlike the setting illustrated in the main text, we study the case in which the restrictions are applied earlier in time (i.e. after a week from the beginning of the epidemics) and the size of the epidemics at the initial time is smaller (the number of patients zero here is 20), being also consistent with an earlier intervention scenario. In Figure 5 , we display the behavior of the number of infected individuals as a function of time, similarly to Figure 2 of the main text. Qualitatively, we retrieve the same behavior we have observed in Figure 2 : inference-based ranking allows for a more effective intervention resulting in a remarkable decrease of the number of infected individuals, and when the number of tests is sufficiently large, the epidemics are stopped in slightly more than two months. Quantitatively, we notice that to control the spreading a reduced number of daily medical tests are needed (about ten times less than those used for the results in Figure 2 ), suggesting that early intervention is equally effective with a more parsimonious usage of testing resources. Figure 6 suggests how robust the containment measures are when the medical tests are Figure 6 : Effect of tests inaccuracy to the evolution of the controlled epidemics. We simulate the same intervention protocol as Figure 5 for 1000 daily observations (bottom panel). We consider here the effects of an additional source of noise, that is a non negligible false negative rate (FNR) of the results of the medical tests, from 0.09 to 0.40. Figure 7 : Effect of a poor adoption fraction of the app to the number of infected individuals. We simulate the same intervention protocol as Figure 5 for 1000 daily observations. We assume here that only a fraction of the population, from 90 % to 60%, uses the app for contact tracing.
inaccurate. We quantify their sensitivity through a false-negative rate (FNR) of the medical tests (similar results are discussed in the main text, see Figure 3 ). The setting is the same as in Figure 5 when 1000 medical tests are performed to the individuals who present the higher risk to be infected, according to RG, CT, MF, and BP. These curves support the conclusion of the main text: inference-based methods successfully contain an epidemic in a realistic setting with non-zero FNR. Indeed, CT and MF are able to contain the epidemics up to FNR equal to 0.09 and 0.25, respectively. BP shows the most robust performance as it is able to stop the epidemics even for larger values of the FNR, up to 0.31. Finally, we show the average epidemic size as a function of the time in Figure 7 when only a fraction of the population uses the app for contact tracing and, therefore, only partial information on potentially infectious contacts is available to the risk assessment methods. Up to an adoption fraction of 0.7, inference-based methods (MF and BP) allows for a significantly slowing down of the epidemic spreading compared to both the random and CT-based testing.