AI Based Digital Twin Model for Cattle Caring
Abstract
In this paper, we developed innovative digital twins of cattle status that are powered by artificial intelligence (AI). The work was built on a farm IoT system that remotely monitors and tracks the state of cattle. A digital twin model of cattle health based on Deep Learning (DL) was generated using the sensor data acquired from the farm IoT system. The health and physiological cycle of cattle can be monitored in real time, and the state of the next physiological cycle of cattle can be anticipated using this model. The basis of this work is the vast amount of data which is required to validate the legitimacy of the digital twins model. In terms of behavioural state, it was found that the cattle treated with a combination of topical anaesthetic and meloxicam exhibits the least pain reaction. The digital twins model developed in this work can be used to monitor the health of cattle.
Index Terms:
Health Detection, Digital Twin, AI, Deep learning, LSTM model.I Introduction
Digital twins are virtual digital representations of physical objects, in which the physical object and its corresponding virtual digital representation interacts remotely in real time[1]. A digital twin model incorporates multi-disciplinary, multi-physical quantity, multi-scale, and multi-probability simulation processes and fully utilises physical models, sensor updates, operation histories, and other data[2]. In addition, digital twins complete the mapping in virtual space so that the full life cycle process of associated entity equipment is reflected[3]. Digital twins are a transcendental idea that can be regarded as one or more crucial and interdependent digital mapping systems for the actual object[4, 5].
Connectivity, modularity, and autonomy between virtual and actual items can all be realised with digital twins. It can be accomplished across the whole production process from product design through product system engineering to production planning, implementation and intelligence, resulting in a self-optimizing closed loop[6]. To put it another way, by connecting the actual object with the virtual number, the real object may offer the real information to optimise the digital model, and the digital model can foresee potential situations to alter the real object. The two complement each other to create a self-closing optimisation mechanism[7]. Nowadays, digital twins have been increasingly employed in a variety of industries, including product design, product manufacturing, medical analysis, engineering construction and other areas[8]. As a result, digital twins can be seen as a major force behind the intelligent manufacturing paradigm[9]. Digital twins have recently been deployed in a variety of fields, including livestock farming[10, 11]. In today’s animal husbandry, testing the health of cattle is a crucial stage. Large cow ranches, in particular, need to keep track on their herd’s health in real time[12, 13].
Deep learning (DL) is a new direction in machine learning that is being introduced to bring it closer to the goal of AI and has made tremendous progress in solving issues that were previously unsolvable in AI [14, 15, 16, 17, 18, 19]. It has proven to be so effective in detecting complicated structures in high-dimensional data that it might be used in a wide range of scientific, business and government applications[20, 21, 22]. The long short-term memory network (LSTM) is a type of cyclic neural network and one of the deep learning algorithms that can analyse and forecast critical time with very long intervals and delays in time series[23, 24].
In a long time series, the LSTM neural network algorithm can determine which information should be stored and which should be discarded[25]. The development of digital twins relies heavily on accurate time series prediction. Internal and external disruptions might result in time series that are exceedingly nonlinear and random. Complex objects time series prediction may be employed at any stage of their life cycle, which is also a major component of the digital twin model[26, 27]. Therefore, it is extremely dependable to use LSTM model to build digital twins.
The goal of this study is to develop an intelligent digital twins technique with LSTM neural network to provide a variety of behavioural detection and prediction of cattle’s health status, including current health analysis and upcoming physiological cycle, etc. The digital twins concept is heavily reliant on massive volumes of data reflecting cattle location, movement and free grazing time, etc, collected by IoT monitoring systems, e.g., [28, 29, 30], wireless sensor networks, e.g., [31, 32, 33, 34, 35, 36] or cellular systems [37, 38, 39, 40].
The outline of the paper is given below. First in section II, existing works are described and reviewed for understanding of relationship between behavioral state and pain in cattle. After that, in section III, the new digital twin system involved in this study is illustrated and explained in detail. In section IV, necessary data mining and data analysing for the IoT system are carried out. In this part, most of the data processing work are accomplished with the help of MATLAB. In section V, cattle’s behaviour states are modeled by training the LSTM neural network in the digital twin model and cattle’s states in the next cycle is predicted by using this deep learning technique. In section VI, The accuracy of the trained LSTM model is discussed and verified, the best pain treatment for the cattle could be determined. Finally, section VII deduces a proper conclusion.
II Related Work
Analysing the relationship between cattle’s states and their level of pain is a crucial step to obtain the cattle’s health. Because animals’ assessments of changes in pain behaviour are highly subjective, it is difficult to apply a single index to assess and judge the severity of pain for cattle. Several studies have evaluated cortisol responses in cattle to establish the intensity and duration of pain related to castration. Cortisol has long been employed as a pain indicator since the magnitude of its reaction, such as peak height, duration of response, and combined response, frequently correlates with the expected toxicity of specific operations. The cattle who had surgery (i.e., those in more pain) ate grass less frequently, took fewer steps with pedometers, spent more time standing, and had symptoms of aberrant behaviour than those in the control group[43, 44]. Another study looked at the association between cow pain levels and various state postures[45, 46, 47]. It stated that the cattle’s pain level is affected by their attention, head position, ear position, face expression, and back position and that the pain level is split into three stages. The cattle that are passive without meals, grooming, or sleeping, for example, have pain on a scale of 1. In contrast, the cattle that are accompanied by lying down immediately after coming out of bed have pain on a scale of 2. if the cattle is active and attention towards the surroundings, it can be regarded as pain on a scale of 0.
Other research backs up these claims, claiming that pain is a subjective emotional state that is difficult to quantify objectively[48]. However, similar pain behaviours, which can be defined as those that occur in the presence or absence of pain, can be used to assess discomfort. After calves are burned or dehorned, postoperative physical pain is associated with increased head-related motor behaviours, such as head shaking and ear tossing. Specific postural alterations, such as limb protection, are also linked to pain disorders. A pedometer that records the number of steps taken has been employed as a significant indicator of pain behaviour monitoring. Cattle in pain take fewer steps, according to some research, and the number of steps taken may help assess behavioural changes following painful manipulations[49]. Cattle eating behaviour and intake can be monitored to detect potential changes in health or pain state, with reduced intake in cattle in pain[49].
At present, there is little previous work using the digital twin to analyze the behavior of cattle in order to monitor their health, because there is little work using the digital twin in animal husbandry. In addition, compared to previous work, e.g., [3, 7, 8, 10], we use a large amount of data collected from the farm Internet of Things to analyze, model, and support our results.
III The Proposed Digital Twin Model
In this work, we propose a digital twin model for cow health status monitoring, animal well-being prediction and appropriate pain treatment. Digital twins are virtual digital models that combine with real-world things. In our proposed model, the farm IoT system first collects relevant state data from physical items and transmits it to a cloud server. The prediction of state dynamics is then completed using the LSTM model of cow state following a data processing sequence and calculations. Actual data and expected results are used to determine the pain and health status of cattle. Finally, the appropriate pain therapy is implemented based on the cow’s projected discomfort status. Simultaneously, new sample data is entered into the cloud server and compared to the prior model’s anticipated value to continuously modify and optimize the model. This method completes the interaction between the virtual digital model and the real-world physical object. The block diagram of the digital twin model is depicted by Fig. 1.

In the following, we will describe the model step by step. We will start with the process of data mining and analysing, follow by the development of an LSTM model for cattle health status prediction, then determine the pain treatment.
IV Data Mining and Analysing
This section primarily discusses the processing method of the data sets, i.e., the original data measured by sensors of the farm’s IoT system. This data set is systematically treated in preparation for future use of the modelling. Particularly, the data sets of the cattle’s states are analysed, and a digital twin model of the cattle is produced using these data sets. A vast amount of data may be used to evaluate the model’s correctness, and the state of the cattle can then be predicted.
IV-A Data Processing
The sensor’s raw data set consists of 11 columns with over 50 million rows; a part of the original data set is displayed in Fig. 2. It entails the treatment of 759 cattle of various breeds and genders in various methods. There are eight categories used to classify cattle’s status: Resting, Rumination, High Activity, Medium Activity, Panting (Heavy Breathing), Grazing and Walking. Each sensor takes a minute-by-minute reading of the cows’ real-time status, with each cow having 74,455 data points collected between AU_time 8:06 am on August 10 and 1:01 am on October 1, 2019. Five cattle breeds are represented in the data sets: Angus, Brahman, Brangus, Charolais and Crossbred. There are also 13 potential therapy combinations, which are depicted in Table I. This section focuses on systematically processing of these data, including data segmentation, data cleaning, and data calculating.

Combined treatment |
---|
Castrating, negative control(C,N) |
Castrating, topical anaesthetic(C,T) |
Castrating, meloxicam(C,M) |
Castrating, topical anaesthetic + meloxicam(C,T+M) |
Dehorning, topical anaesthetic(D,T) |
Dehorning, meloxicam(D,M) |
Dehorning, topical anaesthetic + meloxicam(D,T+M) |
Dehorning, negative control(D,N) |
Dehorning + castrating, topical anaesthetic(D+C,T) |
Dehorning + castrating, meloxicam(D+C,M) |
Dehorning + castrating, topical anaesthetic + meloxicam(D+C,T+M) |
Dehorning + castrating, negative control(D+C,N) |
Positive control(P) |
IV-A1 Data segmentation
The first step in data processing is the segmentation. The data are grouped by cattle of the same sex, breed, and treatment. Because the original data are massive, we segment the data using RStudio and R programming language. Table II shows the number of cows segmented and integrated; the first column of the table reflects the various abbreviations for combined treatment. As indicated in Table II, F and M denote Female and Male, respectively and the number represents the number of animals. Cows are just dehorned, but bulls are typically castrated or castrated plus dehorned, as shown in Table II.
Furthermore, the number of other breeds is limited, and data is sparse except for the Brahman breed. The Brahman breed covers all of the combined treatments and is relatively numerous. This characteristic facilitates subsequent data analysis and processing. This is because a vast amount of data facilitates the analysis of overall data characteristics and avoid errors caused by individual and particular data. As a result, the resting state of Brahman’s Female with Positive Control is used to demonstrate data processing and prediction.
Combined treatment | An-gus F | M | Brah-man F | M | Bran-gus F | M | Char-olais F | M | cross-bred F | M |
---|---|---|---|---|---|---|---|---|---|---|
C,M | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 |
C,N | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
C,T | 0 | 1 | 0 | 3 | 0 | 2 | 0 | 0 | 0 | 6 |
C,T+M | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
D,M | 0 | 0 | 70 | 0 | 1 | 0 | 2 | 2 | 13 | 0 |
D,N | 0 | 0 | 39 | 0 | 1 | 0 | 2 | 2 | 9 | 0 |
D,T | 0 | 0 | 101 | 3 | 3 | 0 | 4 | 7 | 20 | 1 |
D,T+M | 0 | 0 | 66 | 2 | 4 | 0 | 3 | 0 | 12 | 0 |
D+C,M | 0 | 0 | 0 | 50 | 0 | 2 | 0 | 0 | 0 | 10 |
D+C,N | 0 | 0 | 0 | 30 | 0 | 2 | 0 | 0 | 0 | 7 |
D+C,T | 0 | 1 | 0 | 81 | 0 | 3 | 0 | 0 | 0 | 22 |
D+C,T+M | 0 | 0 | 0 | 50 | 0 | 1 | 0 | 0 | 0 | 13 |
P | 13 | 14 | 14 | 5 | 10 | 0 | 3 | 1 | 38 | 0 |
Total number | 13 | 19 | 290 | 227 | 19 | 11 | 14 | 11 | 92 | 62 |
IV-A2 Data cleaning
As shown in Fig. 2, when the sensor detects and transmits the status of the cow, it also sends a lot of invalid data. The accuracy of the original data will be considerably influenced if using these data directly. Therefore, the initial step is to clear up the corrupted data.
Because the data returned by the sensor represents the cattle’s states at a specific point in time, quantifying that state is critical for further design. In this work, the time of various states each hour in minutes is taken as the research object. Because corrupted or invalid data usually aggregate, identifying the point at which incorrect data arrives as 0 is not precise and may impact subsequent calculations. Therefore, deleting the corresponding time does not influence the total calculation when cleaning the corrupted data.

The flow chart of data cleaning is shown in Fig. 3. Data cleaning mainly focuses on the segmented data to clean and organize and finally obtains the cleaned data and its corresponding time series. This step primarily calculates the resting time of cattle in each hour. If it exists any corrupted data during the calculated hour, that hour’s data will be destroyed.
IV-B The state of cattle throughout the sampling period
Acquiring the cattle’s state changes across the sample period needs to average one group’s data of cows due to large amount of discrete and lost data from a single cow. For example, averaging the resting time per hour of 14 Brahman females under Positive control can determine variations in the resting state of Brahman treated with Positive control during the sample period. The time series after data cleaning are different between each cattle’s data set, since invalid data collected by sensors in the farm’s IoT system is usually a random process. Therefore, the data processing in this step is to average the state data of the cattle with the same time serial number and obtain the state curve of the cattle in the whole cycle. The process flow chart of an average state time for several cattle can be found in Fig. 4.
The state diagram of cattle in the entire cycle can be obtained after the program has been executed. Fig. 5 shows the calculated hourly rest time of the cattle in the whole cycle (Brahman Female with Positive Control). The number on the abscissa corresponds to the corresponding day, which includes all 24 hours. The ordinate represents the rest time corresponding to this hour in minutes.
Fig. 6 is a detailed zoomed-in part of Fig. 5 and located between days 16 and 20. It is obvious that the rest time of cattle varies periodically with a cycle of one day. The peaks of the daily rest time can be found in both early morning and late-night while the valleys can usually be identified at forenoon and afternoon hours.



IV-C The average 24 hour state of cattle
The averaged single rest cycle data result (which is 24 hours) of a single cattle is plotted in Fig. 7. The entire sampling cycle is approximately 52 days as shown in Fig. 5. The abscissa refers to the o’clock, i.e., from 0:00 to 23:59, and the ordinate relates to the rest period in minutes at this hour (Brahman Female with Positive control). The average period’s plot is flatter than a single period’s plot. However, the trend and structure of these two are nearly identical, and a single cycle has more individual points and noises.

IV-C1 Fitting curve for the average state period (24 hours)
Curve fitting is commonly used to obtain the data relationship for such irregular curves. Typical fitting methods include minimum binomial fitting, exponential function fitting, power function fitting, and hyperbola fitting. Different fitting approaches are compared in this section to obtain the most ideal mathematical model[50, 51].
Fitting method | The best number of items | Variance |
---|---|---|
Gaussian Fitting | 8 | 3.0037 |
Sum of sine | 8 | 20.1288 |
Polynomial | 9 | 245.3264 |
Fourier | 8 | 25.4590 |
Using the MATLAB fitting toolbox and the Brahman Female with Positive control as an example, four fitting approaches are utilized to fit the 24-hour average rest duration of cattle: Gaussian fitting, Sum of Sine fitting, Polynomial fitting, and Fourier fitting. The independent variable is the time, and the dependent variable is the rest period of cattle corresponding to that time while fitting the curve. The relationship between the time and the associated rest time can be established, and the curve of the cattle’s rest period throughout the day can be obtained. As indicated in Table III, Gaussian (item number 8) fitting is found to be the most accurate model among all candidates in terms of the fitting variance result. The fitted curve shape is depicted in Fig. 8. The formula of the fitting curve–Gauss eight-term formula is:
(1) |

In Equation 1, is the clock of a day, while denotes the rest time within one hour of that clock. Regarding the low standard deviation and variance of this fitting result, this model is considered to be the proper candidate to describe the resting time of cattle in a day for Brahman Females with Positive control. The models for other breeds, genders, states, and combined therapies can be obtained in the same way.
IV-C2 Compare the state time of cattle between different treatments
State | Description |
---|---|
Rest | Standing still, lying, and transition between these 2 events. Allowed to move head and legs during standing if movement is only of short duration (10 seconds), e.g. Head tossing associated with fly avoidance, stomping, briefly licking/sniffing self or environment but if movement of head/legs becomes dominant feature (e.g. sniffing/licking/chewing/pawing with leg or otherwise interacting with self/environment/other animal for more than 10 secs at a time) then no longer rest. While lying, allowed to do any kind of movement with head/neck/legs (e.g. tongue rolling). Only exception is paddling or otherwise struggling e.g. if secondary to being stuck under gate (which should then be classified as ”undefined”). |
Rumination | Rhythmic circular/side to side movements of jaw not associated with eating or medium activity, interrupted by brief (5 seconds) pauses during time that bolus is swallowed, followed by continuation of rhythmic jaw movements. If ruminating, record as such regardless of body position or location in pen. |
Panting (Heavy Breathing) | Respiratory rate80, fast and shallow movement of thorax visible when looking animal from side, along with forward heaving movement of body while breathing. May or may not have open mouth, salivation, and/or extended tongue. |
High Activity | Includes any combination of running, mounting, head-butting, repetitive head-weaving/tossing, leaping, buck-kicking, rearing and head tossing. |
Eating | Muzzle/tongue physically contacts and manipulates feed, often but not always followed by visible chewing. May move from one location to another while eating, as long as break in eating doesn’t last for more than 1 minute. More than 1 minute break in contact with feed and/or chewing-ends behavior. Searching for or otherwise manipulating in area of feed bunk or any other area in the pen in absence of feed is ”bicycle”. |
Grazing | Eating (see above definition) growing grass and pasture, while either standing in place or moving at slow, even or uneven pace between patches. |
This part investigates and compares the performance of cattle in various states when given the combination therapy. To be more specific, the average 24-hour data from each state is compared to examine changes in the state of cattle due to various pain treatments. For Brahman Female cattle, just the dehorning procedure is performed, corresponding to four different pain treatments: Topical anesthetic, Meloxicam, Topical anaesthetic+Meloxicam, and Negative control. Resting, walking, panting (heavy breathing), grazing, and eating are the five state behaviours evaluated and compared in different pain therapies. Detailed descriptions for different cattle states, e.g., Rest, Rumination, Panting, High activity, eating and grazing are explained in Table IV.
The Dehorning treatment is also employed for all the cattle, as shown in the dynamic comparison diagram of the cattles’ rest in Fig. 9, and various pain therapies result in various states. The positive control, a comparison variable, is the cow that does not receive any combined therapy. When the cattle’s horns are removed without pain relief, which is known as a negative control, they rest the longest. Except for the midday interval, cows treated with the other three anesthetic treatments rest slightly longer than those treated with a positive control and slightly shorter than those treated with a negative control. Nevertheless, in general, apparent similarity can still be found among their cases. This situation can be attributed to the rest state’s subjective and environmental effect, as the difference in pain treatment cattle at rest is not significant.


The cattle’s walking dynamics vary more significantly after various pain treatments than the cow’s resting dynamics. As shown in Fig. 10, after the dehorning treatment, every group walks for a shorter time than under the positive control. The cows provided with both topical anesthetic and Meloxicam are found to have the most prolonged walking duration, followed by those with topical anesthesia alone, and finally those with Meloxicam alone. However, cattle which is not anesthetized, such as Negative Control, have the least walking time. In summary, the cattle’s walking time decreases with the dehorning but increases when the anesthetic is introduced. This phenomenon also reflects, to some extent, that cattle’s pain condition directly ties to their walking time and that the administration of anesthetics affects cattle’s walking dynamics.
The cattle grazing behaviours are also notably varied under different Pain treatments. The cattle treated with a positive control have the most prolonged grazing duration, followed by those treated with a negative control and those treated with a local anesthetic, as seen in Fig. 11. The cattle grazing takes much less time when cattle are given Meloxicam or both. Although the association between pain and grazing time cannot be demonstrated, it is clear that different anesthetic treatments have varying effects on grazing time and that the duration of the effects also varies correspondingly.

The most noticeable of these stages is the time to pant (defined as breathing heavily). The panting period is the longest when the calves receive Meloxicam or Meloxicam and topical anesthetic, as depicted in Fig. 12. There is no significant graphical difference between these two treatments. The panting time during topical anesthetic is the second factor, followed by the panting time under a hostile control. During the positive control, the amount of time spent on panting is the shortest. The cows only pant for less than 2 min/h in the early morning and late at night. However, most of the panting occur between 6 a.m. and 6 p.m., and the amount of panting change dramatically across pain treatments.

Cattle eat between 6 a.m. and 5 p.m., as shown in Fig. 13. The positive control group spends the most time eating, followed by the negative control group. The three with the anesthesia take less time than the negative control. As a result, the dynamic analysis at the eating time can distinguish between the cattle that do not receive any treatment (positive control) and the cattle that do not receive any treatment (negative control). However, the type of anesthesia can not be determined accurately.

IV-D Noise reduction using low-pass FIR filter
Throughout the sample period, the cattle’s condition varies on daily basis. The plot of the entire activity cycle contains noise and outliers in Fig. 5. Therefore, denoising the sampled data is required.
FIR and IIR are two types of digital filters that are extensively employed. In theory, an IIR function’s filtering effect is superior to that of an FIR function of the same order, but divergence can occur. The IIR digital filter has a high precision for amplitude-frequency characteristics, with a non-linear phase, it is suited for audio signals that are insensitive to phase information. FIR digital filters have lesser amplitude-frequency precision than IIR digital filters. However, the phase is linear, meaning the time difference between signals of various frequency components remains unaltered after going through the FIR filter. In addition, the calculation time delay is relatively tiny, it is suited for real-time signal processing[52, 53]. Because the state of the cattle is a time-series data, it is critical to ensure that the filtered phase remains constant. Therefore, in this work, we use the FIR low-pass filter for denoising.

Cattle monitoring data are sampled once every 60 seconds in this study, resulting in a sampling frequency of around 0.0167Hz. Noise frequency is more extensive than sampling frequency, so the signal between 0 and 0.0167Hz is kept while the signal above 0.0167Hz is eliminated. In Fig. 14, the filter length is set to 5, and the filter’s shape corresponds to its frequency. The filtered result is depicted in Fig. 15, which uses the resting time of Brahman Female’s cow with Positive control as an example.

Fig. 16 is a local detailed version of Fig. 15, focusing on the comparison of before using FIR filtering and after using FIR filtering from the 16th to the 20th day. Data performance is optimized after introduction of the FIR filter for smooth signal processing, and the data trend can be clearly identified.


After going through the FIR filter, Fig. 17 provides an image of a single rest period (one day, Day 17). In comparison to Fig. 7, it exhibits the same trend, i.e., one day’s rest time after filtering is nearly the same as one day’s typical rest time. This feature demonstrates that the cattle’s condition changes on a regular basis. It also indicates that the FIR filtered signal is effective and precise. The FIR filter effectively minimizes noise, and eliminates outliers, and gross inaccuracy. As a result, the signal filtered by the FIR filter can be used for subsequent modeling and prediction.
V Prediction based on LSTM model
In DL, LSTM network is a unique RNN model. Its unique structural design allows it to avoid long-term reliance. The default nature of LSTM is to remember information from a long time ago[20, 21, 53, 54]. In this section, we employ the LSTM model to forecast the status of cattle based on the above research content. To be more explicit, the structure and properties of LSTM and how to construct an LSTM model are first discussed. Second, using the LSTM model, the cattle status is modeled and forecast. Finally, the model is optimized in order to improve its accuracy.
V-A Build the LSTM model of the cattle state
The program flow chart for establishing the LSTM model is shown in Fig. 18. First, import the data previously filtered by the FIR filter, and divide it into a test set and a training set. Second, the LSTM model is created. Setting parameters: the number of input neurons, output neurons, hidden neurons, learning rate, batch size, epoch size (i.e., the number of training cycles) and the number of LSTM layers[25]. The loss error is chosen as the mean square error, and the LSTM neural network is trained using the Adam optimisation technique[25]. The cycle ends when the number of training times is reached, and the lowest loss error will be the output.

V-B Using the LSTM model to predict the state of cattle
It is critical to determine the input, output, and time series before using the constructed LSTM model for cattle state prediction. The cattle’s state must be presented as the output, and the number of the independent variable hours must be seen as a time series, according to the characteristics of the data sets. As a result, determining input variables is a challenging aspect of this approach. Because the output variable must be data with periodic changes, the input must be a known fixed periodic function. Time series as a fixed periodic function can be used as input. To be more specific, given that the state cycle of cattle is one day, it is appropriate to determine the input variable as the number of hours on the clock each day. The input and output variables, as well as the time series, for the resting time of Brahman Female’s cattle with Positive control are as follows:
Input: The number of hours on the clock each day (24 hours).
Output: The resting time during this hour (e.g. The resting time at 7:00 means that the resting time during one hour from 7:00 to 7:59).
Time series : The sequence number of this hour (e.g. 0:00am on the first day is the first hour, and is 1. So on, 0:00am on the second day is the 25th hour, and is 25).
-
•
Training:
Both the input and output data are periodicity. The distinction is that the input in this cycle has a set value and trend, whereas the output in each cycle has a varied value. For example, the input is 0 at 0:00 am on Day 17th and 0:00 am on Day 24th, as shown by the two red lines in Fig. 19, but the output is different. In other words, the same input might result in multiple outcomes regardless of time. Although the input is the same, the input’s matching time series is not. As a result, when a single input correlates to numerous outputs in a time series, the LSTM model can successfully handle the problem.Figure 19: The input and output based on the LSTM model. -
•
Testing and prediction:
90% of the data is used for training, and 10% for prediction and testing. For example, the input data sets for training are through , while the data sets for testing are through . The training outcomes are depicted in Fig. 21.Figure 20: The training-loss during the LSTM model training. Figure 21: The predictive results after training and testing.
The predict and actual results are similar shown in Fig. 20. The training loss reduce during the training process, showing that model is converged and practical. However, the prediction results’ error is relatively significant, which indicates further requirements of the parameter optimization in the model.
V-C Parameter optimization
For optimization and comparison purpose, the number of hidden units, LSTM layers, the batch size, and the epoch size were all modified.
Hidden units size: 4, 8, 16, 32, 64, 128, 256.
The number of LSTM layers: 1, 2, 3, 4, 5, 6, 7.
The batch size: 3, 6, 12, 24, 48, 96.
The epoch size: 100, 500, 1000, 2000, 5000, 10000, 20000.
-
•
Selection of the number of LSTM layers
The number of hidden units is 16, the batch size is 24, and the epoch size is 2000, all of which are randomly chosen. Only the number of layers in the LSTM is modified with the other parameters fixed: 1, 2, 3, 4, 5, 6, 7. The box diagram for the mean square deviation in the model learning process is shown in Fig. 22.Figure 22: The mean square error with different number of LSTM layers. The top line and bottom line represent the edge’s maximum and minimum values respectively. The upper quartile is represented by the box’s upper edge, while the box’s lower edge represents the lower quartile. The orange line represents the median. When comparing the seven box charts, increasing the number of layers has a minor impact on the mean square error of model training. However, in terms of model performance, using more LSTM layers, the running speed will be slower and it becomes more complex, and the result of the model operation is affected[25]. As a result, two layers of LSTM are best for this model.
-
•
Selection of the hidden units size
Figure 23: The mean square error with different hidden units size. To determine the size of the hidden units, we keep the batch size and epoch size unchanged and run the LSTM model with different hidden units size, i.e., 4, 8, 16, 32, 64, 128, 256. The box diagram of the mean square is shown in Fig. 23. In terms of error size and ultimate training effect, the choice of 128 hidden units is the best for training the data, with the majority of the mean square error values falling below 25.
-
•
Selection of the epoch size
Select two layers of LSTM with 128 hidden units while keeping the rest of the settings the same: the batch size is 24, but the epoch size can be any of 100, 500, 1000, 2000, 5000, 10000, or 20000. Fig. 24 shows a box diagram for the mean square deviation in the model learning process.Figure 24: The mean square error with different epoch size. The epoch size is the number of times the learning algorithm works in the entire training data set. An epoch means that each sample in the training data set has the opportunity to update internal model parameters. In theory, the more training sessions there are, the better the fit and the lower the error. In practice, however, overfitting occurs when the epoch size exceeds a specific threshold, causing the training outcomes to deteriorate[25]. The epoch size of 100, 500, 1000, 2000, 5000, 10000, and 20000 is chosen in Fig. 24. The inaccuracy rapidly decreases and approaches zero as the epoch size increases from 100 to 10000. When the epoch size increases to 20,000, the error is still tiny, but it is greater than when the epoch size is 10,000, indicating an overfitting occurrence. Therefore, the model with a 10000 epoch size has the best effect.
-
•
Selection of the the batch size
Figure 25: The mean square error with different batch size. The batch size, which can be 3, 6, 12, 24, 48, or 96, is altered when using two layers of LSTM with 128 hidden units and an epoch size of 10000. The box diagram is shown in Fig. 25. The batch size refers to the number of samples fed into the model at once and divides the original data set into batch size data sets for independent training. This method helps to speed up training while also consuming less memory. To some extent, batch size training can help to prevent the problem of overfitting[25]. As a result, when building the model, an acceptable batch size should be chosen. When the batch size is 24, the minimum value of the produced mean square deviation data set is the smallest in terms of minimum value and median.


To sum up, the best parameters for the LSTM model are 128 hidden neurons, 24 batch size, 10000 epoch size, 2 LSTM layers. Fig. 26 shows the loss value after optimizing parameters, while Fig. 27 shows the training and prediction outcomes after optimizing model parameters. The LSTM model has a good prediction on the resting state of cattle, which largely adheres to the periodic changes in cattle state and has a modest error. Loss-train: 0.00787; Loss-test: 7.823968.
VI Results and Analysis
In this section, the digital twin model of cattle is analyzed and evaluated to determine its reliability and accuracy. In addition, this section conducts a behavioural evaluation on the status of cattle. It evaluates the pain conditions of cattle based on the results produced from the previous sections.
VI-A Applicability of the model
Figs.28-31 depicts the LSTM model’s training and prediction on different sexes, breeds, combined treatments, and states, respectively.
The trend of the results predicted by this LSTM model are nearly identical to the actual data. The model for Brahman males performs relatively poorly, which can be attributed to their relatively random rest state, poor cycle regularity, and other external environmental factors. It is possible that increasing the size of the data collection may result in improved predictions. Overall, the LSTM-based model for cattle states cycle is accurate and effective, and it can accurately predict the dynamic trend of the next cattle state cycle.
-
•
The LSTM model is applied to the other gender of cattle.
Figure 28: Prediction of rest dynamics during the whole cycle of Brahman Male cattle with Positive control. -
•
The LSTM model is applied to the other breed of cattle.
Figure 29: Prediction of rest dynamics during the whole cycle of Angus Male cattle with Positive control. -
•
The LSTM model is applied to the other combined treatment of cattle.
Figure 30: Prediction of rest dynamics during the whole cycle of Brahman Female cattle with dehorning treatment plus negative control. -
•
The LSTM model is applied to the other state of cattle.
Figure 31: Prediction of pant dynamics during the whole cycle of Brahman Female cattle with Positive control.
VI-B The relationship between cattle’s states and pain treatment
This work primarily involves three different pain treatments for pain management: topical anesthetic, meloxicam, and a combination of the two. In animal practice, topical anesthetics are the most widely utilized pre-emptive analgesics[55]. Without causing loss of consciousness, these chemicals cause a reversible loss of sensation in the local area. Local anesthetics enter nerve cells and block open sodium channels, inhibiting nerve impulse production and transmission. However, topical anesthetic must work in an alkaline environment, and the quality of local anesthesia in diseased, ischemic, or damaged tissue is frequently poor because the more acidic environment inhibits the medication from being separated[43, 55]. Topical anesthetics typically take 2 to 5 minutes to take effect, and studies have shown that they reduce plasma cortisol concentrations following castration, but not the mean area under the cortisol effect curve[43]. This issue shows that using topical anesthetics alone can help reduce the immediate pain associated with castration[43]. Meloxicam, an oxicam-class NSAID, has been licensed for the adjuvant treatment of acute respiratory illnesses in the European Union. Meloxicam muscle injection and horn nerve block lowered serum cortisol response for longer than cattle with a topical anesthetic before cauterization. This phenomenon means that the use of meloxicam before horn removal is effective in reducing pain in cattle. However, meloxicam alone is not effective in reducing castration-related acute distress. As a result, using a combination of topical anesthetic and meloxicam to reduce discomfort during castration or dehorning is beneficial[43].
VII Conclusion
VII-A Achievements at the current stage
The construction of a smart digital twin model of the state of cattle is primarily achieved in this work. It is primarily built on a farm IoT system to collect the state data of cattle under various combined treatments, with data cleaning and calculating. The average data of 24 hours are fitted, and the data of the whole sampling period are de-noised. In addition, a deep learning-based LSTM model for cattle state dynamics is developed using the data after noise reduction, and the model can predict the state change of cattle in the next cycle. The model’s accuracy and effectiveness are demonstrated when the prediction results are compared to the actual results.
Furthermore, the association between various behaviour patterns and bovine pain, the relationship between pain degree and behaviour pattern of cattle under various pain treatments are investigated. It is fund that the cattle in pain spent less time walking and ate less food, according to the final data. In cattle undergoing castrating or dehorning, combining topical anesthetic with meloxicam can be observed to successfully reduce the cattle’s pain.
VII-B Future outlook
Because pain is regarded as an emotion with a high subjective aspect, and the cattle behaviour is significantly impacted by external influences, existing data and technology do not quantify pain in a fully effective fashion. As a result, simply connecting the state of a cow with pain may not be accurate or helpful enough. Quantifying pain and measuring the intensity of discomfort in proportion to the duration of each behavioural state is a critical challenge that will need to be addressed in the future. Furthermore, encapsulating the entire research into another system is a critical step towards commercializing digital twins in the future.
References
- [1] 1S. Haag and R. Anderl, “Digital twin–proof of concept, manufacturing letters 15 (2018) 64–66,” 2018.
- [2] B. Schleich, N. Anwer, L. Mathieu, and S. Wartzack, “Shaping the digital twin for design and production engineering,” CIRP Annals, vol. 66, no. 1, pp. 141–144, 2017.
- [3] H. Pargmann, D. Euhausen, and R. Faber, “Intelligent big data process- ing for wind farm monitoring and analysis based on cloud-technologies and digital twins: A quantitative approach,” in 2018 IEEE 3rd In- ternational Conference on Cloud Computing and Big Data Analysis (ICCCBDA). IEEE, 2018, pp. 233–237.
- [4] C. Verdouw and J. W. Kruize, “Digital twins in farm management: illustrations from the fiware accelerators smartagrifood and fractals,” in 7th Asian-Australasian Conference on Precision Agriculture Digital, 2017, pp. 1–5.
- [5] M. Grieves and J. Vickers, “Digital twin: Mitigating unpredictable, un- desirable emergent behavior in complex systems,” in Transdisciplinary perspectives on complex systems. Springer, 2017, pp. 85–113.
- [6] S. Boschert and R. Rosen, “Digital twin—the simulation aspect,” in Mechatronic futures. Springer, 2016, pp. 59–74.
- [7] F. Yang, K. Wang, Y. Han, and Z. Qiao, “A cloud-based digital farm management system for vegetable production process management and quality traceability,” Sustainability, vol. 10, no. 11, p. 4007, 2018.
- [8] F. Tao, M. Zhang, Y. Liu, and A. Y. Nee, “Digital twin driven prognostics and health management for complex equipment,” Cirp Annals, vol. 67, no. 1, pp. 169–172, 2018.
- [9] T. Grober and O. Grober, “Improving the efficiency of farm management using modern digital technologies,” in E3S Web of Conferences, vol. 175. EDP Sciences, 2020, p. 13003.
- [10] L.-E. Cojocaru, G. Burlacu, D. Popescu, and A. M. Stanescu, “Farm management information system as ontological level in a digital business ecosystem,” in Service orientation in Holonic and multi-agent manufac- turing and robotics. Springer, 2014, pp. 295–309.
- [11] B. Tekinerdogan and C. Verdouw, “Systems architecture design pattern catalogfor developing digital twins,” Sensors, vol. 20, no. 18, p. 5103, 2020.
- [12] L. Li, H. Wang, Y. Yang, J. He, J. Dong, and H. Fan, “A digital management system of cow diseases on dairy farm,” in International Conference on Computer and Computing Technologies in Agriculture. Springer, 2010, pp. 35–40.
- [13] K. Smith, A. Martinez, R. Craddolph, H. Erickson, D. Andresen, and S. Warren, “An integrated cattle health monitoring system,” in 2006 International Conference of the IEEE Engineering in Medicine and Biology Society. IEEE, 2006, pp. 4659–4662.
- [14] X. Yan, D. Yang, Z. Lin, and B. Vucetic, “Significant low-dimensional spectral-temporal features for seizure detection,” IEEE Transactions on Neural Systems and Rehabilitation Engineering, vol. 30, pp. 668–677, 2022.
- [15] M. Liu, Z. Lin, P. Xiao, and W. Xiang, “Human biometric signals monitoring based on wifi channel state information using deep learning,” 10.48550/ARXIV.2203.03980, 2022.
- [16] X. Yan, Z. Lin, and P. Wang, “Wireless electrocardiograph monitoring based on wavelet convolutional neural network,” in 2020 IEEE Wireless Communications and Networking Conference Workshops (WCNCW), 2020, pp. 1–6.
- [17] L. Meng, K. Ge, Y. Song, D. Yang, and Z. Lin, “Long-term wearable electrocardiogram signal monitoring and analysis based on convolutional neural network,” IEEE Transactions on Instrumentation and Measure- ment, vol. 70, pp. 1–11, 2021.
- [18] Z. Chen, Z. Lin, P. Wang, and M. Ding, “Negative-resnet: noisy ambula- tory electrocardiogram signal classification scheme,” Neural Computing and Applications, vol. 33, pp. 1–13, 07 2021.
- [19] P. Wang, Z. Lin, X. Yan, Z. Chen, M. Ding, Y. Song, and L. Meng, “A wearable ecg monitor for deep learning based real-time cardiovascular disease detection,” arXiv preprint arXiv:2201.10083, 2022.
- [20] Y. LeCun, Y. Bengio, and G. Hinton, “Deep learning,” nature, vol. 521, no. 7553, pp. 436–444, 2015.
- [21] N. Wagner, V. Antoine, M.-M. Mialon, R. Lardy, M. Silberberg, J. Koko, and I. Veissier, “Machine learning to detect behavioural anomalies in dairy cows under subacute ruminal acidosis,” Computers and Electronics in Agriculture, vol. 170, p. 105233, 2020.
- [22] J. Schmidhuber, “Deep learning in neural networks: An overview,” Neural networks, vol. 61, pp. 85–117, 2015.
- [23] F. A. Gers, J. Schmidhuber, and F. Cummins, “Learning to forget: Continual prediction with lstm,” 1999.
- [24] R. J. Williams and D. Zipser, “A learning algorithm for continually running fully recurrent neural networks,” Neural computation, vol. 1, no. 2, pp. 270–280, 1989.
- [25] M. Sundermeyer, R. Schluter, and H. Ney, “Lstm neural networks for language modeling,” in Thirteenth annual conference of the international speech communication association, 2012.
- [26] W. Hu, Y. He, Z. Liu, J. Tan, M. Yang, and J. Chen, “Toward a digital twin: Time series prediction based on a hybrid ensemble empirical mode decomposition and bo-lstm neural networks,” Journal of Mechanical Design, vol. 143, no. 5, 2021.
- [27] J. Schmidhuber and S. Hochreiter, “Long short-term memory,” Neural Comput, vol. 9, no. 8, pp. 1735–1780, 1997.
- [28] J. Leng, Z. Lin, and P. Wang, “Poster abstract: An implementation of an internet of things system for smart hospitals,” in 2020 IEEE/ACM Fifth International Conference on Internet-of-Things Design and Implemen- tation (IoTDI), 2020, pp. 254–255.
- [29] D. Zhai, H. Chen, Z. Lin, Y. Li, and B. Vucetic, “Accumulate then trans- mit: Multiuser scheduling in full-duplex wireless-powered iot systems,” IEEE Internet of Things Journal, vol. 5, no. 4, pp. 2753–2767, 2018.
- [30] J. Wang, G. Wang, B. Li, Z. Lin, H. Wang, and G. Chen, “Optimal power splitting for mimo swipt relaying systems with direct link in iot networks,” Physical Communication, vol. 43, p. 101169, 2020. 12
- [31] J. Yue, Z. Lin, B. Vucetic, and P. Xiao, “The design of degree distribution for distributed fountain codes in wireless sensor networks,” in 2014 IEEE International Conference on Communications (ICC), 2014, pp. 5796– 5801.
- [32] K. Pang, Z. Lin, Y. Li, and B. Vucetic, “Joint network-channel code design for real wireless relay networks,” in 2010 6th International Symposium on Turbo Codes Iterative Information Processing, 2010, pp. 429–433.
- [33] J. Yue, Z. Lin, and B. Vucetic, “Distributed fountain codes with adaptive unequal error protection in wireless relay networks,” IEEE Transactions on Wireless Communications, vol. 13, no. 8, pp. 4220–4231, 2014.
- [34] J. Yue, Z. Lin, and B. Vucetic, “On estimation of protection parameters for unequal error pro- tection distributed fountain codes in wireless relay networks,” in 2014 IEEE Wireless Communications and Networking Conference (WCNC), 2014, pp. 468–473.
- [35] J. Yue, Z. Lin, B. Vucetic, G. Mao, M. Xiao, B. Bai, and K. Pang, “Network code division multiplexing for wireless relay networks,” IEEE Transactions on Wireless Communications, vol. 14, no. 10, pp. 5736– 5749, 2015.
- [36] Y. Ma, Z. Lin, H. Chen, and B. Vucetic, “Multiple interpretations for multi-source multi-destination wireless relay network coded systems,” in 2012 IEEE 23rd International Symposium on Personal, Indoor and Mobile Radio Communications - (PIMRC), 2012, pp. 2253–2258.
- [37] Y. Chen, J. Li, Z. Lin, G. Mao, and B. Vucetic, “User association with unequal user priorities in heterogeneous cellular networks,” IEEE Transactions on Vehicular Technology, vol. 65, no. 9, pp. 7374–7388, 2016.
- [38] Z. Lin, B. Vucetic, and J. Mao, “Ergodic capacity of lte downlink multiuser mimo systems,” in 2008 IEEE International Conference on Communications, 2008, pp. 3345–3349.
- [39] Z. Lin, P. Xiao, B. Vucetic, and M. Sellathurai, “Analysis of receiver algorithms for lte lte sc-fdma based uplink mimo systems,” IEEE Transactions on Wireless Communications, vol. 9, no. 1, pp. 60–65, 2010.
- [40] Y. Chen, M. Ding, D. Lopez-Perez, J. Li, Z. Lin, and B. Vucetic, “Dynamic reuse of unlicensed spectrum: An inter-working of LTE and wifi,” IEEE Wireless Communications, vol. 24, no. 5, pp. 52–59, 2017.
- [41] P. Wang, G. Mao, Z. Lin, X. Ge, BDO. Anderson, ”Network coding based wireless broadcast with performance guarantee”, IEEE Transactions on Wireless Communications 14 (1), 532-544
- [42] Zihuai Lin and B. Vucetic, ”Power and rate adaptation for wireless network coding with opportunistic scheduling,” 2008 IEEE International Symposium on Information Theory, 2008, pp. 21-25, doi: 10.1109/ISIT.2008.4594940.
- [43] J. F. Coetzee, “A review of pain assessment techniques and pharma- cological approaches to pain relief after bovine castration: Practical implications for cattle production within the united states,” Applied Animal Behaviour Science, vol. 135, no. 3, pp. 192–213, 2011.
- [44] M. A. Islam, S. Lomax, A. K. Doughty, M. R. Islam, and C. E. Clark, “Automated monitoring of panting for feedlot cattle: Sensor system accuracy and individual variability,” Animals, vol. 10, no. 9, p. 1518, 2020.
- [45] K. B. Gleerup, P. H. Andersen, L. Munksgaard, and B. Forkman, “Pain evaluation in dairy cattle,” Applied Animal Behaviour Science, vol. 171, pp. 25–32, 2015.
- [46] K. B. Gleerup, B. Forkman, N. D. Otten, L. Munksgaard, and P. H. Andersen, “Identifying pain behaviors in dairy cattle,” WCDS Adv Dairy Technol, vol. 29, pp. 231–239, 2017.
- [47] B. Robert, B. White, D. Renter, and R. Larson, “Evaluation of three- dimensional accelerometers to monitor and classify behavior patterns in cattle,” Computers and Electronics in Agriculture, vol. 67, no. 1-2, pp. 80–84, 2009.
- [48] S. T. Millman, “Behavioral responses of cattle to pain and implications for diagnosis, management, and animal welfare,” Veterinary Clinics: Food Animal Practice, vol. 29, no. 1, pp. 47–58, 2013.
- [49] M. E. Theurer, D. E. Amrine, and B. J. White, “Remote noninvasive assessment of pain and health status in cattle,” Veterinary Clinics: Food Animal Practice, vol. 29, no. 1, pp. 59–74, 2013.
- [50] W. M. Kolb, Curve fitting for programmable calculators. Imtec, 1984.
- [51] N. Buttchereit, E. Stamer, W. Junge, and G. Thaller, “Evaluation of five lactation curve models fitted for fat: protein ratio of milk and daily energy balance,” Journal of Dairy Science, vol. 93, no. 4, pp. 1702– 1712, 2010.
- [52] L. Rabiner, J. Kaiser, O. Herrmann, and M. Dolan, “Some comparisons between fir and iir digital filters,” Bell System Technical Journal, vol. 53, no. 2, pp. 305–331, 1974.
- [53] I. Goodfellow, Y. Bengio, A. Courville, and Y. Bengio, Deep learning. MIT press Cambridge, 2016, vol. 1, no. 2.
- [54] T. Xie, H. Yu, and B. Wilamowski, “Comparison between traditional neural networks and radial basis function networks,” in 2011 IEEE International Symposium on Industrial Electronics. IEEE, 2011, pp. 1194–1199.
- [55] D. E. Anderson and W. W. Muir, “Pain management in cattle,” Veterinary Clinics: Food Animal Practice, vol. 21, no. 3, pp. 623–635, 2005