From data to decision

An implementation of a sow replacement model is presented. The model estimates the economic value and potential of sows based on litter size history and inseminations of the individual sow as well as herd speci ﬁ c information about production level, farrowing rates and mortality. Herd speci ﬁ c prices and feeding are also considered. The software, called SoLiv, is both a decision support application for culling strategies in pig farms and an evaluation tool for consultants and veterinarians. The application supports the management software AgroSoft and Cloudfarms from which historical data is extracted and analysed using dynamical models, in order to assess herd speci ﬁ c trends. Further, the software can display historical trends, determine the optimal age distribution, and ascertain historical losses by having a non-optimal culling strategy.


Introduction
Several sow replacement models (SRMs) have been proposed in literature (examples include Huirne et al., 1991;Pla et al., 2004;Kristensen and Søllested, 2004b;Rodríguez et al., 2011). The most common technique applied to livestock replacement models is Markov decision processes. For a more comprehensive overview of models, reference is made to Nielsen and Kristensen (2014).
Today, farmers mostly base their replacement decisions on basic characteristics of the individual animal such as parity, litter size and health state without a systematic and formal numerical assessment of the individual properties. Despite the existence of the aforementioned SRMs, the application of them in practice has proven to be a challenging procedure. Thus, the SRM described by Kristensen and Søllested (2004a,b) requires significant knowledge about the calibration process needed for use in a specific herd.
Generally, an SRM seeks to model the dynamic production of the animals by applying the most representative parameters such as farrowing rates, mortality rates, and litter sizes. It is therefore essential that the SRM is properly calibrated to the herd in question. Providing a well calibrated and effective SRM to farmers as an assisting decision support tool can prove to be a great asset to pig farmers in their replacement decisions. Optimizing the culling strategy can affect the annual replacement rate, piglet production capacity, the expected life time of a sow and ultimately have a great economical impact (Rodríguez et al., 2011). This paper presents an application, called SoLiv, integrating the sow replacement model with three dynamic linear models (DLMs), deployed as a decision support tool for the farmer and an evaluation tool for farmers, veterinarians and consultants. The three DLMs (modeling mortality rate, farrowing rate and litter size, respectively) estimate the production parameters that are required to calibrate the SRM to herd specific conditions. A DLM is a dynamic regression analysis of a time series, which means that it will require historical data from the herd in order to function. Using such models ensures that the most representative production variables are dynamically estimated and updated. Subsequently, the SRM will provide an economic estimate on each animal, which will demonstrate whether an animal is economically viable or not.
The application has been set up to interface with the databases of the management software AgroSoft (Tørring, Denmark) and Cloudfarms (Bratislava, Slovakia), from which the DLMs estimate the herd trends. The three dynamic models also serve as a dynamic production monitoring tool. The results of these three models are locally stored in a database (specific to each herd), which allows the user to evaluate historical progress or decline in various parameters. Thus, the application includes a full implementation of the dynamic monitoring tools described by Bono et al. (2012Bono et al. ( , 2013Bono et al. ( , 2014. Except for a few external calibration parameters (prices of feed, piglets and gilts etc.) the application relies completely on already existing information stored in the database of the commercial management software used in the herd. As a logical consequence, information which is not available in the database (e.g. the health state of sows) is not taken into account.

Software development
The core of the software is the estimation of the herd-specific parameters using three DLMs, which are subsequently used as calibration parameters for the SRM.

Programming language
The software system has been developed as a desktop application programmed entirely in Java. The user interface is based on the JavaFX software platform.

Models
Several models are included in the system. It is outside the scope of this article to present these models in detail. They are described in Bono et al. (2012Bono et al. ( , 2013Bono et al. ( , 2014 and Kristensen and Søllested (2004a,b). Here, only a brief description is presented.

Dynamic linear models
As previously mentioned, a DLM is a dynamic regression analysis of a time series represented in state space. This regression in state space allows for variability in the regression coefficients, such that the system properties can change over time. Other methods often assume no variability at all or a variability that is approximately constant over time (e.g. linear trend estimation), which makes them unfit in a dynamic system such as in pig production.
In general, the results generated by the DLMs can be applied as a dynamic monitoring system, which will allow a manager to make decisions based on dynamically updated forecasts.
The DLM for litter size provides estimation at herd level as well as individual sow level. At herd level it estimates the litter size profile (average litter size as a function of parity) and at sow level, it estimates the litter size potential of the sow. This potential expresses to what extent the sow's litter size history surpasses or falls behind the herd average for its corresponding parity. Therefore, the unit of the potential is number of (total born) piglets.
The two other DLMs only estimate parameters at herd level. The DLM for farrowing rate estimates the parity specific farrowing rate (also accounting for previous unsuccessful inseminations) and the DLM for mortality estimates parity and stage (pregnant versus nursing) dependent mortality rates of sows, parity specific stillbirth rates and preweaning mortality rate of live born piglets.

Sow replacement model
The SRM implemented is a re-programmed version of the model presented by Kristensen and Søllested (2004a,b). Like the rest of the software system, the model is programmed in Java as a plug-in to the general MLHMP software system developed by Kristensen (2003). Thus, the optimization algorithm is provided by MLHMP.
Like the original model, the re-programmed version takes parity, full litter size history and insemination history (within parity) into account for the individual sow whereas prices, feed intake and sow weight are considered as herd level properties. The herd level productivity is expressed through models for litter size, farrowing rates and mortality rates. Those models are calibrated to the specific herd by use of the DLMs.
The output from the SRM is an economic value of the sow, defined as the "future profitability" (originally defined by van Arendonk, 1985, for dairy cows) or the "retention pay-off" (Huirne et al., 1991). It expresses the economic benefit of keeping a sow compared to immediate replacement. Thus, a negative number indicates that the sow should be replaced and a positive number indicates that it should be kept. The value can be used directly for ranking of sows for replacement.

Software structure
The structure of the program is divided into two parts: calibration and herd assessment. Fig. 1 depicts how the data, databases and models relate to each other, which is also explained in the following: 1. The software applies historical data from the herd, such as inseminations, farrowings, litter sizes, culling etc., which are extracted from a third-party management database. 2. Subsequently, the data is organized into weekly subsets which makes up the input data to the three DLMs: Litter Size, Farrowing rates and Mortality rates. These models are executed individually, using data that spans back five years, in order to ensure that all parameters are properly estimated. 3. The SRM is then instantly calibrated using the up-to-date estimates generated by the DLMs, and a set of external calibration parameters (feed prices, sow weight specifications etc.). In order to reduce computation time, the results of the DLMs are stored in a local database for future usage. 4. After calibrating the SRM, each sow is evaluated with its individual history and assigned an economic value and a litter size potential. The results are finally organized into two tables, where the first is of all active sows and the second contains all culled sows.

Implementation
A central element in the development of the application was to ensure its user-friendliness, so that farmers or other professionals without any training or particular background can use it. The following is a short review of the main features of the software and its functionality.

Graphical user interface
Upon opening the application, the user is presented with a loginscreen in order to access to the management database in question. The "Management database" is the database maintained by the external commercial management software used in the herd, and the "Local database" is the internal database maintained by SoLiv.
Additional options such as language and currency can be specified before login.
After accessing the management database through the login-page, the user is prompted to execute the DLMs before the central part of the software can be accessed. Upon finishing the execution, the user can navigate to a table containing all the sows that are currently active in the herd, as illustrated in Fig. 2.

Culling strategy and historical losses
All sows are evaluated using the SRM and organized into two tables. The first table consists of all active sows, which can be utilized to optimize the current culling strategy by replacing sows that generate negative value (i.e. decision support). It is possible to filter the results so that, for instance, only sows having farrowed within the last two weeks are shown or only sows above parity four etc.
The second table consists of all culled sows, along with an associated economic assessment of the historical losses due to non-optimal culling. The assessment is divided into three categories: culled too early, dead sows (lost slaughter value) and culled gilts. Both tables are supported by various sorting functions, making it easy for the farmer to specify the animals that should be evaluated. The table is used for a retrospective evaluation of the culling policy. Since the historical losses are based on currently defined prices, the evaluation should be interpreted as a rough estimate for the real losses in the past.

Dynamic production monitoring tool
As previously mentioned, the three DLMs also serve as a dynamic production monitoring tool. All the results of the DLMs are stored in a local database (specific to each herd), which allows the user to evaluate historical progress or decline in numerous production parameters.
An example is illustrated in Fig. 3 which shows the weekly sow mortality by parity over a three year period.

Discussion and conclusion
The sow replacement model as described by Kristensen and Søllested (2004a,b) has until the SoLiv system was developed only been applied in relation to teaching at University of Copenhagen, Aarhus University and University of Lleida by use of the general MLHMP software system developed by Kristensen (2003) for hierarchical Markov decision processes. To extract data from a management database, estimate parameters for calibration, entering the parameters into the MLHMP software and importing sow information from the management database was a tedious task requiring substantial knowledge about the procedure.
By developing the SoLiv system, the entire data communication and calibration of the sow replacement model has been made automatic. Thus, a major obstacle for practical use of the sow replacement model developed in research has been removed.
Currently, two commercial management information systems (AgroSoft and Cloudfarms) are supported. Thus, the vast majority of sow herds in Denmark will be able to use the system just by installing the free software system. A generic communication interface of SoLiv makes it easy to later implement interfaces for management information systems used in other countries. The dynamic monitoring system provided by SoLiv is a kind of  byproduct of the automated calibration procedure. Nevertheless, it constitutes a full implementation of the dynamic models developed by Bono et al. (2012Bono et al. ( , 2013Bono et al. ( , 2014. The dynamic monitoring system breaks fundamentally with traditional management information systems where static statements of selected key figures calculated for a specific time interval (typically a quarter or a year) are presented to the manager. Instead, the dynamic system continually updates estimates of herd and sow level performance as new observations are made and takes autocorrelations over time into account. This allows the manager to make timely interventions, as it is not necessary to wait until a new quarterly production report is available.