A data query method, system, device and computer-readable storage medium
By performing segmented first-order linear fitting of the objective function of the target lookup table, the target lookup table is constructed, which solves the problem of poor data query accuracy in the existing technology and achieves higher data query accuracy.
Patent Information
- Application Number
- CN202111676172.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2041-12-31
AI Technical Summary
The prior art leads to poor accuracy of data query when using LUT to implement neural network activation function calculation.
By determining the objective function and target lookup interval corresponding to the target lookup table, segmenting them and performing first-order linear fitting, building a target lookup table, and data query is performed based on the lookup table.
The accuracy of data query is improved, and the linear fitting function is closer to the feature of the objective function, which enhances the construction accuracy of the lookup table and the accuracy of data query.
Smart Images

Figure CN114357375B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and more specifically, to a data query method, system, device and computer-readable storage medium. Background Art
[0002] For current artificial intelligence calculations, such as neural networks such as RNN and CNN, when designing hardware calculators, LUT (Lookup Table) is often used to implement the activation function calculation. Specifically, the LUT is divided into several sub-intervals, and the slope and intercept values of the line connecting the two end points on the function curve at both ends of the interval are saved, so as to approximate the function value corresponding to the independent variable in the interval. For example, [x0, x1] is one of the sub-intervals, and the slope a and intercept value b of the straight line segment connecting the corresponding points A and B are saved in the LUT; when calculating, when the obtained x value falls within the [x0, x1] sub-interval, the a and b values corresponding to the sub-interval are taken out from the LUT, and the ax+b result is calculated as the approximate value of y. However, the approximate value of y corresponding to the x value found in this way has a large deviation from the true value, which makes the data query accuracy poor.
[0003] In summary, how to improve the accuracy of data query is a problem that needs to be solved urgently by those skilled in the art. Summary of the invention
[0004] The purpose of this application is to provide a data query method, which can solve the technical problem of how to improve the accuracy of data query to a certain extent. This application also provides a data query system, device and computer-readable storage medium.
[0005] In order to achieve the above objectives, this application provides the following technical solutions:
[0006] A data query method, comprising:
[0007] Determine the target function and target table lookup interval corresponding to the target lookup table;
[0008] Segmenting the target table lookup interval to obtain each segmented interval and corresponding segmented interval points;
[0009] Determine the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals;
[0010] Determine metadata corresponding to each of the segmented interval points based on the original first-order linear fitting function, and construct the target lookup table based on the segmented interval points and the metadata;
[0011] Obtaining a query request, wherein the query request at least includes: target data;
[0012] Determine, based on the target data, the target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table;
[0013] A target query result of the target data is determined based on the target interval point and the corresponding metadata.
[0014] Preferably, the query request further includes: query requirement information corresponding to the target data;
[0015] The step of determining the target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table based on the target data includes:
[0016] If the query requirement information represents a low-latency query, then from the various segmented interval points recorded in the target lookup table, the segmented interval point closest to the target data is used as the target interval point;
[0017] The determining the target query result of the target data based on the target interval point and the corresponding metadata includes:
[0018] The metadata corresponding to the target interval point in the target lookup table is used as the target query result corresponding to the target data.
[0019] Preferably, the query request further includes: query requirement information corresponding to the target data;
[0020] The step of determining the target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table based on the target data includes:
[0021] If the query requirement information represents a high-precision query, then from each of the segmented interval points recorded in the target lookup table, two segmented interval points closest to the target data are used as the target interval points;
[0022] The determining the target query result of the target data based on the target interval point and the corresponding metadata includes:
[0023] An interpolation calculation is performed based on the target data, the target interval points and the metadata corresponding to the target interval points in the target lookup table to obtain the target query result corresponding to the target data.
[0024] Preferably, the interpolation calculation is performed based on the target data, the target interval points and the metadata corresponding to the target interval points in the target lookup table to obtain the target query result corresponding to the target data, including:
[0025] A second value is calculated using a binary floating point format based on the target data, the target interval point, and metadata corresponding to the target interval point in the target lookup table by using a first calculation formula;
[0026] Determining the segment interval length of the target lookup table and determining an exponential value of the segment interval length relative to 2;
[0027] If the exponent value is 0, the second value is directly used as the third representation result; if the exponent value is greater than 0, the decimal point of the second value is shifted left by the target position to obtain the third representation result; if the exponent value is less than 0, the decimal point of the second value is shifted right by the target position to obtain the third representation result; wherein the value of the target position is equal to the modulus value of the exponent value;
[0028] Converting the third representation result into an output format to obtain the target query result;
[0029] The first operation formula includes:
[0030]
[0031] Wherein, σ represents the second value; x t 、x t+1 represents the target interval point; Represents x t the corresponding metadata; Represents x t+1 The corresponding metadata; x represents the target data.
[0032] Preferably, the determining of metadata corresponding to each of the segmented interval points based on the original first-order linear fitting function includes:
[0033] Determine whether the objective function has corresponding constraints; if the objective function has the constraints, adjust the original first-order linear fitting function based on the constraints to obtain an initial first-order linear fitting function that satisfies the constraints; if the objective function does not have the constraints, directly use the original first-order linear fitting function as the initial first-order linear fitting function;
[0034] The metadata corresponding to each of the segmented interval points is determined based on the initial first-order linear fitting function.
[0035] Preferably, the determining the metadata corresponding to each of the segmented interval points based on the initial first-order linear fitting function includes:
[0036] Determine whether the initial first-order linear fitting function on adjacent segmented intervals is continuous; if not, obtain a continuous target first-order linear fitting function based on the initial first-order linear fitting function; if continuous, use the initial first-order linear fitting function as the target first-order linear fitting function; use the function value of each segmented interval point in the target first-order linear fitting function as the corresponding metadata.
[0037] Preferably, the determining of the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals includes:
[0038] Based on the second operation formula, determining the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals;
[0039] The second operation formula includes:
[0040] h t (x) = α t x+β t ;
[0041]
[0042]
[0043] Among them, h t (x) represents the original first-order linear fitting function; F'(x) represents the density function of the probability distribution function of the independent variable in the segmented interval; x t 、x t+1 Represents two segmentation interval points of the segmentation interval.
[0044] Preferably, the second operation formula specifically includes:
[0045] h t (x) = α t x+β t ;
[0046]
[0047] Among them, h t (x) represents the original first-order linear fitting function; It means [x t ,x t+1 ] Sampling points on the segmented interval, i = 1, 2, ..., m, express Function value in the objective function; T represents the transpose.
[0048] Preferably, the adjusting the original first-order linear fitting function based on the constraint condition to obtain an initial first-order linear fitting function that satisfies the constraint condition includes:
[0049] Constructing an adjustment function based on the constraint conditions, the multiplier variables, and the slack variables;
[0050] Derivative each variable in the adjustment function and set each derivative to zero to obtain a target parameter;
[0051] The original first-order linear fitting function is adjusted based on the target parameter to obtain the initial first-order linear fitting function that meets the constraint condition.
[0052] Preferably, obtaining a continuous target first-order linear fitting function based on the initial first-order linear fitting function comprises:
[0053] Obtaining the continuous target first-order linear fitting function based on the initial first-order linear fitting function through a third operation formula;
[0054] The third operation formula includes:
[0055]
[0056] in, represents the target first-order linear operation function; δ = x t+1 -x t , t=0,1,...,n-1; when 0<t<n,
[0057] A data query system, comprising:
[0058] A parameter determination module is used to determine the target function and target table lookup interval corresponding to the target lookup table;
[0059] An interval segmentation module is used to segment the target table lookup interval to obtain each segmented interval and the corresponding segmented interval point;
[0060] A fitting function determination module, used for determining the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals;
[0061] A lookup table construction module, used to determine the metadata corresponding to each of the segmented interval points based on the original first-order linear fitting function, and to construct the target lookup table based on the segmented interval points and the metadata;
[0062] A query request acquisition module, used to acquire a query request, wherein the query request at least includes: target data;
[0063] An interval point determination module, configured to determine a target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table based on the query request;
[0064] A query result determination module is used to determine a target query result of the target data based on the target interval point and the corresponding metadata.
[0065] A data query device, comprising:
[0066] Memory for storing computer programs;
[0067] A processor is used to implement the steps of any of the above data query methods when executing the computer program.
[0068] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above data query methods are implemented.
[0069] It can be seen from the above scheme that a data query method provided by the present application includes determining the target function and target lookup interval corresponding to the target lookup table; segmenting the target lookup interval to obtain each segmented interval and the corresponding segmented interval points; determining the original first-order linear fitting function corresponding to the target function on each segmented interval; determining the metadata corresponding to each segmented interval point based on the original first-order linear fitting function, and constructing a target lookup table based on the segmented interval points and the metadata; obtaining a query request, the query request at least includes: target data; determining the target interval points corresponding to the target data from each segmented interval point recorded in the target lookup table based on the target data; determining the target query result of the target data based on the target interval points and the corresponding metadata.
[0070] In the present application, in the process of constructing a lookup table, it is necessary to determine the target function and target lookup interval corresponding to the target lookup table; segment the target lookup interval to obtain each segmented interval and the corresponding segmented interval point; determine the original first-order linear fitting function corresponding to the target function in each segmented interval, which is equivalent to linearly fitting the corresponding target function in each segmented interval, so that the linear fitting function of the segmented interval is closer to the characteristics of the target function in each segmented interval. In this way, the metadata corresponding to each segmented interval point is determined based on the original first-order linear fitting function, and the target lookup table is constructed based on the segmented interval points and metadata. The interpolation calculated based on the metadata of the segmented interval points recorded in the constructed target lookup table can be closer to the true value of the segmented interval point in the target function, which can improve the accuracy of the construction of the lookup table. In addition, after determining the target data and query demand information, it is also necessary to determine the target interval points corresponding to the target data from the segmented interval points recorded in the target lookup table based on the target data, and determine the target query result of the target data based on the target interval points and the corresponding metadata, which can ensure the accuracy of the data query. The data query system, device and computer-readable storage medium provided in this application also solve the corresponding technical problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0072] Figure 1 A flowchart of a data query method provided in an embodiment of the present application;
[0073] Figure 2 A schematic diagram of data query in the data query method provided in this application;
[0074] Figure 3 It is a schematic diagram of the segmented interval points corresponding to the tanh(x) function;
[0075] Figure 4 A flowchart for constructing a target lookup table in the data query method provided in this application;
[0076] Figure 5 A schematic diagram of using linear interpolation to approximate the objective function value;
[0077] Figure 6 A schematic diagram of the structure of a data query system provided in an embodiment of the present application;
[0078] Figure 7 The figure is a schematic diagram of the hardware structure of the electronic device according to the embodiment of the present invention. DETAILED DESCRIPTION
[0079] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0080] See also Figure 1 , Figure 1 A flowchart of a data query method provided in an embodiment of the present application.
[0081] A data query method provided in an embodiment of the present application may include the following steps:
[0082] Step S11: Determine the target function and target table lookup interval corresponding to the target lookup table.
[0083] In practical applications, the target function and target table lookup interval corresponding to the target lookup table can be determined first. The contents of the target function and the target table lookup interval can be determined according to actual needs, and this application does not make specific limitations here.
[0084] Step S12: segment the target table lookup interval to obtain each segmented interval and the corresponding segmented interval point.
[0085] In practical applications, because the target lookup table records each segmented interval point and the corresponding function value, after determining the target function and target lookup interval corresponding to the target lookup table, the target lookup interval can be segmented to obtain each segmented interval and the corresponding segmented interval point.
[0086] Step S13: Determine the original first-order linear fitting function corresponding to the objective function in each segmented interval.
[0087] In practical applications, after the target lookup interval is segmented to obtain each segmented interval and the corresponding segmented interval points, in order to make the segmented interval points and the corresponding metadata recorded in the target lookup table meet the characteristics of the objective function itself, it is necessary to determine the original first-order linear fitting function corresponding to the objective function in each segmented interval, that is, to perform linear fitting on the corresponding objective function in each segmented interval to obtain the corresponding first-order linear fitting function.
[0088] Step S14: determining metadata corresponding to each segmented interval point based on the original first-order linear fitting function, and constructing a target lookup table based on the segmented interval points and the metadata.
[0089] In practical applications, after determining the original first-order linear fitting function corresponding to the objective function in each segmented interval, the metadata corresponding to each segmented interval point can be determined based on the original first-order linear fitting function, and a target lookup table can be constructed based on the segmented interval points and the metadata. For example, the segmented interval points and the corresponding metadata can be saved in a blank lookup table to construct a target lookup table.
[0090] Step S15: Obtain a query request, where the query request at least includes: target data.
[0091] In actual applications, after the target lookup table is constructed, a query request containing the target data to be queried can be obtained. The type of target data can be determined according to actual needs. For example, the target data can be data with the same properties as the segmented interval points, or can be converted into data with the same properties as the segmented interval points, etc. This application does not make specific limitations here.
[0092] Step S16: Based on the target data, determine the target interval point corresponding to the target data from each segmented interval point recorded in the target lookup table.
[0093] Step S17: Determine the target query result of the target data based on the target interval point and the corresponding metadata.
[0094] In actual applications, after determining the target data, the target interval points corresponding to the target data can be determined from each segmented interval point recorded in the target lookup table based on the target data, and the target query results of the target data can be determined based on the target interval points and the corresponding metadata.
[0095] In a data query method provided by an embodiment of the present application, in the process of constructing a lookup table, it is necessary to determine the target function and target lookup interval corresponding to the target lookup table; segment the target lookup interval to obtain each segmented interval and the corresponding segmented interval point; determine the original first-order linear fitting function corresponding to the target function in each segmented interval, which is equivalent to linearly fitting the corresponding target function in each segmented interval, so that the linear fitting function of the segmented interval is closer to the characteristics of the target function in each segmented interval, so that the metadata corresponding to each segmented interval point is determined based on the original first-order linear fitting function, and the target lookup table is constructed based on the segmented interval points and metadata, so that the interpolation calculated based on the metadata of the segmented interval points recorded in the constructed target lookup table can be closer to the true value of the segmented interval point in the target function, which can improve the accuracy of constructing the lookup table. In addition, after determining the target data and query demand information, it is also necessary to determine the target interval points corresponding to the target data from each segmented interval point recorded in the target lookup table based on the target data, and determine the target query result of the target data based on the target interval points and the corresponding metadata, which can ensure the accuracy of data query.
[0096] See also Figure 2 , Figure 2 A schematic diagram of data query in the data query method provided in this application.
[0097] In a data query method provided in an embodiment of the present application, the query request may further include query requirement information representing performance information of the query data. Accordingly, the data query process may include the following steps:
[0098] Step S101: Obtain a query request, which at least includes: target data and query requirement information.
[0099] Step S102: parse the query requirement information.
[0100] Step S103: If the query requirement information represents a low-latency query, the segmented interval point closest to the target data is taken as the target interval point from each segmented interval point recorded in the target lookup table, and the metadata corresponding to the target interval point in the target lookup table is taken as the target query result corresponding to the target data.
[0101] In actual applications, when the query requirement information represents a low-latency query, it is necessary to find the target query result corresponding to the target data as soon as possible. To this end, the segmented interval point closest to the target data can be directly selected from the various segmented interval points recorded in the target lookup table as the target interval point, and the metadata corresponding to the target interval point in the target lookup table can be used as the target query result corresponding to the target data. Of course, in the absence of query requirement information, after determining the target data, the segmented interval point closest to the target data can be directly selected from the various segmented interval points recorded in the target lookup table as the target interval point, and the metadata corresponding to the target interval point in the target lookup table can be used as the target query result corresponding to the target data, etc. This application does not specifically limit the process of searching for data based on the lookup table, and it can be flexibly selected according to actual needs.
[0102] It should be noted that in order to save as much data as possible, the data recorded in the target lookup table are the points of each segment interval and the corresponding data values. Taking the corresponding data of the [0,4] interval on the tanh(x) function recorded in the target lookup table as an example, assuming that the number of segment intervals is 32 and the length of each segment interval is 0.125, the points of each segment interval recorded in the target lookup table can be as follows: Figure 3 shown.
[0103] Step S104: If the query requirement information represents a high-precision query, the two segmented interval points closest to the target data are selected as target interval points from each segmented interval point recorded in the target lookup table, and interpolation calculations are performed based on the target data, target interval points and the metadata corresponding to the target interval points in the target lookup table to obtain the target query result corresponding to the target data.
[0104] In practical applications, when the query requirement information represents a high-precision query, it is necessary to ensure the accuracy of the target query results obtained. To this end, the two segmented interval points closest to the target data can be used as target interval points from the various segmented interval points recorded in the target lookup table, and interpolation calculations are performed based on the target data, target interval points, and the metadata corresponding to the target interval points in the target lookup table to obtain the target query results corresponding to the target data. Of course, in the absence of query requirement information, after determining the target data, the two segmented interval points closest to the target data can be directly used as target interval points, and interpolation calculations are performed based on the target data, target interval points, and the metadata corresponding to the target interval points in the target lookup table to obtain the target query results corresponding to the target data, etc. This application does not specifically limit the process of searching for data based on the lookup table, and it can be flexibly selected according to actual needs.
[0105] It should be noted that in the process of performing data query based on query requirement information, if the target data is directly the same as a segmented interval point recorded in the target lookup table, the metadata corresponding to the segmented interval point in the target lookup table can be directly used as the target query result corresponding to the target data, and this application will not go into details here.
[0106] In a data query method provided in an embodiment of the present application, target data to be queried and corresponding query requirement information are obtained; the query requirement information is parsed; if the query requirement information represents a low-latency query, the segmented interval point closest to the target data from each segmented interval point recorded in the target lookup table is used as the target interval point, and the metadata corresponding to the target interval point in the target lookup table is used as the target query result corresponding to the target data; if the query requirement information represents a high-precision query, the two segmented interval points closest to the target data from each segmented interval point recorded in the target lookup table are used as the target interval points, and interpolation calculation is performed based on the target data, the target interval point and the metadata corresponding to the target interval point in the target lookup table to obtain the target query result corresponding to the target data. In the present application, when the query demand information represents a low-latency query, the metadata corresponding to the segmented interval point in the target lookup table that is closest to the target data can be directly used as the target query result corresponding to the target data, with low query latency and high efficiency; when the query demand information represents a high-precision query, the two segmented interval points in the target lookup table that are closest to the target data can be used as target interval points, and interpolation calculations can be performed based on the target data, target interval points, and the metadata corresponding to the target interval points in the target lookup table to obtain the target query result corresponding to the target data, with high query accuracy and good applicability.
[0107] In a data query method provided in the present application, it is assumed that the examples of each segment interval point recorded in the target lookup table are x t , t represents the number of the segmented interval point, and t∈{0,1,...n}, n represents the total number of segmented interval points, then in the process of taking the segmented interval point closest to the target data as the target interval point, the formula can be used To determine the label of the target interval point, and then determine the target interval point.
[0108] Of course, the target interval point number can also be quickly determined by simplifying the target interval point determination process into a shift operation through the length of each segmented interval. For example, the target data can be represented by a 16-bit binary half-floating point number (fp16) to obtain a first representation result; determine the segmented interval length of the target lookup table, and represent the segmented interval length by a 16-bit binary half-floating point number to obtain a second representation result; determine the exponent difference value between the first representation result and the second representation result; take out the first data corresponding to the exponent difference value of the decimal part of the first representation result; left-fill the first data with 1 bit "1" and convert it to a decimal number to obtain a first numerical value, and use the segmented interval point with the same subscript as the first numerical value as the target interval point.
[0109] For ease of understanding, assuming that the segment interval length is 0.125 and the target data is 1.0625, then after 1.0625 is represented by a 16-bit binary half-floating point number (fp16), the first representation result is 0011 1100 0100 0000, where bits 2 to 6 from the left are the exponent bits, i.e. 01111; similarly, the exponent bits of the 0.125 binary half-floating point number are 01100, and the difference between the two is 3; at this time, take the first 3 bits of the decimal part from the first representation result, i.e. bits 7 to 9 from the left, and left-padded with 1 bit "1" to get 1000, convert it to decimal, and get the first value of 8, at this time x8 is the target interval point corresponding to the target data.
[0110] In practical applications, the interpolation calculation formula obtained by Newton's first-order interpolation method is:
[0111]
[0112] After deformation, we can get:
[0113]
[0114] at this time, and The two parts can be calculated in parallel without wasting clock cycles. t+1 -x t is the segment interval length, which can be expressed as 2 q , q is an integer, so No division is required. Just add The final result can be obtained by shifting the decimal point of the calculation result in the binary floating point format by |q| positions. When q is greater than 0, the decimal point is shifted to the left, when q is greater than 0, the decimal point is shifted to the right, and when q is equal to 0, the shift operation is ignored. That is, in the process of performing interpolation calculation based on the target data, the target interval point and the metadata corresponding to the target interval point in the target lookup table to obtain the target query result corresponding to the target data, the target query result can also be quickly determined based on the shift operation. At this time, it is necessary to use the first calculation formula, based on the target data, the target interval point and the metadata corresponding to the target interval point in the target lookup table, to calculate the second value in the binary floating point format; determine the segmented interval length of the target lookup table, and determine the exponential value of the segmented interval length relative to 2; if the exponential value is 0, the second value is directly used as the third representation result; if the exponent value is greater than 0, the decimal point of the second value is shifted to the left by the target position to obtain the third representation result, and if the exponent value is less than 0, the decimal point of the second value is shifted to the right by the target position to obtain the third representation result; wherein the value of the target position is equal to the modulus value of the exponent value; convert the third representation result into an output format, such as a decimal number, to obtain the target query result;
[0115] The fourth operation formula includes:
[0116]
[0117] Wherein, σ represents the second value; x t 、x t+1 Indicates the target interval point; Represents x t The corresponding metadata; Represents x t+1 Corresponding metadata; x represents the target data.
[0118] For ease of understanding, assume that the segment interval length is 2 -3 , that is, 0.125. At this time, the result of any 16-bit binary format value divided by 0.125 is equal to the binary format value shifted right by 3 decimal places. Assuming the divisor is 0.03125, the representation of the 16-bit binary half floating point number in hardware is: 0010 1000 0000 0000; the decimal point is shifted right by 3, that is, the exponent corresponding to the value is added by 3, that is, 3 is added from 2 to 6 from the left, and the result is: 0011 0100 0000 0000, which is converted to decimal as 0.25, that is, the quotient of 0.03125 and 0.125 is 0.25. Therefore, the target query result can be quickly obtained with the help of shift operation.
[0119] See also Figure 4 , Figure 4 This is a flowchart for constructing a target lookup table in the data query method provided in this application.
[0120] In a data query method provided by the present application, the process of constructing a target lookup table may include the following steps:
[0121] Step S201: Determine the target function and target table lookup interval corresponding to the target lookup table.
[0122] Step S202: segment the target table lookup interval to obtain each segmented interval and corresponding segmented interval points.
[0123] Step S203: Determine the original first-order linear fitting function corresponding to the objective function in each segmented interval.
[0124] In practical applications, after the target lookup interval is segmented and each segmented interval and the corresponding segmented interval points are obtained, the original first-order linear fitting function corresponding to the target function in each segmented interval can be determined. For example, the original first-order linear fitting function corresponding to the target function in each segmented interval can be determined by the least squares method.
[0125] In a specific application scenario, in the process of determining the original first-order linear fitting function corresponding to the objective function on each segmented interval, for an independent variable with non-uniform distribution, the original first-order linear fitting function corresponding to the objective function on each segmented interval can be determined based on the second operation formula;
[0126] The second operation formula includes:
[0127] h t (x) = α t x+β t ;
[0128]
[0129]
[0130] Among them, h t (x) represents the original first-order linear fitting function; F'(x) represents the density function of the probability distribution function of the independent variable in the segmented interval; x t 、x t+1 Represents two segmentation interval points of the segmentation interval. In this case, the segmentation interval is [x t ,x t+1 ].
[0131] In specific application scenarios, after determining the original first-order linear fitting function corresponding to the objective function in each segmented interval, for uniformly distributed independent variables, assuming that the fitting error is assumed to obey a normal distribution with a mean of zero, according to the maximum likelihood estimation, the loss function can be written as:
[0132] It means [x t ,x t+1 ] Sampling points on the segmented interval, i = 1, 2, ..., m;
[0133] According to the least squares method, we know that α t ,β t = arg min J(α t ,β t ); after solving the normal equation, we can get:
[0134]
[0135] Therefore, in the process of determining the original first-order linear fitting function corresponding to the objective function in each segmented interval based on the second operation formula, the second operation formula can be specifically as follows:
[0136] h t (x) = α t x+β t ;
[0137]
[0138] Among them, h t (x) represents the original first-order linear fitting function; It means [x t ,x t+1 ] Sampling points on the segmented interval, i = 1, 2, ..., m, express Function value in the objective function; T denotes transpose.
[0139] Step S204: Determine whether the objective function has corresponding constraints; if the objective function has constraints, execute step S205; if the objective function does not have constraints, execute step S206.
[0140] Step S205: adjusting the original first-order linear fitting function based on the constraint condition to obtain an initial first-order linear fitting function that satisfies the constraint condition, and executing step S207.
[0141] Step S206: directly use the original first-order linear fitting function as the initial first-order linear fitting function, and execute step S207.
[0142] In practical applications, when there are constraints on the objective function, the original first-order linear fitting function needs to be adjusted based on the constraints to obtain an initial first-order linear fitting function that meets the constraints; when there are no constraints on the objective function, the original first-order linear fitting function can be directly used as the initial first-order linear fitting function.
[0143] In specific application scenarios, in the process of adjusting the original first-order linear fitting function based on the constraints to obtain the initial first-order linear fitting function that meets the constraints, the adjustment function can be constructed based on the constraints, multiplier variables, and slack variables; the Lagrange multiplier method is used to differentiate the variables in the adjustment function, and each derivative is set to zero to obtain the target parameters; the original first-order linear fitting function is adjusted based on the target parameters to obtain the initial first-order linear fitting function that meets the constraints.
[0144] It is easy to understand that it is zero. Taking the tanh(x) function as an example, its constraints are That is, in the segmented interval [x t ,x t+1 ] must satisfy stα t x t +β t ≥-1,α t x t+1 +β t ≤1, then the adjustment function constructed by introducing the multiplier variable λ and the slack variable η is:
[0145] ; Then, according to the Lagrange multiplier method, the variables in the adjustment function are differentiated and each derivative is set to zero, and the target parameter α can be obtained. t and β t , and then the initial first-order linear fitting function can be obtained.
[0146] Step S207: Determine whether the initial first-order linear fitting function on adjacent segment intervals is continuous. If not, execute step S208; if continuous, execute step S209.
[0147] Step S208: Obtain a continuous target first-order linear fitting function based on the initial first-order linear fitting function, and execute step S210.
[0148] Step S209: taking the initial first-order linear fitting function as the target first-order linear fitting function, and executing step S210.
[0149] In practical applications, because a segmented interval point participates in the construction of the initial first-order linear fitting function of two adjacent segmented intervals, the application of the initial first-order linear fitting function on the two adjacent segmented intervals is continuous. Therefore, this application also needs to determine whether the initial first-order linear fitting function on the adjacent segmented intervals is continuous. If it is not continuous, a continuous target first-order linear fitting function is obtained based on the initial first-order linear fitting function; if it is continuous, the initial first-order linear fitting function is used as the target first-order linear fitting function to obtain a continuous target first-order linear fitting function to ensure the continuity of the data recorded in the target lookup table.
[0150] In a specific application scenario, in the process of obtaining a continuous target first-order linear fitting function based on an initial first-order linear fitting function, a continuous target first-order linear fitting function can be obtained based on the initial first-order linear fitting function through a third operation formula;
[0151] The third operation formula includes:
[0152]
[0153] in, represents the target first-order linear operation function; δ = x t+1 -x t , t=0,1,...,n-1; when 0<t<n,
[0154] Step S210: taking the function value of each segment interval point in the target first-order linear fitting function as the corresponding metadata.
[0155] Step S211: construct a target lookup table based on segment interval points and metadata.
[0156] In practical applications, after obtaining the target first-order linear fitting function, the function value of each segmented interval point in the target first-order linear fitting function can be used as the corresponding metadata, and a target lookup table can be constructed based on the segmented interval points and the metadata. The format of the target lookup table can be shown in Table 1.
[0157] Table 1 Target search table example
[0158]
[0159] It should be noted that if the objective function curve in the segmented interval is a convex function or a concave function, if the slope and intercept values corresponding to the segmented interval points in the original first-order information fitting function are directly saved, the cumulative error of the approximate value of the relative objective function value will increase monotonically with the increase in the number of calculations, for example Figure 5 In the case of convex functions, the sum of the errors corresponding to the bright spots C and D in any subinterval is greater than their respective errors, resulting in a large data query error. However, the target lookup table of the present application does not directly store the slope and intercept corresponding to the segmented interval points, nor does it directly store the function values of the segmented interval points on the target function. Instead, it stores the segmented interval points and the function values of the segmented interval points in the target first-order linear fitting function. The target first-order linear fitting function satisfies the constraints of the target function and has continuity, so the data query error of the present application is relatively low. In addition, when the error levels of the segmented interval points in each segmented interval are different and the differences are large, for example, the target function values of the independent variables corresponding to the two segmented interval points are expressed as line segments. Approximation, the error is different, but the target first-order linear fitting function of each segmented interval of the present application is constructed directly based on the characteristics of the segmented interval, and is continuous in adjacent segmented intervals, so the present application can also reduce the error level between points in two segmented intervals.
[0160] See also Figure 6 , Figure 6 A schematic diagram of the structure of a data query system provided in an embodiment of the present application.
[0161] A data query system provided in an embodiment of the present application includes:
[0162] A parameter determination module 101 is used to determine the target function and target table lookup interval corresponding to the target lookup table;
[0163] An interval segmentation module 102 is used to segment the target table lookup interval to obtain each segmented interval and corresponding segmented interval points;
[0164] A fitting function determination module 103 is used to determine the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals;
[0165] A lookup table construction module 104 is used to determine metadata corresponding to each of the segmented interval points based on the original first-order linear fitting function, and to construct the target lookup table based on the segmented interval points and the metadata;
[0166] The query request acquisition module 105 is used to acquire a query request, and the query request at least includes: target data;
[0167] An interval point determination module 106 is used to determine, based on the target data, a target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table;
[0168] The query result determination module 107 is used to determine the target query result of the target data based on the target interval point and the corresponding metadata.
[0169] For the relevant description of each module in a data query system provided in an embodiment of the present application, reference can be made to the above embodiment and will not be repeated here.
[0170] Based on the hardware implementation of the above program modules and in order to implement the method of the embodiment of the present invention, the embodiment of the present invention further provides an electronic device, Figure 7 FIG. 1 is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. Figure 7 As shown, the electronic equipment includes:
[0171] Communication interface 1, capable of exchanging information with other devices such as network devices;
[0172] The processor 2 is connected to the communication interface 1 to implement information interaction with other devices and is used to execute the user operation processing method provided by one or more technical solutions when running a computer program. The computer program is stored in the memory 3.
[0173] Of course, in actual application, the various components in the electronic device are coupled together through the bus system 4. It can be understood that the bus system 4 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 4 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Figure 7 Various buses are labeled as bus system 4.
[0174] The memory 3 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program used to operate on the electronic device.
[0175] It can be understood that the memory 3 can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM, SyncLink Dynamic Random Access Memory), and direct RAM bus random access memory (DRRAM, Direct Rambus Random Access Memory).The memory 2 described in the embodiments of the present invention is intended to include but is not limited to these and any other suitable types of memories.
[0176] The method disclosed in the above embodiment of the present invention can be applied to the processor 2, or implemented by the processor 2. The processor 2 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 2 or the instruction in the form of software. The above processor 2 can be a general-purpose processor, a DSP, or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 2 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiment of the present invention. The general-purpose processor can be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present invention, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in the memory 3. The processor 2 reads the program in the memory 3 and completes the steps of the above method in combination with its hardware.
[0177] When the processor 2 executes the program, the corresponding processes in the various methods of the embodiments of the present invention are implemented, which will not be described here for the sake of brevity.
[0178] In an exemplary embodiment, the embodiment of the present invention further provides a storage medium, namely a computer storage medium, specifically a computer readable storage medium, for example, including a memory 3 storing a computer program, and the above-mentioned computer program can be executed by a processor 2 to complete the steps of the above-mentioned method. The computer readable storage medium can be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface storage, optical disk, or CD-ROM.
[0179] In the several embodiments provided in the present application, it should be understood that the disclosed devices, terminals and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0180] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0181] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0182] A person of ordinary skill in the art can understand that: all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium, which, when executed, executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, disks or optical disks.
[0183] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for an electronic device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0184] For the description of the relevant parts of the data query system, electronic device, and computer-readable storage medium provided in the embodiments of the present application, please refer to the detailed description of the corresponding parts in the data query method provided in the embodiments of the present application, which will not be repeated here. In addition, the parts of the above technical solutions provided in the embodiments of the present application that are consistent with the implementation principles of the corresponding technical solutions in the prior art are not described in detail to avoid excessive elaboration.
[0185] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0186] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A data query method, characterized in that: include: Determine the target function and target table lookup interval corresponding to the target lookup table; Segmenting the target table lookup interval to obtain each segmented interval and corresponding segmented interval points; Determine the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals; Determine metadata corresponding to each of the segmented interval points based on the original first-order linear fitting function, and construct the target lookup table based on the segmented interval points and the metadata; Obtaining a query request, wherein the query request at least includes: target data; Determine, based on the target data, the target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table; Determine a target query result of the target data based on the target interval point and the corresponding metadata; The determining of the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals includes: Based on the second operation formula, determining the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals; The second operation formula includes: h t (x)=a t x+b t ; Among them, h t (x) represents the original first-order linear fitting function; F'(x) represents the density function of the probability distribution function of the independent variable in the segmented interval; x t 、x t+1 represents two segmented interval points of the segmented interval; J(α t ,β t ) is the loss function of the original first-order linear fitting function.
2. The method according to claim 1, characterized in that The query request also includes: query requirement information corresponding to the target data; The step of determining the target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table based on the target data includes: If the query requirement information represents a low-latency query, then from the various segmented interval points recorded in the target lookup table, the segmented interval point closest to the target data is used as the target interval point; The determining the target query result of the target data based on the target interval point and the corresponding metadata includes: The metadata corresponding to the target interval point in the target lookup table is used as the target query result corresponding to the target data.
3. The method according to claim 1, characterized in that The query request also includes: query requirement information corresponding to the target data; The step of determining the target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table based on the target data includes: If the query requirement information represents a high-precision query, then from each of the segmented interval points recorded in the target lookup table, two segmented interval points closest to the target data are used as the target interval points; The determining the target query result of the target data based on the target interval point and the corresponding metadata includes: An interpolation calculation is performed based on the target data, the target interval points and the metadata corresponding to the target interval points in the target lookup table to obtain the target query result corresponding to the target data.
4. The method according to claim 3, characterized in that: The interpolation calculation is performed based on the target data, the target interval points and the metadata corresponding to the target interval points in the target lookup table to obtain the target query result corresponding to the target data, including: A second value is calculated using a binary floating point format based on the target data, the target interval point, and metadata corresponding to the target interval point in the target lookup table by using a first calculation formula; Determining the segment interval length of the target lookup table and determining an exponential value of the segment interval length relative to 2; If the exponent value is 0, the second value is directly used as the third representation result; if the exponent value is greater than 0, the decimal point of the second value is shifted left by the target position to obtain the third representation result; if the exponent value is less than 0, the decimal point of the second value is shifted right by the target position to obtain the third representation result; wherein the value of the target position is equal to the modulus value of the exponent value; Converting the third representation result into an output format to obtain the target query result; The first operation formula includes: Wherein, σ represents the second value; x t 、x t+1 represents the target interval point; Represents x t the corresponding metadata; Represents x t+1 The corresponding metadata; x represents the target data.
5. The method according to any one of claims 1 to 4, characterized in that: The determining of metadata corresponding to each of the segmented interval points based on the original first-order linear fitting function includes: Determine whether the objective function has corresponding constraints; if the objective function has the constraints, adjust the original first-order linear fitting function based on the constraints to obtain an initial first-order linear fitting function that satisfies the constraints; if the objective function does not have the constraints, directly use the original first-order linear fitting function as the initial first-order linear fitting function; The metadata corresponding to each of the segmented interval points is determined based on the initial first-order linear fitting function.
6. The method according to claim 5, characterized in that The determining the metadata corresponding to each of the segmented interval points based on the initial first-order linear fitting function includes: Determine whether the initial first-order linear fitting function on adjacent segmented intervals is continuous; if not, obtain a continuous target first-order linear fitting function based on the initial first-order linear fitting function; if continuous, use the initial first-order linear fitting function as the target first-order linear fitting function; use the function value of each segmented interval point in the target first-order linear fitting function as the corresponding metadata.
7. The method according to claim 6, characterized in that The second operation formula specifically includes: h t (x)=a t x+b t ; Among them, h t (x) represents the original first-order linear fitting function; It means [x t ,x t+1 ] Sampling points on the segmented interval, i = 1, 2, ..., m, express Function value in the objective function; T represents the transpose.
8. The method according to claim 7, characterized in that The adjusting the original first-order linear fitting function based on the constraint condition to obtain an initial first-order linear fitting function that satisfies the constraint condition includes: Constructing an adjustment function based on the constraint conditions, the multiplier variables, and the slack variables; Derivative each variable in the adjustment function and set each derivative to zero to obtain a target parameter; The original first-order linear fitting function is adjusted based on the target parameter to obtain the initial first-order linear fitting function that meets the constraint condition.
9. The method according to claim 8, characterized in that The step of obtaining a continuous target first-order linear fitting function based on the initial first-order linear fitting function comprises: Obtaining the continuous target first-order linear fitting function based on the initial first-order linear fitting function through a third operation formula; The third operation formula includes: Among them, represents the target first-order linear operation function; δ = x t+1 - x t , t = 0, 1, …, n - 1; when 0 < t < n, 10. A data query system, characterized in that: include: A parameter determination module is used to determine the target function and target table lookup interval corresponding to the target lookup table; An interval segmentation module is used to segment the target table lookup interval to obtain each segmented interval and the corresponding segmented interval point; A fitting function determination module, used for determining the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals; A lookup table construction module, used to determine the metadata corresponding to each of the segmented interval points based on the original first-order linear fitting function, and to construct the target lookup table based on the segmented interval points and the metadata; A query request acquisition module, used to acquire a query request, wherein the query request at least includes: target data; An interval point determination module, configured to determine a target interval point corresponding to the target data from each of the segmented interval points recorded in the target lookup table based on the query request; A query result determination module, used to determine a target query result of the target data based on the target interval point and the corresponding metadata; The fitting function determination module is specifically used to determine the original first-order linear fitting function corresponding to the objective function in each of the segmented intervals based on the second operation formula; The second operation formula includes: h t (x)=a t x+b t ; Among them, h t (x) represents the original first-order linear fitting function; F'(x) represents the density function of the probability distribution function of the independent variable in the segmented interval; x t 、x t+1 represents two segmented interval points of the segmented interval; J(α t ,β t ) is the loss function of the original first-order linear fitting function.
11. A data query device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the data query method according to any one of claims 1 to 9 when executing the computer program.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data query method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Data processing method, device and system
CN113407788A