1. Introduction
It is common practice in modern intensive pig husbandry to confine sows in farrowing crates, usually for four to five weeks, including at least a few days before the onset of farrowing. The main reason for this practice is to improve piglet survival rate by protecting newborn piglets from fatal or injurious crushing by the mother sow [
1]. However, the confinement of sows in crates has a negative impact on the sows’ welfare, such as limited freedom of movement, limited social interactions with newborn piglets [
2,
3], and diminished health [
4,
5]. Confinement also prevents much of the prenatal nest-building behaviour, an essential part of the behavioural repertoire in sows, which starts approximately 24 h before parturition, is most intense 6 to 12 h before parturition, and then, decreases as parturition begins [
6,
7]. Increased physiological stress for the sow is a consequence of the confinement in a crate, which is indicated by changes in the hypothalamic–pituitary–adrenal (HPA) axis, consistent with chronic stress [
8].
The concept of temporary crating was developed as a response to increased public concern about welfare of crated sows [
9]. According to this concept, sows should be temporarily confined in farrowing crates only during the critical period of the piglets’ life, when piglet crushing is most probable, i.e., in the first days after farrowing [
10,
11]. When the crate is opened, the farrowing pen offers additional space for the sow, providing a compromise between the needs of the farmer, the sow, and her piglets [
1]. This allows the sow to stay unconfined during the prenatal nest-building phase from 24 h ante partum until the approach of farrowing, which has a positive impact on the sow’s welfare [
12]. It is challenging to choose the right moment to confine an individual sow in a farrowing crate under farm conditions in a way that makes nest building possible and does not increase the risk of piglet crushing. Due to the biological variability in gestation length, time-consuming observations of sows would be necessary. However, in many sows, confinement of sows in crates based on a calculated farrowing date of the batch could either disturb adequate nest-building behaviour or the farrowing process.
The activity level of a sow that builds a nest before farrowing increases due to hormonal changes and the presence of external stimuli [
7,
13,
14]. This increase in activity level can be automatically detected with sensor technology. To date, three types of sensor technologies have been used for this purpose, i.e., infrared photocells, force sensors, and accelerometers. Infrared photocells and force sensors have been installed in farrowing crates and as the farrowing approached, the measured activity of sows increased slightly, then, more than doubled the day before farrowing [
15,
16]. Accelerometers were tested for measurement of activity of sows with sensors installed in collars and in tags [
17,
18,
19]. Measurement of the activity of sows with accelerometers installed in collars indicated, similarly to other sensor technologies, an increase of activity 16 to 20 h before the onset of farrowing [
19]. When an accelerometer was installed inside an ear tag, the increase in activity was detected 48 h before the onset of farrowing [
17].
Automated detection of increases in sow activity with the use of sensor technology makes possible the prediction of the onset of farrowing. This could be useful in practical conditions to shorten surveillance intervals by farm staff, and the pen could be prepared for an optimal farrowing (e.g., providing nest-building material and activating a heating source) [
17]. However, for selecting the optimal period of temporary crating of sows, there is a need for a reliable method to detect when an individual sow starts and finishes nest-building behaviour. We hypothesize that providing a “second-stage” alarm, indicating the end of nest-building behaviour, should ensure that farm staff confine a sow in a crate after nest building is finished but before farrowing starts. Then, the potential of farrowing pens with the possibility of temporary crating to achieve a compromise between the needs of the farmer, the sow, and her piglets could be realized.
Thus, the objective of this paper was to model the dynamics of acceleration data in a period before the onset of farrowing, in three types of farrowing pens, to automatically detect the beginning and end of nest-building behaviour. The technique developed should allow provision of a “first-stage” and “second-stage” alarm for the farm staff which should be especially relevant for improving sow welfare in pens with the possibility of temporary crating.
3. Results
The KALMSMO algorithm was fitted recursively to the acceleration data of 27 sows in the training dataset to generate alarms indicating approaching farrowing (
Figure 8). The fitting procedure was repeated with increasing confidence interval bounds from 38.29% to 99.9999%. As confidence interval bounds increased from 38.29% to 99.9999%, the median duration between the time when the “first stage” alarm was generated and the onset of farrowing, decreased from 64 h 31 min to 6 h 26 min (
Figure 9). This was due to the fact that lower confidence interval bounds mean narrower threshold bounds for the model.
Changes in activity not related to approaching farrowing can raise the number of false alarms when a narrow threshold is crossed. However, health problems that could cause lower activity of animals, such as lameness, should not result in earlier alarms as “first-stage” alarms were generated only when the upper confidence interval bound was crossed. Nevertheless, with lower confidence interval bounds, the “first-stage” alarms were generated after sows entered farrowing pens and further away from the onset of farrowing. The biggest change in median duration, between the time when the “first-stage” alarm was generated and the onset of farrowing, was between confidence interval bounds of 98.45% and 98.76%. The median decreased from 57 h 4 min to 11 h 29 min (
Figure 9a).
The higher median of the duration between the time when a “first-stage” alarm was generated and the onset of farrowing, indicated that approaching farrowing was detected earlier. Earlier detection of approaching farrowing means that the model is more sensitive to behavioural changes of the sow. Additionally, earlier alarms give more time for the farmer to intervene before farrowing starts (e.g., preparation of the farrowing pen for farrowing). A very high median (e.g., >24 h) could be caused by false alarms, due to detection of behavioural changes that were not related to approaching farrowing.
The values of the interquartile range of the duration between the time when an alarm was genereated and the onset of farrowing formed two groups depending on the value of confidence interval bounds as follows: one with higher values of 52 h 47 min to 32 h 51 min for confidence interval bounds between 38.29% and 98.76%, and the second with lower values of 11 h 8 min to 3 h 26 min for confidence interval bounds between 99.73% and 99.9999% (
Figure 9a).
A lower interquartile range was an indicator that “first-stage” alarms were generated at similar intervals before the onset of farrowing. This suggests that alarms were generated because of changes in sow behaviour related to one cause, specifically approaching farrowing and not because of other reasons. Thus, when deciding on optimal confidence interval bounds, the group with lower interquartile range was preferred.
In addition to the median and interquartile range of the duration between the time when an alarm was generated and the onset of farrowing, the following characteristic values were considered: the number of “first-stage” alarms that occurred earlier than 48 h before the onset of farrowing, the number of “first-stage” alarms generated after the onset of farrowing, and the number of sows for which no “first-stage” alarms were generated. The number of “first-stage” alarms that were generated earlier than 48 h before the onset of farrowing decreased from 20 (74.07%) to zero sows, as confidence interval bounds increased from 38.29% to 99.9999%. The number of sows with “first-stage” alarms generated after the onset of farrowing stayed between two (7.41%) and one (3.7%), and the number of sows for which no “first stage” alarms were generated increased from zero to 15 (55.56%). A decreasing trend in the number of “first-stage” alarms generated earlier than 48 h before the onset of farrowing meant that as confidence interval bounds increased, alarms were generated nearer to the onset of farrowing. Simultaneously, for more and more sows no alarm was generated (
Figure 9b).
The sum of “first-stage” alarms that occurred earlier than 48 h before onset of farrowing, “first stage” alarms generated after the onset of farrowing, and sows for which no “first stage” alarms were generated was the lowest (n = 8, 29.63%) for the confidence interval bounds of 99.73% and 99.95%. For both of these confidence interval bounds, the median of duration between the time when the “first-stage” alarms were generated and the onset of farrowing were similar (8 h 36 min and 7 h 35 min). The interquartile range was more than double for a confidence interval bound of 99.73% than for 99.95% (11 h 8 min and 4 h 28 min). This suggests that, for a confidence interval bound of 99.95%, alarms were generated more consistently around the time of farrowing than for the confidence interval bound of 99.73%. Thus, we decided that the confidence interval bound of 99.95% is optimal for the first stage of model fitting (
Figure 9b).
In the second stage, the KALMSMO algorithm was fitted to the acceleration data from the time point of the “first-stage” alarms, where “first-stage” alarms were generated on the optimal 99.95% confidence interval bound. The KALMSMO algorithm, in the second stage, was also fitted with increasing confidence interval bounds from 38.29% to 99.9999%. As confidence interval bounds increased, the median duration between the time when a “second-stage” alarm was generated and the onset of farrowing, decreased from 2 h 58 min before the onset of farrowing, to 73 h 33 min after the onset of farrowing. Thus, similar to “first stage” model fitting, narrower confidence interval bounds resulted in earlier “second-stage” alarms. The interquartile range of “second-stage” alarms increased from 5 h 1 min to 54 h 32 min (
Figure 10a).
The number of alarms generated earlier than 48 h, before the onset of farrowing, decreased from 2 (7.41%) to zero, as the confidence interval changed. The number of sows for which no alarm was generated was five (18.52%) for confidence intervals between 38.29% and 98.76%. For confidence intervals above 98.76%, the number of sows for which no alarm was generated, increased to 19 (70.37%).
The aim of algorithm fitting, in the “second stage”, was to provide alarms mainly before the onset of farrowing. Thus, optimal confidence interval bounds were selected, and therefore the median duration of “second-stage” alarms was before the onset of farrowing. This condition was met only for confidence interval bounds of 38.29% and 68.27%. The sum of no alarms and the alarms generated earlier than 48 h before the onset of farrowing was seven (25.93%) for both of these confidence interval bounds, which was low as compared with the result of the other confidence interval bounds. Only for confidence interval bounds of 86.64% to 98.76%, this value was lower at six (22.22%). The interquartile range was lower for a confidence interval of 38.29% (5 h 1 min) than 68.27% (7 h 16 min). A lower interquartile range was an indication that “second-stage” alarms were generated at similar intervals before the onset of farrowing. This suggested that “second-stage” alarms based on confidence interval bounds of 38.29% were generated more likely because of changes in sows’ behaviour related to approaching farrowing rather than because of other reasons. Thus, the confidence interval bounds of 38.29% were selected as optimal for “second stage” model fitting.
Optimal confidence interval bounds selected on the basis of the training dataset were validated on a group of 26 sows. The distribution of first- and second-stage alarms was similar in both datasets. In the training set, the median of “first-stage” alarms was 7 h 35 min before the onset of farrowing with 1st quartile of 5 h 44 min and 3rd quartile of 10 h 12 min, whereas, in the validation set, the median of “first-stage” alarms was 9 h 38 min with 1st quartile of 6 h 3 min and 3rd quartile of 13 h 46 min (
Figure 11).
In the training set, the median of “second-stage” alarms was 1 h 32 min before the onset of farrowing with 1st quartile of 2 h 23 min after the onset of farrowing and 3rd quartile of 4 h 53 min before the onset of farrowing, whereas in the validation set the median of “second-stage” alarms was 2 h 4 min before the onset of farrowing with 1st quartile of 34 min after the onset of farrowing and 3rd quartile of 5 h 15 min before the onset of farrowing (
Figure 11).
The distribution of first- and second-stage alarms in both training and validation datasets indicates that the “second-stage” alarms occurred later than the “first stage” alarms (
Figure 11). However, for some of the animals in the training and validation datasets, alarms were not generated or were not generated in the preferred period. Specifically, in the training dataset, “first-stage” alarms were not generated, and “second-stage” alarms were generated for five (18.52%) animals (
Table 2). If no “first-stage” alarm was generated for a certain animal, also no “second-stage” alarm was generated for this animal, both in training and in validation datasets. In the validation set, no first- and second-stage alarms were generated for eight (30.77%) animals (
Table 3). The alarms that were generated outside of the desired period in the “first stage” were alarms generated after the onset of farrowing and earlier than 48 h before the onset of farrowing. The alarms that were generated outside of the desired period in the “second stage” were alarms generated earlier than 48 h before the onset of farrowing and alarms generated after the end of farrowing. In the training dataset, there was one (3.7%) “first-stage” alarm generated after the onset of farrowing, two (7.41%) alarms generated earlier than 48 h before the onset of farrowing, two (7.41%) “second-stage” alarms generated earlier than 48 h before the onset of farrowing, and four (14.81%) “second stage” alarms generated after the end of farrowing (
Table 2). In the validation dataset, there were four (14.81%) “second-stage” alarms generated after the end of farrowing (
Table 2).
Out of 27 sows in the training dataset, for 19 (70.37%) sows, a “first-stage” alarm was generated in a period of 48 h before the onset of farrowing until the onset of farrowing. For 16 (59.96%) animals, a “second-stage” alarm was generated 48 h before the onset of farrowing until the end of farrowing. Out of 26 sows in the validation dataset, for 18 (69.23%), a “first-stage” alarm was generated in a period of 48 h before the onset of farrowing until the onset of farrowing. For 17 (65.38%) animals, a “second-stage” alarm was generated over a period of 48 h before the onset of farrowing until the end of farrowing (
Table 3).
The median of “first-stage” alarms in SWAP pens was 7 h 45 min before the onset of farrowing with a 1st quartile of 5 h 35 min and a 3rd quartile of 11 h 59 min. In the trapezoid pens, the median of “first-stage” alarms was 7 h 48 min before the onset of farrowing with a 1st quartile of 6 h 3 min and a 3rd quartile of 10 h 12 min. Finally, in wing pens the median of “first-stage” alarms was 10 h 36 min before the onset of farrowing with a 1st quartile of 5 h 44 min and a 3rd quartile of 15 h 1 min.
The median of “second-stage” alarms in SWAP pens was 1 h 09 min before the onset of farrowing with a 1st quartile of 3 h 21 min after the onset of farrowing and a 3rd quartile of 3 h 2 min before the onset of farrowing. In the trapezoid pens, the median of “second stage” alarms was 3 h 9 min before the onset of farrowing with a 1st quartile of 34 min after the onset of farrowing and a 3rd quartile of 5 h 5 min before the onset of farrowing. Finally, in the wing pens, the median of “second-stage” alarms was 1 h 46 min before the onset of farrowing with a 1st quartile of 22 min after the onset of farrowing and a 3rd quartile of 6 h 48 min after the onset of farrowing.
Assuming that the standard working time of farm staff in farrowing compartments starts at 6:00 and ends at 18:00, 65% (26) of “first-stage” alarms and 52.5% (21) of “second-stage” alarms in training and validation sets were generated when farm staff were present to assist with the farrowing process (
Figure 12).
4. Discussion
In this research we considered pigs as CITD systems, which stands for complex, individually different, time-varying, and dynamic (CITD) systems [
26]. The individually different character of pigs, as any other living organisms, can be observed in their differing baseline of activity levels. All animals are individually different in their responses [
27]. In some animals, the baseline activity measured by ear mounted accelerometers was double that of others (
Figure 8). These differences in activity level between individuals are also related to time varying characteristics of living organisms. An animal response to a stimulus or stressor could be different each time it happens. An animal is constantly looking for a good energy balance and, consequently, is continuously changing its physical and mental status [
27]. In the study by Manteuffel et al. [
23], an improvement of the quantitative prediction of farrowing was achieved by using a different approximation function for very young sows. Thus, the dynamics of activity can change in the same animal over time as it grows older. In addition to individual differences between animals, factors such as breed [
28] and environment [
29] can affect the activity of sows on a group level, which makes modeling animal activity for the purpose of farrowing prediction more challenging. However, the objective of this study was to model the data for real-time monitoring, despite differences in activity between individual animals.
For this purpose, a KALMSMO model was individually and recursively fitted to acceleration data. Then, changes in dynamics of the activity of sows were detected as an increased and decreased trend in acceleration data. Such an individual modeling approach, in which models adapt to the activity of individuals, was also applied for prediction of farrowing in research by Pastell et al. [
14], Traulsen et al. [
17], and Manteuffel et al. [
23], whereas in research by Oczak et al. [
13], Oliviero et al. [
16], and Cornou and Kristensen [
30] group level modeling was applied. Individual modeling of sows’ activity for farrowing prediction has an advantage, because the performance of such models depends on similarity in dynamics of sows’ activity and is independent from baseline activity level of the animals. Thus, performance of these models should be similar when validated on independent datasets such as multiple pig sites with various breeds and housing conditions.
In previous research on farrowing prediction, the main objective was to predict the onset of farrowing as accurately as possible [
14,
17,
23]. The basis for estimation of onset time of farrowing was the increase of sows’ activity related to nest-building behaviour [
7,
15]. In our research, increase in the activity level of sows was modeled to provide “first-stage” alarms. The median duration, before the onset of farrowing, of “first-stage” alarms in our validation set, was 9 h 38 min with a 1st quartile of 6 h 3 min and a 3rd quartile of 13 h 46 min. This result was similar to the results of a study by Pastell et al. [
14] in which accelerometers were attached to neck collars. In the study by Pastell et al. [
14] the median duration of alarms before the onset of farrowing was around 13 h with a slight variation of 30 min depending on adjustment of model parameters. Traulsen et al. [
17] reported that for 84.2% of all sows equipped with a SMARTBOW
® accelerometer sensor, farrowing was successfully predicted; only one of the animals was outside the 12 h window before the onset of farrowing. This does not accurately compare with our results but suggests that the outcome was similar to ours and to the result of Pastell et al. [
14]. In research by Manteuffel et al. [
23], who used light barriers for farrowing prediction, the best performing qualitative prediction generated alarms with a 1st quartile of 13 h and a 3rd quartile of 20 h before the onset of farrowing. This result seems to indicate that alarms were generated earlier than in our study. However, the authors also reported a shorter duration between alarm and onset of farrowing for alternative models, which had a poorer performance when evaluated with accuracy, sensitivity, and specificity. The reason for the difference in results between our study and Manteuffel et al. [
23] could have been the different methodology of evaluation of algorithm performance. Additionally, different sensors were used, and sows were kept confined in crates during the experiment, while in our experiment sows were allowed to move freely in the pen. In our own previous study, in which the SMARTBOW
® accelerometer senor was used, alarms were generated, on average, 11 h before the onset of farrowing [
13].
The practical application of “first-stage” alarms, generated approximately 6 to 13 h before the onset of farrowing, could be to warn the farmer about approaching farrowing in an automated way. This could reduce labor costs otherwise required for regular control of sows in farrowing compartments. It should also limit the need to get in close contact with sows which could interrupt the sow’s activities at a time when she is sensitive to outside disturbances [
16].
Austrian legislation requires that in the week before farrowing, the animals should be provided with suitable nest-building material but only when the slurry system allows it [
31]. Thus, when the “first stage” alarm is generated “nest-building” material could be provided to the sow. Providing nest-building material in higher amounts after the “first-stage” alarm is generated or only after this alarm could limit the risk of blocking the slurry system with nest-building material and improve welfare of sows. Additionally, the procedure for preparing a farrowing pen for newborn piglets could be started when a “first-stage” alarm was generated [
17]. However, when considering practical uses of such a monitoring system, the time of day when alarms are geknerated also has to be taken into account. In our study, only 65% (26) of the “first-stage” alarms were generated between 6:00 and 18:00. This raises a question of how alarms that were generated when no staff were present at the farm can be used.
According to the Austrian Animal Welfare Directive, which becomes mandatory in 2033, sows should only stay confined in farrowing crates during the “critical period” of the piglets’ life [
11]. In order to reduce piglet crushing, farmers should be permitted to confine sows in farrowing crates from the onset of farrowing to a few days after farrowing. To provide sows with space for nest-building without increasing the risk of piglets getting crushed, crating should start after nest-building is finished and before farrowing starts. The crate has to be opened four days after farrowing [
32]. “First-stage“ alarms, generated on the basis of increased activity of sows, provide information when nest-building behaviour starts. The time of the beginning of nest-building behaviour could be used to approximate when a sow will start to farrow. In our study, 61% (11 out of 18) of “first-stage” alarms in the validation dataset were generated between 6 and 13 h before the onset of farrowing. This variability in duration of nest-building behaviour was also apparent in our previous study in which different nest-building behaviours were accurately labeled [
13]. Out of eight animals included in our previous study, seven had a clear peak of nest-building behaviour and in one animal it was not possible to distinguish the peak. Factors such as age or weight could influence motivation for nest-building behaviour [
23]. Some sows had the peak of nest-building behaviour already 8 h before the onset of farrowing, while other sows peaked only 2 h pre partum. Thus, confining sows in crates just on the basis of the time of beginning of nest-building behaviour could leave many sows at risk of staying in crates during the nest-building phase and in many cases also during the peak of nest-building behaviour, which should be avoided. Quantitative prediction of onset of farrowing allows prediction of farrowing with a prediction error of approximately 4.5 h and with a standard deviation ranging from 5 h to 7.5 h [
23]. Confining sows in crates on the basis of this prediction would also leave many sows at risk of staying in crates during the nest-building phase.
In this study, the method used to generate “second-stage” alarms is based on the change in trend in sow activity when nest-building behaviour ends. This change in trend is visible as “flattening” of the feature variable extracted from the acceleration data (
Figure 4 and
Figure 8). An advantage of this method is that when the “second-stage” alarm is generated, most of the nest-building activity of a sow should be finished. Thus, confining a sow, after the “second-stage” alarm was generated, should create little risk for sows staying in crates during nest-building, and especially during the peak of nest-building behaviour.
In order to select the right time to confine a sow in a crate, it also has to be considered that many sows still perform nest-building behaviour after the onset of farrowing, when the first piglet is already born [
24,
33]. It seems that this finding was confirmed in our research, because out of 18 “second-stage” alarms generated in the validation dataset, five (28%) were generated after the onset of farrowing. Thus, the “critical period” of piglets’ lives, as mentioned in the Austrian Animal Welfare Directive [
11], could overlap with the time of nest-building behaviour at least for some sows.
In research on farrowing prediction [
14,
17,
23], including this and our previous study [
13] the onset of farrowing was defined as the birth of first piglet. This event is easily observable in a farrowing pen and was also commonly used for defining the onset of farrowing in scientific literature [
34]. However, uterine contractions increase in frequency on average already 6 h before the first piglet is born together with an elevation of oxytocin levels [
7]. Thus, it is expected that most “second-stage” alarms, with a median of 2 h 4 min before the onset of farrowing, would be generated when a sow experiences uterine contractions before the first piglet is born. Confining a sow in a crate in most situations involves moving the animal from one location in a farrowing pen to another, which is stressful for the animal if the farrowing process has already started. The influence of this human intervention on sow welfare has to be also taken into account when considering the right time to confine a sow in a crate.
Similar to “first-stage” alarms, many (47.5%) “second-stage” alarms were generated between 18:00 and 6:00 when mostly there would be no staff present on farms. Assuming that a practical application of developed model would be to confine sows in crates just after the “second-stage” alarm is generated, many of the sows that farrow in the night would stay unrestrained during farrowing.
This leads to the question of whether the application of a monitoring tool, which can be used effectively only in half of farrowing animals, is justified under practical conditions. We would hypothesise that most farmers would keep the sows confined in crates over night after they have received a “first-stage” alarm, in many cases in time for nest-building behaviour, as when the “second-stage” alarm is generated during the night they would not be able to intervene in the farrowing compartment. This suggests that the next step in our research should be to implement the developed model in a real-time system and verify how it could be used under practical conditions. Additionally, automated confinement of sows, without the need of human intervention is an interesting topic for further research.
Considering that for eight out of 26 sows (30.8%) no “first-stage” alarms were generated in our study, in future research we plan to include additional information on the health status of animals. Health problems such as lameness could affect the activity of sows and this could result in less “first-stage” alarms. In order to improve the performance of farrowing prediction we also plan to automatically detect and differentiate between behaviours that constitute nest-building behaviour i.e., rooting, pawing, and manipulation of pen or crate [
13]. Such capability could provide more detailed information on sows’ behaviour and possibly also increase the performance of developed models. This is more likely to be successful with image analysis techniques, which have been applied for detection of complex behaviour in livestock but not for farrowing prediction [
35,
36].