Animal board invited review: Quantification of resilience in farm animals

animal responses to perturbations. Case studies were developed to illustrate alternative approaches to real-time and post-treatment of data. In addition, perspectives on the use of hybrid models for better understanding and predicting animal resilience are presented. Quantiﬁcation of resilience at the individual level makes possible the inclusion of this trait into future breeding programmes. This would allow improvement of the capacity of animals to adapt to a changing environment, and therefore potentially reduce the impact of disease and other environmental stressors on animal welfare. Moreover, such quantiﬁcation allows the farmer to tailor the management strategy to help individual animals to cope with the perturbation, hence reducing the use of pharmaceuticals, and decreasing the level of pain of the animal.


Introduction
During the last decades, there has been an explosion in the number of sensors in the context of precision livestock farming.Sensors such as cameras, microphones and accelerometers made it possible to monitor animals automatically and individually in real time (Halachmi et al., 2019;Caja et al., 2020;Gómez et al.,

Animal
The international journal of animal biosciences 2021) and with a lower cost (Wolfert et al., 2017).These new monitoring technologies have exponentially increased the number of data collected and therefore our capacity to observe animals.The data obtained from these devices can be of great interest to farmers and the livestock sector to adapt future selection strategies and farm management, in order to improve production, animal health and welfare (Friggens et al., 2008;Højsgaard and Friggens, 2010).Extracting relevant information from this increasing quantity of heterogeneous data generated by sensors is a major challenge (Morota et al., 2018;González et al., 2018;Tedeschi, 2019;Ellis et al., 2020).It requires new skills and methods for data processing, analysis and predictive modelling.Combination of records of such sensors with adequate data analysis algorithms and models enables the monitoring of welfare and prediction of productivity of animals (Werkheiser, 2018;Benjamin and Yik, 2019).
The capacity of modern technologies to monitor automatically, and simultaneously, multiple traits from sensors with high frequency at the individual level also provides huge opportunities to study the resilience of individual animals.Improving individual animals' resilience is of great interest for livestock farming systems, as resilient animals contribute to the capacity of the herd to cope with fluctuating and unpredictable environmental conditions (Dumont et al., 2014).Furthermore, these technologies may facilitate early prediction of an animal's capacity for resilience, e.g. through the application of artificial intelligence methods to analyse multiple non-invasive indicators of animal responses to environmental and physiological challenges.Such an algorithm could help the farmer to adopt a timely and adequate strategy to help animals cope with different types of perturbations (for example by using preventative measures such as vaccines).
The literature contains many definitions of resilience and related concepts (e.g.plasticity, robustness, genotype by environment interactions).In this paper, we adopt the definition of resilience as a dynamic trait that refers to an animal's capacity to rapidly respond to short-term environmental (temperature, sanitary stress, etc.) challenges and to be able to return rapidly to the prechallenge status (Colditz and Hine, 2016).In general, the dynamic response of the animal to a perturbation can be decomposed into a first period that captures the response of the animal to the perturbation and a second period corresponding to the recovery phase of an animal postperturbation (Doeschl-Wilson, 2011;Mulder and Rashidi, 2017;Scheffer et al., 2018;Knap and Doeschl-Wilson, 2020).It should be noted that there could also be a latency period, at the beginning of an infection, for example, during which the perturbing factor is present but has not yet caused an impact on animal performance (Sandberg et al., 2006;Sauvant and Martin, 2010).
The response of the animal to a perturbing factor is a function of both the adaptive capacity of the animal and the type and magnitude of the perturbing factor.Time-series data of performance traits measured by sensors represent animal responses to different types of disturbing factors (with known or unknown origins).To quantify the resilience of the animal, the first step is to define a metric that is representative of the animal response and transforms the concept of resilience into a quantitative variable (Todman et al., 2016;Ingrisch and Bahn, 2018).In the definition of this metric, factors such as the nature and the number of indicators of performance, and the research question should be considered (Fig. 1).Table 1 lists some of these metrics and their use in the context of animal adaptive response.Mathematical models are powerful tools to put together theoretical frameworks, existing knowledge and available data to provide new insights on unknown phenomena.In the context of this study, an adequate mathematical model could help in developing a metric for animal resilience.
With respect to data frequency and existing knowledge on underlying mechanisms, there are two main categories of models to characterise animal's adaptive response.The first category is concept-driven or mechanistic models considering the systemic aspect of an animal response, and the second category is models based on data and thus called data-driven models.Both categories have been often used to understand the animal adaptive response, in particular when faced with nutritional challenges (Tedeschi, 2019).Ellis et al. (2020) suggested that, in future, modern animal production systems will take advantage of hybrid models including both data-driven and concept-driven approaches.
Since resilience is a dynamic trait, a dynamic mathematical model is expected to describe it best.Inputs, parameters and outputs are the main components of dynamic models (Fig. 2).The main role of a modeller is to specify the structure of the models and to determine the parameters that describe the characteristics of the system under study (animal).In what are called 'forward problems', given a model structure, inputs and parameter values, the model predicts outputs.In contrast to the 'forward problem', the 'inverse problem' is a mathematical framework that allows information to be obtained on model parameters, given the model structure and the available data from observations or measurements of animal response.The inverse problem needs to address both theoretical and practical challenges for identifying accurately the model parameters (Muñoz-Tamayo et al., 2018;Vargas-Villamil et al., 2020).This approach has been used in the literature to quantify individual resilience defined as a parameter in perturbation models (Nguyen-Ba et al., 2020;Ben Abdelkrim et al., 2021a).Using mechanistic models for animal growth, Doeschl-Wilson et al. (2007) demonstrated that the parameter estimates obtained from such model inversion techniques could be used as new phenotypes for genetic selection.
The main objective of this paper was to illustrate how mathematical modelling can adapt to this new generation of data (i.e., with high-frequency recording) to quantify animal responses to perturbations, and in this way contribute to a better understanding of animal resilience capacity.In addition, perspectives on the use of hybrid models for better understanding and predicting animal resilience are presented.Our discussions are supported by case studies.Models were implemented in the free software R (version 3.4.2,https://www.r-project.org/).To promote open science practices (Muñoz-Tamayo et al., 2022) and facilitate the understanding of the modelling approaches, the R codes of the examples are available at https://quantanimal.github.io/.

Perturbations and the theoretical trajectory of performance
When developing a model to describe an animal response to short-term perturbations, the first step is to determine what is called a perturbation.A perturbation in the context of this study consists of all short-term changes in the farm environment, such as temperature, feed compositions, presence of a pathogen, that have an impact on animal performance.The second step is to consider the available indicators of performance impacted by these perturbations, and to determine the theoretical trajectory associated with these indicators.The theoretical trajectory is defined as the performance of the animal in the absence of all perturbations in the environment (Nguyen-Ba et al., 2020).For farm animals, the theoretical performance trajectory of an animal depends on multiple factors, such as the animal genetic make-up, its longterm environment and the feeding strategy.Finally, deviations (positive or negative) from this trajectory can then be quantified as the impact of perturbation (having ensured that the detected deviations are not part of inherent variations in the animal behaviour).Depending on the available data, one or several indicators of performance could be used to quantify the animal adaptive response (Table 1).

From classical models to a new generation of models
Since the 1970s, mechanistic models have been developed to study the effect of feed composition and feed availability on animal performance (Whittemore and Fawcett, 1976;Whittemore, 1986;van Milgen et al., 2008;Martin and Sauvant, 2010;Puillet et al., 2016).These models are typically based on concepts of a performance potential, nutrient partitioning and efficiency of nutrient utilisation (i.e., input-output relationships).There are also a few models considering the influence of infection or other environmental challenges on animal performance (Wellock et al., 2003;Sandberg et al., 2006;Doeschl-Wilson et al., 2009).The small number of such models is likely due to difficulties in characterising the environment and the multiple traits with which the animal responds to environmental changes.These models are so-called 'forward models', which, given a model structure, specified values for the environmental descriptors (e.g.feed composition, feeding frequency) and animal-specific parameters (genetic potential for growth rate, feed efficiency) and predict animal performance as an output (BW, number of offspring).The common denominator of these models is that they require an understanding of the underlying biological mechanisms that relate the model input parameter Fig. 1.The hypothetical response of three animals to a given perturbation.The observable response started at T1.The recovery started at T2.Animal a has a largest decrease in performance but recovers faster, while animals b and c have the smallest decrease in performance but they recover later.Moreover, animal c seems to compensate for the loss of performance.It is therefore necessary to define metrics for animal adaptive response based on the same criteria.This example is generic and independent of the animal species.

Table 1
List of potential variables to describe and quantify animal resilience.These variables can be adapted for any species.

Item
Definition Examples

Magnitude of perturbation
Maximum of the difference between the theoretical trajectory of performance and the actual perturbed performance (Codrea et al., 2011)

Dairy cows Time of recovery
The time between the minimum value of performance reached and the time of complete recovery (return to the theoretical trajectory).(Sadoul et al., 2015) Rainbow trout Surface The area between the theoretical trajectory and the actual performance during the perturbation interval values to the outputs (Fig. 2).The availability of dynamic data, such as Indicators of animal performance, enables the identification of the mechanistic model parameters at individual scale, that more closely represent the individuals' intrinsic, or genetic response capacity, such as an animal's target growth trajectory in the absence of environmental challenges (Doeschl-Wilson et al., 2007;Yu et al., 2021).When data are available, but knowledge on the underlying mechanisms responsible for the loss in performance is missing or not needed, statistical methods can be used.These approaches involve the development of models based on data recorded dynamically (in the case of adaptive response), and the effort of the modeller is to determine the function that mimics the evolution of a trait over time.Such approaches have been used, in pigs for example, to describe growth with a Gompertz function (Schulin-Zeuthen et al., 2008;Lewis and Emmans, 2020), or cumulative feed intake with a Gamma function (van Milgen et al., 2008), or infection profiles (Islam et al., 2013).During recent years, the application of such classical approaches has evolved in line with the new generation of data from precision livestock farming (Yu et al., 2021).
Evolution in data-driven approaches to quantify animal resilience is mostly driven by the availability of performance data at high frequency and for a large number of animals.This new generation of data opens new horizons for real-time precision management targeted at individual animals, thus offering huge scope for improvement of the welfare of individual animals as performance measures are adjusted to the individual (Sun et al., 2010;Kamphuis et al., 2010).In this respect, such modelling approaches are often used for the detection of perturbations in real time, which provide support for targeted and timely management strategies or medical treatments.To go further towards application, such models are often implemented in decision-support systems to aide farm management, and suggest the best treatment in relation with a detected perturbation (Rutter, 2014;Van Nuffel et al., 2015;Gómez et al., 2021).
In what follows, examples of models are described that detect and quantify the animal capacity of response to perturbations.These models are separated into two categories: models for posttreatment of data, and models for real-time treatment of data.
Although the examples presented are not an exhaustive list, and other approaches exist, they reflect the way that the classical modelling approaches evolved to integrate the high-frequency records of performance data.Moreover, we discuss the interest of coupling both approaches and moving towards hybrid models and processes, to predict the resilience capacity of animals.

Post-treatment of longitudinal data
Defining or finding a function that fits the perturbed data with a good accuracy is the main difficulty when studying performance trajectories during perturbation periods.Some popular functions such as the Gompertz function (Schulin-Zeuthen et al., 2008) to describe the theoretical growth of farm animals and the Wood function (Wood, 1967) for milk yield of dairy cows in nonlimiting environments are widely used by animal scientists and modellers.Despite the usefulness of these functions to represent the time-trends of these traits, they cannot fit the evolution of data during periods of perturbation.Some of these functions were modified to account for the potential periods of perturbation.For example, the modified Gompertz function (Golubev, 2009) considers the possibility of deviations from the classical Gompertz function to describe the influence of a perturbation on performance.It was used successfully to quantify piglet robustness at weaning (Revilla et al., 2019).A modified Wood function was used to simu-late milk yield in the presence of environmental and nutritional perturbations (Ben Abdelkrim et al., 2021a).Some authors suggested the use of the well-known physical 'spring and damper system' to mimic animal adaptive response (Sadoul et al., 2015;Todman et al., 2016;Taghipoor et al., 2017).In this approach, inputs and outputs are recorded and the objective is the estimation of model parameters (inverse problem, Fig. 2).In such models, the first step is the development of a module that estimates the theoretical performance trajectory in a long-term stable environment, and subsequently adding the perturbation module to characterise the animal response to the perturbation.This approach was used to describe deviations from the expected trajectory of feed intake in growing pigs (Nguyen-Ba et al., 2020).
Although the modelling approaches described above have proven successful in some examples, it is not obvious how they can respond if the time-trend of the response cannot be described by the already defined, or known, functions or systems of equations that represent the underlying biological mechanisms.This is especially pertinent when the shape of the theoretical trajectory is unknown.If available data are recorded at high frequency, a purely data-driven model could be used to describe an animal's capacity of response.One of these methods is differential smoothing of time-series measurements, hereafter termed functional data analysis (Ramsay and Silverman, 2002;Codrea et al., 2011;Ben Abdelkrim et al., 2021b).The combination of this approach with other regression methods such as quantile regression makes it possible to estimate the expected trajectory of the performance and detect the perturbation periods (Scheffer et al., 2018;Berghof et al., 2019b;2019a;Poppe et al., 2020;Nguyen-Ba et al., 2020;Adriaens et al., 2020).
In the subsequent sections, two case studies have been developed to illustrate different approaches for post-treatment of longitudinal performance data.Although, in these examples, the theoretical trajectory of performance is considered as known, the methods described in the previous paragraph could be adopted to estimate it from perturbed performance data, in the case that it was unknown.

Case study 1. Dynamic model with biologically meaningful parameters
Let's assume an animal experiences a perturbation j, which started at t b j and was over at t s j , and during this period, the animal decreased its performance y t ð Þ.To describe the intensity of animal response to perturbations, let's further assume that Eq. ( 1) describes the variation of the intensity of the perturbation where k 1j and k 2j are model parameters and characterise the animals response to perturbation j in term of loss of the performance and recovery capacity, respectively.1 j t ð Þ is the identity function which is one during the perturbation interval and 0, elsewhere.
The value a j t b À Á stands for the initial value of the function a j .Therefore, the function a j is one in non-perturbed conditions and less than one during the perturbation periods.Then, the trajectory of animal performance y t ð Þ during n perturbations can be described as Eq. ( 2).
where the function f P; t ð Þ describes the theoretical expected trajectory of animal performance, P is the set of model parameters describing the characteristics of the theoretical trajectory, t is time.The set of parameters that characterise the animal response to these two perturbations are k 1j ; k 2j À Á and the time interval of perturbation j (Dt j ¼ t s j À t b j Þ.In the case where the periods of perturbations are not reported, the perturbation time parameter values can be estimated.Fig. 3 shows the estimated theoretical performance trajectory, the perturbation intervals and their dynamics using this model.
Given the fact that the development of the model is based on knowledge on the shape of the response, i.e. decrease followed by an increase, we can consider the model as based on existing knowledge.However, the use of this model requires the availability of longitudinal data with high frequency, and in this respect, it is useful only if such data are available.

Case study 2. Differential smoothing model
This example shows the use of a purely data-driven approach for the post-treatment of performance data under perturbations.Fig. 4 shows a hypothetical example, in which the theoretical performance is equal to 1, and the deviations from this value could be considered as perturbations.Data were smoothed using B-Spline bases of order 5 with the roughness penalty k ¼ 10 4 to estimate animal performance (https://quantanimal.github.io/).Three features are used to characterise the animal response to the perturbation i: the area between the theoretical trajectory and the perturbed curve (A i ), the maximum amplitude of deviation from the theoretical performance (h i ), and the duration of perturbation (DT i ).These criteria allowed comparison of the animal responses to each of the perturbations, and also, in the case of a larger number of animals, to rank animals for their adaptive capacity.Other features such as the maximum decrease and increase rates (zeros of the second derivative) could also be extracted using function derivatives.Table 2 shows values of different defined features for the hypothetical example shown in Fig. 4, which shows two deviations from the theoretical trajectory of performance.Since a deviation could be part of the inherent behaviour of the animal, one needs to determine the criteria that are used to classify a deviation as perturbation, such as the length and the magnitude of a deviation (Nguyen-Ba et al., 2020).Another criterion is the determination of common periods of deviations among all animals in a pen that suggests that the origin of the perturbations is in the farm environment (Ben Abdelkrim et al., 2021a).This approach with the use of functional derivatives is particularly useful in the case of studying a large number of animals, to automatise the individual analyses of performance data and the detection and quantification of perturbations.For example, in the case of Fig. 4, the beginning of a perturbation is when the perturbed curve of the performance deviates negatively from the theoretical performance, usually after a local maximum, which can be easily detected by calculating the derivative of the perturbed curve.The end of a perturbation is a local minimum of the perturbed curve (when the recovery starts) and is associated to the zeros of the derivative, where it changes from negative to positive values.

Real-time treatment of data
In this section, we discuss the mathematical and statistical methods for real-time detection of perturbations, in which the models use real-time data for detecting and quantifying perturbations.Real-time detection is commonly used in early warning systems where the aim is to detect, for example, sick animals as early as possible (Dominiak and Kristensen, 2017).In addition to detecting the occurrence of a perturbation, it can be useful to quantify the magnitude of the animal response and thereby to plan the correct veterinary treatment or management action, such as adjustment of feeding.

Using state-space models and observers to detect perturbations
In the state-space modelling approach to time series, it is assumed that the development of a system is associated with latent states described by a series of state vectors h t which are associated with observations y t and control inputs u t .The relationship between h t and y t is specified by a state-space model such that the system state at time t contains all the information necessary to predict future values of y t .As an example, animal activity level for the next hours or days can be forecasted using estimated mean, slope and periodic components based on activity measurements.
A system can be represented in state-space model form using the differential equation (or equivalent difference equation): where P is the parameter vector, the function f determines the rate of change of the state vector as a function of state h and control, and the function h gives the measured values as functions of state and control (Astrom and Murray, 2008).
In contrast to the models for post-treatment of data, one of the challenges in real-time approaches is related to knowledge on the individual theoretical trajectory of performance.In such cases, hypotheses for the theoretical trajectory are tested, and oftenknown functions such as polynomials are used.In the following sections, two case studies based on the use of state-space modelling are presented, depending on whether the theoretical trajectory is known or unknown.

Case study 3. Known theoretical trajectory
In this example, we show the use of state observers to quantify dynamic perturbations.An observer is an object that combines a mathematical model and on-line data to estimate unmeasured variables (Dochain, 2003).For our case study, we aim to use realtime records of BW to extract information on the perturbation that an animal is facing.For that, we assume that the theoretical trajec- tory of growth follows a Gompertz function.This example is developed from the work of Revilla et al. (2019).
The following equation describes the dynamic changes in BW (y) in the presence of perturbations The term u is assumed to be unknown and represents a dynamic perturbation factor that explains the deviations from the theoretical trajectory.If u ¼ 0, Eq. ( 4) is the classical Gompertz model with parameters p 1 ; p 2 (assumed to be known).
We are then interested in estimating the dynamic perturbation factor u t ð Þ.This estimation can be done by the following extended model: This extended model is called a state observer or software sensor.Here, b y is the estimation of y and b u is the estimation of u.The dynamics of the estimated variables are driven by the observation error y À b y À Á . The parameters x 1 ; x 2 are the design parameters of the observer which are chosen to set desired properties of the error time-trends.For example, we are interested in setting adequate values to make sure that the error reaches rapidly the zero value.
To illustrate the observer-based estimator, we generated simulated data for 80 days by setting a piecewise constant function for the perturbation term, ¼ 0:1; if t 2 210 ½ , u ¼ 0:05; if t 2 4045 ½ and u ¼ 0, elsewhere.The model parameters were set to The tuning parameters were set to x 1 ¼ 4:0; x 2 ¼ 0:5.u can be used further to construct a model with an explicit function of the perturbation.This can be done using either mechanistic, empirical or hybrid models (Chen et al., 2000).The main limitation of the approach is the need of establishing known functions of the expected trajectory of performance, which can be a challenging task.

Case study 4. Unknown theoretical trajectory
In the previous example, the theoretical trajectory of animal performance was assumed to be known.Another approach based on state-space models is to estimate the expected trajectory and the impact of perturbation on it in real time using a dynamic linear model (DLM).A DLM is a linear and discrete Gaussian state-space model specified by a pair of difference equations (Eq.( 5)) (Whittemore, 1986;Petris et al., 2009).
DLMs are often used to detect when the state of the animal is perturbed in online monitoring applications.The objective of this method is an online estimate of the theoretical trajectory f P; t ð Þ shows the expected performance of the animal, which for simplicity is assumed to be 1.Ai; hi and DTi are the area under the perturbed curve, the maximum effect of the perturbation and the time length of the perturbation, respectively.This example is generic and independent of the animal species.A; h and DT are the area under the perturbed curve, the maximum effect of the perturbation and the time duration of the perturbation, respectively.
to forecast future values f P; t þ k ð Þ .A common method to detect perturbation is to inspect the model forecast errors.This approach involves finding the right DLM for online estimation of the theoretical trajectory f P; t ð Þ of the system, forecasting the theoretical trajectory k steps ahead and comparing the forecast error to the observed value.If the forecast estimates drift away from zero, we conclude that a perturbation (a change point) has occurred, and the estimate for the magnitude of perturbation can be obtained from the residual: This principle was used by Stygar et al. (2018) for detecting perturbations from pig growth using frequent weight measurements.Their model also incorporated a diurnal component in the system model using trigonometric functions.
The approaches using a single DLM work for detecting changes from the theoretical trajectory, but offer little with respect to characterising the perturbation.In the presence of perturbations, the dynamics of the system often change, requiring the use of a different model to estimate the perturbed state.Switching DLMs provide a method for detecting regime shifts in real-time and modelling systems with several dynamic regimes.These models can also be called multi-process class I models, switching linear dynamical systems, or multiple model algorithms (Gustafsson, 2001;Norberg et al., 2008).
We revisit the problem presented in the differential smoothing section by estimating the perturbations from the data presented in Fig. 5 using a switching model.We use one dynamic model for the unperturbed state and a separate model for the perturbed state, and a discrete latent variable s t 2 unperturbed; perturbed indicates which model is active at each time.By observing the data, we see that, in the unperturbed state, the series has a constant mean whereas, in the perturbed state, there is clear change in the slope.We model the unperturbed state using a local level model (1st order polynomial) and the perturbed state using a local linear trend model (2nd order polynomial).Fig. 6 shows the state estimate for both models, the probability of each being active and the estimated slope for the second-order model.The linear trend model has a higher posterior probability during the perturbations and thus provides an online estimate of time of onset of perturbations that can be used to make management decisions.The online estimate of slope has a similar shape to one provided by the differential smoothing method in Fig. 5.

Discussion and perspectives
The objective of this work was to show, with examples, how animal responses to short-term environmental perturbations can be quantified using a combination of data from new monitoring technologies and adequate mathematical models.
In this paper, the models were separated into two categories, concept-driven or mechanistic and data-driven models, and the usefulness of each of them were described.Data-driven models have often been assigned the name 'black box models' for which forecasting is possible.In this respect, models considering the underlying mechanisms of animal responses could be considered as 'white-box models'.In the era of big data and powerful computing machines, it is unrealistic to focus solely on only one of these approaches.This is particularly true for the study of animal resilience, which is a complex trait.The combination of these two approaches will lead to so-called 'grey box' or hybrid models, which benefit from the inclusion of some a priori knowledge (Fig. 7).
One of the main white-box inputs to data-driven models for real-time detection of perturbations is to provide a function that allows the determination of the theoretical trajectory of a trait from data that includes perturbations.Including prior knowledge on the shape of the expected trajectory (a simple example is the increasing function for growth, or an increasing plateau for feed u by the observer model (solid line) compared with the real trajectory u ().Note that in practice, the real trajectory u is unknown.In the example, we can plot it because it was set by construction.This example is generic and independent of the animal species.intake) will make the estimate more realistic.Indeed, in the case of long-lasting perturbations, a purely data-driven method will inevitably include some of the perturbation effects in the estimation of the normal baseline of the animal, and will therefore underestimate its impact.This then leads to the need for a theoretical reference curve that may be derived from concept-driven models.It is worth mentioning that the integration of a priori mechanisms may change based on how much detail is required for the model.For example, in the case of detection of perturbations, it is sufficient to only have information about the shape of the expected tra-jectory of performance, whereas real-time prediction of animal resilience capacity would require a more detailed understanding of the underlying response mechanisms.In the latter case, a mechanistic model of animal responses combined with a data-driven approach for online prediction may help predict the resilience capacity of an individual.
The use of hybrid models is a key aspect to tackle the multivariate nature of resilience.Interpreting time-series data in one dimension of animal performance (for instance milk production, BW) is a necessary first step.However, to achieve a comprehensive view of Fig. 6.Example of using a switching model for detecting perturbations in animal response.The series is filtered using two different filters: A 1st order model representing unperturbed dynamics and a 2nd order model representing perturbed dynamics.The first panel shows the state estimate for both models, second panel shows the posterior probability for each model being the correct one at time t, and the bottom panel shows the estimated slope based on the second-order model.This example is generic and independent of the animal species.Fig. 7.A hybrid modelling approach takes advantage of both data-and concept-driven models to extract the maximum information from existing data.This scheme is generic and independent of the animal species.FI = Feed Intake.
animal resilience, the challenge is to merge knowledge and information from different dimensions of animal adaptive capacities.
Recent work has shown the potential of combining different metrics/indicators of resilience (Llonch et al., 2020).There are several examples: (a) Adriaens et al. (2020) used various sensor features related to milk production and activity to compute a resilience index for individual dairy cows, (b) Ben Abdelkrim et al. (2021b) used BW and milk yield deviations to reveal three profiles of responses to perturbations, (c) Højsgaard and Friggens (2010) showed how multiple time-series indicators could be combined for improved detection of degree of mastitis, (d) Lough et al. (2015) used time-series data of infection severity and performance to derive two-dimensional resilience trajectories of infected animals that capture the dynamic interplay of host resistance and tolerance mechanisms of infected animals.A second aspect in interpreting multiple time series is the use of a theoretical framework, reflecting assumptions on underlying mechanisms and potential interactions between biological functions that are behind the measured traits.This kind of biological background (embedded in hybrid models) is a key if one needs to account for potential trade-offs among functions and non-linear genotype by environment effects.These are important issues in implementing breeding programmes or management strategies to improve resilience in farm animals (Puillet et al., 2021).
Another aspect to be considered is the capacity of real-time models to predict health problems sufficiently early to avoid the decrease in animal production performance (Friggens et al., 2007).In other words, the model should be able to detect preclinical signs of the problems.In this respect, (Wagner et al., 2021) have shown that longitudinal observations of animal behaviour can be useful for predicting preclinical signs of health problems.Moreover, their model considered the circadian cycle as an inherent part of cow behaviour, and the combination of this input with an adequate approach to machine learning improved the early detection of health problems in the various farms used in their study.Based on the case studies presented here, solutions are suggested for the determination of the theoretical trajectories in cases of (i) post-treatment of data, with or without knowledge on underlying mechanisms (case studies 1 and 2, respectively), and (ii) in cases of real-time treatment of data when knowledge is available (case study 3).The issue is how to handle the need for real-time treatment of data in the absence of knowledge of the underlying mechanisms or the shape of the theoretical trajectory (case study 4).In such cases, one approach is to make simple assumptions on the shape of the expected trajectory.In the case study 4, the expected curve has been assumed to have a constant value.Although it may be possible to make assumptions for wellstudied variables, such as BW or milk yield, it is seldom feasible for other variables such as animal behaviour.In the latter cases, even though accurate early detection is possible in the absence of a priori assumptions about the shape of the expected trajectory (Friggens et al., 2007), approaches based on purely data-driven methods such as machine learning can be useful.In this regard, (a) Sun et al. (2010) used the neural network for prediction of mastitis risk; (b) Warner et al. (2020) tested the usefulness of a machine learning approach based on decision tree induction for the detection of dairy herds at high risk of lameness; (c) Morota et al (2018) provides a complete overview on the use of machine learning to analyse big data in precision agriculture.The common point in such approaches is to provide a training dataset with enough data to enable robust predictions on the test dataset.
To date, machine learning approaches enable the prediction of risks at individual scale (detection of perturbations).As the use of sensors in farms increases, and in the context of studying animal resilience capacity, we can expect more accurate information on the potential causes and timing of perturbated performance (eg.mastitis, lameness, etc.) and, most of all, on the resilience capacity of the animal.Considering Fig. 1, one of the main challenges is to be able to predict the response of an animal to future perturbations based on historical data.Such predictions would help the farmer to decide whether or not pharmaceutical or other interventions are required for the animal to recover, or if the animal is able to recover by itself.However, resilience capacity is not a directly measurable feature and, in this paper, examples to quantify this characteristic with mathematical models are being developed (e.g.case studies 1 and 2).New approaches based on machine learning are needed that consider indirect measures of resilience to predict the adaptive capacity of an animal.Ellis et al. (2020) explained that machine learning approaches will offer greater benefits when they are used together with concept-based approaches.Tedeschi et al. (2021) highlighted the value of hybridising artificial intelligence methods with mechanistic models for the optimisation of information extracted from Precision Livestock Farming data, to improve the sustainability of animal production.
In summary, both data-driven and concept-driven approaches have been discussed with respect to their ability to detect perturbations in performance trajectories and to quantify the resilience capacity of individual animals.Although the examples presented here are not exhaustive, they highlight the usefulness of each of the approaches.The availability of high-frequency performance data enables better quantification of animal resilience at individual scale.The use of hybrid models seems promising for predicting this trait in real time.

(
Fig.2.Difference in the concepts of forward and inverse problems.a. ''Forward problem" is the use of mechanistic models to predict the response of the animal (outputs) to stimuli (inputs), given the animal characteristics (parameters) and a model structure (representation of underlying mechanisms or input-output behaviour).b.In the case of the ''inverse problem", the dynamic data of model outputs can be measured.Then given these data, and model structure, the user can estimate the characteristic of the animal (model parameters), using an adequate optimisation procedure.This scheme is generic and independent of the animal species.

Fig. 3 .
Fig. 3. Hypothetic example of animal responses to two different perturbations.Two consecutive perturbations occurred at t b 1 ¼ 10 and t b 2 ¼ 75, and were over at t e 1 ¼ 25 and t e 2 ¼ 85 days of age.Parameters k1i; k2i ð Þare 0:05; 0:15 ð Þ for the first perturbation and 0:1; 0:05 ð Þ for the second.Compared to the second perturbation (10 days), the animal took more time to start the recovery period in the first perturbation (15 days).This example is generic and independent of the animal species.

Fig. 5
Fig. 5 shows the comparison between the online data (y) and the estimated BW (b y).The figure also shows the estimated b u.Note that the observer did not require the information of the time at which the perturbations occurred.The trajectory of b u can be used to detect the perturbation times.In addition to providing different characteristics of the perturbation, b

Fig. 4 .
Fig. 4. Estimation of animal performance using differential smoothing.The upper graph shows the estimated function against (black curve) observation (dot).The lower graph shows the derivative of the estimated function.Zeros of derivatives are associated with maximums and minimums of the function.The blue line on the upper graphshows the expected performance of the animal, which for simplicity is assumed to be 1.Ai; hi and DTi are the area under the perturbed curve, the maximum effect of the perturbation and the time length of the perturbation, respectively.This example is generic and independent of the animal species.

Fig. 5 .
Fig. 5. A. Comparison of the real online trajectory of BW (y) () against the estimated trajectory (b y) by the observer model (solid line).B. Estimated trajectory b

Table 2
Quantification of the animal's response to two perturbations of the case study 2, regardless to the species.