Methods, apparatus and computer equipment for finding approximate medians of datasets
Through the two-state mechanism and the cumulative frequency distribution table method, the problem of low efficiency of median search in the existing technology is solved, the median approximate value is quickly found, the data processing efficiency is improved, and it is suitable for large-scale data scenarios.
Patent Information
- Application Number
- CN202210572598.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-25
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2042-05-25
AI Technical Summary
Existing median search methods are inefficient when processing large-scale data due to sorting and comparison operations, making it difficult to quickly find the median, affecting the accuracy and efficiency of rainfall warning decisions.
The median approximate value search method of the two-state mechanism is used to construct a cumulative frequency distribution table by calculating the mean and standard deviation of the array to be processed, and find the data grouping where the median approximate value is located, reducing sorting operations and improving search efficiency.
There is no need to sort the array to be processed to find the approximate median value, which simplifies the search process, reduces data reading and comparison operations, significantly improves the efficiency of median search, and reduces time overhead.
Smart Images

Figure CN114860811B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data search, and in particular to a method, device, computer equipment, storage medium and computer program product for searching an approximate median value of a data set. Background Art
[0002] The median is usually a statistical indicator with high value in a data set, which can better reflect the average level of the data set than the mean. Median search is a method that aims to find the exact median in an unsorted array. Fast median search methods can solve technical problems in many fields. Specifically in application scenarios, for example, in the scenario of rainfall warning, people usually find the approximate range of the median of the sensor data set based on the sensor data set composed of data collected by meteorological rainfall sensors, determine the approximate median, and then compare the approximate median with the preset warning threshold to make a rainfall warning decision. However, due to the large number of meteorological rainfall sensors and the continuous data collection process of the sensors, the collected sensor data will be massive data, which undoubtedly increases the difficulty of finding the median and the difficulty of making warning decisions. Therefore, it is of great significance to provide a median search method with fast search capabilities.
[0003] At present, the more commonly used median search methods include full sorting search method, partial sorting search method, random selection algorithm and approximate median search algorithm. The full sorting median search method is mostly implemented through a principal element selection strategy, the partial sorting median search method is implemented by only sorting some elements through strategies such as dimension conversion and forgetting selection, and the approximate median search algorithm is implemented based on the triple adjustment algorithm to take the median.
[0004] However, when faced with the task of searching for the median with a large amount of data, the above existing median search methods all involve a large number of comparison and exchange operations between data during the sorting process. These operations will result in excessive time overhead, thereby reducing the efficiency of the median search. Summary of the invention
[0005] Based on this, it is necessary to provide a method, device, computer equipment, computer-readable storage medium and computer program product for finding the approximate median of a data set that can improve the efficiency of median search in order to address the above technical problems.
[0006] In a first aspect, the present application provides a method for finding an approximate median value of a data set, wherein the data set includes multiple arrays, and the multiple arrays use the same mean and standard deviation to characterize data distribution. The method includes:
[0007] Get the current array to be processed and the current status of the predefined approximate median search event;
[0008] Find the current state of the event based on the predefined approximate median value and determine the mean and standard deviation of the array to be processed;
[0009] According to the mean and the standard deviation, a cumulative frequency distribution table is constructed, wherein the cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed;
[0010] Based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, find out the data group where the median approximate value of the array to be processed is located, determine the median approximate value of the array to be processed, and pass the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located to the next array. If the current state of the predefined approximate median search event is the first state, switch the first state to the second state. The position identifier is used to characterize the position of the data group in the array after the data division is completed.
[0011] Returns the step of obtaining the current status of the array to be processed and the predefined approximate median search event until the median approximate value of all arrays in the data set is found.
[0012] In one embodiment, determining the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event includes:
[0013] When the current state of the predefined approximate median search event is the first state, the mean and standard deviation of the array to be processed are calculated;
[0014] When the current state of the predefined approximate median search event is the second state, the received mean and standard deviation of the last array to be processed are determined as the mean and standard deviation of the array to be processed.
[0015] In one embodiment, based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, finding the data group where the median approximate value of the array to be processed is located, and determining the median approximate value of the array to be processed includes:
[0016] When the current state of the predefined approximate median search event is the first state, the data group where the median approximate value of the array to be processed is located is searched out according to the cumulative frequency distribution table, and the median approximate value of the array to be processed is determined;
[0017] When the current state of the predefined approximate median search event is the second state, the data group where the median approximate value of the array to be processed is located is searched according to the cumulative frequency distribution table, and the first data group position identifier is obtained. When the first data group position identifier is consistent with the second data group position identifier, the received median approximate value of the previous array is determined as the median approximate value of the array to be processed;
[0018] Among them, the data group position identifier is used to represent the position of the data group in the array after the data division is completed. The first data group position identifier is the position identifier of the data group where the median approximation of the array to be processed is located, and the second data group position identifier is the position identifier of the data group where the median approximation of the previous array received is located.
[0019] In one of the embodiments, after obtaining the first data packet location identifier, the method further includes:
[0020] If the first data group position identifier is inconsistent with the second data group position identifier, determining whether the absolute value of the difference between the first data group position identifier and the second data group position identifier satisfies a preset error;
[0021] If the absolute value of the difference satisfies the preset error, the median approximation is determined according to the data grouping where the median approximation of the array to be processed is located;
[0022] If the absolute value of the difference does not meet the preset error, the current state of the predefined approximate median search event is switched to the first state, and the step of determining the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event is returned.
[0023] In one embodiment, constructing a cumulative frequency distribution table according to the mean and the standard deviation includes:
[0024] Determine multiple data division intervals based on the mean and standard deviation;
[0025] According to a plurality of data partition intervals, the array to be processed is divided into a plurality of data groups;
[0026] Count the cumulative frequency of each data group;
[0027] Based on each data grouping and the cumulative frequency of each data grouping, a cumulative frequency distribution table is constructed.
[0028] In one embodiment, counting the cumulative frequency of each data group includes:
[0029] Count the number of data distributed in each data group to obtain the frequency of each data group;
[0030] Determining the frequency of each data group based on the frequency of each data group;
[0031] The frequencies of the data groups are cumulatively summed upward to obtain the cumulative frequencies of the data groups.
[0032] In a second aspect, the present application also provides a device for finding an approximate median value of a data set, wherein the data set includes multiple arrays, and the multiple arrays use the same mean and standard deviation to characterize data distribution. The device includes:
[0033] A data acquisition module, used to obtain the current array to be processed and the current state of the predefined approximate median search event;
[0034] A mean and standard deviation determination module is used to determine the mean and standard deviation of the array to be processed based on the current state of the predefined approximate median search event;
[0035] A cumulative frequency distribution table construction module is used to construct a cumulative frequency distribution table according to the mean and standard deviation. The cumulative frequency distribution table includes multiple data groups, and the data groups are obtained by dividing the array to be processed;
[0036] A median approximate value determination module is used to find out the data group where the median approximate value of the array to be processed is located based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, determine the median approximate value of the array to be processed, and pass the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located to the next array. If the current state of the predefined approximate median search event is the first state, the first state is switched to the second state. The position identifier is used to characterize the position of the data group in the array after the data division is completed;
[0037] The loop processing module is used to control the data acquisition module to execute the operation of acquiring the current state of the array to be processed and the predefined approximate median search event until the median approximate values of all arrays in the data set are found.
[0038] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0039] Get the current array to be processed and the current status of the predefined approximate median search event;
[0040] Find the current state of the event based on the predefined approximate median value and determine the mean and standard deviation of the array to be processed;
[0041] According to the mean and the standard deviation, a cumulative frequency distribution table is constructed, wherein the cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed;
[0042] Based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, find out the data group where the median approximate value of the array to be processed is located, determine the median approximate value of the array to be processed, and pass the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located to the next array. If the current state of the predefined approximate median search event is the first state, switch the first state to the second state. The position identifier is used to characterize the position of the data group in the array after the data division is completed.
[0043] Returns the step of obtaining the current status of the array to be processed and the predefined approximate median search event until the median approximate value of all arrays in the data set is found.
[0044] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0045] Get the current array to be processed and the current status of the predefined approximate median search event;
[0046] Find the current state of the event based on the predefined approximate median value and determine the mean and standard deviation of the array to be processed;
[0047] According to the mean and the standard deviation, a cumulative frequency distribution table is constructed, wherein the cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed;
[0048] Based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, find out the data group where the median approximate value of the array to be processed is located, determine the median approximate value of the array to be processed, and pass the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located to the next array. If the current state of the predefined approximate median search event is the first state, switch the first state to the second state. The position identifier is used to characterize the position of the data group in the array after the data division is completed.
[0049] Returns the step of obtaining the current status of the array to be processed and the predefined approximate median search event until the median approximate value of all arrays in the data set is found.
[0050] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0051] Get the current array to be processed and the current status of the predefined approximate median search event;
[0052] Find the current state of the event based on the predefined approximate median value and determine the mean and standard deviation of the array to be processed;
[0053] According to the mean and the standard deviation, a cumulative frequency distribution table is constructed, wherein the cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed;
[0054] Based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, find out the data group where the median approximate value of the array to be processed is located, determine the median approximate value of the array to be processed, and pass the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located to the next array. If the current state of the predefined approximate median search event is the first state, switch the first state to the second state. The position identifier is used to characterize the position of the data group in the array after the data division is completed.
[0055] Returns the step of obtaining the current status of the array to be processed and the predefined approximate median search event until the median approximate value of all arrays in the data set is found.
[0056] The above-mentioned median approximate value search method, device, computer equipment, storage medium and computer program product for the data set introduce a two-state mechanism, determine the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event, and then construct a cumulative frequency distribution table, and then find out the data group where the median approximate value of the array to be processed is located through the cumulative frequency distribution table and the current state of the predefined approximate median search event, and determine the median approximate value, so that the array approximate median can be found without sorting the array to be processed, which simplifies the search process. Moreover, after the median approximate value of the current array to be processed is found, the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located will be passed to the next array to facilitate the median search of the next array, reducing data reading and comparison and exchange operations between data, saving time overhead. In summary, the use of this method can improve the efficiency of median approximation search. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 A diagram of an application environment of a method for finding an approximate median value of a data set in one embodiment;
[0058] Figure 2 A schematic diagram of a flow chart of a method for finding an approximate median value of a data set in one embodiment;
[0059] Figure 3 A detailed flow chart of a method for finding an approximate median value of a data set in another embodiment;
[0060] Figure 4It is a schematic diagram of an algorithm of a method for finding an approximate median value of a data set in another embodiment;
[0061] Figure 5 It is a structural block diagram of a device for finding an approximate median value of a data set in one embodiment;
[0062] Figure 6 FIG. 4 is a structural block diagram of a computer device in one embodiment. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0064] The method for finding the median approximation of a data set provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Specifically, the staff may upload the data set to be processed to the data storage system in advance, and the data set includes multiple arrays that use the same mean and standard deviation to characterize the data distribution. Then, the staff sends a median approximate value search message to the server 104 through the terminal 102. The server 104 responds to the message, obtains the current array to be processed from the data storage system, and obtains the status of the predefined approximate median search event. Then, according to the current status of the predefined approximate median search event, the mean and standard deviation of the array to be processed are determined, and then according to the mean and standard deviation, a cumulative frequency distribution table is constructed. Based on the cumulative frequency distribution table and the current status of the predefined approximate median search event, the data group where the median approximate value of the array to be processed is located is found, the median approximate value of the array to be processed is determined, and the mean , standard deviation, median approximation and the position identifier of the data group where the median approximation is located are passed to the next array. If the current state of the predefined approximate median search event is the first state, the first state is switched to the second state, and the step of obtaining the current state of the array to be processed and the predefined approximate median search event is returned until the median approximation of all arrays in the data set is found. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented by an independent server or a server cluster consisting of multiple servers.
[0065] In one embodiment, as Figure 2 shown, a method for finding the median approximation value of a data set is provided. The data set includes multiple arrays, and the multiple arrays are characterized by the same mean and standard deviation to represent the data distribution. Taking the server in Figure 1 as an example for illustration, the method includes the following steps:
[0066] Step 100, obtain the current array to be processed and the current state of a predefined approximate median search event.
[0067] In practical applications, the median approximation value (hereinafter referred to as the approximate median) of each array in a data set containing multiple arrays is searched. The arrays in this data set have approximately the same data distribution, that is, the data distribution of each array can be measured by the same mean and standard deviation. The array to be processed refers to the array for which the approximate median is to be searched at the current time. It can be understood that, generally, the data in the array to be processed at this time is in disorder. In this embodiment, in combination with the principle of a finite state machine, an approximate median search event for finding the median approximation value of an array is predefined. This approximate median search event has a finite number of states, and different states represent different meanings. According to actual needs, this model can complete the specified approximate median search task in different states. In this embodiment, two states are set for the approximate median search event, including state 0 and state 1. In the cases of state 0 and state 1 of this approximate median search event, the approximate median is searched according to different approximate median search logics. Specifically in implementation, the first state is state 0, the second state is state 1, and the initial state of the approximate median search event is state 0, waiting for the arrival of a new array. It can be understood that in other embodiments, the first state can also be defined as state 1, and the second state can also be state 0, which is not limited herein.
[0068] Step 200, determine the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event.
[0069] When the data distribution strictly follows the normal distribution, the mean and the median are equivalent. However, in practical applications, the data does not always follow the normal distribution. Therefore, the mean in the array cannot be directly used to replace the median. Through research, it is found that when the data distribution is positively skewed, at this time, M>Me>M0, that is, the mean is greater than the median, and the median is greater than the mode; while when the data distribution is negatively skewed, at this time, M<Me<M0, that is, the mean is less than the median, and the median is less than the mode. Inspired by the characteristics of the above data distribution, in this embodiment, the mean (defined as μ) and the standard deviation (defined as σ) are used to locate the median.
[0070] In practical applications, different approximate median search processes are defined for different states of the approximate median search event. After obtaining the current array to be processed and the current state of the approximate median search event, the corresponding mean and standard deviation processing process is determined according to the state of the approximate median search event, and then the mean and standard deviation of the array to be processed are determined.
[0071] Step 300: construct a cumulative frequency distribution table according to the mean and the standard deviation. The cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed.
[0072] Cumulative Frequency Table (CFT), also known as cumulative relative frequency distribution table and cumulative frequency table, is to accumulate and sum the frequencies (also known as frequencies) of each group from bottom to top or from top to bottom, and obtain the cumulative frequencies of each group after each accumulation, and then express it in the form of a statistical table. For example, the corresponding relationship between data groups and their frequencies is [10,30)~0.2, [30,40)~0.3 and [30,40)~0.5. Then, the frequencies of each group are accumulated and summed upward, and [10,30)~0.2, [30,40)~0.5 and [30,40)~1 should be obtained. The cumulative frequency distribution table includes each data group, the frequency of each data group, the frequency and the corresponding cumulative frequency.
[0073] Step 400, based on the current state of the cumulative frequency distribution table and the predefined approximate median search event, find out the data group where the median approximation of the array to be processed is located, determine the median approximation of the array to be processed, and pass the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located to the next array, and return to step 100 until the median approximation of all arrays in the data set is found.
[0074] In this embodiment, the position identifier is used to characterize the position of the data group in the array after the data division is completed. After the cumulative frequency distribution table is constructed, the median (median) will be located in the first group where the cumulative frequency exceeds 50%, and this group can be regarded as the group where the median is located. In addition, the approximate value of the median can be obtained by calculating half of the sum of the upper and lower boundaries of the group. In practical applications, since the specific values in the group interval of the array are not clear, and the numerical requirements of the median do not have to be completely accurate, in this embodiment, the method of finding the median approximate value is used instead of the median search. In specific implementation, the cumulative frequency of each data group in the cumulative frequency distribution table can be read one by one. If the cumulative frequency of the data group currently read exceeds 0.5, it is considered that the median approximate value of the array to be processed is distributed in this data group. Further, based on the data group where the median approximate value is located and the current state of the approximate median search event, the median approximate value of the array to be processed is determined. At the same time, the mean, standard deviation, position identifier of the group where the median approximate value of the current array to be processed and the median approximate value are passed to the next array. It should be noted that if the current state of the approximate median search event is the first state, i.e., state 0, after the median approximate value search of the current array to be processed is completed, state 0 needs to be switched to state 1. If the current state of the approximate median search event is the second state, i.e., state 1, after the median approximate value search of the current array to be processed is completed, the state switching operation may not be performed, and the current state of the approximate median search event may continue to be maintained as state 1. Then, return to step 100 and start processing the next array, in the above manner, until the median approximate values of all arrays in the data set are found. It can be understood that when the current state of the approximate median search event is state 1, in the process of searching for the median approximate value, state 1 may also be switched to state 0, and then the median approximate value search process under state 0 may be used to search for the median approximate value of the current array to be processed.
[0075] In the above-mentioned median approximate value search method for the data set, a two-state mechanism is introduced. According to the current state of the predefined approximate median search event, the mean and standard deviation of the array to be processed are determined, and then a cumulative frequency distribution table is constructed. Then, the data group where the median approximate value of the array to be processed is located is found through the cumulative frequency distribution table and the current state of the predefined approximate median search event, and the median approximate value is determined, so that the approximate median of the array to be processed can be found without sorting the array to be processed, which simplifies the search process. Moreover, after the median approximate value of the current array to be processed is found, the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located will be passed to the next array to facilitate the median search of the next array, reducing data reading and comparison and exchange operations between data, saving time overhead. In summary, the use of this method can improve the search efficiency.
[0076] like Figure 3 As shown, in one embodiment, step 200 includes: step 220, when the current state of the predefined approximate median search event is the first state, calculating the mean and standard deviation of the array to be processed; step 240, when the current state of the predefined approximate median search event is the second state, determining the mean and standard deviation of the previous array to be processed received as the mean and standard deviation of the array to be processed.
[0077] In a specific implementation, since the arrays have similar data distribution, the data distribution can be characterized by the same mean and standard deviation. Therefore, when the current state of the predefined approximate median search event is state 0, the mean and standard deviation of the array to be processed are calculated. When the current state of the predefined approximate median search event is state 1, the mean and standard deviation of the previous array to be processed received are determined as the mean and standard deviation of the array to be processed. In this way, when the approximate median search event is in state 1, the operation of calculating the mean and standard deviation of the array to be processed can be omitted, thereby reducing time overhead.
[0078] like Figure 3 As shown, in one embodiment, step 300 includes: step 320, determining multiple data partition intervals based on the mean and the standard deviation, dividing the array to be processed into multiple data groups based on the multiple data partition intervals, counting the cumulative frequency of each data group, and constructing a cumulative frequency distribution table based on each data group and the cumulative frequency of each data group.
[0079] In the specific implementation, the 68-95-99.7 rule in the normal distribution can be referred to, and μ and σ can be used to determine the data division interval, and the boundary of each data group can be set, so as to divide the array to be processed into multiple data groups. For example, the data groups can be divided into (-∞,μ-3σ], (μ-3σ,μ-2σ], (μ-2σ,μ-σ], (μ-σ,μ], (μ,μ+σ], (μ+σ,μ+2σ], (μ+2σ,μ+3σ], (μ+3σ,+∞). Then, the frequency of each data group is accumulated, and the cumulative frequency of each data group is counted. Based on each data group and the cumulative frequency of each data group, a cumulative frequency distribution table is constructed. It is worth mentioning that through a large number of data experiments, it is found that when counting the frequency of statistical data groups, the data falls into two middle groups, namely (μ-σ ,μ] and (μ,μ+σ] have a high probability. Therefore, in order to further improve the accuracy of the median approximation, in another embodiment, (μ-σ,μ] and (μ,μ+σ] can be evenly divided into three groups, that is, the length of each group is divided into σ / 3, so as to refine the division of data groups. In this embodiment, the cumulative frequency distribution table is constructed through the standard deviation and the mean, so that the standard deviation, the mean and the cumulative frequency distribution table can be determined by traversing the array to be processed once, which saves time, and the time complexity is linear, only O(n) is required, and n is the length of the array.
[0080] In one embodiment, counting the cumulative frequency of each data group includes: counting the number of data distributed in each data group to obtain the frequency of each data group, determining the frequency of each data group based on the frequency of each data group, and accumulating and summing the frequencies of each data group to obtain the cumulative frequency of each data group.
[0081] In this embodiment, the cumulative frequency of each data group can be counted by traversing the data of the array to be processed, determining the data group into which each data falls, and then, based on the frequency of each data group, determining the frequency of each data group, and then using an upward accumulation method to perform upward accumulation and summation on the frequency of each data group to obtain the cumulative frequency of each data group. It can be understood that in other embodiments, the frequency of each data group can also be accumulated downward and summed, which is not limited here. In this embodiment, the cumulative frequency of the data group can be correctly and orderly counted by the upward accumulation and summation method.
[0082] like Figure 3As shown, in one embodiment, based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, the data group where the median approximate value of the array to be processed is located is found, and the median approximate value of the array to be processed is determined, including: step 420, when the current state of the predefined approximate median search event is the first state, then according to the cumulative frequency distribution table, the data group where the median approximate value of the array to be processed is located is found, and the median approximate value of the array to be processed is determined; step 440, when the current state of the predefined approximate median search event is the second state, then according to the cumulative frequency distribution table, the data group where the median approximate value of the array to be processed is found, and the median approximate value of the array to be processed is determined. Find the data group where the median approximation of the array to be processed is located, obtain the first data group position identifier, and when the first data group position identifier is consistent with the second data group position identifier, determine the received median approximation of the previous array as the median approximation of the array to be processed; wherein the data group position identifier is used to characterize the position of the data group in the array after the data division is completed, the first data group position identifier is the position identifier of the data group where the median approximation of the array to be processed is located, and the second data group position identifier is the position identifier of the data group where the median approximation of the previous array received is located.
[0083] In specific implementation, the data group position identifier indicates the arrangement position of the data group in the array where it is located and the data group number. It can be that when the current state of the predefined approximate median search event is state 0, the cumulative frequency of each data group in the cumulative frequency distribution table is directly read. If the cumulative frequency of the data group currently read exceeds 0.5, it is considered that the median approximation is distributed in the current data group, and it is determined as the data group where the median approximation is located. Then, half of the sum of the upper and lower boundaries of the data group where the median approximation is located is determined as the median approximation of the entire array to be processed. For example, assuming that the frequency of a data group is recorded as Num(i), i is the data group position identifier, which is the data group number counted from left to right in the array after the data division is completed, and i is numbered from 1. When calculating CFT, a variable Allsum is defined. According to the calculation method of the cumulative score table, Allsum = Num(1) + Num(2) + Num(3) + Num(4) + ... In the process of frequency accumulation, it can be judged whether Allsum reaches 0.5. If it reaches 0.5, the accumulation can be stopped and the current accumulated i value is recorded. The i value is the data group position identifier of the median approximation value of the current array to be processed.
[0084] When the current state of the predefined approximate median search event is state 1, the data group where the median approximation is located is searched in the same manner as above, the position identifier of the data group where the median approximation is located is obtained, and the position identifier of the data group where the median approximation is located is compared to see if the position identifier of the data group where the median approximation of the array to be processed is consistent with the position identifier of the data group where the median approximation of the previous array received is located. If they are consistent, it indicates that the data distribution of the current array to be processed is similar to that of the previous array. At this time, the median approximation of the previous array received is directly used as the median approximation of the current array to be processed, and then, the state 1 is maintained, and the step 100 is returned to continue to search for the median approximation of the next array in the case of state 1. In this embodiment, when the approximate median search event is state 1, if the position identifier of the data group where the median approximation of the array to be processed is consistent with the position identifier of the data group where the median approximation of the previous array received is located, the median approximation of the previous array received is directly used as the median approximation of the current array to be processed, which can simplify the search process of the median approximation and save the search time.
[0085] In one of the embodiments, after obtaining the first data group position identifier, it also includes: if the first data group position identifier is inconsistent with the second data group position identifier, determining whether the absolute value of the difference between the first data group position identifier and the second data group position identifier satisfies a preset error; if the absolute value of the difference satisfies the preset error, determining the median approximation according to the data group where the median approximation of the array to be processed is located; if the absolute value of the difference does not satisfy the preset error, switching the current state of the predefined approximate median search event to the first state, and returning to step 200.
[0086] Continuing from the above embodiment, if the first data group position identifier is inconsistent with the second data group position identifier, it indicates that the data distribution of the array to be processed is not very similar to that of the previous array. The first data group position identifier and the second data group position identifier can be compared to see whether they float within the interval of one data group. Specifically, the absolute value of the difference between the first data group position identifier and the second data group position identifier can be compared to see whether it is 1. If it is 1, it indicates that the first data group position identifier and the second data group position identifier float within the interval of one data group. At this time, the median approximate value of the array to be processed is determined according to the upper and lower boundaries of the group where the median approximate value of the array to be processed is located. If the absolute value of the difference between the first data group position identifier and the second data group position identifier is not 1, it indicates that the data distribution of the array to be processed is not similar to that of the previous array. It is necessary to recalculate the mean and standard deviation of the array to be processed to search for the median approximate value. At this time, the state of the approximate median search event can be switched from state 1 to state 0, and then, the process returns to step 200, and the median approximate value of the array to be processed is searched according to the situation of state 0. In this embodiment, an error of the data group position identifier is set, and a corresponding method for determining the median approximation is determined according to the error, which can be closer to the actual situation and find a more accurate median approximation.
[0087] In order to make a clearer description of the method for finding the median approximate value of a data set provided in this application, the following is a specific embodiment and Figure 4 To explain:
[0088] The user predefines the approximate median search event and initializes the state of the event to 0. Then, the data set to be searched for the approximate median is uploaded to the server. The data set includes multiple arrays with approximate data distribution. The arrays can all use the same mean and standard deviation to describe the data distribution. Then, the user sends an approximate median search message to the server through the terminal. The server responds to the message and searches for the approximate median of the arrays in the data set one by one.
[0089] Specifically, the process of approximate median search can be: obtain the current state of the first array to be processed and the predefined approximate median search event, at this time, the state of the approximate median search event is the initialization state, that is, state 0, then, calculate the standard deviation and mean of the array to be processed, determine multiple data partition intervals according to the mean and the standard deviation, divide the array to be processed into multiple data groups according to the multiple data partition intervals, count the cumulative frequency of each data group, and construct a cumulative frequency distribution table based on each data group and the cumulative frequency of each data group. Next, the cumulative frequency of each data group in the cumulative frequency distribution table is read. If the cumulative frequency of the data group currently read exceeds 0.5, it is considered that the median approximation is distributed in the current data group, and it is determined as the data group where the median approximation is located. Then, half of the sum of the upper and lower boundaries of the data group where the median approximation is located is determined as the median approximation of the entire array to be processed, and the median approximation is output. The standard deviation, mean, median approximation of the array to be processed and the position identifier of the data group where the median approximation is located are transferred to the next array. Then, the state of the approximate median search event is switched from 0 to state 1, and the step of obtaining the current array to be processed and the current state of the predefined approximate median search event is returned. When the next array is passed in, at this time, the state of the approximate median search event is state 1, and the next array is used as the current array to be processed. According to the standard deviation and mean of the previous array received, the cumulative frequency distribution table is obtained in accordance with the above-mentioned method of constructing the cumulative frequency distribution table. Then, the cumulative frequency of each data group in the cumulative frequency distribution table is read, the data group where the median approximation is located is found, and the first data group position identifier is obtained. When the first data group position identifier is consistent with the second data group position identifier, the median approximation of the received previous array is determined as the median approximation of the array to be processed; if they are inconsistent, it is determined whether the absolute value of the difference between the first data group position identifier and the second data group position identifier satisfies the preset error 1. If the absolute value of the difference satisfies the preset error 1, the median approximation is determined according to the data group where the median approximation of the array to be processed is located. If the absolute value of the difference does not satisfy the preset error, the predefined approximate median search event is switched from state 1 to state 0, and the step of obtaining the current array to be processed and the current state of the predefined approximate median search event is returned again until the median approximation of all arrays in the data set are found.
[0090] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0091] Based on the same inventive concept, the embodiment of the present application also provides a device for finding the median approximate value of a data set for implementing the method for finding the median approximate value of a data set involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiment of the device for finding the median approximate value of one or more data sets provided below can refer to the limitations of the method for finding the median approximate value of a data set above, and will not be repeated here.
[0092] In one embodiment, Figure 5 As shown, a device for finding the median approximation of a data set is provided, the data set includes multiple arrays, and the multiple arrays use the same mean and standard deviation to characterize the data distribution. The device includes: a data acquisition module 510, a mean standard deviation determination module 520, a cumulative frequency distribution table construction module 530, a median approximation determination module 540 and a loop processing module 550, wherein:
[0093] The data acquisition module 510 is used to acquire the current array to be processed and the current state of the predefined approximate median search event.
[0094] The mean standard deviation determination module 520 is used to determine the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event.
[0095] The cumulative frequency distribution table construction module 530 is used to construct a cumulative frequency distribution table according to the mean and the standard deviation. The cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed.
[0096] The median approximation determination module 540 is used to find out the data group where the median approximation of the array to be processed is located based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, determine the median approximation of the array to be processed, and pass the mean, standard deviation, median approximation and the position identifier of the data group where the median approximation is located to the next array. If the current state of the predefined approximate median search event is the first state, the first state is switched to the second state.
[0097] The loop processing module 550 is used to control the data acquisition module to execute the operation of acquiring the current state of the array to be processed and the predefined approximate median search event until the median approximate values of all the arrays in the data set are found.
[0098] The above-mentioned median approximate value search device for the data set introduces a two-state mechanism, and determines the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event, and then constructs a cumulative frequency distribution table. Then, through the cumulative frequency distribution table and the current state of the predefined approximate median search event, the data group where the median approximate value of the array to be processed is located is found, and the median approximate value is determined, so that the approximate median of the array can be found without sorting the array to be processed, which simplifies the search process. Moreover, after the median approximate value of the current array to be processed is found, the mean, standard deviation, median approximation of the current array and the position identifier of the data group where the median approximation is located will be passed to the next array to facilitate the median search of the next array, reducing data reading and comparison and exchange operations between data, saving time overhead. In summary, the use of this device can improve the search efficiency.
[0099] In one embodiment, the mean-standard deviation determination module 520 is also used to calculate the mean and standard deviation of the array to be processed when the current state of the predefined approximate median search event is a first state, and to determine the mean and standard deviation of the previous array to be processed received as the mean and standard deviation of the array to be processed when the current state of the predefined approximate median search event is a second state.
[0100] In one embodiment, the median approximation determination module 540 is also used to, when the current state of the predefined approximate median search event is the first state, find out the data group where the median approximation of the array to be processed is located according to the cumulative frequency distribution table, and determine the median approximation of the array to be processed; when the current state of the predefined approximate median search event is the second state, find out the data group where the median approximation of the array to be processed is located according to the cumulative frequency distribution table, and obtain the first data group position identifier; when the first data group position identifier is consistent with the second data group position identifier, determine the median approximation of the previous array received as the median approximation of the array to be processed, wherein the data group position identifier is used to characterize the position of the data group in the array after data division is completed, the first data group position identifier is the position identifier of the data group where the median approximation of the array to be processed is located, and the second data group position identifier is the position identifier of the data group where the median approximation of the previous array received is located.
[0101] In one embodiment, the median approximation determination module 540 is also used to determine whether the absolute value of the difference between the first data group position identifier and the second data group position identifier satisfies a preset error if the first data group position identifier is inconsistent with the second data group position identifier. If the absolute value of the difference satisfies the preset error, the median approximation is determined based on the data group where the median approximation of the array to be processed is located. If the absolute value of the difference does not satisfy the preset error, the current state of the predefined approximate median search event is switched to the first state, and the data acquisition module 510 is controlled to perform an operation of determining the mean and standard deviation of the array to be processed based on the current state of the predefined approximate median search event.
[0102] In one of the embodiments, the mean-standard deviation determination module 520 is also used to determine multiple data partition intervals based on the mean and the standard deviation, divide the array to be processed into multiple data groups based on the multiple data partition intervals, count the cumulative frequency of each data group, and construct a cumulative frequency distribution table based on each data group and the cumulative frequency of each data group.
[0103] In one embodiment, the cumulative frequency distribution table construction module 530 is also used to count the number of data distributed in each data group to obtain the frequency of each data group, determine the frequency of each data group based on the frequency of each data group, and accumulate and sum the frequencies of each data group upward to obtain the cumulative frequency of each data group.
[0104] Each module in the above-mentioned device for finding the median approximate value of the data set can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0105] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data sets, median approximations, standard deviations, mean values and other data for which median approximations are to be found. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for finding the median approximation of a data set is implemented.
[0106] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0107] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps in the above-mentioned method for finding an approximate median value of a data set are implemented.
[0108] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method for finding an approximate median value of a data set are implemented.
[0109] In one embodiment, a computer program product is provided, including a computer program, which, when executed by a processor, implements the steps in the above-mentioned method for finding an approximate median value of a data set.
[0110] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0111] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0112] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0113] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for finding an approximate median value of a data set, characterized in that: The data set is a sensor data set, including multiple arrays, and the multiple arrays use the same mean and standard deviation to characterize data distribution; The method for finding the median approximate value of the data set includes: Get the current array to be processed and the current status of the predefined approximate median search event; Determining the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event; According to the mean and the standard deviation, a cumulative frequency distribution table is constructed, wherein the cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed; Based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, find out the data group where the median approximation of the array to be processed is located, determine the median approximation of the array to be processed, and pass the mean, the standard deviation, the median approximation and the position identifier of the data group where the median approximation is located to the next array, if the current state of the predefined approximate median search event is the first state, switch the first state to the second state, the position identifier is used to characterize the position of the data group in the array after the data division is completed; Return to the step of obtaining the current state of the array to be processed and the predefined approximate median search event until the median approximate values of all arrays in the data set are found.
2. The method for finding the median approximation of a data set according to claim 1, characterized in that: Determining the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event includes: When the current state of the predefined approximate median search event is the first state, the mean and standard deviation of the array to be processed are calculated; When the current state of the predefined approximate median search event is the second state, the mean and standard deviation of the previous array to be processed received are determined as the mean and standard deviation of the array to be processed.
3. The method for finding the median approximation of a data set according to claim 1, characterized in that: The step of searching for the data group where the median approximate value of the array to be processed is located based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, and determining the median approximate value of the array to be processed comprises: When the current state of the predefined approximate median search event is the first state, the data group where the median approximate value of the array to be processed is located is searched out according to the cumulative frequency distribution table, and the median approximate value of the array to be processed is determined; When the current state of the predefined approximate median search event is the second state, the data group where the median approximate value of the array to be processed is located is searched according to the cumulative frequency distribution table, and a first data group position identifier is obtained, and when the first data group position identifier is consistent with the second data group position identifier, the received median approximate value of the previous array is determined as the median approximate value of the array to be processed; The first data group position identifier is the position identifier of the data group where the median approximation of the array to be processed is located, and the second data group position identifier is the position identifier of the data group where the median approximation of the previous array received is located.
4. The method for finding the median approximation of a data set according to claim 3, characterized in that: After obtaining the first data packet location identifier, the method further includes: If the first data group position identifier is inconsistent with the second data group position identifier, determining whether an absolute value of a difference between the first data group position identifier and the second data group position identifier satisfies a preset error; If the absolute value of the difference satisfies the preset error, determining the median approximation according to the data grouping where the median approximation of the array to be processed is located; If the absolute value of the difference does not meet the preset error, the current state of the predefined approximate median search event is switched to the first state, and the step of determining the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event is returned.
5. The method for finding the median approximation of a data set according to claim 1, characterized in that: The constructing a cumulative frequency distribution table according to the mean and the standard deviation comprises: Determine multiple data partition intervals according to the mean and standard deviation; Dividing the to-be-processed array into a plurality of data groups according to the plurality of data partition intervals; Count the cumulative frequency of each data group; Based on each data grouping and the cumulative frequency of each data grouping, a cumulative frequency distribution table is constructed.
6. The method for finding the median approximation of a data set according to claim 5, characterized in that: The counting of the cumulative frequency of each data group comprises: Count the number of data distributed in each data group to obtain the frequency of each data group; Determining the frequency of each data group based on the frequency of each data group; The frequencies of the data groups are cumulatively summed upward to obtain the cumulative frequencies of the data groups.
7. A device for finding an approximate median value of a data set, characterized in that: The data set is a sensor data set, including multiple arrays, and the multiple arrays use the same mean and standard deviation to characterize data distribution; The median approximate value finding device of the data set comprises: A data acquisition module, used to obtain the current array to be processed and the current state of the predefined approximate median search event; A mean standard deviation determination module, used to determine the mean and standard deviation of the array to be processed according to the current state of the predefined approximate median search event; A cumulative frequency distribution table construction module, used to construct a cumulative frequency distribution table according to the mean and the standard deviation, wherein the cumulative frequency distribution table includes a plurality of data groups, and the data groups are obtained by dividing the array to be processed; a median approximate value determination module, for finding out the data group where the median approximate value of the array to be processed is located based on the cumulative frequency distribution table and the current state of the predefined approximate median search event, determining the median approximate value of the array to be processed, and passing the mean, the standard deviation, the median approximation and the position identifier of the data group where the median approximation is located to the next array, and if the current state of the predefined approximate median search event is the first state, switching the first state to the second state, the position identifier is used to characterize the position of the data group in the array after the data division is completed; The loop processing module is used to control the data acquisition module to execute the operation of acquiring the current state of the array to be processed and the predefined approximate median search event until the median approximate values of all arrays in the data set are found.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
