Livestock online weighing error analysis method based on state classification and time-frequency characteristics

By combining state classification and time-frequency feature analysis with variational mode decomposition and machine learning models, the problem of insufficient error analysis accuracy in the online livestock weighing system was solved, achieving high-precision weighing error prediction and compensation, and improving the robustness of the system.

CN121256347APending Publication Date: 2026-01-02INNER MONGOLIA AGRICULTURAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511449636.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-11
Publication Date
2026-01-02

AI Technical Summary

Technical Problem

Existing error analysis methods for online livestock weighing systems suffer from low prediction accuracy, insufficient robustness, and poor error compensation.

Method used

An analysis method based on state classification and time-frequency features is adopted. By collecting dynamic weighing signals and adding state labels, the weight prediction value is generated using variational mode decomposition. Time-domain and frequency-domain features are extracted, and feature selection and dimensionality reduction are performed by combining support vector machine and random forest regression models. The state classification and error prediction models are then trained to achieve high-precision weighing error prediction.

Benefits of technology

This improves the weighing accuracy and robustness of the online livestock weighing system, enabling it to accurately compensate for weighing errors under different activity levels, thus promoting the development of precision farming.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121256347A_ABST
    Figure CN121256347A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of animal husbandry management, and particularly relates to a livestock online weighing error analysis method based on state classification and time-frequency characteristics. According to the scheme, firstly, an original weighing signal is subjected to modal decomposition to obtain a weight prediction value, and a reference error is calculated in combination with a static weighing value; secondly, extracting time-frequency domain characteristic parameters after self-adaptive windowing processing is carried out on the signals, and exploring the relation between the time-frequency domain characteristic parameters and reference errors in different active states; and finally, establishing a state classification model and two types of error prediction models, and performing hyper-parameter optimization on the error prediction models by using a myxobacteria optimization algorithm. In practical application, the state classification model is utilized to perform state classification on the weighing object, and the specified error prediction model is called in combination with the classification result to realize weighing error prediction. According to the invention, the problems of insufficient precision and poor generalization of the existing scheme are overcome; the method can be used for compensating the error of the online weighing platform so as to promote the development of fine breeding.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of animal husbandry management, specifically relating to an analysis method for online weighing errors of livestock based on state classification and time-frequency characteristics, as well as the corresponding computer program product, storage medium, and analysis device for online weighing errors of livestock. Background Technology

[0002] Body weight is a crucial indicator for the intensive farming of livestock such as cattle and sheep. Accurate acquisition of body weight is essential for assessing livestock nutritional status, growth and development, health, and production performance. With technological advancements, intelligent and automated dynamic weighing systems have been developed. Taking cattle farming as an example, technicians have designed automated walking weighing systems at the exit of rotating dairy farms. As cattle pass through the system, the system uses a consistency correlation coefficient to perform online weight assessment based on the collected weighing signals. However, due to the influence of multiple factors, including the cattle's movement, the weighing results obtained by existing online weighing devices still contain significant errors.

[0003] To address the error issues inherent in dynamic weighing methods, technicians have proposed classifying cattle movement states and employing different strategies for processing. For example, Feng Ningning et al. proposed an EMD-based dynamic measurement algorithm based on cattle behavior information, categorizing dairy cow movement states into walking / stopping, slow, fast, and vigorous activity, and using different methods for prediction, achieving a prediction error of less than 1.35%. Feng et al. established an activity level classification model, using signal characteristics to classify cattle movement into low, medium, and high activity states, and then predicted weight for each, with average error rates of 0.1838%, 0.6724%, and 0.9462%, respectively. Both methods utilize cattle behavior information during the weighing process and employ different strategies based on different behavioral states; however, they do not further analyze the classified signals themselves, only using filtering combined with mode decomposition for processing.

[0004] The combination of signal processing techniques and intelligent algorithms to address errors in dynamic weighing has seen widespread application in recent years. Ma Cong et al. proposed a method using LSTM combined with a BP neural network for error analysis in dynamic weighing of beef cattle, reducing the dynamic weighing error to 1.70%. He Zhijiang et al. proposed utilizing the time-domain characteristics of the signal to establish a sparrow-optimized support vector regression (SSA-SVR) error compensation model, thereby correcting the dynamic weighing algorithm for predicting the weight parameters of dairy cows, achieving an average percentage error of 0.68%. Both methods utilize hidden information in the signal, improving the accuracy of dynamic cattle weighing. However, the former does not quantify the hidden information, and the LSTM network is unstable in complex environments, while the latter only utilizes time-domain characteristics, neglecting the application of frequency-domain characteristics, which are also hidden information in the signal.

[0005] Based on the above problems, the existing error analysis methods for various online livestock weighing systems still suffer from low prediction accuracy, insufficient robustness, and poor error compensation. Summary of the Invention

[0006] To address the issues of insufficient accuracy and poor reliability in existing online livestock weighing systems, this invention provides a method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics, along with a corresponding system, device, and computer program for analyzing online livestock weighing errors.

[0007] This invention is achieved using the following technical solution: An analysis method for online livestock weighing error based on state classification and time-frequency characteristics, comprising: Collect dynamic weighing signals and static weighing values ​​of livestock, and add status tags to the dynamic weighing signals; the status tags are divided into high-activity status and low-activity status.

[0008] The effective signal is extracted after low-pass filtering of the dynamic weighing signal; the weight prediction value is generated based on the effective signal using variational mode decomposition; the difference between the static weighing value and the weight prediction value is used as the reference error.

[0009] Extract the time-domain features of the effective signal; perform a fast Fourier transform on the effective signal after adaptive windowing, and then extract the frequency-domain features; the extracted time-domain features and frequency-domain features together constitute the time-frequency features of each effective signal.

[0010] The time-frequency characteristics of all acquired valid signals are correlated with the state labels, filtered, and dimensionality reduced to obtain the first feature. The time-frequency characteristics of all acquired valid signals with state labels of high activity and low activity are correlated with their respective reference errors, filtered, and dimensionality reduced to obtain the second and third features.

[0011] Each first feature and its associated state label form a set of sample data, constituting the first dataset. Each second and third feature and its associated reference error form a set of sample data, constituting the second and third datasets, respectively. The SVM model is trained using the first dataset to obtain a state classification model that can predict the activity state of livestock based on the first features. The RF model is trained using the second and third datasets to obtain error prediction models for the corresponding activity states.

[0012] The first feature of the dynamic weighing signal of the livestock to be tested is extracted and input into the state classification model to identify the active state; the second or third feature of the dynamic weighing signal is extracted based on the active state and input into the corresponding error prediction model to generate the weighing error.

[0013] The present invention also includes a computer program product comprising a computer program that, when executed by a processor, creates an error prediction system comprising a pre-trained state classification model and two error prediction models as described in the aforementioned analysis method for livestock online weighing errors based on state classification and time-frequency features; the error prediction system is used to classify the weighing object according to the state of the input livestock dynamic weighing signal, and then call the corresponding error prediction model in combination with the classification result to generate the corresponding weighing error.

[0014] The present invention also includes a storage medium storing a computer program. When the computer program is executed by a processor, it creates an error prediction system that includes a pre-trained state classification model and two error prediction models, as described in the aforementioned method for analyzing livestock online weighing errors based on state classification and time-frequency features. The error prediction system is used to classify the weighing object according to the input dynamic weighing signal of the livestock, and then call the corresponding error prediction model based on the classification result to generate the corresponding weighing error.

[0015] The present invention also includes an analysis device for online livestock weighing errors, comprising a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it creates an error prediction system comprising a pre-trained state classification model and two error prediction models as described in the aforementioned method for analyzing online livestock weighing errors based on state classification and time-frequency features. The error prediction system is used to classify the weighing object according to the state of the input dynamic weighing signal of the livestock, and then calls the corresponding error prediction model based on the classification result to generate the corresponding weighing error.

[0016] The technical solution provided by this invention has the following beneficial effects: This invention, based on an in-depth analysis of the formation principle and underlying mechanism of online weighing errors in livestock scales, proposes a novel error prediction mechanism. This mechanism includes: first, deep extraction of multi-dimensional features from the weighing signal; then, analysis of the correlation between each extracted time-domain and frequency-domain feature and the state category; and further analysis of the correlation between each time-domain and frequency-domain feature and the weighing error under different active states. Finally, it optimizes the feature information highly correlated with the state category and the weighing error under different active states. Finally, it trains the optimized network model using a large amount of real-world feature data, resulting in a high-precision state classification model and an error prediction model that predicts the weighing error of livestock based on the input signal under different active states. The combined use of these three models enables high-precision measurement of weighing errors.

[0017] In the feature extraction stage, this invention also optimizes the fixed parameters of the window function and establishes an adaptive window function to reliably analyze the signal frequency domain. Time-frequency analysis is used to quantitatively analyze the hidden information and behavioral information of the cattle dynamic weighing signal; the potential correlation between the time and frequency domain features of the cattle dynamic weighing signal and the motion state and error is explored. In the error prediction model training stage, this invention also uses a slime mold optimization algorithm to optimize the optimal model hyperparameters. After distinguishing different motion states of livestock during the weighing process, the scheme of this invention can adaptively select the best error prediction model to perform error correction for the corresponding state.

[0018] Applying the solution of this invention to online weighing systems can significantly improve the weighing accuracy, robustness, and generalizability of livestock online weighing systems while ensuring weighing efficiency. This strongly promotes the development of precision farming. Attached Figure Description

[0019] Figure 1 This is a technical roadmap for the analysis method of online livestock weighing error based on state classification and time-frequency characteristics provided in Embodiment 1 of the present invention.

[0020] Figure 2 This is a schematic diagram of the data acquisition platform used in Embodiment 1 of the present invention.

[0021] Figure 3 This is a schematic diagram of the effective signal extraction method in Embodiment 1 of the present invention.

[0022] Figure 4 This is a graph showing the energy variation under different K values ​​obtained when the VMD method is used to analyze the effective signal in this invention.

[0023] Figure 5 This is the result of the present invention using the VMD method to perform mode decomposition on dynamic weighing signals.

[0024] Figure 6 A heatmap showing the correlation between the dimensional time-domain characteristics of the weighing signal and the movement state of the livestock.

[0025] Figure 7 A heatmap showing the correlation between the dimensionless time-domain characteristics of the weighing signal and the movement state of livestock.

[0026] Figure 8 A heatmap showing the correlation between the frequency domain characteristics of the weighing signal and the movement state of the livestock.

[0027] Figure 9 This is a heatmap showing the correlation between the dimensional time-domain characteristics of the weighing signal and the reference error under high-activity conditions.

[0028] Figure 10This is a heatmap showing the correlation between the dimensionless time-domain characteristics of the weighing signal and the reference error under high-activity conditions.

[0029] Figure 11 This is a heatmap showing the correlation between the frequency domain characteristics of the weighing signal under high-activity conditions and the reference error state.

[0030] Figure 12 This is a heatmap showing the correlation between the dimensional time-domain characteristics of the weighing signal and the reference error under low-activity conditions.

[0031] Figure 13 This is a heatmap showing the correlation between the dimensionless time-domain characteristics of the weighing signal and the reference error under low-activity conditions.

[0032] Figure 14 This is a heatmap showing the correlation between the frequency domain characteristics of the weighing signal under low-activity conditions and the reference error state.

[0033] Figure 15 This is a graph showing the relationship between the information content of the features and the number of principal components when using PCA to reduce the dimensionality of the first feature.

[0034] Figure 16 This is a physical image of the weighing platform built for the testing experiment. Detailed Implementation

[0035] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0036] Example 1 Taking cattle as an example, the technicians in this embodiment discovered during their error research on the online weighing system that the measurement error obtained is correlated with various time and frequency domain features contained in the weighing signal when the cattle are in different active states during the weighing process. Furthermore, the time and frequency domain features highly correlated with the reference error in the weighing signal are not the same in different active states. For this reason, the traditional approach of using the cattle's motion state as an enhancement feature to dynamically correct the weighing result predicted using weighing information essentially ignores the intrinsic correlation between motion state and weighing error, and therefore cannot effectively compensate for the influence of motion state on the measurement process. Based on this, this embodiment further develops and utilizes the multi-dimensional information and behavioral characteristics implicit in the weighing signal, and proposes an analysis method for livestock online weighing errors based on state classification and time-frequency features.

[0037] The technical solution provided in this embodiment first performs in-depth extraction of multi-dimensional features from the weighing signal, and analyzes the correlation between each extracted time-domain feature and frequency-domain feature and the state category. Furthermore, it analyzes the correlation between each time-domain feature and frequency-domain feature and the weighing error under different active states. Finally, it selects features highly correlated with the state category and the weighing error under different active states. Then, based on the extracted sample data, it trains a network model to obtain a state classification model capable of classifying livestock states based on the input signal, and an error prediction model capable of predicting the weighing error of livestock under different active states based on the input signal. Finally, based on the above two network models, this embodiment can generate a more accurate weighing error using the input dynamic weighing signal, thereby achieving error compensation for the weighing results.

[0038] Specifically, such as Figure 1 As shown, the method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics provided in this embodiment includes the following process: 1. Collect dynamic weighing signals and static weighing values ​​of livestock, and add status tags to the dynamic weighing signals; the status tags are divided into high-activity status and low-activity status.

[0039] This embodiment first collects the dynamic signals and static weight values ​​of the target livestock. The dynamic weight signal is a continuous time-domain weight signal collected by the online weighing platform as the livestock moves across it. During this measurement process, the livestock is in motion, and the obtained signal fluctuates constantly; therefore, it can only serve as state data of the weighing process and cannot be used as the final weight result. The static weight value, on the other hand, is the weight result obtained when the livestock is stationary on the weighing equipment. This measurement result is obtained when the livestock is stationary, eliminating the influence of motion. Therefore, the obtained static weight value can be considered the accurate value of the livestock's weight.

[0040] In this practical application, a livestock passage can be set up in the data collection scenario, with the data acquisition platform installed at the exit of the passage. The data acquisition platform includes an online weighing system and a static weighing platform. The former is used to collect dynamic weighing signals from the livestock, while the latter collects static weighing values. The two platforms are spaced at an appropriate distance according to the actual situation to avoid the impact of cattle urinating or other behaviors on the accuracy of the method during the two measurements. A schematic diagram of the data acquisition platform in this embodiment is shown below. Figure 2 As shown.

[0041] During signal acquisition, considering the low frequency of the dynamic weighing signal, according to the Nyquist theorem, an appropriate margin needs to be added to ensure accurate signal sampling. The sampling rate needs to be greater than twice the frequency of the sampled signal. However, in practical applications, setting the sampling rate to 5 to 10 times the frequency can better acquire the signal. In this embodiment, the sampling rate is set to 20Hz. When the livestock arrives at the static weighing platform, the livestock is intercepted, and the static weighing value is obtained after the livestock has been stationary for 2 to 4 seconds.

[0042] When collecting dynamic weighing signals for each animal, the animal's movement and health status directly affect the signal waveform. Factors such as leg lift height and walking speed cause different changes in the signal, thus affecting both the time and frequency domains. This embodiment allows for manual observation of the animal's natural walking pattern during the weighing process. Based on indicators such as hoof health, mental state, leg lift height, and walking speed, the animal's movement status is categorized into two types: low-activity and high-activity. Corresponding state labels are then added to the collected dynamic weighing signals. These state labels serve as supervisory information for the subsequent training of the state classification model.

[0043] 2. After low-pass filtering the dynamic weighing signal, the effective signal is extracted; the variational mode decomposition method is used to generate the weight prediction value based on the effective signal; the difference between the static weighing value and the weight prediction value is used as the reference error.

[0044] In this embodiment, when cattle pass over the dynamic weighing platform, a low-pass filter can be used to preprocess the acquired dynamic weighing signal to eliminate the influence of interference signals. During the dynamic weighing signal acquisition process, the weighing signal obtained after the livestock steps onto the online acquisition platform is not entirely a valid signal. It includes the weight signal immediately after stepping onto the platform and the signal generated by the pressure exerted on the platform by the hind legs even after the forelegs have left the platform. Therefore, this embodiment needs to extract the valid signal from the entire acquired weighing signal to obtain the interval signal corresponding to the time period when the livestock's weight is completely applied to the online weighing platform for subsequent processing.

[0045] Specifically, such as Figure 3 As shown, this embodiment uses a threshold method to extract the effective signal. The signal extraction method includes: First, set a threshold based on the maximum value of the livestock dynamic weighing signal; for example, set the threshold to 0.8 times the maximum value of the livestock dynamic weighing signal; then, extract the portion of the dynamic weighing signal whose amplitude exceeds the threshold. Next, find the left and right maxima contained in the corresponding interval of the extracted signal. Finally, use the portion of the signal between the left and right maxima as the valid signal.

[0046] The dynamic weighing signal of livestock contains multiple frequencies, including the animal's own weight, the impulse generated by movement, and various noises. To address this, this embodiment extracts the steady-state signal related to the animal's gravity by acquiring and analyzing trend components, and uses this signal as the predicted weight value of the livestock to be tested. Specifically, this embodiment uses Variational Mode Decomposition (VMD) to generate the predicted weight value based on the effective signal extracted above. The process includes: firstly, progressively decomposing the effective signal according to a preset number of variational modes K to obtain K modal components IMF1 to IMFK; then, using the average value of IMF1 as the predicted weight value.

[0047] When applying the VMD method, the first step is to determine the value of the variational mode number K. A K value that is too small cannot adequately decompose the effective signal, leading to a certain degree of signal aliasing. A K value that is too large will generate too many modes, introducing unnecessary noise. In this embodiment, the K value is continuously increased starting from K=2 to decompose the effective signal; the energy change results under different K values ​​are as follows: Figure 4 As shown in the figure. Analysis of the data in the figure shows that the optimal K value should be set to 6. In this embodiment, after setting the K value to 6, the modal decomposition results of the dynamic weighing signal are as follows. Figure 5 As shown in the diagram, IMF1 to IMF6 are the decomposed mode functions, where IMF1 is the steady-state trend component representing body weight. In this embodiment, the average value of IMF1 is used as the initial predicted body weight for further analysis. Considering that the static weighing value can be considered the true body weight of livestock, this embodiment uses the difference between the static weighing value and the predicted body weight generated by the variational mode decomposition method as the reference error of the dynamic weighing platform. This reference error will serve as the label information for training error prediction models under different active states later.

[0048] 3. Extract the time-domain features of the effective signal; perform fast Fourier transform on the effective signal after adaptive windowing, and then extract the frequency-domain features; thus obtaining the time-frequency features of each effective signal.

[0049] The time-domain characteristics of a signal can reflect its variation over time. In this embodiment, to comprehensively analyze the relationship between various characteristics and weighing error, various time-domain characteristics of the effective signal are extracted in all aspects, resulting in 12 time-domain characteristics of the effective signal, as shown in Table 1. Table 1: Statistical Table of Time-Domain Characteristics of Dynamic Weighing Signals

[0050] Frequency domain features of a signal can provide important information about its structure, components, and behavior. In this embodiment, the effective signal is first windowed, then subjected to a Fast Fourier Transform (FFT) to extract the corresponding frequency domain features. Specifically, the six frequency domain features of the effective signal finally extracted in this embodiment are shown in the table below: Table 2: Statistical Table of Frequency Domain Characteristics of Dynamic Weighing Signals

[0051] During frequency domain feature extraction, the length of the effective signal is often not precisely aligned with the frequency of the Fast Fourier Transform (FFT) window; that is, the edges of each signal time window are discontinuous. This causes energy in each frequency domain to spill over into adjacent frequency ranges, resulting in spectral leakage. Spectral leakage mainly manifests as a certain frequency component of the signal extending to adjacent frequencies, resulting in main lobe expansion and the formation of side lobes. This affects the frequency analysis of the signal, making it difficult to distinguish frequency components, thereby reducing the accuracy and resolution of spectral analysis. To address this problem, this embodiment employs an adaptive windowing method to window the effective signal.

[0052] Specifically, this embodiment uses the following four-term combined cosine window function as the adaptive window function: ; in, The value of the window function. N The length of the window function. n For the current sample point index, n ∈[0, N -1]; These are the weights of the cosine terms in the adaptive window function.

[0053] Combining multiple cosine window functions allows for better balance between main lobe width and side lobe attenuation by adjusting the number of cosine terms, weighting coefficients, and total window length according to specific application requirements, thereby improving the reliability of signal analysis. In practical applications, this embodiment utilizes the Sparrow Search Algorithm (SSA) to optimize the weights of each cosine term in the adaptive window function during the windowing process, thus establishing an adaptive window function to achieve adaptive weight optimization based on the signal's inherent characteristics.

[0054] The effective signal for frequency domain feature extraction in this embodiment has the following characteristics: (1) Low frequency dominance. The movement of cattle on all fours and the changes in posture on the data acquisition platform make the dynamic weighing signal relatively smooth and low frequency. (2) Less noise. The high-frequency noise has been filtered out to a certain extent by low-pass filtering, so there is less high-frequency noise in the signal. (3) Slow change. Cattle usually do not engage in vigorous movement when walking naturally, so the frequency domain features of the signal are mainly concentrated in a narrow frequency range. Based on this characteristic, in order to suppress side-frequency leakage and ensure the accuracy of frequency domain feature extraction during the weight optimization process using the sparrow search algorithm, the following fitness function is designed in this embodiment. F fit : ; ; In the above formula, SSR This indicates the sidelobe suppression ratio of the signal. P s and P m Decibels represent the signal power of the sidelobe and main lobe components; Indicates the spectral smoothness of the signal; α and β These represent the weighting coefficients for sideband leakage and smoothness, respectively. α >0, β >0 and α + β =1. Final setting in this embodiment α and β The values ​​were 0.2 and 0.8, respectively, to improve spectral smoothness while ensuring good sidelobe suppression.

[0055] In this embodiment, the 12 time-domain features and 6 frequency-domain features of the extracted effective signal are used together as the time-frequency features of the effective signal and then used for subsequent analysis and application.

[0056] Fourth, perform correlation analysis, filtering, and dimensionality reduction on the time-frequency characteristics of all collected valid signals with state labels to obtain the first feature. Then, perform correlation analysis, filtering, and dimensionality reduction on the time-frequency characteristics of all collected valid signals with high-activity and low-activity state labels with their respective reference errors to obtain the second and third features.

[0057] As previously mentioned, the technicians in this embodiment discovered that the correlation between each time-frequency feature extracted from the dynamic weighing signal and the livestock's state and weighing error is inconsistent. Therefore, a targeted state classification model and error prediction model were designed. In this embodiment, it is necessary to analyze the features most relevant to the livestock's state, the features most relevant to the weighing error of livestock in a highly active state, and the features most relevant to the weighing error of livestock in a low-activity state. In this embodiment, these are referred to as the first feature, the second feature, and the third feature, respectively, for subsequent model training.

[0058] This embodiment first extracts a raw multidimensional array from a large amount of collected real sample data, consisting of all interrelated time-frequency features, state labels, and their reference errors. Then, it performs correlation analysis between the 18 different dimensions of the time-frequency features in the raw multidimensional array and the motion state. The corresponding correlation analysis results are as follows: Figures 6-8 As shown, based on the analysis results, the features with an absolute correlation value of not less than 0.2 are selected as follows: peak value, peak-to-peak value, standard deviation, shape factor, impact factor, impulse factor, margin factor, kurtosis, skewness, spectral centroid, spectral flatness, spectral entropy, spectral slope, spectral energy, and spectral spread. All of the above 15 features are related to the state of livestock and can be used as basic features included in the first feature.

[0059] Next, this embodiment filters out the multidimensional data with the state label of "high activity" from the original multidimensional array, and performs correlation analysis between the 18 different dimensions of the time-frequency features of each multidimensional array and the reference error. The corresponding correlation analysis results are as follows: Figures 9-11 As shown, based on the analysis results, the features with an absolute correlation value of not less than 0.2 are selected as follows: impulse factor, impact factor, margin factor, spectral centroid, spectral flatness, spectral entropy, spectral slope, and spectral spread. All of the above 8 features are related to the weighing error of livestock in a highly active state and can be used as the basic features included in the second feature.

[0060] Finally, this embodiment filters out the multidimensional data with the state label of "low activity" from the original multidimensional array, and performs correlation analysis between the 18 different dimensions of the time-frequency features of each multidimensional array and the reference error. The corresponding correlation analysis results are as follows: Figures 12-14 As shown, based on the analysis results, the features with an absolute correlation value of not less than 0.2 are selected as follows: peak-to-peak value, kurtosis, peak factor, impulse factor, impact factor, margin factor, spectral centroid, spectral flatness, spectral entropy, spectral slope, and spectral spread. All of the above 11 features are related to the weighing error of livestock in a low-activity state and can be used as the basic features included in the third feature.

[0061] Further analysis Figures 6-14 The various correlation heatmaps also reveal that some features among the selected first, second, and third features (such as peak-to-peak value and standard deviation, margin factor, and impulse factor) exhibit high correlation, forming a strongly correlated set of features. Using both as base features for a particular type of feature vector results in feature redundancy. Therefore, this embodiment further performs feature dimensionality reduction on the selected features to obtain the desired first, second, and third features.

[0062] Specifically, in practical applications, this embodiment uses principal component analysis (PCA) to reduce the dimensionality of time-frequency features; the process includes: (1) The original feature matrix X Subtract the mean from each element in μ The standardized matrix was then obtained. X st The calculation formula is: ; ; In the above formula, x i Represents the original feature matrix X The first included i The value of each feature; n Representation of the characteristic matrix X The number of elements in it.

[0063] (2) Calculate the normalization matrix X st covariance matrix C Covariance matrix C It can describe the relationship between different features, and its calculation formula is: .

[0064] (3) For the covariance matrix C Decompose to obtain eigenvalues λ and eigenvectors v The decomposition formula is as follows: .

[0065] (4) Based on the eigenvectors, new coordinate axes are formed along the principal component directions to construct the principal component matrix. P ; ; in, v 1, v 2, ..., v k For the frontk 1 eigenvector.

[0066] Eigenvalues λ This represents the variance corresponding to the principal component. New coordinate axes, i.e., the principal component directions, are formed based on the eigenvectors. Projecting these axes onto a lower-dimensional space yields a matrix. P .

[0067] (5) Standardize the matrix X st Project onto the selected k On each principal component, the dimensionality-reduced feature matrix is ​​obtained. X r The corresponding conversion formula is as follows: .

[0068] In this embodiment, when standardizing the feature information in the first feature and performing PCA principal component dimensionality reduction, the proportion of information in the dimensionality-reduced feature is also analyzed as the number of principal components increases. The results are as follows: Figure 15 As shown in the figure, analysis of the data reveals that when the number of principal components is 5, the information percentage is 89.3%, representing most of the relevant feature information. Therefore, this embodiment selects a PCA principal component count of 5 for dimensionality reduction of the time and frequency domain features. Correspondingly, performing the same PCA principal component analysis on the second feature and the second feature reveals that for the second feature, when the PCA principal component count is 3, the cumulative information percentage is 96.90%, representing most of the information. This embodiment ultimately sets the principal component count for it in the PCA dimensionality reduction operation to 3. For the third feature, when the PCA principal component count is 5, the cumulative information percentage is 92.14%, representing most of the information. Therefore, this embodiment selects the optimal principal component count as 5.

[0069] 5. Each first feature and its associated state label are used as a set of sample data to form the first dataset. Each second and third feature, along with their associated reference errors, are used as a set of sample data to form the second and third datasets, respectively. The SVM model is trained using the first dataset to obtain a state classification model capable of predicting livestock activity states based on the first features. The RF model is trained using the second and third datasets to obtain error prediction models for the corresponding activity states.

[0070] The preceding text describes how, through effective signal extraction, time-frequency feature extraction, correlation analysis, and screening of the collected dynamic weighing information, as well as PCA dimensionality reduction, refined features—namely, the first feature, the second feature, and the third feature—are highly correlated with the livestock's movement state and weighing errors under different states, and contain no redundant information. This embodiment continues to use the label information from the original multidimensional array of each first feature as the label information for the first feature, thus obtaining the first sample data. Multiple first sample data sets are generated based on the large amount of collected data to form the required first dataset. Similarly, this embodiment uses the reference error from the original multidimensional array of each second feature as the label information for the second feature, thus obtaining the second sample data. This embodiment generates multiple second sample data sets based on the large amount of collected data, thereby obtaining the second dataset. Similarly, using the reference error from the original multidimensional array of each third feature as the label information for the third feature, third sample data is obtained. This embodiment generates multiple third sample data sets based on the large amount of collected data, thereby obtaining the third dataset.

[0071] Next, this embodiment will use the first dataset to train a state classification model that can classify the movement state of the livestock being weighed based on the first feature of the input dynamic weighing signal, and an error prediction model that can predict the weighing error of the livestock being weighed based on the second or third feature of the input dynamic weighing signal under different movement features.

[0072] In selecting base models for state classification models, common classification models include logistic regression, support vector machines (SVM), decision trees, random forests, etc., each with its own advantages. This embodiment selects the support vector machine (SVM) model based on data characteristics and model features. The SVM model has stronger non-linear data processing capabilities, and its flexible kernel function enhances its generalization ability. Support vector machines are a powerful supervised learning model; their core idea is to construct a decision boundary to maximize the margin, thereby handling various classification problems and completing the classification task.

[0073] Specifically, in the SVM model, to address the linear inseparability of feature information for motion state classification, this embodiment utilizes the Lagrangian function for dual transformation, thereby nonlinearly mapping the input samples to a high-dimensional space. A hyperplane is then constructed in this high-dimensional space for motion state classification. The kernel function in the SVM model improves the linear separability of data by mapping it to a high-dimensional space. Common kernel functions include linear kernels, Gaussian kernels, Laplace kernels, and polynomial kernels. This embodiment ultimately chooses the Gaussian kernel function for data mapping due to its strong noise resistance, excellent adaptability to nonlinear data, superior performance, and suitability for the livestock state classification task in this embodiment. After training, this embodiment uses accuracy, precision, recall, and F1 score as evaluation metrics to assess the model's classification performance.

[0074] In selecting the base model for the state classification model, this embodiment chooses the Random Forest Regression (RF) model based on the characteristics of the dataset. The Random Forest algorithm is a machine learning algorithm based on ensemble learning. This algorithm constructs multiple decision trees and combines their predictions in an ensemble learning manner, maintaining good stability even with small sample sizes, exhibiting good robustness and higher accuracy. In practical applications, this embodiment establishes error prediction models for the two types of motion states separately to predict errors under different motion states, thereby improving the accuracy of error prediction. Since the datasets used for training the RF models in high-activity and low-activity states are different, the optimal hyperparameters of the two regression models are also different.

[0075] The principle of the random forest regression model is as follows: First, the random forest regression model constructs multiple training subsets. Repeated random sampling with replacement is performed on the dimensionality-reduced dataset for each livestock state, ensuring the number of samples is equal to the original dataset, thus generating multiple error prediction regression training subsets.

[0076] Secondly, multiple decision trees are generated. Each decision tree has a different subset of feature parameters after dimensionality reduction, so the generated models are independent and have different predictive abilities and characteristics, thereby reducing variance and improving the stability and accuracy of the final prediction.

[0077] Then, time-frequency domain features are randomly selected. When constructing each decision tree, in order to reduce the correlation between trees, the random forest algorithm does not use all features at each node. Instead, it selects the optimal features by calculating the prediction accuracy of out-of-band data and splits the nodes until the stopping condition is met. This method of evaluating the prediction error of out-of-band data can effectively measure the generalization ability of the model.

[0078] Finally, regression prediction and ensemble analysis are performed. For each new input time-frequency domain feature parameter, each decision tree independently provides a predicted value, and the final prediction is the average of all the predictions from the decision trees. Through this ensemble strategy, random forests can significantly reduce the errors and overfitting problems caused by individual trees, thereby improving the accuracy and robustness of the regression model.

[0079] To improve the accuracy of the prediction error calculation of the random forest regression model, this embodiment uses the slime mold optimization algorithm (SMA) to optimize the hyperparameters of the RF model, namely the number of trees and the maximum depth. Compared with other heuristic algorithms, the slime mold optimization algorithm used in this embodiment has the following characteristics: (1) Excellent convergence performance. The slime mold optimization algorithm can find a better solution quickly, while balancing global search and local search, reducing the possibility of getting trapped in local optima. (2) Good robustness and stability. The SMA algorithm has strong noise resistance and performs well in discrete optimization and multi-objective optimization problems. (3) Strong dynamic adaptability. The SMA algorithm can dynamically adjust the search strategy according to the changes in space, and can make more precise fine-tuning when it is close to the optimal solution.

[0080] In practical applications, this embodiment uses the SMA algorithm to optimize the hyperparameters of the RF model, and the steps are as follows: (1) Initialize the population and calculate the fitness value. Wherein, the fitness value of the first... i The initial position of the individual X i as follows: ; In the above formula, UB and LB To search for upper and lower bounds, rand A random number between 0 and 1: According to the coefficient of determination R 2 and mean square error MSE Establish the following fitness function F fit : ; in, R 2 This indicates the interpretability of the model. MSE This indicates the regression accuracy of the model.

[0081] (2) During the exploration phase, some slime mold isolates explored other areas, attempting to find higher quality food sources. The position of any individual after this round of updates X ( t +1) as follows: ; Among them, the preset parametersz Less than 0.03; (3) During the development phase, when slime molds find food, they will contract, and their contraction pattern can be described by the following formula: ; In the above formula, vb It is a random number within a preset range. vc It is a parameter that oscillates within [-1,1] and eventually tends to zero; X b ( t This represents the position of the individual with the best current fitness. X ( t This indicates the current location of the slime mold individual. X A ( t )and X B ( t () represents the positions of two random individuals. t Indicates the current iteration number. W This represents the weighting coefficient of slime molds.

[0082] During the iteration process, the weights of the slime mold optimization algorithm are updated using the following update formula. W and parameters a , b : ; ; ; In the above formula, N Indicates population size. S ( i ) indicates the first i The fitness of an individual slime mold. DF This represents the currently achieved optimal fitness. r Represents a random number between [0, 1]. T Indicates the number of iterations; bF This represents the best fitness obtained in the current iteration. wF This represents the worst fitness obtained in the current iteration.

[0083] The slime mold algorithm searches for the optimal combination of tree number and tree depth to calculate the minimum fitness, thus finding the optimal combination of absolute coefficient and mean squared error. After optimization, in this embodiment, the number of trees and tree depth in the high-activity error prediction model are 400 and 27, respectively; while in the low-activity error prediction model, the number of trees and tree depth are 600 and 13, respectively.

[0084] 6. Extract the first feature of the dynamic weighing signal of the livestock to be tested and input it into the state classification model to identify the active state; extract the second or third feature of the dynamic weighing signal based on the active state and input it into the corresponding error prediction model to generate the weighing error.

[0085] Example 2 The method for analyzing livestock online weighing errors based on state classification and time-frequency characteristics provided in Example 1 is essentially a data processing method. In order to apply this method in practice, this example further provides a storage medium, a computer program product, and a device for analyzing livestock online weighing errors that can implement this method.

[0086] Specifically, the storage medium provided in this embodiment stores a computer program. When the computer program is executed by the processor, it creates an error prediction system that includes a pre-trained state classification model and two error prediction models, as described in Embodiment 1, which are based on the state classification and time-frequency characteristics analysis method for online livestock weighing errors. The error prediction system is used to classify the weighing object according to the input dynamic weighing signal of the livestock, and then call the corresponding error prediction model based on the classification result to generate the corresponding weighing error.

[0087] The computer program product provided in this embodiment includes a computer program. When the computer program is executed by the processor, it creates an error prediction system that includes the pre-trained state classification model and two error prediction models from the analysis method of livestock online weighing error based on state classification and time-frequency features in Embodiment 1. The error prediction system is used to classify the weighing object according to the dynamic weighing signal of the input livestock, and then call the corresponding error prediction model in combination with the classification result to generate the corresponding weighing error.

[0088] The livestock online weighing error analysis device provided in this embodiment includes a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it creates an error prediction system that includes a pre-trained state classification model and two error prediction models, as described in Embodiment 1, based on the state classification and time-frequency features of the livestock online weighing error analysis method. The error prediction system is used to classify the weighing object according to the input dynamic weighing signal of the livestock, and then calls the corresponding error prediction model based on the classification result to generate the corresponding weighing error.

[0089] The livestock online weighing error analysis device provided in this embodiment is essentially a computer device. In practical applications, it can be an embedded device installed in the online weighing platform to directly analyze the error of the output dynamic weighing signal. Alternatively, it can be a standalone computer device, such as a laptop, tablet, desktop computer, or a rack server, blade server, tower server, or cabinet server (including standalone servers or server clusters composed of multiple servers) capable of executing computer programs, to perform post-processing on the dynamic weighing signal output by the front-end weighing system.

[0090] Simulation test To verify the performance of the livestock online weighing error analysis method and livestock online weighing method based on state classification and time-frequency characteristics provided by this invention, technicians simulated and trained the relevant schemes and tested the performance of the trained network models.

[0091] I. Data Acquisition Platform Setup and Data Acquisition This experiment first constructs an online weighing platform and signal acquisition hardware circuit, which consists of a weighing sensor, a weighing transmitter, a 24V regulated power supply, a data acquisition card, and a PC terminal. The corresponding physical diagram is shown below. Figure 16 As shown.

[0092] The experiment was conducted in 2024 at a small ranch in a certain area, with 414 cattle, including 221 beef cattle and 193 dairy cattle, as the research subjects. To ensure the diversity of data, multiple random samplings were conducted on the cattle. At the same time, three relevant experts were invited to score the movement status of the cattle, and weighing data of the cattle in their natural walking state were collected at different time periods.

[0093] II. Weighing Error Analysis This experiment decomposed the effective signal of cattle using the VMD algorithm, and obtained preliminary weight predictions by averaging the trend component IMF1. The prediction performance differences between the VMD algorithm and the ensemble empirical mode decomposition (EEMD) and empirical mode decomposition (EMD) algorithms were compared. The root mean square error (RMSE), mean absolute error (MAE), and mean absolute percentage error (MAPE) of the weight prediction results for each scheme under high and low activity levels are shown in Tables 3 and 4, respectively. Table 3: Comparison of Weight Prediction Accuracy under Low Activity Levels

[0094] Table 4: Comparison of Weight Prediction Accuracy under High Activity Levels

[0095] Based on the data in the table above, it can be seen that the VMD algorithm, due to its own characteristics, is more suitable for weighing cattle and performs better than other mode decomposition algorithms.

[0096] III. Model Training This experiment obtained 951 sets of raw weighing signal data, of which 495 sets were in low-high activity and 456 sets were in high activity states. In this embodiment, the data from each set of weighing signals were preprocessed to obtain the corresponding first, second, and third features, which constitute their respective datasets. During the experiment, 80% of the data was randomly selected as the training set, and the remaining 20% ​​was used as the test set for training and testing the network model.

[0097] 3.1 State Classification Model This experiment used an SVM model to train the corresponding state classification model, and simultaneously trained three state classification models based on RF (Random Forest), LR (Logistic Regression), and DT (Decision Tree) as control groups for performance comparison. Accuracy (ACC), Precision (PREC), Recall (REC), and F1 score were selected as evaluation metrics. The performance of the proposed invention and the control group schemes are shown in Table 5. Table 5: Performance Comparison of State Classification Models under Different Schemes

[0098] Analysis of the data in the table above shows that the SVM model of this invention achieves the best performance in most aspects, indicating that the state classification model provided by this invention has higher robustness and accuracy compared with other schemes.

[0099] 3.2 High-activity error prediction model This experiment used the random forest model (denoted as SMA-RF) optimized by the slime mold optimization algorithm provided in this invention to train the corresponding high-activity error prediction model, and simultaneously trained three error prediction models based on SVR (Support Vector Regression), GBR (Gradient Boosting Regression), and LR (Linear Regression) for performance comparison. Root mean square error (RMSE), mean absolute error (MAE), and mean absolute percentage error (MAPE) were selected as evaluation metrics. The performance of the proposed invention and the control group schemes are shown in Table 6. Table 6: Performance Comparison of High-Activity Error Prediction Models under Different Schemes

[0100] 3.2 Low Activity Error Prediction Model This experiment used the random forest model (denoted as SMA-RF) optimized by the slime mold optimization algorithm provided in this invention to train the corresponding low-activity error prediction model, and simultaneously trained three error prediction models based on SVR, GBR, and LR for performance comparison. RMSE, MAE, and MAPE were selected as evaluation indicators, and the performance of the proposed method and the control group is shown in Table 7: Table 7: Performance Comparison of Low-Activity Error Prediction Models under Different Schemes

[0101] Analysis of the data in Tables 6 and 7 shows that the solution provided by this invention significantly improves the predicted weighing error under different active states compared to existing solutions. This indicates that the solution of this invention possesses good accuracy, robustness, and generalization ability, and can be practically promoted and applied.

[0102] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics, characterized in that, It includes: Collect dynamic weighing signals and static weighing values ​​of livestock, and add status tags to the dynamic weighing signals; Status tags are divided into high-activity status and low-activity status; The effective signal is extracted after low-pass filtering of the dynamic weighing signal; the weight prediction value is generated based on the effective signal using the variational mode decomposition method; the difference between the static weighing value and the weight prediction value is recorded as the reference error. Extract the time-domain features of the effective signal; perform a fast Fourier transform on the effective signal after adaptive windowing, and then extract the frequency-domain features; Both constitute the time-frequency characteristics of an effective signal; The time-frequency characteristics of all the collected valid signals are correlated with the state labels, filtered, and dimensionality reduced to obtain the first feature; The time-frequency features of all valid signals with state labels of high-activity and low-activity are subjected to correlation analysis, screening, and dimensionality reduction with their respective reference errors to obtain the second and third features. Each first feature and its associated state label are used as a set of sample data to form the first dataset; Each second feature and third feature is associated with a reference error as a set of sample data to form the second dataset and the third dataset; the SVM model is trained using the first dataset to obtain a state classification model that predicts the activity state of livestock based on the first feature. The RF model was trained using the second and third datasets respectively, and the error prediction model for the corresponding active state was obtained. The first feature of the dynamic weighing signal of the livestock to be tested is extracted and input into the state classification model to identify the active state; the second or third feature of the dynamic weighing signal is extracted based on the active state and input into the corresponding error prediction model to generate the weighing error.

2. The method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics as described in claim 1, characterized in that, The method for extracting the effective signal is as follows: Set a threshold based on the maximum value of the livestock dynamic weighing signal; extract the portion of the dynamic weighing signal with an amplitude higher than the threshold and determine the left and right maxima contained therein; use the signal interval between the left and right maxima as the valid signal; And / or, the threshold is set to 0.8 times the maximum value of the livestock dynamic weighing signal.

3. The method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics as described in claim 2, characterized in that, The process of generating predicted body weight values ​​based on effective signals using variational mode decomposition includes: The effective signal is progressively decomposed according to a preset number of variational modes K to obtain K modal components IMF1~IMFK; the average value of IMF1 is used as the predicted weight value. And / or, K=6.

4. The method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics as described in claim 1, characterized in that, The time-domain features of the extracted effective signal include: average value, peak value, peak-to-peak value, rectified average value, root mean square value, standard deviation, shape factor, impulse factor, pulse factor, margin factor, kurtosis, and skewness; the frequency-domain features of the effective signal include: spectral centroid, spectral flatness, spectral entropy, spectral slope, spectral energy, and spectral spread. After correlation analysis, retain features with an absolute correlation value of not less than 0.2; Among them, the time-frequency features retained in the first feature include: peak value, peak-to-peak value, standard deviation, shape factor, impact factor, impulse factor, margin factor, kurtosis, skewness, spectral centroid, spectral flatness, spectral entropy, spectral slope, spectral energy, and spectral spread. The time-frequency features retained in the second feature include: impulse factor, impact factor, margin factor, spectral centroid, spectral flatness, spectral entropy, spectral slope, and spectral spread; The time-frequency features retained in the third feature include: peak-to-peak value, kurtosis, peak factor, impulse factor, impact factor, margin factor, spectral centroid, spectral flatness, spectral entropy, spectral slope, and spectral spread.

5. The method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics as described in claim 1, characterized in that: In the extraction of the first, second, and third features, principal component analysis is used to reduce the dimensionality of the time-frequency features; the process includes: (1) The original feature matrix X Subtract the mean from each element in μ The standardized matrix was then obtained. X st ; (2) Calculate the normalization matrix X st covariance matrix C ; (3) For the covariance matrix C Decompose to obtain eigenvalues λ and eigenvectors v ; (4) Based on the eigenvectors, new coordinate axes are formed along the principal component directions to construct the principal component matrix. P ; ; in, v 1, v 2, ..., v k For the front k 1 eigenvector; (5) Standardize the matrix X st Project onto the selected k On each principal component, the dimensionality-reduced feature matrix is ​​obtained. X r ; And / or, when using principal component analysis to reduce the dimensionality of time-frequency features, the number of principal components of the first and third features... k Set to 5, the number of principal components for the second feature. k Set it to 3.

6. The method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics as described in claim 5, characterized in that: The following adaptive window function is used during the windowing process for valid signals: ; in, The value of the window function. N The length of the window function. n For the current sample point index, n ∈[0, N -1]; These are the weights of each cosine term in the adaptive window function; And / or, the sparrow search algorithm can be used to adaptively optimize the weights of the window function based on the characteristics of the signal. Fitness function of the sparrow search algorithm F fit as follows: ; In the above formula, SSR Indicates the sidelobe suppression ratio of the signal. Indicates the spectral smoothness of the signal; α and β These represent the weighting coefficients for sideband leakage and smoothness, respectively.

7. The method for analyzing online livestock weighing errors based on state classification and time-frequency characteristics as described in claim 1, characterized in that: During the training phase of the state classification model, the hyperparameters were set to default parameters, and the kernel function was selected as a Gaussian kernel; accuracy, precision, recall, and F1 score were used as evaluation metrics. During the training phase of the error prediction model, the slime mold optimization algorithm is used to optimize the number and depth of trees in the hyperparameters; and the root mean square error, mean absolute error, and mean absolute percentage error are used as performance evaluation indicators. In the high-activity error prediction model, the number of trees and the depth of the trees are 400 and 27 respectively; in the low-activity error prediction model, the number of trees and the depth of the trees are 600 and 13 respectively.

8. A computer program product comprising a computer program, characterized in that, When the computer program is executed by the processor, it creates an error prediction system that includes a pre-trained state classification model and two error prediction models as described in any one of claims 1-7 for the analysis method of livestock online weighing error based on state classification and time-frequency features. The error prediction system is used to classify the weighing object according to the input dynamic weighing signal of the livestock, and then call the corresponding error prediction model in combination with the classification result to generate the corresponding weighing error.

9. A storage medium storing a computer program, characterized in that: When the computer program is executed by the processor, it creates an error prediction system that includes a pre-trained state classification model and two error prediction models as described in any one of claims 1-7 for the analysis method of livestock online weighing error based on state classification and time-frequency features. The error prediction system is used to classify the weighing object according to the input dynamic weighing signal of the livestock, and then call the corresponding error prediction model in combination with the classification result to generate the corresponding weighing error.

10. An analysis device for online weighing errors of livestock, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, it creates an error prediction system that includes a pre-trained state classification model and two error prediction models as described in any one of claims 1-7 for the analysis method of livestock online weighing error based on state classification and time-frequency features. The error prediction system is used to classify the weighing object according to the input dynamic weighing signal of the livestock, and then call the corresponding error prediction model in combination with the classification result to generate the corresponding weighing error.