Ref: C0460
A Model to Detect Farrowing based on Sow Activity Matti Pastell, MTT Agrifood Research Finland,
[email protected]
Koetilantie 5, FI-00790, Finland.
Juha Hietaoja and Johannes Tiusanen, Department of Agricultural Sciences, P.O Box 28, FI00014 University of Helsinki, Finland. Jinheon Yun and Anna Valros, Faculty of Veterinary Medicine, P.O Box 57, FI-00014 University of Helsinki, Finland
Abstract Automatic monitoring of farrowing has potential to increase the profitability of piglet production. On average one piglet per litter is lost during parturition and an additional piglet within a few days after birth. Wireless 3D accelerometers were attached to neck collar of 20 sows at least 48 hours before farrowing in a farrowing pen. Acceleration data was logged at 20Hz using dedicated logging software. Accelerometers were custom made for the project and used 868 MHz radio frequency and a power saving radio protocol which included a motion trigger that caused the sensor only transmit data when there were changes in the acceleration as compared to previously transmitted data. Farrowing times of the sows were registered from video. Total activity of each sow was calculated as the sum of absolute first order differences of the total acceleration in 10 minute epochs and the activity of each sow was normalized based on their activity during the first 24 hours of measurement. The data was log transformed and a dynamic liner model was used to decompose the data into trend, slope and Fourier form seasonal component with a period of 24 hours. The trend Tt and slope St components were used in further analysis. A Hidden Markov Model was used to detect approaching farrowing based on a logistic regression classifier. Data from 10 sows was used to fit the model and from another 10 sows to test it. We were able to detect an activity increase in all sows from 19.6 to 5.5 before farrowing. Keywords: Farrowing, accelerometer, machine learning
Introduction Automatic monitoring of farrowing has potential to increase the profitability of piglet production. On average one piglet per litter is lost during parturition and an additional piglet within a few days after birth (Valros 2003). In large litters some of the piglets are also more likely to be weaker and need assistance soon after birth in order to survive (Smith, 1997). Usually, dystocia in the pig is due to prolonged farrowing because one or more piglets are blocked in the birth canal or because uterine contractions are weak. If human intervention is not performed to reduce the obstruction or to stimulate the uterus with pharmaceuticals, it often leads to the loss of the entire litter and eventually the condition may result in the loss of the sow.
Proceedings International Conference of Agricultural Engineering, Zurich, 06-10.07.2014 – www.eurageng.eu
1/5
Sows behavior typical changes significantly before farrowing. A nest building sequence begins with an increased activity level of the sow 1-2 days before parturition. From approximately 12 hours prior to parturition, the sow engages in more and more actual nest building activity, such as rooting, pawing and arranging available materials (Haskell & Hutson, 1994). Cornou et al. (2011) have used accelerometers to measure the activity of sows before farrowing and also developed models (Cornou & Christensen, 2012, ) to detect the onset of farrowing based on activity changes. We have measured farrowing in crates using force sensors and photocells (Oliviero et al., 2008) and accelerometers (Pastell et al. 2013). We have developed a small wireless accelerometer that can be used to measure the activity changes related to farrowing (Pastell et al. 2013). The aim of this study is develop a system to predict farrowing based on accelerometers attached to a neck collar of sows in farrowing pens.
Materials and methods 1.1 Measurements Wireless 3D accelerometers were attached to neck collar of 20 sows at least 48 hours before farrowing in a farrowing pen. Acceleration data was logged at 20Hz using dedicated logging software. Accelerometers were custom made for the project and used 868 MHz radio frequency and a power saving radio protocol which included a motion trigger that caused the sensor only transmit data when there were changes in the acceleration as compared to previously transmitted data. Farrowing times of the sows were registered from video.
1.2 Preprocessing The acceleration data was interpolated to 20Hz sampling rate using piecewise cubic interpolation to fill in missing data during inactive periods of the sow. Sum acceleration was calculated as from the three axes as:
Total activity
+
=
+
of each sow was calculated in 10 minute epochs as: =
(
)
The log transform was used because the data was found to be log normally distributed. Further in order to standardize the activity measure across animals the amplitude the data was normalized using the normal activity of the animal: =
,where is the average activity of the animal during first 24 hours of the measurement. There was an obvious diurnal rhythm in the activity characterized as high activity periods during feeding times and low activity during resting. The data was log transformed and a dynamic liner model was used to decompose the data into trend, slope and Fourier form seasonal component with a period of 24 hours (Pastell et al. 2013). R 2.15.2 (R Core Team 2013) with dlm-package (Giovanni et al. 2009) was used for fitting the DLMs. The trend Tt and slope St components were used in further analysis. Proceedings International Conference of Agricultural Engineering, Zurich, 06-10.07.2014 – www.eurageng.eu
2/5
1.3
Model to detect farrowing
We hypothesized that farrowing can be detected as increased activity during 12h before farrowing. In order to detect rise in activity levels we used a logistic regression (LR) classifier combined with a Hidden Markov Model (HMM). The dataset was split into test set and training set both consisting of data from 10 different sows. Two different time periods were selected from training set in order to train a classifier to detect increased activity before farrowing: 1. Low activity, 18 - 24 hours before farrowing. 2. High activity, 6 - 12 hours before farrowing. Data from 10 sows was used to train a LR classifier to calculate the sow being in state of low or high activity at each 10 epoch based on activity Trend Tt and slope St obtained from preprocessing stage. The fitted LR model was used to calculate the probability of each sow being in a state of low or high activity for each 10 minute epoch. The calculated probability Pt for each epoch was used as emission probabilities in HMM., HMMs can be used to estimate the unknown state of a process based on observed measurements. The model needs a probability for each state given the observations (emission probability) and state transition matrix which encodes the probability of the process changing state. In our case HMM has two states low activity LA and high activity HA and we set the initial state to be LA. The state vector then becomes: 1 0
,
=1
The state transition matrix was obtained directly from training set as: =
0.99 0 1 0.01
Note that we have set the transition probability from HA to LA to 0, indicating that once the model indicates that the sow is in a state of high activity, indicating that farrowing is approaching, it cannot transition back to LA state. We have included this into the model as design parameter. We used the Viterbi algorithm to infer the most likely state that the sow is in for each time step based on Pt and . The Viterbi algorithm is a recursive method to calculate the most likely path of hidden states given observed probabilities (Marsland 2009). The Python programming language and scikit-learn package (Pedregosa et al. 2011) was used in the model development and validation.
1.4
Summary of the algorithm
The algorithm for detecting farrowing can be summarized as follows: 1. Compute activity in 10 minute epochs and normalize for individual level. 2. Use DLM to remove diurnal components and estimate trend Tt and slope St. 3. Calculate the probability of each epoch belonging to LA or HA state using logistic regression. 4. Use HMM with Viterbi algorithm do detect when sow is in HA state based on emission probabilities and state transition matrix . 5. Farrowing is approaching when state changes to HA.
Proceedings International Conference of Agricultural Engineering, Zurich, 06-10.07.2014 – www.eurageng.eu
3/5
Results and Discussion Figure 1 one shows the activity trend of one during 48 hours before farrowing until 24 hours after farrowing. The lower graph shows the forecasted probabilities for low and high activity state obtained from LR and the estimated from HMM. We can see that the eventhough P(LA) is higher than P(HA) already 38h before farrowing the estimated state change only occurs at a more reasonable time at 11h before farrowing. This is due to low state transition probability from LA to HA and also a desired system behavior.
Figure 1. Activity trend, state probabilities and process state for one sow.
The performance of the model was estimated using the validation of 10 sows. Figure 2 shows the distribution of detected activity increases using the model. An activity raise was detected in all sows between 19.6 to 5.5 hours before farrowing. This could be used as a pre-alarm as an expected farrowing or as an input to a model detecting following activity decrease. However, it is not accurate enough to give a good estimate about the start of farrowing for all sows.
Figure 2. The distribution of detected pre-farrowing activity increase for sows in the validation dataset (N=10).
Conclusions Using logistic regression classifier together with a Hidden Markov Model takes sequential observations into account and was a suitable model for the data. The developed method showed good results for detecting increased activity before farrowing. However, we could not obtain accurate predictions for parturition time. Future work will focus on detecting the exact farrowing moment.
References Cornou, C. & Lundbye-Christensen, S. (2012). Modeling of sows diurnal activity pattern and detection of parturition using acceleration measurements. Computers and Electronics in Agriculture, 80, 97-104. Cornou, C., Lundbye-Christensen, S., Kristensen, A, R. (2011). Modelling and monitoring sows' activity types in farrowing house using acceleration data. Computers and Electronics in Agriculture, 76, 316-324. Giovanni, P., Petrone, S. and Campagnoli, P. (2009). Dynamic Linear Models with R. Springer. pp 252. Haskell, M.J. & Hutson, G.D. (1994). Pre-farrowing behavior of sows and gilts with access to space for locomotion. Australian Journal of Experimental Agriculture. 34, 1099-1105. Marsland, S. (2009). Machine Learning: An Algoritmic Perspective. Boca Raton: CRC Press. Oliviero, C. Pastell, M., Heinonen, M., Heikkonen, J., Valros, A., Ahokas, J., Vainio, O. & Peltoniemi, O. (2008). Using movement sensors to detect the onset of farrowing. Biosystems Engineering, 100(2), 281-285. Pastell, M., Hietaoja, J., Yun, J., Tiusanen, J., & Valros, A. (2013). Predicting farrowing based on accelerometer data. Precision Livestock Farming 13. 370-378 pp. Leuven, Belgium. Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R.,Dubourg, V.,Vanderplas, J.,Passos, A., Cournapeau, D., Brucher, M., Perrot, M. & Duchesnay, E. (2011). Scikit-learn: Machine Learning in Python. Journal of Machine Learning Research, 21, 2825-2830. R Core Team (2013). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL http://www.R-project.org/. Smith, C.A.,(1997). Normal and abnormal parturition in Swine. Current therapy in large animal theriogenology. Youngquist, R.S., Threlfall, W.R., (eds.) chapter 106 pp. 722, Saunders. Valros, A., (2003). Behaviour and physiology of lactating sows - associations with piglet performance and sow postweaning reproductive success. PhD-thesis, Helsinki University, Yliopistopaino, Helsinki.
Proceedings International Conference of Agricultural Engineering, Zurich, 06-10.07.2014 – www.eurageng.eu
5/5