{'fraction_non_alphanumeric': 0.02627066748315983, 'fraction_numerical': 0.01065523576240049, 'mean_word_length': 4.878689704823614, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Developing Algorithms and a Mathematical Model for Monitoring the Physiological State of Cattle

This study involved theoretical and experimental research at farms with existing hardware and software. Measurements were conducted with non-invasive methods using special bolus transmitters (smaXtec animal care GmbH, Graz, Austria) developed for cow health monitoring. The boluses were introduced orally into the rumen of the studied cows. Algorithms and mathematical models were constructed for identifying estrus, calving and illnesses, and for monitoring feed and water consumption. Initial data were imported from a standard file, compatible with other applications (CSV table). Additionally, correlations were analyzed between temperature indicators, the rumen pH and the motor activity of the cattle. Illustrations include plots of the main vital factors and the correlated functions, and a screenshot of the software working console. Also included are tables with the results for each cow, the average values and the RMS deviation. The mathematical model developed is a set of algorithms and calculation results. Code for its implementation was written in Matlab R2019b and is attached to this report. This mathematical model may be used to process and interpret data obtained by boluses put into the rumen of animals.


Introduction
Efficient management of large farms is the main task that the animal husbandry sector faces. This task is solved by development of smart digital production management systems, so-called Human-Machine-Animal biotechnical systems, alternatively known as smart animal husbandry [1]. Development of such a system may be included with the next stage of the scientific and technical revolution [2].
Nowadays, obsolete control processes are still used in working with animals in the territory of the Russian Federation. Untimely discovery of an animal's problems may DonAgro lead to contingent expenses, which could have been prevented by automatic systems of animal health monitoring. According to data of the Russian Ministry of Agriculture, late diagnostics of caked udder results in losses of 150 €, thermal stress leads to a loss of 250 €. Annual mortality of dairy cattle in Russia is 2%.
Smart animal husbandry is a sector of agriculture involved in husbandry of agricultural animals featuring introduction of a new generation of systems and technologies in automation of animal care, aiming at increasing animal productivity and reducing costs [3].
In order to identify approaching calving and estrus, large animal farms are ever more reliant on automated systems that use transmitters (e.g., accelerometer, step counter, pressure transmitter, etc.) to collect and interpret data on the animals.
Several studies were dedicated to the use of transmitters in order to identify approaching calving and estrus in dairy cows. For example, Jensen (2012) used an accelerometer fixed at a hind leg of a cow (IceTag 3D, IceRobotics) to register changes in instances of laying down and general activity preceding calving [4]. Maltz and Antler (2007) in their study came to a conclusion that 10 out of 12 cases of calving were successfully detected in 24 hours before the event using an algorithm linking the time spent lying, the number of steps and their ration with the timing of calving [5].
Thus, sensitivity (69 -82%) and specificity (86 -87%) of the prognostic model were satisfactory, but positive prognostic value (accuracy) was low (3 -4%) and the number of false positives was significant. Schirmann et al (2013) in their study confirmed that cows spend on feeding on average 66 minutes less during the 24 hours before calving. The rumination and feeding time continued reducing after calving, by 133 and 82 minutes on average in comparison with the initial level [6].
In another study, a combination of two motor activity transmitters HR Tag (SCR Engineers Ltd., Netanya, Israel) and IceQube (IceRobotics Ltd., South Queensferry, UK) used to predict the moment of calving by activity of neck, the number of motor acts, time spent lying demonstrated sensitivity of 82.8% and specificity of 80.4% [7].
Basing on their review, Reith and Hoy (2018) recommended paying more attention to estrus automatic detection with transmitters as the most successful tool [12].
However, most research works and systems currently available are focusing on a single task (e.g., calving or estrus) using a single transmitter, which a farmer shall buy DonAgro and then integrate into various systems from different vendors, depending on their goal. Thus, existing algorithms and mathematical models are insufficiently accurate and efficient for monitoring of physiological health of cattle.
Integration of several transmitters in a single device and development of mathematical models for monitoring of physiological state of cattle will allow tracking individual parameters of every animal at a farm in real time, thus reliable detect estrus and approaching calving, control milk yield, monitor changes in chewing and motor activity, as well as the level of water and feed consumption [13].
The purpose of this study is to develop a mathematical model to detect estrus, approaching calving, early symptoms of an illness, monitoring of feed and water consumption by cattle.

Materials and Methods
The study was conducted by analysis of statistical data obtained during laboratory and practical study in an actual farm conditions covering 20 heads of cattle starting from 18 days at 3 farms. The cows were selected according to the following criteria: all the cows in each group had the same diet and housing conditions, age of 2-3 lactations and mass of over 350 kg.
Within this work, data from two samples were processed. In the first sample, data was processed from boluses implanted into stomach of 20 cows in 10 farms (2 cows per farm). Duration of the data collection for each cow was at least 2 months. In one of the farm -Gusev Private Farm (Tomsk oblast, Russia) -pasture was used for fattening up of livestock. In the second sample, data was processed from boluses implanted into stomach of 20 cows in 3 farms.
Before the study, selected cows were inspected in according to the clinical examination procedure [14]. The average weight of the cows in the experiment was 526 (± 2.03) kg. No clinical symptoms of diseases were identified.
The input data is represented by cattle health indicators measurements performed by the system of internal monitoring (boluses smaXtec animal care GmbH, Graz, Austria), that were implanted orally before collecting the data. Three parameters were measured: pH level, rumen temperature and motor activity. Pairwise correlation of parameters (motor activity, pH and temperature) was using a Chaddock scale.

Results
Average level of rumen pH in the analyzed group was 6.22, RMS deviation was 0.26, the maximum value was 6.7.
Average level of rumen temperature in the analyzed group was 38.94, RMS deviation was 0.17, the maximum value was 39.11.
Average level of motor activity in the analyzed group was 8.7, RMS deviation was 1.4, the maximum value was 11.7.
From the results of the analysis, a mathematical model was developed to detect estrus, approaching calving, monitoring of feed and water consumption by cattle. The mathematical model is a set of formulas and dependences between the indicators of rumen temperature, motor activity and rumen pH. From the analysis of the body of data presented in this work, it has been revealed that the level of motor activity is different in cows with differing housing type and this shall be taken into account in modeling of the parameter in question. It is proposed to introduce several settings for various times of day.
Dependences were determined on the basis of calculated linear correlation coefficients for rumen temperature and motor activity, rumen temperature and pH, motor activity and rumen pH. There are recommendations included for cases when the indicators of rumen temperature, motor activity or rumen pH deviate from the corresponding setting point.

Discussion
The mathematical model for identification of estrus, approaching calving and symptoms of diseases is an algorithm that allows from available data getting information on probability of estrus, approaching calving and symptoms of diseases.
Calculations for estrus starts from checking motor activity (y 1 ) and rumen temperature (y 2 ) of an animal for the last 30 minutes. If the animal's activity is in excess of triple RMS deviation from the setting and the rumen temperature is elevated, then the animal is in estrus. However, if the service period of the animal (х 1 ) is shorter than 20 days, than the program outputs a message that according to indications the cow shall come into estrus, but it contradicts service period value entered by the operator and with a probability of 80%, this situation is operator's error and the cow is in estrus (Figure 1).
Calculation for approaching calving starts with checking the animal's rumen temperature (у 1 ) for the last 5 hours. If it is below 39°C, then motor activity of the animal (y 2 ) is checked for the last hour. If it deviates from the setting for more than 10%, then according to the algorithm described in item 3, the number of drinking acts for the last 24 hours is checked. If water consumption is reduced (less than 5 acts), then the cow approaches calving. However, if the pregnancy of the animal (х 2 ) is shorter than 270 days, than the program outputs a message that according to indications the cow shall come into calving, but it contradicts pregnancy period value entered by the operator DonAgro and with a probability of 80%, this situation is operator's error and the cow approaches calving ( Figure 2). The mathematical model for monitoring feed and water consumption is an algorithm that from its input measurements allows getting information on necessity to provide the animal with feed or water.
In order to check the feed consumption level, the rumen pH (y) and rumen temperature (x) are checked for the last hour. If the pH level is below 6 (shifted to acidic) and the rumen temperature is higher than the setting point throughout the whole hour, the program produces an output message that the animal requires feeding (Figure 4).
In order to check for water consumption, the function first checks the rumen temperature (x) for the last hour. If it is higher than the setting point, then the function checks the number of drinking instances during the last 24 hours. A drinking instance is recorded if the rumen temperature between the two sequential measurements went down by 2 degrees and/or fell below 38°C. If during the last 24 hours the program identifies less than 5 drinking instances, it produces an output message that the animal needs water ( Figure 5). Here and below, to simplify the calculations, t is the number of a corresponding row of measurements in the input data table (and thus, the index in the input data array).
Equations to calculate the factors kt and bt are obtained from the condition to minimize the RMS deviation for each 24-hour period: DonAgro where is an initial moment of the ith 24-hour period, Y(t) is the actual measurement results for the studied parameter of the animal at moment t.
(for stall conditions, for pasture conditions, the formulas are the same but changed to kt1 and bt1).
kt0(i) and bt0(i) are unknown values, thus we calculate the minimum of a function of two variables; a mandatory condition for such minimum is that local derivative for each of the two variables is equal to zero.
After removal of parentheses and simplification of the expression, we get a system of two linear equations for two unknowns: where n is a number of measurements in a given day in stall.
Correlation of two random values X and Y is a value that characterizes a relation between these two values. In this mathematical model, a linear correlation coefficient is calculated between pairs of parameters (temperature and pH, temperature and motor activity, pH level and motor activity).
Linear correlation coefficient for random values X and Y is calculated with the formula: where N is a number of measurements, X and Y are the results of the ith measurement, and are average values.
The result of the calculations is a correlation matrix. Along its diagonal there are ones (the value correlates with itself), while other elements are pairwise correlations between the values. It is obvious, that the matrix is symmetrical. The higher (closer to DonAgro 1) is the correlation, the higher is the probability that there is a relation between the corresponding parameters.
The linear correlation coefficient allows evaluating simultaneous mutual influence of the parameters. In practice, however, often various parameters are related not simultaneously, but with a time delay. In order to evaluate mutual influence between random values with a time delay a mutual correlation function is used. In order to evaluate the dependence similar to that of a linear correlation coefficient, it is most convenient to use a normalized mutual correlation function. Normalized mutual correlation function of random values X and Y is a counterpart of the linear correlation coefficient, but one array is shifted by several position to the left or to the right: where ( ) is the mutual correlation function, j is delay (in the number of measurements).
It allows estimating mutual dependence between the values with a time delay, for example the influence of a motor activity half an hour ago onto the current rumen temperature.
The program constructs plots of the normalized mutual correlation function for devia- Corresponding functions construct plots of the motor activity, its setting points and regression ( Figure 7); rumen pH level, its setting points and regression; motor activity, its setting points and regression.
This cow (Figure 7) is calm and housed in a stall. Daily fluctuations of activity are low, but may be seed every day, at least due to sleep and wakefulness.
Results of calculations for average motor activity, average pH level, average temperature and their linear correlation coefficients are given in Table 1. RMS deviation of N values of x from their average was calculated with the formula:

Conclusion
This mathematical model is appropriate for calculation of a current state of the animal due to evaluation of their needs in feed and water, approaching calving, estrus and health state. The implemented program operates with standard Microsoft Excel tables in the CSV format, which are compatible with many applications.
The rumen pH level is an important vital parameter. It is of interest to measure the pH level both in a stall and in a range. For a more comprehensive study of pasturing influence onto cattle and their vital parameters, it is recommended to install the boluses DonAgro into the rumen somewhat before the ranging season ( January -February) in order to track the dynamics of the parameters first in the stall and then in the range.
The novelty of this development is that the animal's location is taken into consideration. In the classic implementation of bolus system algorithms from other manufacturers this option is missing. It distorts the picture due to the fact that motor activity of animals in free range and stall-range system (with constitutional walk) differs due to factors other than those related to illnesses. Due to that, for these two locations, the setting points (and as a result, RMS deviation and regression) will differ. Due tot the fact that the information on ranging the animal is rarely input into the program, it was decided to implement this function. Evaluation of the animal's location is performed from analysis of amplitudes of its motor activity, however, due to various individual variations, the amplitudes may differ significantly, thus the data on the animal's location are not exact.
Due to that, to improve the accuracy of information, it is suggested to consider to record ranging of cattle in some kind of journal with subsequent transmission of the data to manufacturer. It will make it possible to upgrade the program.
Further research requires field testing of the developed mathematical model in conditions and at a scale of actual animal husbandry farms.