New Research In
Physical Sciences
Social Sciences
Featured Portals
Articles by Topic
Biological Sciences
Featured Portals
Articles by Topic
- Agricultural Sciences
- Anthropology
- Applied Biological Sciences
- Biochemistry
- Biophysics and Computational Biology
- Cell Biology
- Developmental Biology
- Ecology
- Environmental Sciences
- Evolution
- Genetics
- Immunology and Inflammation
- Medical Sciences
- Microbiology
- Neuroscience
- Pharmacology
- Physiology
- Plant Biology
- Population Biology
- Psychological and Cognitive Sciences
- Sustainability Science
- Systems Biology
How a well-adapting immune system remembers
Edited by Herbert Levine, Rice University, Houston, TX, and approved March 21, 2019 (received for review July 25, 2018)

Significance
The adaptive immune system is able to protect us from a large variety of pathogens, even ones it has not seen yet. Can predicting the future pathogen distribution help in protection? We find that a combination of probabilistic forecasting and occasional sampling of the current environment reduces infection costs—a scheme easily implemented by the memory repertoire. The proposed theoretical framework offers a modular recipe for updating the memory repertoire, which quantitatively predicts the strength of the immune response in flu-vaccination experiments, unlike other update schemes. It also links the observed early life dynamics of the memory pool to the sparseness properties of the pathogen distribution and competitive receptor dynamics for pathogens.
Abstract
An adaptive agent predicting the future state of an environment must weigh trust in new observations against prior experiences. In this light, we propose a view of the adaptive immune system as a dynamic Bayesian machinery that updates its memory repertoire by balancing evidence from new pathogen encounters against past experience of infection to predict and prepare for future threats. This framework links the observed initial rapid increase of the memory pool early in life followed by a midlife plateau to the ease of learning salient features of sparse environments. We also derive a modulated memory pool update rule in agreement with current vaccine-response experiments. Our results suggest that pathogenic environments are sparse and that memory repertoires significantly decrease infection costs, even with moderate sampling. The predicted optimal update scheme maps onto commonly considered competitive dynamics for antigen receptors.
All living systems sense the environment, learn from the past, and adapt predictively to prepare for the future. Their task is challenging because environments change constantly, and it is impossible to sample them completely. Thus, a key question is how much weight should be given to new observations vs. accumulated past experience. Because evidence from the world is generally uncertain, it is convenient to cast this problem in the language of probabilistic inference where past experience is encapsulated in a prior probability distribution which is updated according to sampled evidence. This framework has been successfully used to understand aspects of cellular (1⇓⇓–4) and neural (5⇓⇓–8) sensing. Here, we propose that the dynamics of the adaptive immune repertoires of vertebrates can be similarly understood as a system for probabilistic inference of pathogen statistics.
The adaptive immune system relies on a diverse repertoire of B- and T-cell receptors to protect the host organism from a wide range of pathogens. These receptors are expressed on clones of receptor-carrying cells present in varying copy numbers. A defining feature of the adaptive immune system is its ability to change its clone composition throughout the lifetime of an individual, in particular via the formation of memory repertoires of B and T cells following pathogen encounters (9⇓⇓⇓⇓–14). In detail, after a proliferation event that follows successful recognition of a foreign antigen, some cells of the newly expanded clone acquire a memory phenotype. These cells make up the memory repertoire compartment that is governed by its own homeostasis, separate from the inexperienced naive cells from which they came. Upon reinfection by a similar antigen, memory guarantees a fast immune response. With time, our immune repertoire thus becomes specific to the history of infections and adapted to the environments we live in. However, the commitment of part of the repertoire to maintaining memory must be balanced against the need to also provide broad protection from as-yet-unseen threats. What is more, memory will lose its usefulness over time as pathogens evolve to evade recognition.
How much benefit can immunological memory provide to an organism? How much memory should be kept to minimize harm from infections? How much should each pathogen encounter affect the distribution of receptor clones? To answer these questions, we extend a framework for predicting optimal repertoires given pathogen statistics (15) by explicitly considering the inference of pathogen frequencies as a Bayesian forecasting problem (16). We derive the optimal repertoire dynamics in a temporally varying environment. This approach can complement more mechanistic studies of the dynamics and regulation of immune responses (12, 17⇓⇓⇓⇓–22) by revealing adaptive rationales underlying particular features of the dynamics. In particular, we link the amount of memory production to the variability of the environment and show that there exists an optimal time scale for memory attrition. Additionally, we demonstrate how biologically realistic population dynamics can approximate the optimal inference process and analyze conditions under which memory provides a benefit. Comparing predictions of our theory to experiment, we argue for a view in which the adaptive immune system can be interpreted as a machinery for learning a highly sparse distribution of antigens.
Theory of Optimal Immune Prediction
The pathogenic environment is enormous, and the immune system can only sample it sparsely, as pathogens enter into contact with it at some rate λ. We consider an antigenic space of K different pathogens with time-varying frequencies
Sketch of a model of immune repertoire dynamics as a sequential inference process about a time-varying pathogen distribution. (A) The organism lives in a pathogenic environment with frequencies of different pathogen strains that change over time. (B) Past pathogen encounters provide an avenue for the immune system to learn the pathogen distribution. Using sequential Bayesian inference provides an optimal way to update the beliefs about the frequencies of different pathogens over time. (C) Based on its beliefs about the prevalence of pathogens, the optimal immune dynamics allocates lymphocytes across different pathogens to minimize the expected harm from infections. Broadly, the more frequent a pathogen is, the more the organism should be covered. This resource allocation maps the changes in beliefs to the changes in the repertoire composition.
How could the immune system leverage a representation of beliefs about pathogen frequencies to provide effective immunity? Each lymphocyte (B or T cell) of the adaptive immune system expresses on its surface a single receptor r out of L possible receptors. This receptor endows the lymphocyte with the ability to specifically recognize pathogens (labeled a) with probability
The internal representation of the environment can be regarded as a system of beliefs, or guesses, about pathogen frequencies. Formally, these beliefs can be represented in the form of a probability distribution function
The Bayesian forecasting framework provides a broad account of the possible adaptive value of many features of the adaptive immune system without the need for additional assumptions. Immune memory formed after a pathogenic challenge is explained as an increase in optimal protection level resulting from an increase in estimated pathogen frequency, following Eq. 3. Attrition of immune memory is also adaptive, because it allows the immune repertoire to forget about previously seen pathogens which it should do in a dynamically changing environment (Eq. 4). Lastly, some of the biases in the recombination machinery and initial selection mechanisms (24) represent an evolutionary prior (Eq. 2) which tilts the naive repertoire toward important regions of antigenic space.
We are proposing an interpretive framework for understanding adaptive immunity as a scheme of sequential inference. This view provides two key insights. First, it confirms the intuition that new experience should be balanced against previous memory and against unknown threats in order for adaptive immunity to work well. Second, it suggests a particular dynamics of implicit belief updates that can globally reorganize the immune repertoire to minimize harm from the pathogenic environment. Going beyond these broad ideas, in Results, we analyze in detail a model for optimal immune prediction in which all these statements can be made mathematically precise. We also show a plausible implementation that the immune system could follow to approximate optimal Bayesian inference, and we compare the resulting dynamics with specific features of the adaptive immune system.
Results
A Lymphocyte Dynamics for Approximating Optimal Sequential Inference.
For concreteness, we consider a drift-diffusion model of environmental change (Eq. 11). The drift-diffusion model, while clearly a much-simplified model of real evolution, captures two key features of changing pathogenic environments: the coexistence of diverse pathogens and the temporal turnover of dominant pathogen strains. The aim of this model of pathogen evolution is not to provide a realistic description of short-term pathogen dynamics within a population such as during an epidemic, but rather to capture overall features of the long-term dynamics of many pathogens over a host’s lifetime. The drift-diffusion model is mathematically equivalent to a classical neutral stochastic evolution of pathogens (25) driven by genetic drift happening on a characteristic time scale τ and immigration from an external pool with immigration parameters
Can a plausible dynamics of lymphocyte receptor clones approximate the optimal repertoire dynamics? In particular, is there an approximate autonomous dynamics for the repertoire composition, which does not require access to the full latent high-dimensional belief distribution
For the pathogen dynamics of Eq. 10, we show, using a decomposition of
A plausible repertoire dynamics can implement approximate Bayesian inference. Frequency
These dynamics have a plausible biological implementation. Each pathogen encounter leads to a fixed increment χ of the number of specific lymphocytes (Eq. 6), implying a regulation mechanism that controls the number of cell divisions upon clonal expansion as a function of precursor frequency. Through thymic output, the repertoire starts at and is renewed by the naive repertoire—encoded in
To gain intuition about what the dynamics of Eqs. 5–7 mean, let us define the rescaled variables
The assumption that
Learnability of Pathogen Distribution Implies a Sparse Pathogenic Landscape.
The immune system must be prepared to protect us not just from one pathogen but a whole distribution of them. Even restricting recognition to short peptides and accounting for cross-reactivity (26), estimates based on precursor frequencies for common viruses give an effective antigen environment of size
This apparent paradox can be resolved by the fact that the pathogenic environment may be sparse, meaning that only a small fraction of the possible pathogens are present at any given time. In our model of the pathogen dynamics, this sparsity is controlled by the parameter θ. In the scenario that we are considering, typical pathogen landscapes Q are drawn from the steady-state distribution
Our theory can be used to quantify the benefit of memory as a function of the different immunological parameters. We compute the optimized cost function
Advantage of immunological memory depends on sufficient sampling. The mean expected cost of an infection in a changing environment is a function of the age of the organism t, the time scale τ on which the environment changes, and the sparsity
Analytical arguments show that in the limit of few samples the relative cost
Optimal Attrition Time Scale.
Our theory suggests that there is an optimal time scale for forgetting about old infections which is related to the time scale over which the environment varies. Eq. 7 shows that memory should optimally be discounted on an effective time scale
Interestingly, our theory predicts that memory should be discounted more quickly when the immune system has gathered more information (larger
Memory Production in Sparse Environments Should Be Large and Decrease with Prior Exposure.
The theory can be used to make quantitative and testable predictions about the change in the level of protection that should follow a pathogen encounter. Consider an infection cost function that depends as a power law on the coverage,
In the simplest model for repertoire updates, recognition of pathogens leads to proliferation proportionally to the number of specific precursor cells, followed by a homeostatic decrease of the memory pool (18, 33). Thus, the fold change
To understand this prediction, first consider the effect of a primary infection on a naive repertoire,
Changes in protection levels upon infections for cost functions
To test Eq. 9 on immunological data, we fit the Bayesian update model to experiments reporting fold changes in antigen titers upon booster vaccinations against influenza from ref. 34 (Fig. 4A) using least squares. Titers correspond to the concentration of antibodies that are specific to the antigen a and can thus be viewed as an experimental estimate of
Interestingly, for T cells, Quiel et al. (38) have shown that fold expansion to peak cell numbers in an adoptive transfer experiment depends on the initial number of T cells as a power law with exponent
Long-Term Dynamics of a Well-Adapting Repertoire.
Our model makes predictions for the dynamics of growth and attrition of memory over time, with consequences for immunity and for the diversity of the immune repertoire. We quantify the dynamics in terms of a memory fraction defined as a sum of the coverage fractions
Relative cost (A and D), memory-cell fraction (B and E), and memory diversity (C) as a function of age. A–C show long-term dynamics for a repertoire following optimal Bayesian update dynamics for three different α. Memory diversity is plotted as richness, i.e., the number of unique memory specificities, as well as the exponential of Shannon entropy S of the memory compartment defined for a probability distribution
To gain insight into these dynamics of our model, we average the stochastic equations over the statistics of pathogen encounters. We show in SI Appendix, section 2B that this mean-field approximation yields a differential equation for the population fraction of different clones with two opposing contributions which balance alignment of the immune repertoire with the current pathogenic environment (i.e., memory production) against alignment with the long-term mean environment (i.e., attrition). Interestingly, the mean-field equation broadly coincides with dynamics that were proposed in ref. 15 to self-organize an optimal immune repertoire. The essential difference here is that the time scale of learning slows down with increasing experience following the rules of optimal sequential update in Eq. 9.
We then asked which features of the proposed repertoire dynamics are most relevant to ensure its effectiveness. How important is the negative correlation between fold expansion and prior immune levels, and how important is attrition? Furthermore, if the immune system follows Bayesian dynamics, it must have integrated on an evolutionary time scale a prior about composition and evolution of the pathogen environment through the parameters θ and τ—however, the prior may be inaccurate. How robust is the benefit of memory to imperfections of the host’s prior assumptions about pathogen evolution? To answer these questions, we compare the long-term immune-repertoire dynamics using the optimal Bayesian scheme to other simplified schemes. We find that a constant fold expansion dynamics quickly leads to very suboptimal repertoire compositions (Fig. 5D, pink line), since the exponential amplification of cells specific to recurrent threats quickly leads to a very large fraction of the repertoire consisting of memory of those pathogens (Fig. 5E, pink line). This suboptimality persists, even if we assume that some global regulation caps the constant fold expansion such that no individual receptor clone can take over all of the repertoire (Fig. 5 D and E, gray line). Thus, negative feedback in T-cell expansion to individual antigens is very important to maintain a properly balanced diverse repertoire. In contrast, within dynamics with a negative correlation, the precise levels of updating do not need to be finely tuned to the environmental statistics: Varying the assumed sparsity of the pathogen distribution, which controls fold expansion upon primary infection in the optimal dynamics, leads to a relatively modest deterioration of the convergence speed of the learning process (SI Appendix, Fig. S2A) and does not matter asymptotically (SI Appendix, Fig. S2B). Attrition does not matter at young age, but can play an important role for long-term adaptation to relatively rapidly changing pathogen distributions (Fig. 5F). However, the attrition time scale need not be finely tuned to get close to optimal dynamics (SI Appendix, Fig. S3).
Adapting a Cross-Reactive Repertoire.
Above, we described adaptation of immune repertoires in terms of changes in the effective coverage
Following Perelson and Oster (41), we will represent the interaction of receptors and antigens by embedding both in a multidimensional metric recognition “shape space,” where receptors are points surrounded by recognition balls. Antigens that fall within a ball’s radius will be recognized by the corresponding receptor. In this presentation, a and r are the coordinates of antigens and receptors, respectively, and their recognition propensity depends on their distance,
Earlier sections have already discussed the optimal dynamics of the coverage
In general, the frequencies of pathogens might be correlated in antigenic space, for example, because mutations from a dominant strain give rise to new neighboring strains. An optimally adapting immune system should incorporate such correlations as a prior probability favoring smoothness of the pathogen distribution. Such priors work their way through the optimal belief update scheme that we have described and weaken the competitive exclusion between clones with overlapping cross-reactivity (SI Appendix, Fig. S4, orange line).
In general, when cross-reactivity is wide or the required clone fraction update is large, numerical analysis shows that achieving optimally predictive immunity after a pathogen encounter requires a global reorganization of the entire repertoire (SI Appendix, Fig. S5, blue line). There is no plausible mechanism for such a large-scale reorganization since it would involve up- and down-regulation, even of unspecific clones. However, in SI Appendix, section 2C we show that the optimal update can be well-approximated by changes just to the populations of specific clones with pathogen-binding propensities
Discussion
The adaptive immune system has long been viewed as a system for learning the pathogenic environment (10). We developed a mathematical framework in which this notion can be made precise. In particular, we derived a procedure for inferring the frequencies of pathogens undergoing an immigration-drift dynamics and showed how such inference might approximately be performed by a plausible population dynamics of lymphocyte clones. Additionally, we analyzed how quickly the immune system can learn about its environment and find that the antigenic environment must be effectively sparse to be learnable with a realistic rate of pathogen encounters.
The optimal repertoire dynamics recapitulate a number of properties of real adaptive immune systems. Two repertoire compartments emerge from the theory: memory, which encodes lived experience, and naive, which encodes prior expectations. Memory is effective in reducing harm from infection despite the high dimensionality of pathogenic space; having encountered circulating pathogens only once on average can reduce the overall cost of infections by half. The first encounter of a naive individual with a pathogen leads to a large response, which increases protection levels by several orders of magnitude. Memory production depends on prior protection levels and eventually is predicted to saturate, as seen in vaccination experiments (34). This saturation is predicted to lead to a sublinear increase with age of the fraction of the total repertoire taken up by memory, consistent with observations in human cohorts (39, 40).
Our work makes a number of concrete predictions amenable to further testing. We make quantitative predictions about how much memory should be formed following an infection, as a function of number of pathogens effectively present in the environment and the number of previous infections. These dependencies might be tested by using a comparative approach, which relates the amount of formed memory in different species to how many pathogens to which they are susceptible. Our model also makes predictions about changes in the size and diversity of the memory compartment with aging, which might be tested in future repertoire-sequencing studies similar to those done by Britanova et al. (42), by sorting cells into naive and memory types before sequencing. Ultimately, we hope that our work might help motivate studies with longitudinal tracking of the long-term repertoire dynamics in model organisms living in controlled pathogenic environments.
Our framework can be extended to incorporate additional constraints on immune-system function or further aspects of pathogen evolution. An example of a constraint would be to introduce a maximal rate of change in the optimization to model maximal cellular division and death rates. A more complex pathogen dynamics might model explicitly their mutational dynamics in antigenic space. Such dynamics will lead to correlations in the pathogen distribution, which we showed will influence the structure of the optimal conjugate repertoire. In particular, the optimal response should spread around the currently dominant antigens to also provide protection against potential future mutations. Hypermutations in B cells may play a role in this diversification, in addition to their known function of generating receptors with increased affinity for antigens of current interest. It would also be interesting to extend our framework to other immune-defense mechanisms, including innate immunity, where the role of memory has received recent attention (43).
Although our study was motivated by the adaptive immune system, some of our main results extend to other statistical inference problems. We have extended earlier results on exactly computable solutions to the stochastic filtering problem for Wright–Fisher diffusion processes (44) to derive an efficient approximate inference procedure. This procedure might be of use in other contexts where changing distributions must be inferred from samples at different time points, e.g., in population genetics. Additionally, we have derived the convergence rate for Bayesian inference of categorical distributions in high dimensions in the undersampled regime, showing that effectively sparse distributions can be inferred much more quickly. These results add to the growing literature on high-dimensional inference from few samples (45, 46), which has arisen in the context of the big-data revolution.
We propose that the adaptive immune system balances integration of new evidence against prior knowledge, while discounting previous observations to account for environmental change. Similar frameworks have been developed for other biological systems. In neuroscience, leaky integration of cues has been proposed as an adaptive mechanism to discount old observations in change-point detection tasks (47, 48), and close-to-optimal accumulation and discounting of evidence has been reported in a behavioral study of rat decision-making in dynamic environments (49). Inference from temporally sparse sampling has been considered in the framework of infotaxis, which is relevant for olfactory navigation (50). In the context of immunity, related ideas about inference and prediction of pathogen dynamics have been used to predict flu-strain and cancer-neoantigen evolution in silico (51, 52). Finally, ideas similar to those developed here could be used in ecology or microbiome studies to reconstruct evolutionary or ecological trajectories of population dynamics from incomplete sampling of data at a finite number of time points, e.g., from animal sightings or metagenomics.
Materials and Methods
Modeling Pathogen Dynamics by an Immigration-Drift Process.
In our model, we describe the stochastic dynamics of the pathogenic environment (Fig. 1A) by a Fokker–Planck equation for the conditional probability distribution
Minimizing the Cost of Infection.
To solve the optimization problem Eq. 1 analytically, a set of necessary conditions for optimality, the so-called Karush–Kuhn–Tucker conditions, can be derived. When all receptors are present at a nonzero frequency in the optimal repertoire
Change in Protection upon a Pathogen Encounter.
The inference dynamics induces via the mapping from
Rewriting Eq. 6 in terms of the expected pathogen frequencies
Acknowledgments
The work was supported by European Research Council Starting Grant 306312, a Lewis–Sigler fellowship (to A.M.), Simons Foundation Mathematical Modeling of Living Systems Grant 400425, and NSF Grant PHY-1734030. Work on this project at the Aspen Center for Physics was supported by NSF Grant PHY-1607611.
Footnotes
↵1A.M.W. and T.M. contributed equally to this work.
- ↵2To whom correspondence may be addressed. Email: awalczak{at}lpt.ens.fr or tmora{at}lps.ens.fr.
Author contributions: A.M., V.B., A.M.W., and T.M. designed research; A.M., V.B., A.M.W., and T.M. performed research; A.M., V.B., A.M.W., and T.M. contributed new reagents/analytic tools; A.M., V.B., A.M.W., and T.M. analyzed data; and A.M., V.B., A.M.W., and T.M. wrote the paper.
The authors declare no conflict of interest.
This article is a PNAS Direct Submission.
This article contains supporting information online at www.pnas.org/lookup/suppl/doi:10.1073/pnas.1812810116/-/DCSupplemental.
- Copyright © 2019 the Author(s). Published by PNAS.
This open access article is distributed under Creative Commons Attribution-NonCommercial-NoDerivatives License 4.0 (CC BY-NC-ND).
References
- ↵
- Perkins TJ,
- Swain PS
- ↵
- ↵
- Siggia ED,
- Vergassola M
- ↵
- Sivak DA,
- Thomson M
- ↵
- ↵
- ↵
- ↵
- ↵
- Murphy K,
- Travers P,
- Walport M
- ↵
- Farmer JD,
- Packard NH,
- Perelson AS
- ↵
- ↵
- ↵
- ↵
- ↵
- Mayer A,
- Balasubramanian V,
- Mora T,
- Walczak AMA
- ↵
- Chen ZHE
- ↵
- Deem MW,
- Lee HY
- ↵
- ↵
- François P,
- Altan-Bonnet G
- ↵
- George JT,
- Kessler DA,
- Levine H
- ↵
- Chakraborty AK
- ↵
- Mayer A,
- Zhang Y,
- Perelson AS,
- Wingreen NS
- ↵
- Percus JK,
- Percus OE,
- Perelson AS
- ↵
- Mora T,
- Walcak A
- ↵
- ↵
- ↵
- ↵
- Antia R,
- Pilyugin SS,
- Ahmed R
- ↵
- ↵
- ↵
- Macallan DC,
- Borghans JA,
- Asquith B
- ↵
- Becker NB,
- Mugler A,
- Ten Wolde PR
- ↵
- De Boer RJ,
- Perelson AS
- ↵
- Ellebedy A, et al.
- ↵
- ↵
- Bocharov G, et al.
- ↵
- ↵
- Quiel J, et al.
- ↵
- ↵
- ↵
- ↵
- Britanova OV, et al.
- ↵
- Netea MG, et al.
- ↵
- Chaleyat-Maurel M,
- Genon-Catalot V
- ↵
- ↵
- Advani M,
- Ganguli S
- ↵
- ↵
- ↵
- Piet AT,
- El Hady A,
- Brody CD
- ↵
- ↵
- ↵
- ↵
- Etheridge A
- ↵
- Griffiths RC,
- Spano D
Citation Manager Formats
Sign up for Article Alerts
Article Classifications
- Physical Sciences
- Physics



















