CN110110284B - Average number calculation method and device and electronic equipment - Google Patents

Average number calculation method and device and electronic equipment Download PDF

Info

Publication number
CN110110284B
CN110110284B CN201910429418.7A CN201910429418A CN110110284B CN 110110284 B CN110110284 B CN 110110284B CN 201910429418 A CN201910429418 A CN 201910429418A CN 110110284 B CN110110284 B CN 110110284B
Authority
CN
China
Prior art keywords
data
remainder
period
sum
average
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910429418.7A
Other languages
Chinese (zh)
Other versions
CN110110284A (en
Inventor
刘庆春
蔡勋
宣扬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hefei Eswin IC Technology Co Ltd
Original Assignee
Hefei Eswin IC Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hefei Eswin IC Technology Co Ltd filed Critical Hefei Eswin IC Technology Co Ltd
Priority to CN201910429418.7A priority Critical patent/CN110110284B/en
Publication of CN110110284A publication Critical patent/CN110110284A/en
Application granted granted Critical
Publication of CN110110284B publication Critical patent/CN110110284B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/15Correlation function computation including computation of convolution operations

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Computational Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Algebra (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Measurement Of Current Or Voltage (AREA)

Abstract

The application discloses an average number calculation method, an average number calculation device and electronic equipment, wherein the method comprises the following steps: acquiring target data input in a current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1; obtaining an average of a previous period of the current period and a remainder of the previous period; and calculating the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period. Therefore, in the application, the target data input in each of the N data input periods and the average number calculated in the previous period of the period are calculated, and then the average number and the remainder of the data in the N data input periods can be obtained immediately after the data input is finished, so that the consumption of clock periods caused by the shift addition after the data input in one row is finished is avoided, and the efficiency of calculating the average number is improved.

Description

Average number calculation method and device and electronic equipment
Technical Field
The present disclosure relates to the field of data processing technologies, and in particular, to a method and an apparatus for calculating an average, and an electronic device.
Background
For averaging, the basic method is to sum all the data in a row to obtain a sum, and divide the sum by the number of data in the row to obtain a quotient, i.e. the average.
Currently, when averaging the data input in the order of data input period, the shift addition is usually implemented, and in this way, the consumed clock period is longer, so that the time for calculating the average is longer, and the efficiency of calculating the average is lower.
Disclosure of Invention
In view of the above, an object of the present application is to provide an averaging method, an averaging device and an electronic apparatus, so as to solve the technical problem of low efficiency of averaging in the prior art.
The application provides an average number calculation method, which comprises the following steps:
acquiring target data input in a current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1;
obtaining an average of a previous period of the current period and a remainder of the previous period;
and calculating the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period.
The above method, preferably, further comprises:
presetting that the initial remainder and the initial average of the N data input periods are both 0.
The above method, preferably, calculating the target data based on the average of the previous period and the remainder of the previous period to obtain the average of the current period and the remainder of the current period includes:
calculating a first data sum of a remainder of the previous period and the target data;
obtaining a quantitative value of the N contained in the first data sum;
calculating a second data sum of the average number of the previous period and the quantity value, wherein the second data sum is the average number of the current period;
calculating the product of the magnitude value and the N and subtracting the product from the first data sum to obtain the remainder of the current cycle.
The above method, preferably, the calculating the target data based on the average of the previous period and the remainder of the previous period to obtain the average of the current period and the remainder of the current period includes:
calculating a first data sum of a remainder of the previous period and the target data;
judging the size between the first data sum and the sum of M N data sums, wherein M is a natural number which is greater than or equal to 0;
if the first data sum is larger than the sum of M N and the first data sum is smaller than the sum of M plus 1N, calculating the average number of the previous period and the second data sum of M, wherein the second data sum is the average number of the current period;
and calculating the product of the M and the N, and subtracting the product from the first data sum to obtain the remainder of the current period.
The present application also provides an average number calculation apparatus, including:
the target obtaining unit is used for obtaining target data input in the current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1;
a history obtaining unit, configured to obtain an average of a previous cycle of the current cycle and a remainder of the previous cycle;
and the current calculating unit is used for calculating the target data based on the average number of the previous period and the remainder of the previous period so as to obtain the average number of the current period and the remainder of the current period.
The above apparatus, preferably, further comprises:
and the presetting unit is used for presetting that the initial remainder and the initial average number of the N data input periods are both 0.
Preferably, in the above apparatus, the current computing unit is specifically configured to:
calculating a first data sum of a remainder of the previous period and the target data; obtaining a quantitative value of the N contained in the first data sum; calculating a second data sum of the average number of the previous period and the quantity value, wherein the second data sum is the average number of the current period; calculating the product of the magnitude value and the N and subtracting the product from the first data sum to obtain the remainder of the current cycle.
Preferably, the current calculating unit is specifically configured to:
calculating a first data sum of a remainder of the previous period and the target data; judging the size between the first data sum and the sum of M N, wherein M is a natural number which is greater than or equal to 0; if the first data sum is larger than the sum of M N and the first data sum is smaller than the sum of M plus 1N, calculating the average number of the previous period and the second data sum of M, wherein the second data sum is the average number of the current period; and calculating the product of the M and the N and subtracting the product from the first data sum to obtain the remainder of the current period.
The present application further provides an electronic device, including:
the memory is used for storing an application program and data generated by the operation of the application program;
a processor for executing the application to perform the functions of: acquiring target data input in a current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1; obtaining an average of a previous period of the current period and a remainder of the previous period; and calculating the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period.
According to the above scheme, the average number calculating method, the average number calculating device and the electronic device provided by the application calculate the target data input in each of the N data input periods and the average number calculated in the previous period of the period, and then immediately obtain the average number and the remainder of the data in the N data input periods after the data input is finished, so that the consumption of clock periods caused by the re-shift addition after one row of data input is finished is avoided, and the efficiency of calculating the average number is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart of an average calculation method according to an embodiment of the present application;
FIG. 2 is a diagram illustrating an exemplary application of an embodiment of the present application;
FIG. 3 is a partial flowchart of a method for calculating an average according to an embodiment of the present application;
FIG. 4 is another partial flowchart of a method for calculating an average according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an average calculating device according to a second embodiment of the present application;
fig. 6 is another schematic structural diagram of an average calculating device according to the second embodiment of the present application;
fig. 7 is a schematic structural diagram of an electronic device according to a third embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, a flowchart of an implementation of a method for calculating an average according to an embodiment of the present application is provided, where the method is mainly used to calculate an average and a remainder of each data sequentially input according to a data input period in a row of data.
Specifically, the method in this embodiment may include the following steps:
step 101: and acquiring target data input in the current period.
In this embodiment, the current period in the data input process is taken as an example to describe the technical scheme in the present application, it is apparent that the technical scheme in the present application is applicable to each of N data input periods, for example, the current period may be a 1 st data input period, or an nth data input period, that is, a last data input period, and it is apparent that a finally obtained average number and a remainder of the current period are average numbers and remainders of the N data.
Step 102: an average of a previous cycle of the current cycle and a remainder of the previous cycle are obtained.
As shown in fig. 2, for the 3 rd cycle, the previous cycle is the 2 nd cycle, and for the 7 th cycle, the previous cycle is the 6 th cycle. The calculation of the average number and the remainder of the previous cycle can also be realized by adopting the technical scheme in the embodiment, that is, in the embodiment, the average number of the target data input in the 1 st, the 2 nd, the 3 rd to the nth data input cycle is sequentially calculated according to the sequence of the data input cycle, and finally the average number of the N data is obtained.
Step 103: and calculating the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period.
As can be seen from the above solutions, in the average number calculating method provided in the embodiment of the present application, the target data input in each of N data input periods and the average number calculated in the previous period of the period are calculated, and then the average number and the remainder of the data in the N data input periods can be obtained immediately after the data input is finished, so that the consumption of clock periods caused by the re-shift addition at the end of a row of data input is avoided, and the efficiency of calculating the average number is improved.
In one implementation manner, before the average of one row of data is calculated in this embodiment, it may be preset that the row of data, that is, the initial remainder initial averages of N data input cycles, are all 0. That is to say, before the target data of the 1 st data input period is input, in this embodiment, the initial remainder and the initial average number are set to be 0, so that when the average number and the remainder of the 1 st data input period are subsequently calculated, calculation may be performed based on the initial remainder and the initial average data, and a specific calculation scheme may refer to fig. 1 and related contents in the foregoing.
Specifically, in the present embodiment, when the step 103 calculates the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period, it may specifically be implemented in the following manner, as shown in fig. 3:
step 301: a first data sum of a remainder of a previous cycle and target data is calculated.
For example, for the 1 st cycle, the previous cycle does not exist, that is, a preset initial remainder, that is, 0 is adopted; for the 2 nd cycle, the remainder of the previous cycle is the remainder calculated for the 1 st cycle, and so on.
Specifically, in this embodiment, the remainder of the previous period and the target value input in the current period may be directly summed, and the obtained sum value is the first data sum.
Step 302: a quantitative value of N contained in the first data sum is obtained.
The quantity value of N included therein refers to a value of the first data and the number of N therein, that is, how many N are included in the first data and the sum is obtained in this embodiment, for example, 2 is included in 23 and 10 (N) is included in 56, and 5 is included in 10, and so on.
Step 303: a second data sum of the average and magnitude values of the previous cycle is calculated.
Wherein the second data sum is an average of the current period. That is, the sum between the average number of the previous cycle and the number of the first data sums and N is taken as the average number of the current cycle in the present embodiment. For example, 5 data sums 56 include 10, the average number of previous cycles is 2, and 7 obtained by adding 5 to 2 is taken as the average number of current cycles.
Step 304: the product of the magnitude value and N is calculated and the first data sum is subtracted from the product to obtain the remainder for the current cycle.
That is, in the present embodiment, after the product of the magnitude value and N is subtracted from the first data sum, the resultant difference is used as the remainder of the current period. For example, 5 data sums 56 contain 10, and the product of 56 minus 5 times 10 yields the difference 6, which is the remainder of the current cycle.
In another implementation manner, in the present embodiment, when the step 103 calculates the target data based on the average of the previous period and the remainder of the previous period to obtain the average of the current period and the remainder of the current period, specifically, the following manner may be implemented, as shown in fig. 4:
step 401: a first data sum of a remainder of a previous cycle and the target data is calculated.
For example, for the 1 st cycle, the previous cycle does not exist, that is, a preset initial remainder, that is, 0 is adopted; for the 2 nd cycle, the remainder of the previous cycle is the remainder calculated for the 1 st cycle, and so on.
Specifically, in this embodiment, the remainder of the previous period and the target value of the current period may be directly summed, and the obtained sum value is the first data sum.
Step 402: the size between the first data sum and the sum of the M N is judged.
Wherein M is a natural number greater than or equal to 0. In a specific implementation, the sum of the first data and 0, N, 2N, and 3N are sequentially combined in step 402. . . M x N are compared in size and, accordingly, if the first data sum is greater than the sum of M N and less than the sum of M plus 1N, step 403 is performed.
For example, the first data sum 56 is greater than 5 sums of 10 and less than 6 sums of 10, where M is 5, thereby performing step 403.
Step 403: the average of the previous cycle is calculated and the second data sum of M.
Wherein the second data sum is an average of the current period. That is, the sum between the average number of previous cycles and M is taken as the average number of the current cycle in the present embodiment. For example, when the sum of the first data 56 is greater than 5 and 10 and less than 6 and 10, the average number of previous cycles is 2, and 7 obtained by adding 2 to 5 is taken as the average number of current cycles.
Step 404: and calculating the product of M and N and subtracting the product from the first data sum to obtain the remainder of the current period.
That is, in the present embodiment, after the product of M and N is subtracted from the first data sum, the obtained difference is used as the remainder of the current period. For example, when the sum 56 of the first data is greater than 5 and less than 6 and 10, the product of multiplying 10 by 5 is subtracted from 56, and the difference 6 is the remainder of the current cycle.
Referring to fig. 5, a schematic structural diagram of an average calculating device according to a second embodiment of the present disclosure is provided, the device is mainly used for calculating an average and a remainder of each data sequentially input according to a data input period in a row of data.
Specifically, the device in this embodiment may be functionally divided into logic units:
a target obtaining unit 501, configured to obtain target data input in the current cycle.
In this embodiment, the technical solution in the present application is described by taking the current cycle in the data input process as an example, and thus, the technical solution in the present application is applicable to each cycle of N data input cycles, for example, the current cycle may be the 1 st data input cycle, or may be the nth data input cycle, that is, the last data input cycle, and it can be seen that the finally obtained average number and the remainder of the current cycle are the average number and the remainder of the N data.
A history obtaining unit 502, configured to obtain an average of a previous cycle of the current cycle and a remainder of the previous cycle.
As shown in fig. 2, for the 3 rd cycle, the previous cycle is the 2 nd cycle, and for the 7 th cycle, the previous cycle is the 6 th cycle. The calculation of the average number and the remainder of the previous cycle can also be realized by adopting the technical scheme in the embodiment, that is, in the embodiment, the average number of the target data input in the 1 st, the 2 nd, the 3 rd to the nth data input cycle is sequentially calculated according to the sequence of the data input cycle, and finally the average number of the N data is obtained.
A current calculating unit 503, configured to calculate the target data based on the average of the previous cycle and the remainder of the previous cycle to obtain an average of the current cycle and a remainder of the current cycle.
As can be seen from the above solutions, the average number calculating device provided in the second embodiment of the present application calculates the average number calculated in the previous period of the period and the target data input in each of N data input periods, and then obtains the average number and the remainder of the data in the N data input periods immediately after the data input is finished, thereby avoiding the consumption of clock cycles caused by the shift addition after the data input in one row is finished, and improving the efficiency of calculating the average number.
In one implementation, the apparatus in this embodiment may further include the following units, as shown in fig. 6:
the presetting unit 504 is configured to preset that initial remainders and initial averages of the N data input periods are both 0.
That is, before the average of one row of data is calculated in this embodiment, it may be preset that the row of data, that is, the initial remainder initial average of N data input cycles, is 0. That is, before the target data of the 1 st data input period is input, the initial remainder and the initial average number are both set to be 0 in this embodiment, so that when the average number and the remainder of the 1 st data input period are subsequently calculated, calculation may be performed based on the initial remainder and the initial average data, and a specific calculation scheme may refer to fig. 1 and related contents in the foregoing.
Specifically, when the current calculating unit 503 calculates the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period, it may specifically be implemented in the following manner:
calculating a first data sum of a remainder of a previous period and target data; obtaining a numerical value of N contained in the first data sum; calculating a second data sum of the average number and the quantity value of the previous period, wherein the second data sum is the average number of the current period; the product of the magnitude value and N is calculated and the first data sum is subtracted to obtain the remainder for the current cycle.
For example, for the 1 st cycle, the previous cycle does not exist, that is, a preset initial remainder, that is, 0 is adopted; for the 2 nd cycle, the remainder of the previous cycle is the remainder calculated for the 1 st cycle, and so on. And the number value of N included refers to the value of the number of N in the first data and the inside, for example, 2 10 (N) in 23, 5 10 in 56, and so on. After that, the sum between the average number of the previous cycle and the number of the first data sum and the number of the N is taken as the average number of the current cycle in the present embodiment. For example, 5 data sums 56 contain 10, the average number of previous cycles is 2, and 7 obtained by adding 5 to 2 is taken as the average number of current cycles. Finally, in the present embodiment, after the product of the magnitude value and N is subtracted from the first data sum, the obtained difference is used as the remainder of the current cycle. For example, 5 data sums 56 contain 10, and the product of 56 minus 5 times 10 yields the difference 6, which is the remainder of the current cycle.
Alternatively, the current computing unit 503 may also be implemented by:
calculating a first data sum of a remainder of a previous period and target data; judging the size between the first data sum and the sum of M N, wherein M is a natural number which is greater than or equal to 0; if the first data sum is larger than the sum of M and N and smaller than the sum of M plus 1N, calculating the average number of the previous period and the second data sum of M, wherein the second data sum is the average number of the current period; the product of M and N is calculated and the first data sum is subtracted to obtain the remainder of the current cycle.
For example, for the 1 st cycle, the previous cycle does not exist, that is, a preset initial remainder, that is, 0 is adopted; for the 2 nd cycle, the remainder of the previous cycle is the remainder calculated for the 1 st cycle, and so on. In a specific implementation, the current calculating unit 503 sums the first data with 0, N, 2N, and 3N in sequence. . . M N compares the magnitude, and accordingly, if the first data sum is greater than the sum of M N and less than the sum of M plus 1N, M is determined. For example, the first data sum 56 is greater than 5 sums of 10 and less than 6 sums of 10, where M is 5. After that, the sum between the average number of the previous period and M is taken as the average number of the current period in the present embodiment. For example, when the sum of the first data 56 is greater than 5 and 10 and less than 6 and 10, the average number of previous cycles is 2, and 7 obtained by adding 2 to 5 is taken as the average number of current cycles. Finally, in the present embodiment, after the product of M and N is subtracted from the first data sum, the obtained difference is used as the remainder of the current period. For example, when the first data sum 56 is greater than 5 and 10 and less than 6 and 10, the product of 5 minus 5 multiplied by 10 is obtained, and the difference 6 is the remainder of the current cycle.
Referring to fig. 7, a schematic structural diagram of an electronic device according to a third embodiment of the present disclosure is provided, where the electronic device may be a computer or a server capable of calculating line data, and is mainly used for calculating an average number and a remainder of each data sequentially input according to a data input period in a line of data.
Specifically, the electronic device in this embodiment may include the following component structures:
a memory 701 for storing an application program and data generated by the application program;
a processor 702 for executing an application to perform the functions of: acquiring target data input in a current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1; obtaining the average of the previous period of the current period and the remainder of the previous period; and calculating the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period.
In this embodiment, the technical solution in the present application is described by taking the current cycle in the data input process as an example, and thus, the technical solution in the present application is applicable to each cycle of N data input cycles, for example, the current cycle may be the 1 st data input cycle, or may be the nth data input cycle, that is, the last data input cycle, and it can be seen that the finally obtained average number and the remainder of the current cycle are the average number and the remainder of the N data.
And, the previous cycle of the current cycle is a cycle adjacent to the current cycle, in which the average calculation has been finished, as shown in fig. 2, the previous cycle is the 2 nd cycle for the 3 rd cycle, and the previous cycle is the 6 th cycle for the 7 th cycle. The calculation of the average number and the remainder of the previous cycle can also be realized by adopting the technical scheme in the embodiment, that is, in the embodiment, the average number of the target data input in the 1 st, the 2 nd, the 3 rd to the nth data input cycle is sequentially calculated according to the sequence of the data input cycle, and finally the average number of the N data is obtained.
As can be seen from the above solutions, in the electronic device provided in the third embodiment of the present application, the target data input in each of the N data input periods and the average number calculated in the previous period of the period are calculated, and then the average number and the remainder of the data in the N data input periods can be obtained immediately after the data input is finished, so that the consumption of clock periods caused by the shift addition after the data input in one row is finished is avoided, and the efficiency of calculating the average number is improved.
In one implementation, the processor 702 may also be configured to: the initial remainder and the initial average of N data input periods are preset to be 0.
Accordingly, when the processor 702 calculates the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period, the following two ways may be specifically implemented:
in one approach, a first data sum of a remainder of a previous cycle and target data is calculated; obtaining a quantitative value of N contained in the first data sum; calculating a second data sum of the average number and the quantity value of the previous period, wherein the second data sum is the average number of the current period; the product of the magnitude value and N is calculated and the first data sum is subtracted from the product to obtain the remainder for the current cycle.
In another mode, the first data sum of the remainder of the previous period and the target data is calculated; judging the size between the first data sum and the sum of M N data sums, wherein M is a natural number which is greater than or equal to 0; if the first data sum is larger than the sum of M and N and smaller than the sum of M plus 1N, calculating the average number of the previous period and the second data sum of M, wherein the second data sum is the average number of the current period; the product of M and N is calculated and the first data sum is subtracted to obtain the remainder of the current cycle.
Based on the above technical solutions, the following exemplifies the average calculation in the specific application of the present application:
in one example, assume that any number of a row of data is less than or equal to the number of a row. For example, one line of data has a size between 0 and 255 (8 bits), with 960 data per line.
Specifically, the scheme comprises the following steps:
the ith data in a row of data is recorded as Ai, i belongs to (1, N), the number of the data in the row of data is N, namely the divisor is recorded as N;
in principle, the average number of a row of data is marked as AVG, and then AVG = ∑ Ai/N; the sum of the first i data is recorded as S =sigmaai, the remainder of the ith data input period is recorded as Si, and the average of the ith data input period is recorded as AVGi;
in this embodiment, for the data Ai input in the ith data input period, assuming that N ≧ Ai, the present applicationFirst, si = S i-1 + Ai, and then judging the sizes of Si and N;
if Si ≧ N, the average AVGi = AVG of the ith data input period i-1 (average of previous cycle) +1,si =si-N. Every data input cycle is done once;
if Si < N, then Si/AVGi remains unchanged.
Where the above execution is done once for each data input cycle.
When all data are input, AVGi is the result average, si is the remainder
As shown in table 1 below:
ai =1/2/3/4/5/5/4/3/2/1, the number N is 10, and the average is 3.
TABLE 1
Figure BDA0002068500760000121
Wherein the initial values of Si/AVGi are all 0. How to obtain the average 3 in this case will be described in detail below.
When the 1 st cycle comes, the input data is 1, and Si in this cycle is S1=1 (initial value 0+ input value 1 in this cycle). Judging whether Si is equal to or larger than N, if not, the AVGi does not maintain 1+ Si on the basis of the previous period;
when the 2 nd cycle comes, the input data is 2, and Si in this cycle is S2=3 (the value of the previous cycle is 1+ the input value of this cycle is 2). Judging whether Si is larger than or equal to N, if not, the AVGi is not plus 1 on the basis of the previous cycle, and Si is maintained for 3;
when the 3 rd cycle comes, the input data is 3, and Si in this cycle is S3=6 (the value of the previous cycle is 3+ the input value of this cycle is 3). Judging whether Si is equal to or larger than N, if not, the AVGi is not plus 1 on the basis of the previous cycle, and Si is maintained for 6;
when the 4 th cycle comes, the input data is 4, and Si in this cycle is S4=10 (previous cycle value 6+ input value 4 in this cycle). Judging whether Si is larger than or equal to N, if so, adding 1 to Si and subtracting N from 0 by AVGi on the basis of the previous period; AVG4=1/S4=0.
When the 5 th cycle comes, the input data is 5, and Si in this cycle is S5=5 (the value of the previous cycle is 0+ the input value of this cycle is 5). Judging whether Si is larger than or equal to N, if not, the AVGi does not maintain 5+ 1 on the basis of the previous period; AVG5=1/S5=5.
When the 6 th cycle comes, the input data is 5, and Si in this cycle is S6=10 (previous cycle value 5+ input value 5 in this cycle). Judging whether Si is larger than or equal to N, if so, adding 1 to Si and subtracting N from 0 by AVGi on the basis of the previous period; AVG6=2/S6=0.
When the 7 th cycle comes, the input data is 4, and Si in this cycle is S7=4 (the value of the previous cycle is 0+ the input value of this cycle is 4). Judging whether Si is larger than or equal to N, if not, the AVGi does not maintain 4+ 1 on the basis of the previous period; AVG7=2/S7=4.
When the 8 th cycle comes, the input data is 3, and Si in this cycle is S8=7 (the value of the previous cycle is 4+ the input value of this cycle is 3). Judging whether Si is equal to or larger than N, if not, the AVGi is not plus 1 on the basis of the previous cycle, and Si is maintained for 7; AVG8=2/S8=7.
When the 9 th cycle comes, the input data is 2, and Si in this cycle is S9=9 (previous cycle value 7+ input value 2 in this cycle). Judging whether Si is larger than or equal to N, if not, the AVGi does not maintain 9+ 1 on the basis of the previous period; AVG9=2/S9=9.
When the 10 th cycle comes, the input data is 1, and Si in this cycle is S10=10 (the value of the previous cycle is 9+ the input value of this cycle is 1). Judging whether Si is larger than or equal to N, if so, adding 1 to Si and subtracting N from 0 by AVGi on the basis of the previous period; AVG10=3/S10=0.
At this point, all data is input, and an average number of 3 (AVG 10) and a remainder number of 0 are obtained (S10).
It can be seen that in the above example, the sum added for each period is compared with the number, and the value of AVG/S is updated according to the comparison result, so as to achieve the purpose that the average number can be obtained after the data input is finished.
It should be noted that the assumption that any number of one row of data is less than or equal to the number of one row in the above example is only an example. Other extensions are also within the scope of the present scheme. Such as: it is assumed that half of any number of one line of data is smaller than or equal to the number of one line, or the size between each data and the number N is not limited, and so on. Specifically, the scheme comprises the following steps:
in principle, the average number of a row of data is marked as AVG, and then AVG = ∑ Ai/N; the sum of the first i data is recorded as S =sigmaai, the remainder of the ith data input period is recorded as Si, and the average of the ith data input period is recorded as AVGi;
in this embodiment, assuming that N ≧ Ai/2 is used for data Ai input in the ith data input period, first, si = S i-1 + Ai, and then judging the multiple size of Si and N;
if Si ≧ N and Si<2N, then AVGi is at AVG i-1 Adding 1,Si = Si-N;
if Si ≧ 2N, AVGi is at AVG i-1 Adding 2,Si = Si-2N;
if Si is present<N, then AVGi holds AVG i-1 The foundation is not changed;
when all data are input, AVGi is the result quotient, and Si is the remainder.
And so on.
As shown in table 2 below:
TABLE 2
Period of time 1 2 3 4 5 6 7 8 9 10
Ai 20 15 12 13 12 20 18 16 60 18
Si 0 5 7 0 2 2 0 6 6 4
AVGi 2 3 4 6 7 9 11 12 18 20
Wherein the initial values of Si/AVGi are all 0.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The above description of the average number calculation method, the average number calculation device and the electronic device provided by the present application are provided in detail, so that those skilled in the art can implement or use the present application through the above description of the disclosed embodiments. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (5)

1. A method of average number calculation, comprising:
acquiring target data input in a current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1;
obtaining an average of a previous period of the current period and a remainder of the previous period;
calculating the target data based on the average of the previous period and the remainder of the previous period to obtain the average of the current period and the remainder of the current period;
wherein the method further comprises:
presetting that initial remainders and initial average numbers of the N data input periods are both 0;
wherein the calculating the target data based on the average number of the previous period and the remainder of the previous period to obtain the average number of the current period and the remainder of the current period comprises:
calculating a first data sum of a remainder of the previous period and the target data;
obtaining a quantitative value of the N contained in the first data sum;
calculating a second data sum of the average number of the previous period and the quantity value, wherein the second data sum is the average number of the current period;
and calculating the product of the quantity value and the N, and subtracting the product from the first data sum to obtain the remainder of the current period.
2. The method of claim 1, wherein calculating the target data based on the average of the previous period and the remainder of the previous period to obtain the average of the current period and the remainder of the current period comprises:
calculating a first data sum of a remainder of the previous period and the target data;
judging the size between the first data sum and the sum of M N, wherein M is a natural number which is greater than or equal to 0;
if the first data sum is larger than the sum of M N and the first data sum is smaller than the sum of M plus 1N, calculating the average number of the previous period and the second data sum of M, wherein the second data sum is the average number of the current period;
and calculating the product of the M and the N and subtracting the product from the first data sum to obtain the remainder of the current period.
3. An average calculation device, comprising:
the target obtaining unit is used for obtaining target data input in the current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1;
a history obtaining unit, configured to obtain an average of a previous cycle of the current cycle and a remainder of the previous cycle;
a current calculating unit, configured to calculate the target data based on the average of the previous period and a remainder of the previous period to obtain an average of the current period and a remainder of the current period;
wherein, still include:
the presetting unit is used for presetting that the initial remainder and the initial average of the N data input periods are both 0;
wherein the current computing unit is specifically configured to:
calculating a first data sum of a remainder of the previous period and the target data; obtaining a quantitative value of the N contained in the first data sum; calculating a second data sum of the average number of the previous period and the quantity value, wherein the second data sum is the average number of the current period; calculating the product of the magnitude value and the N and subtracting the product from the first data sum to obtain the remainder of the current cycle.
4. The apparatus of claim 3, wherein the current computing unit is specifically configured to:
calculating a first data sum of a remainder of the previous period and the target data; judging the size between the first data sum and the sum of M N data sums, wherein M is a natural number which is greater than or equal to 0; if the first data sum is larger than the sum of M N and the first data sum is smaller than the sum of M plus 1N, calculating the average number of the previous period and the second data sum of M, wherein the second data sum is the average number of the current period; and calculating the product of the M and the N, and subtracting the product from the first data sum to obtain the remainder of the current period.
5. An electronic device, comprising:
the memory is used for storing an application program and data generated by the running of the application program;
a processor for executing the application to perform the functions of: acquiring target data input in a current period, wherein the current period is one of N data input periods, and N is a positive integer greater than or equal to 1; presetting that the initial remainder and the initial average of the N data input periods are both 0; obtaining an average of a previous period of the current period and a remainder of the previous period; calculating a first data sum of a remainder of the previous period and the target data; obtaining a quantitative value of the N contained in the first data sum; calculating a second data sum of the average number of the previous period and the quantity value, wherein the second data sum is the average number of the current period; calculating the product of the magnitude value and the N and subtracting the product from the first data sum to obtain the remainder of the current cycle.
CN201910429418.7A 2019-05-22 2019-05-22 Average number calculation method and device and electronic equipment Active CN110110284B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910429418.7A CN110110284B (en) 2019-05-22 2019-05-22 Average number calculation method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910429418.7A CN110110284B (en) 2019-05-22 2019-05-22 Average number calculation method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN110110284A CN110110284A (en) 2019-08-09
CN110110284B true CN110110284B (en) 2023-02-07

Family

ID=67491651

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910429418.7A Active CN110110284B (en) 2019-05-22 2019-05-22 Average number calculation method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN110110284B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105824441A (en) * 2015-01-26 2016-08-03 原相科技(槟城)有限公司 Navigation device and track smoothing method thereof
CN109428598A (en) * 2017-08-30 2019-03-05 北京智云芯科技有限公司 The calibration method and system of data sampling

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3732450B2 (en) * 2002-03-19 2006-01-05 沖電気工業株式会社 Remainder calculator

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105824441A (en) * 2015-01-26 2016-08-03 原相科技(槟城)有限公司 Navigation device and track smoothing method thereof
CN109428598A (en) * 2017-08-30 2019-03-05 北京智云芯科技有限公司 The calibration method and system of data sampling

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
一种基于循环减法原理除法器的加速方法;宣淑巍等;《微电子学与计算机》;20091205(第12期);全文 *

Also Published As

Publication number Publication date
CN110110284A (en) 2019-08-09

Similar Documents

Publication Publication Date Title
CN108733347B (en) Data processing method and device
CN106681690A (en) Montgomery modular multiplication based data processing method, modular multiplication operation method and device
US7672990B2 (en) Digital computation method involving euclidean division
CN110110284B (en) Average number calculation method and device and electronic equipment
US6182100B1 (en) Method and system for performing a logarithmic estimation within a data processing system
JP3551113B2 (en) Divider
CN114003194A (en) Operation method and device based on multiplier and computer readable storage medium
EP1652066A2 (en) Methods and apparatus for extracting integer remainders
Pallister et al. Data dependent energy modelling: A worst case perspective
CN108334305B (en) Division operation method, device, equipment and storage medium
CN108319447A (en) Convenient for hard-wired Algorithm for square root
CN115129297A (en) Multi-point multiplication operation system, method, graphic processor, electronic device and equipment
CN109947393B (en) Operation method and device based on remainder device
US20180004485A1 (en) Architecture and instruction set to support interruptible floating point division
RU2214624C2 (en) Device for simulating decision taking process
CN109901931B (en) Reduction function quantity determination method, device and system
CN116225366B (en) Multiplication instruction expansion method and device applied to embedded pipeline CPU (Central processing Unit) kernel
CN111506382A (en) Progress bar curve determination method and device, storage medium and electronic equipment
CN114706557B (en) ASIC chip and implementation method and device of Montgomery modular multiplication
CN113434113B (en) Floating-point number multiply-accumulate control method and system based on static configuration digital circuit
US20090144353A1 (en) Method and apparatus for efficient modulo multiplication
CN115659380B (en) Ciphertext data fitting calculation method and device and electronic equipment
CN111400377B (en) Method and device for determining target data set
JP2006023974A (en) Remainder calculation processor and remainder calculation processing method
JP5305392B2 (en) IQ data square sum route calculation means

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant