WO2021073196A1 - 基于高精度取舍方式的误差可控的数据处理系统及方法 - Google Patents

基于高精度取舍方式的误差可控的数据处理系统及方法 Download PDF

Info

Publication number
WO2021073196A1
WO2021073196A1 PCT/CN2020/104885 CN2020104885W WO2021073196A1 WO 2021073196 A1 WO2021073196 A1 WO 2021073196A1 CN 2020104885 W CN2020104885 W CN 2020104885W WO 2021073196 A1 WO2021073196 A1 WO 2021073196A1
Authority
WO
WIPO (PCT)
Prior art keywords
calculation
module
numbers
rounding
digits
Prior art date
Application number
PCT/CN2020/104885
Other languages
English (en)
French (fr)
Inventor
汪浩
Original Assignee
汪浩
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 汪浩 filed Critical 汪浩
Publication of WO2021073196A1 publication Critical patent/WO2021073196A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2462Approximate or statistical queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/211Schema design and management

Definitions

  • the present invention relates to the technical field of data analysis, in particular to a data processing system and method with controllable errors based on high-precision selection methods.
  • Data is processed according to data sources such as databases, and it is widely used in finance, computer, chemical, telecommunications and other industries, such as bank interest rate, exchange rate calculation systems, telecommunications branch systems, and merchant analysis systems on platforms such as WeChat.
  • finance computer, chemical, telecommunications and other industries
  • bank interest rate exchange rate calculation systems
  • telecommunications branch systems and merchant analysis systems on platforms such as WeChat.
  • the application of big data has spread rapidly, and it has expanded rapidly from industries such as e-commerce and the Internet to traditional industries such as finance, government, public utilities, energy, and transportation.
  • industries such as e-commerce and the Internet
  • industries such as finance, government, public utilities, energy, and transportation.
  • JPEG uses discrete cosine transform to achieve data compression.
  • rounding is used to process the data, resulting in a higher data distortion rate.
  • the calculation of the exponential function takes up system resources.
  • the principle of approximation is mainly to determine the upper and lower rounding limits to round off the original data (such as the upper and lower rounding limits can be set to a fixed value, if set to 4 and 5 respectively, it is rounded, if the upper and lower rounding limits are respectively 4, 6 is rounding, rounding up, rounding down, etc., or the upper and lower limits of rounding can also be set to variable values, etc.), and all the above methods will inevitably occur in the processing of data Huge error, and error will produce superposition, it is difficult to achieve accurate calculation.
  • the upper and lower rounding limits can be set to a fixed value, if set to 4 and 5 respectively, it is rounded, if the upper and lower rounding limits are respectively 4, 6 is rounding, rounding up, rounding down, etc., or the upper and lower limits of rounding can also be set to variable values, etc.
  • the technical problem to be solved by the present invention is that in the current data processing practice, because a large amount of data is floating-point data, it is difficult to perform accurate calculations except for addition and subtraction, so approximate calculations occupy a dominant position in data processing. In the approximate calculation, there is almost no way to evaluate the error of the calculation result before the calculation result is available.
  • the present invention provides an error-controllable data processing device, system and method based on a high-precision selection method, and a corresponding judgment module is designed to determine the number of bits to be selected according to the input data and accuracy requirements. Reduce errors caused in the process of data processing, improve the matching and usability of statistical data, facilitate statistical data verification, and facilitate the production of statistical charts, data compression, and digital calculations.
  • an error-controllable data processing system based on a high-precision selection method, including an input module, a judgment module, an intelligent selection module, a calculation module, and an output module; Input the accuracy requirements to the judgment module, and then the raw data of the input module is processed by the intelligent selection module according to the requirements of the judgment module, and then output by the output module after being calculated by the calculation module;
  • the input module is that the operator or other systems input the original data, the accuracy requirements (that is, the final need to be accurate to the number of digits before/after the decimal point) or the number of significant digits (that is, the final number of accurate values is required), and then the judgment module Determine the number of rounding digits; or directly enter the original data and rounding requirements by the operator, directly enter the intelligent rounding module, and according to the input conditions, choose to return the original value to the intelligent rounding module, and return the accuracy requirements or effective digits to the judgment module ;
  • the judgment module judges which rounding operation needs to be performed according to the accuracy requirements or the number of significant digits provided by the operator; the intelligent selection module performs preprocessing such as marking and sorting of the input data, and selects the numbers according to the selection requirements; calculation module Call the calculation function to calculate the reserved numbers.
  • the output module selects the calculation results according to the accuracy requirements or the number
  • the specific rounding judgment of the judgment module for the multiplication is shown in Figure 4. If the precision requirement result is accurate to n d digits (if n d is a positive value, it is accurate to n d digits after the decimal point, if n Negative value of d means accurate to the decimal point
  • , n d 0 means accurate to the integer part), the original number is recorded as A 1 ⁇ 10 x1 , A 2 ⁇ 10 x2 , according to scientific notation.
  • the value of n ki can be fixed or changed as needed. For example, when there is subtraction, the maximum value can be used.
  • n k n max +r.
  • r can be fixed to a certain value as needed.
  • N y is the number of significant digits of the number with the least significant number of digits among all approximate values.
  • the intelligent selection module includes a sorting module, a storage module and a high-precision selection module.
  • the sorting module sorts the numbers according to the size of the first few digits of the number (the following takes the sorting from small to large as an example); the storage module receives the returned original value; The original data is processed by the storage module according to the requirements of the judgment module and then enters the high-precision selection module for processing, and the data processed by the high-precision selection module enters the calculation module; the storage module processing process is as follows:
  • the information entered by the input module can be stored normally in the addition and subtraction algorithm or after selection or selection;
  • the digits within the reserved digits and the lower digits are stored separately. For example, if 123456 is reserved to ten thousand digits, the original number is split into 120000 and 3456, and further according to the scientific notation, with the reserved digits as the unit, store two numbers, that is, 120000 is recorded as 12 ⁇ 10 ⁇ 4, 3456 is recorded as 0.3456 ⁇ 10 ⁇ 4, and the two numbers are marked as a i ⁇ 10 ⁇ n, b i ⁇ 10 ⁇ n(b i ⁇ 1);
  • the storage module will gradually meet or obtain the total number according to the steps to make a judgment.
  • the number of arithmetic and the number of calculation steps can be stored in the storage module, which can be recorded as N and M respectively,
  • (Dividend) and divisor such as 350000 as 35 ⁇ 10 ⁇ 4, 4321 as 0.4321 ⁇ 10 ⁇ 4; 120000 as 12 ⁇ 10 ⁇ 4, 3456 as 0.3456 ⁇ 10 ⁇ 4; 230000 and 4567 as 23 respectively ⁇ 10 ⁇ 4 and 0.4567 ⁇ 10 ⁇ 4, and mark each number according to the algorithm, such as mi ⁇ 10 ⁇ n, mti ⁇ 10 ⁇ n (multiplier or dividend) and dj ⁇ 10 ⁇ n, dtj ⁇ 10 ⁇ n (divisor);
  • split is mainly for the convenience of description in this description. In practice, the split can be carried out in the ordering, selection and other links.
  • the rounding digits can be rationally adjusted, and the adjustment methods include but are not limited to the following steps:
  • the record returns nj>0 times or the number of operations is count1, and the total number of calculations or operations is count2.
  • thr1/2 is a threshold determined according to the actual work. When it exceeds/belows this threshold, the retention accuracy is appropriately increased or decreased to reduce the number of returns n j or reduce the amount of single operation, the same below.
  • the processing process is as follows:
  • the high-precision selection module has the following processing process:
  • the original number is retained as (m i +1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i -1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • the original number is retained as (m i -1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i +1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • multipliers (dividends) and keep them as (m i -1) ⁇ 10 ⁇ n, or
  • the number remains as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • Example 7-10 See Example 7-10 for the partial implementation of other selection order.
  • the above-mentioned selection method is also applicable to addition and subtraction.
  • the divisor corresponds to the subtraction
  • the multiplier or the dividend corresponds to other numbers, and there is no need to sort in addition and subtraction, but the decimal point needs to be aligned.
  • Sorting is mainly to reduce the limit error generated by the operation. If it is not sorted (for example, it is not sorted in a mixed operation), it can be considered as a special skipping method.
  • numbers are adjusted, and the other numbers are kept as m i ⁇ 10 ⁇ n, or d j ⁇ 10 ⁇ n.
  • the original number is retained as (m i +1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i -1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • the original number is retained as (m i -1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i +1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • multipliers (dividends) and keep them as (m i -1) ⁇ 10 ⁇ n, or
  • the number remains as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • the adjustment can also start from the middle at this time; you can start from the two ends, and you can round to the middle from the smallest/maximum ends of the sequence respectively; you can also use skipping choices to make the numbers that need to be adjusted relatively even.
  • the distribution is in all figures.
  • the calculation module calls the calculation function to calculate the retained number.
  • different calculation ideas can be adopted according to different application environments. For example, for multi-digit multiplication and division calculations such as bank compound interest, in order to ensure that the calculation is accurate to specific digits, the following two calculation ideas can be used:
  • o 3 is a parameter related to o 1 and o 2.
  • n k is a certain value.
  • it can also be grouped according to calculation steps, or numbers and steps can be mixed and grouped calculations.
  • the error analysis module is a closeable module. If the module is closed, the calculation result will directly enter the output module. If the calculation result needs to be verified, it will be post-installed.
  • the error analysis module can have but not limited to the following implementation methods:
  • N k n k .
  • the error analysis module also includes a pre-error analysis module:
  • the first n y digits in the formula can be artificially determined to be estimated, and the n j value is returned according to the first n y digits of the calculation result.
  • the magnitude of the calculation result can be estimated for judgment. It can also be determined to keep the first n y bits in the calculation formula for estimation.
  • the number and/or method of the number and/or the number to be selected is judged according to the sum and difference of the low-order digits.
  • the accuracy of the selection is higher and it is more conducive to reducing the data processing process.
  • the error caused by the conventional rounding method reduces the data error caused by the data processing, improves the consistency and usability of the statistical data, and makes the data processing result more accurate.
  • It has a pre-check module, which can quickly determine the number of reserved bits according to the calculation result, and then call the stored data for selection and calculation.
  • the system has a wide range of applications. In addition to computer software and hardware implementation, it can also be migrated to all transferable ranges, such as data compression processing, statistical chart production, financial banking data calculation, and promotion of the use of statistical data Wait.
  • Fig. 1 is a block diagram of the processing system of the first embodiment.
  • Fig. 2 is a block diagram of the processing system of the twelfth embodiment.
  • Fig. 3 is a block diagram of a processing system for multiple numbers in the twelfth embodiment.
  • Figure 4 is a flow chart of the specific rounding judgment of the judgment module for multiplication.
  • Figure 5 is a flow chart of the specific rounding judgment of the judgment module for division.
  • Fig. 6 is a specific rounding judgment flow chart of the judgment module for the mixed multiplication and division operation.
  • Figure 7 is a specific rounding judgment flow chart of the judgment module when the number of significant digits is given.
  • the input module inputs the accuracy requirements or the number of significant digits to the judgment module, and then the raw data of the input module is judged according to the intelligent selection module
  • the processing of the module's requirements will be output by the output module after being calculated by the calculation module;
  • the input module is to input raw data, accuracy requirements or effective digits, and then the judgment module determines the rounding digits; or the operator directly enters the raw data and rounding requirements, directly enters the intelligent rounding module, and according to the input situation , Choose to return the original value to the smart selection module, and return the accuracy requirements to the judgment module; the judgment module determines which rounding operation needs to be performed according to the accuracy requirements provided by the operator; the smart selection module preprocesses the input data and follows the selection requirements The number is selected; the calculation module calls the calculation function to calculate the reserved number; the output module selects the calculation result according to the accuracy requirements, and then outputs the calculation result.
  • the judgment module's rounding judgment for multiplication is as follows.
  • the value of n ki can be fixed or changed as needed. For example, when there is subtraction, the maximum value can be used.
  • n k n max +r.
  • r is a variable value, which can be selected according to the requirements of calculation accuracy (it can be a positive value, a negative value or zero).
  • N y is the number of significant digits of the number with the least significant number of digits among all approximate values.
  • thr1 0.02
  • thr2 0
  • n j return times 100
  • r is the initial value 1.
  • the intelligent selection module includes a sorting module, a storage module, and a high-precision selection module.
  • the sorting module sorts the numbers according to the size of the first few digits (the following is an example of sorting from small to large); the storage module receives The original value returned; the original data is processed by the storage module according to the requirements of the judgment module and then enters the high-precision selection module for processing, and the data processed by the high-precision selection module enters the calculation module; the storage module processing process is as follows:
  • the information entered by the input module can be stored normally in the addition and subtraction algorithm or after selection or selection;
  • the digits within the reserved digits and the lower digits are stored separately. For example, if 123456 is reserved to ten thousand digits, the original number is split into 120000 and 3456, and further according to the scientific notation, with the reserved digits as the unit, store two numbers, that is, 120000 is recorded as 12 ⁇ 10 ⁇ 4, 3456 is recorded as 0.3456 ⁇ 10 ⁇ 4, and the two numbers are marked as a i ⁇ 10 ⁇ n, b i ⁇ 10 ⁇ n(b i ⁇ 1);
  • the storage module will gradually meet or obtain the total number according to the steps to make a judgment.
  • the number of arithmetic and the number of calculation steps can be stored in the storage module, which can be recorded as N and M respectively,
  • N y the number of significant digits with the lowest number of significant digits in the approximate value is recorded as N y .
  • (Dividend) and divisor such as 350000 as 35 ⁇ 10 ⁇ 4, 4321 as 0.4321 ⁇ 10 ⁇ 4; 120000 as 12 ⁇ 10 ⁇ 4, 3456 as 0.3456 ⁇ 10 ⁇ 4; 230000 and 4567 as 23 respectively ⁇ 10 ⁇ 4 and 0.4567 ⁇ 10 ⁇ 4, and mark each number according to the algorithm, such as mi ⁇ 10 ⁇ n, mti ⁇ 10 ⁇ n (multiplier or dividend) and dj ⁇ 10 ⁇ n, dtj ⁇ 10 ⁇ n (divisor);
  • split is mainly for the convenience of description in this description. In practice, the split can be carried out in the ordering, selection and other links.
  • the rounding digits can be rationally adjusted, and the adjustment methods include but are not limited to the following steps:
  • the record returns nj>0 times or the number of operations is count1, and the total number of calculations or operations is count2.
  • thr1/2 is a threshold determined according to the actual work. When it exceeds/belows this threshold, the retention accuracy is appropriately increased or decreased to reduce the number of returns n j or reduce the amount of single operation.
  • the intelligent selection module includes a sorting module, a storage module, and a high-precision selection module.
  • the sorting module sorts the numbers according to the size of the first few digits (the following is an example of sorting from small to large); the storage module receives The original value returned; the original data is processed by the storage module according to the requirements of the judgment module and then enters the high-precision selection module for processing, and the data processed by the high-precision selection module enters the calculation module; the storage module processing process is as follows:
  • the information entered by the input module can be stored normally in the addition and subtraction algorithm or after selection or selection;
  • the storage module will gradually meet or obtain the total number according to the steps to make a judgment.
  • the number of arithmetic and the number of calculation steps can be stored in the storage module, which can be recorded as N and M respectively,
  • N y the number of significant digits with the lowest number of significant digits in the approximate value is recorded as N y .
  • the rounding digits can be rationally adjusted, and the adjustment methods include but are not limited to the following steps:
  • thr1/2 is a threshold determined according to the actual work. When it exceeds/belows this threshold, the retention accuracy is appropriately increased or decreased to reduce the number of returns n j or reduce the amount of single operation.
  • the intelligent selection module includes a sorting module, a storage module, and a high-precision selection module.
  • the sorting module sorts the numbers according to the size of the first few digits (the following is an example of sorting from small to large); the storage module receives The original value returned; the original data is processed by the storage module according to the requirements of the judgment module and then enters the high-precision selection module for processing, and the data processed by the high-precision selection module enters the calculation module; the storage module processing process is as follows:
  • the information entered by the input module can be stored normally in the addition and subtraction algorithm or after selection or selection;
  • the storage module will gradually meet or obtain the total number according to the steps to make a judgment.
  • N the number of arithmetic is stored in the storage module, denoted as N,
  • N y the number of significant digits with the lowest number of significant digits in the approximate value is recorded as N y .
  • the numbers that need to be reserved within the digits and the lower digits are split, and further according to the scientific notation, the digits are reserved
  • the number is the unit, store each number, and use symbols/letters to mark the multiplier (dividend) and divisor separately, and mark each number according to the algorithm, such as mi ⁇ 10 ⁇ n, mti ⁇ 10 ⁇ n (multiply Number or dividend) and dj ⁇ 10 ⁇ n, dtj ⁇ 10 ⁇ n (divisor);
  • the high-precision round-off module rounds the original number according to the rounding requirements when processing two-digit operations.
  • the processing process is as follows:
  • the processing process of the high-precision selection module is as follows:
  • the high-precision round-off module processes the original numbers according to the rounding requirements during multi-digit operations.
  • the processing process is as follows:
  • the original number is retained as (m i +1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i -1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • the original number is retained as (m i -1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i +1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • multipliers (dividends) and keep them as (m i -1) ⁇ 10 ⁇ n, or
  • the number remains as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • the high-precision round-off module processes the original numbers according to the rounding requirements during multi-digit operations.
  • the processing process is as follows:
  • the high-precision round-off module processes the original numbers according to the rounding requirements during multi-digit operations.
  • the processing process is as follows:
  • the original number is retained as (m i +1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i -1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • the original number is retained as (m i -1) ⁇ 10 ⁇ n
  • the original number is a divisor
  • the original number is retained as (d i +1) ⁇ 10 ⁇ n
  • other numbers are reserved as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • multipliers (dividends) and keep them as (m i -1) ⁇ 10 ⁇ n, or
  • the number remains as m i ⁇ 10 ⁇ n or d j ⁇ 10 ⁇ n.
  • the high-precision round-off module processes the original numbers according to the rounding requirements during multi-digit operations.
  • the processing process is as follows:
  • the processing process includes but is not limited to the following methods:
  • each group o 1 2 formulas, that is, the original formula is transformed into (14710 ⁇ 21310)( ⁇ 32350 ⁇ 44310)( ⁇ 54830 ⁇ 63120)( ⁇ 78290 ⁇ 81240) ⁇ 93210.
  • the processing process includes but is not limited to the following methods:
  • n k is a certain value.
  • it can also be grouped according to calculation steps, or mixed grouping calculations.
  • the calculation is grouped by step: 14710 ⁇ 21310 ⁇ 32350 ⁇ 44310-54830 ⁇ 63120 ⁇ 78290 ⁇ 81240 ⁇ 93210.
  • the original formula is divided into two steps (first calculation of multiplication and division, and then calculation of addition and subtraction) , Keep 3 digits for calculation, the original formula is transformed into
  • an error analysis module is also included between the calculation module and the output module;
  • the error analysis module is a closeable module. If the module is closed, the calculation result will directly enter the output module. If the calculation result needs to be verified, it will enter the error analysis module.
  • the error analysis module is divided into rough error analysis mode or precise error analysis mode:
  • the rough error analysis mode processing process is as follows:
  • the error analysis module is a closeable module. If the module is closed, the calculation result will directly enter the output module. If the calculation result needs to be verified, the post-error analysis module can have but not limited to the following implementation methods:
  • N k n k .
  • the error analysis module further includes a pre-error analysis module:
  • An error-controllable data processing method based on a high-precision selection method uses the data processing system of any one of Embodiments 1-14 to perform accuracy judgment, calculation, selection, and output of data.
  • the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention may adopt a complete hardware embodiment, a complete software embodiment, or a combination of software and hardware embodiments, and may even include forms such as written arithmetic or mental arithmetic with the aid of the system. Moreover, the present invention may be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program codes.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block and/or multiple blocks in the block diagram.
  • These computer program instructions can also be loaded on a computer and/or other programmable data processing equipment, so that the instructions executed on the computer and/or other programmable equipment are provided for implementing a flow in the flowchart and/or multiple flows and / Or block diagram a block and/or steps of functions specified in a plurality of blocks.

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Probability & Statistics with Applications (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Fuzzy Systems (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Complex Calculations (AREA)

Abstract

涉及数据分析技术领域,一种基于高精度取舍方式的误差可控的数据处理系统及方法。包括输入模块、判断模块、智能取舍模块、计算模块和输出模块;由输入模块向判断模块输入精度要求(即最终需要精确到小数点前/后第几位)或有效数字位数(即最终需要几位精确值),然后输入模块的原始数据经由智能取舍模块按照判断模块的要求处理,经由计算模块计算后由输出模块输出。设计了对应的判断模块,能够根据输入数据及精度要求判断需要取舍的位数,减小数据处理过程中造成的误差,提高统计数据的匹配性和可用性,方便统计数据核对,有利于统计图表的制作,数据压缩及数字计算等。

Description

基于高精度取舍方式的误差可控的数据处理系统及方法 技术领域
本发明涉及数据分析技术领域,尤其涉及一种基于高精度取舍方式的误差可控的数据处理系统及方法。
背景技术
根据数据库等数据来源对数据进行处理,在金融、计算机、化工、电信等行业有着广泛应用,例如银行利率、汇率计算系统,电信的经分系统、微信等平台的商户分析系统等。近几年,大数据应用快速普及,并从电子商务、互联网等行业向传统的金融、政府、公共事业、能源、交通等行业快速扩展。而随着大数据应用在金融、计算机、电信、政府、公共事业、能源、交通、制造等行业的普及,如何合理的开展大数据分析业务、管理和利用海量数据成为各行各业的关键问题,就意味着各行业对数据处理的要求也越来越高。
同时,基础科研对于计算能力要求越来越高,如天气预报、借助密度泛函理论的第一性原理计算,对数据的处理动辄以小时、甚至以月为单位,运算量非常巨大,且对运算精度要求非常之高。
而如果统计数据不准,分析方式不可靠,统计数据就会失真,进而导致统计分析出错,监督失责:
①数据处理对金融银行业的重要性。在现代,银行的业务越来越广泛,然而在货币兑换、利润计算等领域仍然普遍存在着近似计算,例如由于目前银行业主要借助四舍五入法进行近似计算,业务量又巨大,导致误差较大。
②数据处理对计算机领域的重要性。比如数据压缩方面,JPEG利用离散余弦变换来实现数据压缩,在压缩过程中,采用四舍五入对数据进行处理,从而造成数据失真率较高。以及对幂指函数进行计算时占用系统资源较大。
③基础科研数据计算量巨大,对于计算精度要求高,采用传统方式耗时久。
④数据处理对企业数据的重要性。在现代企业的经营管理中,涉及的数据错综复杂,企业数据包含各类信息,如不进行仔细的分类和处理将无法实现企业的有序经营,这将会制约企业的整体发展。由此可见,数据统计、数据处理对提高企业数据分类和处理能力具有重要作用,是满足企业经营管理的实际需要。
除此之外,提高统计数据质量、改善数据处理方法几乎是各行各业的重点问题。而目前数据处理实践中,由于大量数据为浮点数据,除加减法外很难做到精确计算,所以近似计算便在数据处理中占据了主导地位。而在近似计算中,目前主要有两种技术手段:
①直接利用人工选取或程序软件进行近似处理。而近似的原理主要是以确定的舍入上下限对原始数据进行取舍(如舍入上下限可设定为固定值,如分别设定为4、5时即四舍五入,若舍入上下限分别为4、6时即四舍六入,向上取整,向下取整等,或舍入上下限也可设定为变化值等方式),而上述所有方法在处理数据中均不可避免的会发生巨大的误差,且误差会产生叠加,难以做到精准计算。
②根据计算的真实结果对误差进行校正,而这种方法无疑会占用大量计算空间,跟真实计算并无二致,尤其是对于除法等运算几乎毫无帮助。
除此之外,目前的数据处理系统中,在计算结果出来之前,几乎没有方法评估计算结果的误差。因此,提高计算精度,改善数据处理方式既是重点,也是各行各业亟待解决的难点。
发明内容
本发明要解决的技术问题是目前数据处理实践中,由于大量数据为浮点数据,除加减法外很难做到精确计算,所以近似计算便在数据处理中占据了主导地位。而在近似计算中在计算结果出来之前,几乎没有方法评估计算结果的误差。
为解决上述问题,本发明提供了一种基于高精度取舍方式的误差可控的数据处理装置、系统及方法,设计了对应的判断模块,能够根据输入数据及精度要求判断需要取舍的位数,减小数据处理过程中造成的误差,提高统计数据的匹配性和可用性,方便统计数据核对,有利于统计图表的制作,数据压缩及数字计算等。
为达到上述目的,本发明具体通过以下技术手段实现:一种基于高精度取舍方式的误差可控的数据处理系统,包括输入模块、判断模块、智能取舍模块、计算模块和输出模块;由输入模块向判断模块输入精度要求,然后输入模块的原始数据经由智能取舍模块按照判断模块的要求处理,经由计算模块计算后由输出模块输出;
其中,输入模块为由操作者或其他系统输入原始数据、精度要求(即最终需要精确到小数点前/后第几位)或有效数字位数(即最终需要几位精确值),然后由判断模块判断舍入位数;或直接由操作者输入原始数据及舍入要求,直接进入智能取舍模块,并根据输入情况,选择返回原始值至智能取舍模块,返回精度要求或有效数字位数至判断模块;判断模块根据操作者提供的精度要求或有效数字位数,判断需要进行何种舍入操作;智能取舍模块为对输入数据进行标记、排序等预处理、按照取舍要求对数字进行取舍;计算模块调用计算功能对保留后的数字进行计算,同时,为了提高计算精确度,根据不同的应用环境,可采用不同的计算思路;输出模块按照精度要求或有效数字位数对计算结果进行取舍,接着输出计算结果。
进一步的,若输入精度要求,判断模块对于乘法的具体舍入判断如图4所示,若精度要求结果精确至n d位(若n d为正值表示精确至小数点后n d位,若n d为负值则表示精确至小数点前|n d|位,n d=0则表示精确至整数部分),将原数字按照科学计数法记作A 1×10 x1、A 2×10 x2、...、A i×10 xi,判断n j=0(n j为校正位数,为校验不通过时返回的一个大于0的数)时,保留位数(n k)=x1+x2...+xi+n d+i+r;判断n j≠0,n k=x1+x2...+xi+n d+i+n j+r。对于乘除混合的舍入判断如图6所示,若精度要求结果精确至n d位,将乘数、被除数按科学计数法记作m 1×10 x1、m 2×10 x2...m i×10 xi,除数记作d 1×10 Y1、d 2×10 Y2...d j×10 Yj;判断n j=0时,n k=x1+x2...+xi-Y1-Y2...-Yj+i+n d+r;判断n j≠0,n k=x1+x2...+xi-Y1-Y2...-Yj+i+n d+n j+r。
其中,简单除法即为i=j=1时乘除混合运算的特殊情况。
进一步的,若输入有效数字位数,判断模块对于乘除法的具体舍入判断如图7所示,若要求计算结果前n x位为精确值,判断n j=0时,n k=n x+r;判断n j≠0,n k=n x+n j+r。
进一步的,若参与运算的为加减乘除混合运算时,可根据图6求得每组乘除运算的n k,并取其中的某个值(n ki),接着返回n k=n ki或按照(64)进行判断;也可按照上述方式分别求得每组乘除运算的n k,并对每组运算分开取舍。
其中n ki的取值可根据需要固定也可变化,如存在减法时可取其中最大值等。
进一步的,若参与运算的原始数字中存在近似值,可按上述方式进行判断,或在按照上述方式判断出n k之后,若n k≤N y+r,正常返回n k,否则返回n k=N y+r。
在加法运算中n k=n max+r。
r为可变值,可根据计算精度的要求取值(可为正值、负值或零)。如:在启用精确校验模块,为保证计算精确无误,r初始值可取为r=2,并根据319-320步骤或人为进行合理化调整;在进行近似计算时,根据精度要求,取r=1或r=2等;在专门针对多数字乘除的处理系统中,r初始值可取为r=2,同时可引入算数个数对r的影响,如r=C+{[log o1N] 取整/o 2} (其中o1、o2为涉及到多数字运算时的纠正参数,C为根据运算需要确定的参数,如当o1、o2较小时C可取为1,这三个参数均可根据计算误差进行人为规定),或根据具体运算步骤与需要给r赋值,如一个计算分为M个步骤,则r可赋值为r=1+M/o 2等,在加法运算中r=C+[lgN],并在必要时进行调整(见319-320)。在复杂加减乘除混合运算中r可根据需要固定为某值。
其中N y为所有近似值中有效数字位数最少的数字的有效数字位数。
进一步的,智能取舍模块包括排序模块、存储模块和高精度取舍模块,排序模块对数字按照数字前几位的大小进行排序(以下以从小到大排序为例);存储模块接收返回的原始值;原始数据经存储模块按照判断模块的要求处理后进入高精度取舍模块处理,高精度 取舍模块处理后的数据进入计算模块;存储模块处理过程如下:
(311)将输入模块输入的信息可在加减算法中正常存储原数字或取舍后再存储;
(312)在两数乘除法运算中,根据舍入位数的要求,将需要保留位数以内的数字及更低位的数字进行分别存储,如对123456保留至万位,即将原数字拆分为120000与3456,并进一步的根据科学计数法,以保留位数为单位,存储两数,即120000记作12×10^4,3456记作0.3456×10^4,将两数分别标记为a i×10^n,b i×10^n(b i<1);
(313)需要时可记录运算中出现的数量级最高的数字所对应的数量级(n max)等数据。
(314)两数相乘中,求得两数字b i的和,并将该和按照给定的舍入上下限取整(如四舍五入、四舍六入等),记作n
(315)两数相除中,求得两数字b i的差,并将该差按照给定的舍入上下限取整,记作n
进一步的,存储模块在多步计算中,根据步骤逐步满足或求得总数进而予以判断,
进一步的,为后续操作方便,可在存储模块中存入算数的个数、运算步骤数,可分别记作N、M,
进一步的,若参与运算的数字存在近似值,记录近似值中有效位数最低的数字的有效数字位数为N y
(316)在多步乘除法运算中,根据舍入位数的要求及运算法则,将需要保留位数以内的数字及更低位的数字进行拆分,如对354321×123456÷234567保留至万位,即将原数字分别拆分为350000与4321,120000与3456,230000与4567,并进一步的根据科学计数法,以保留位数为单位,存储各数,并利用符号/字母等方式分别标记乘数(被除数)及除数,如350000记作35×10^4,4321记作0.4321×10^4;120000记作12×10^4,3456记作0.3456×10^4;230000与4567分别记作23×10^4与0.4567×10^4,并按照运算法则标记各数字,如标记为mi×10^n,mti×10^n(乘数或被除数)及dj×10^n,dtj×10^n(除数);
注:拆分主要是为本说明方便进行描述,在实践中可在排序、取舍等环节再进行拆分。
(317)在多步乘除法运算中,按照mi或dj的大小进行排序,如对354321×123456÷234567排序后,顺序为12(3456),23(4567),35(4321);
(317)在多步乘除法运算中,若采取先乘后除的运算结合方式,则先按照运算法则进行分类,接着对其中的乘数(被除数)、除数分别排序,如对354321×123456÷234567排序后,顺序为m1=12,m2=35,d1=23;
(318)在多步加减乘除混合运算中,按照运算优先级,先按316-317步骤对其中乘除法进行取舍,接着对其中加减法进行取舍,或对其中加减法进行精确计算。
进一步的,可以对舍入位数进行合理化调整,调整方式包括但不限于如下步骤:
(319)记录返回nj>0次数或运算次数为count1,总的计算次数或运算次数为count2。当count2大于或等于某一给定值时,若count1÷count2>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值或校验频率,且令count1=0,count2=0;若count1÷count2≤thr2时令r=r-1或调整o 2、o 1等一个或多个参数值或校验频率,且令count1=0,count2=0;
其中:thr1/2为根据工作实际确定的阈值,当超过/低于这一阈值,保留精度进行适当提高或降低,以减小返回n j次数或降低单次运算量,下同。
对舍入位数进行调整的步骤如下:
(319)记录总的计算时间为T1,不返回n j>0的计算时间为T2,当T1大于或等于某一给定值时。若T1÷T2>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值或校验频率,且令T1=0,T2=0;若T1÷T2<=thr2时令r=r-1或调整o 2、o 1等一个或多个参数值或校验频率,且令T1=0,T2=0;
若需要对r、o 2、o 1进行精确调整,可开启自适应模式:
(320)以原始数据进行计算并完成取舍,若取舍结果与本系统计算结果不同,则修改标记+1,在给定数据的计算中,当标记数>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值;若标记数<=thr2时令r=r-1或调整o 2、o 1等一个或多个参数值。
进一步的,高精度取舍模块为了提高乘除法计算的精度,舍入方式不进行简单的四舍五入或四舍六入,这是因为四舍五入之类的舍入方式在计算乘除法时误差偏大,且误差会叠加。比如,当计算15*15=225时,若保留1位进行计算,原式将转化为20*20=400,实际值(225)跟估算值(400)之间差距过大,难以满足对于误差控制的要求。因此,为了兼顾计算精度及计算速度,对于乘除法的取舍应根据其取舍位的和或差进行取舍判断,处理过程如下:
(321)加减法运算直接跳入计算模块进行精确计算,或取舍后进入计算模块。
(322)在两数相乘中,若n =0,则将两数保留为a i×10^n进行计算即可。比如12.1×16.1,若只保留至整数部分进行计算,则两数b i=0.1,两数b i的和为0.2,舍入后(即根据需要选择四舍五入或四舍六入,下同)n =0(以下除特殊说明,均以四舍五入为例),则12.1×16.1转化为12×16;
(323)在两数相乘中,若n =2,则将两数保留为(a i+1)×10^n进行计算即可。比如12.8×16.8,若只保留至整数部分进行计算,则两数b i=0.8,两数b i的和为1.6,舍入后n =2,则12.8×16.8转化为13×17;
(324)在两数相乘中,若n =1,接着比较两数a i的大小,a i小的数字按照舍入上下 限正常舍入,另一个数字反向取舍。比如12.6×16.6,若只保留至整数部分进行计算,则两数b i=0.6,两数b i的和为1.2,舍入后n =1,则12.6×16.6转化为13×16。
(325)在两数相除中,若n =0,接着比较两数a i的大小,a i小的数字按照舍入上下限正常舍入,另一个数字同向取舍。比如12.4÷16.6,若只保留至整数部分进行计算,则两数b i分别为0.4与0.6,b i的差为0.2,舍入后n =0,则12.4÷16.6转化为12÷16。
(326)在两数相除中,若n ≠0,进行正常舍入。
进一步的,高精度取舍模块为了提高乘除法计算的精度,处理过程如下:
(321)加减法运算直接跳入计算模块进行精确计算,或取舍后进入计算模块。
(322)在两数相乘中,若n =1,接着比较两数a i的大小,a i小的数字按照舍入上下限正常舍入,另一个数字反向取舍。比如12.6×16.6,若只保留至整数部分进行计算,则两数bi=0.6,两数bi的和为1.2,舍入后n =1,则12.6×16.6转化为13×16。
(323)在两数相乘中,若n ≠1,进行正常舍入。
(324)在两数相除中,若n =0,接着比较两数a i的大小,a i小的数字按照舍入上下限正常舍入,另一个数字同向取舍。比如12.4÷16.6,若只保留至整数部分进行计算,则两数b i分别为0.4与0.6,b i的差为0.2,舍入后n =0,则12.4÷16.6转化为12÷16。
(325)在两数相除中,若n ≠0,进行正常舍入。
(331)在多数字乘除运算中,若数字未分类,首先求得
Figure PCTCN2020104885-appb-000001
注:其中|no|为需要进行调整数字的个数,其他数字均保留为m i×10^n及d i×10^n。
若no=0,则所有数字保留为m i×10^n及d i×10^n。
若no>0,且该数字为乘数(被除数),则原数保留为(m i+1)×10^n,若原数为除数,则原数保留为(d i-1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中no个乘数(被除数),将其保留为(m i+1)×10^n,或no个除数,保留为(d i-1)×10^n,其他数字保留为m i×10^n或d j×10^n。
若no<0,且该数字为乘数(被除数),则原数保留为(m i-1)×10^n,若原数为除数,则原数保留为(d i+1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中|no|个乘数(被除数),将其保留为(m i-1)×10^n,或|no|个除数,保留为(d i+1)×10^n,其他数字保留为m i×10^n或d j×10^n。
(332)在多数字乘除运算中,若未按照运算法则对数字分类,若从中间开始取舍,求得fr=(i+j-|no|)/2+1。在(i+j-|no|)/2非整数时可根据需要进行取整。
注:这里主要列举了从中间开始取舍,除从中间开始进行取舍之外,也可从两端进行取舍,甚至可以包括跳跃式取舍。
(333)按m i及d j的大小顺序,若从中间开始取舍,对m i×10^n、d j×10^n中的数字进行舍入:对其中第fr往后no个数字做出调整;若从两头开始,则分别从序列最小/最大两端向中间进行取整;若采取跳跃式取舍,则将需要调整的数字相对均匀的分布在所有数字中:
(334)若从中间开始调整,如
1201000010007×0.0001202×12.0300010×0.0001204÷120500072÷0.0000000012060031×0.12070001÷120.8×0.1209≈173.81,若保留前三位,其no=1则原式将转化为:
1200000000000×0.000120×12.0×0.000120÷119000000÷0.00000000120×0.120÷120×0.120≈174.25。
注:其他取舍顺序的部分实现方式见实施例7-10。且上述取舍方式同样适用于加减法,在加减法中除数对应减数,乘数或被除数对应其他数字,且加减法运算中无需排序,但需对齐小数点。而在混合运算中需按照运算优先级逐级结合。排序主要是为了降低运算产生的极限误差,如不进行排序(如混合运算中不进行排序)可被认为是一种特殊的跳跃取舍方式。
(331)在多数字乘除运算中,若数字未分类,则依次(按m i及d j的大小顺序,如从小到大,下同)求得mt i、(-dt j)的加和,并将该结果按照设定的舍入上下限进行取整,若取整结果与先前不同,则对应将m i×10^n保留为(m i+1)×10^n,或将d j×10^n保留为(d j+1)×10^n。
(332)如
12010000100×0.0001202×12.030001×0.0001204÷12050007÷0.0000000012060031×0.12070001÷120.8×0.1209≈173.81,若保留前三位原式将转化为:
120000000000×0.00012×12.1×0.00012÷120000000÷0.00000000121×0.121÷121×0.121≈174.24。
(331)在多数字乘除运算中,若按照运算法则等对数字分类,首先求得每组分类中的
Figure PCTCN2020104885-appb-000002
(332)在每组分类中其中|no|个数字进行调整,其他数字均保留为m i×10^n,或d j×10^n。
若no=0,则所有数字保留为m i×10^n及d i×10^n。
若no>0,且该数字为乘数(被除数),则原数保留为(m i+1)×10^n,若原数为除数,则原数保留为(d i-1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其 中no个乘数(被除数),将其保留为(m i+1)×10^n,或no个除数,保留为(d i-1)×10^n,其他数字保留为m i×10^n或d j×10^n。
若no<0,且该数字为乘数(被除数),则原数保留为(m i-1)×10^n,若原数为除数,则原数保留为(d i+1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中|no|个乘数(被除数),将其保留为(m i-1)×10^n,或|no|个除数,保留为(d i+1)×10^n,其他数字保留为m i×10^n或d j×10^n。
(332)同样,此时调整也可从中间开始取舍;可从两头开始,可分别从序列最小/最大两端向中间进行取整;还可采取跳跃式取舍,可将需要调整的数字相对均匀的分布在所有数字中。
(333)如
1201000010007×0.0001202×12.0300010×0.0001204×120500072×0.0000000012060031÷0.12070001÷120.8÷0.1209≈17237.52,中no=0,若保留前三位原式将转化为:
1200000000000×0.00012×12×0.00012×120000000×0.0000000012÷0.12÷120÷0.120≈17280。
(331)在多数字乘除运算中,若按照运算法则等对数字分类,则在每组分类中依次(按m i及d j的大小从小到大)求得mt i、(-dt j)的加和,并将该结果按照设定的舍入上下限进行取整,若取整结果与先前不同,则对应将m i×10^n保留为(m i+1)×10^n,或将d j×10^n保留为(d j+1)×10^n。
(332)如
1201000010007×0.0001202×12.0300010×0.0001204×120500072×0.0000000012060031÷0.12070001÷120.8÷0.1209≈17237.52,若保留前三位原式将转化为:
1200000000000×0.00012×12.1×0.00012×121000000×0.0000000012÷0.121÷121÷0.12≈17280。
进一步的,计算模块即调用计算功能对保留后的数字进行计算。同时,为了提高计算精确度,根据不同的应用环境,可采用不同的计算思路。如对于银行复利等多数字乘除计算为保证实现计算精确到具体位数,可以采用如下两种计算思路:
一、按照上述流程将算式直接计算,从而求出最终值。
(41)按照计算法则直接计算,求得结果。其优点是简单易实现,缺点是随着计算的进行,位数会不断加大,运算量会增加。
二、为了保证计算精度,可以按照如下做法:
(41)由于除法运算不易控制计算精度,因此可以采取先乘后除的计算结合方式进行计算。
(42)将计算结果传入误差分析模块,进一步判断如何进行舍入以满足计算精度要求。
(43)若计算结果不满足对于精度的控制要求,则根据误差分析判断确定舍入方式,进而进行计算。
三、分组计算,然后求出最终结果。
(41)以r=C+{[log o1N] 向下取整/o 2} 向上取整为例,按数字分组计算。
(42)求得[log o1N] 向下取整/o 2=s...rm;
(43)取舍后将参与运算的数字每o 1个数字为一组,计算出每组数字的结果;
(44)对每组数字计算出的结果重新进行取舍,并重复上述操作,反复进行rm次后,令r=r-o 3,或n k=n k-o 3,再次进行取舍,并令rm=o 2
其中o 3为与o 1、o 2相关的参数,当o 1、o 2不大时可令o 3=1。
(45)反复进行上述部分操作,直至计算出最终结果。
(41)以r=C+{[log o1N] 向下取整/o 2} 向上取整为例,按数字分组计算。
(42)取舍后将参与运算的数字每o 1个数字为一组,计算出每组数字的结果;
(44)对每组数字计算出的结果重新进行取舍,并重复上述操作,反复进行o 2次后,令r=r-o 3,或n k=n k-o 3,再次进行取舍;
(45)反复进行上述操作,直至计算出最终结果。
注:当o 3=0时,该方式每次进行取舍时r值不变,即n k为一定值。除此之外,也可按照运算步骤进行分组,或数字与步骤混合分组计算。
进一步的,计算模块和输出模块之间还包括误差分析模块,误差分析模块为可关闭模块,若该模块关闭,则计算结果将直接进入输出模块,若需要对计算结果进行校验,则后置误差分析模块可有但不限于如下实现方式:
一、粗略误差分析模式:
(51)对于加减法,直接通过。
(52)对于多步乘除,取计算结果的前n位,记作c 1
(53)判断c 1×10^(-n)×Q的大小,若c 1×10^(-n)×Q<1,则校验通过。
(54)Q为校正参数,可以根据工作实际选取恰当的值。比如,当两数相乘/除时,若保留位数为1位时Q可取值为Q=0.6×10^(1-r)等。
(55)进一步的,若c 1×10^(-n)×Q≥1,且10^n j>c 1×10^(-n)×Q≥10^(n j-1),则返回n j(n j≥1)。
二、精确误差分析模式:
(51)对于乘除法,取计算结果的前n位,记作c 1
(52)判断c 1×10^(-n)×Q的大小,若c 1×10^(-n)×Q>=1, 且10^n j>c 1×10^(-n)×Q≥10^(n j-1),则返回n j(n j≥1)。
(53)若c 1×10^(-n)×Q<1,对于乘除法,判断计算结果需要保留的精确位的下一位,若计算结果需要保留的精确位的下一位为舍入上下限分别对应的数值(本说明以四舍五入为例,即舍入上下限分别对应4、5,下同),进行下一步校验,若不是,校验通过。
(541)若两数计算结果需要保留的精确位的下一位为4,则取计算结果的前n位,记作c 1
求得c 1×10^(1-n)×Q的大小,接着在计算结果第N k(N k的取值,在多数情况下N k=n k,在涉及减法的运算中若计算结果的数量级为L,且L<n max,则N k可取值为N k=n k-n max+L或最终保留位的下r位等,下同)位加上c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
R为精确校验参数,当精确校验不通过时人为规定的校验值,比如可直接令R=1。
对于多步乘除法,取计算结果的前n位,记作c 1
若c 1×10^(1-n)×Q<1。在计算结果第N k位加上c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
(542)若两数计算结果需要保留的精确位的下一位为5,则取计算结果的前n位,记作c 1
求得c 1×10^(1-n)×Q的大小,接着在计算结果第N k位减去c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
(55)对于多步乘除法,取计算结果的前n位,记作c 1
(56)若c 1×10^(1-n)×Q<1。在计算结果第N k位减去c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
显然,本领域的技术人员应当理解,为避免进入死循环,建议只进行一次或两次校验。
进一步的,误差分析模块还包括前置误差分析模块:
在部分场合下,为了1、核对已计算出的数据;2、避免计算完毕后返回n j,造成运算资源浪费;3、避免保留位数过多带来过大的运算压力;4、加减乘除混合运算。需要对数据进行前置的误差分析,然后再确定保留几位进行计算。
(61)核对已计算出的数据:
当需要对已计算出的数据进行核对时,若要保证校验计算结果的前n x位是否正确,则按照高精度取舍方式保留原数据的前n k=n x+1位进行分析。如,A报表统计出1.2535×5.3621≈6.721,要核对计算结果前2位是否正确,则对应保留其前3位进行校验,即原式可保留为1.25×5.37≈6.71。
且借助高精度取舍方式保留n x+1位计算出的两数乘除结果可保证前n x位误差极小,前n x+1位的误差小于等于计算结果首位的一半,其直观感受就是保留n x+1位求得的带误差的最大最小值的前n x+1位的误差小于等于计算结果首位,前n x位的误差不大于1。
(62)避免计算完毕后返回n j,造成运算资源浪费:
当需要降低运算压力时,可人为确定保留算式中的前n y位进行估算,并根据计算结果的前n y位返回n j值。
(63)避免保留位数过多带来过大的运算压力:
当需要降低运算压力时,可人为确定保留算式中的前n y位进行估算,若计算结果可写为rt×10^x,且需要保留计算结果至小数点后n d位,则保留位数为n k=x+n d+1+r。
(64)加减乘除混合运算:
当参与运算的为加减乘除混合运算时,可返回n k=n ki进行取舍。可估计运算结果数量级进行判断。也可人为确定保留算式中的前n y位进行估算,若计算结果可写为rt×10^x 1,若n y>|x 1-n max|,且x 1≠n max时,返回n j=|x 1-n max|+h,若x 1=n max时,返回n j=h(若rt首位为1,则h可取值为h=1,否则可取值为h=0);若n y≤|x 1-n max|,则返回n j=|x 1-n max|+Cr,或令n y=n y+Cr,再次进行验证(其中Cr为混合运算校正参数,为人为规定的一个参数)。
本发明的有益效果在于:
(1)具有智能判断模块,在乘除运算中可自行判断需要保留的计算位数,从而让计算结果的精度更为科学、可靠。
(2)独创性的设计了更为合理的取舍方式,在乘除运算中根据低位数字的和、差判断取舍数字的个数和/或方式,取舍精度更高,更有利于降低数据处理过程中造成的误差,降低常规舍入方法处理数据导致的数据误差,提高统计数据的一致性和可用性,使得数据处理结果更为精确。
(3)具有事后校验模块,可在计算结束之后便捷的对数据误差进行分析校对,而非很多校验系统需要在计算出精确结果后对误差进行校验。
(4)具有前置校验模块,可根据计算结果快速判断保留位数,接着调用存储数据进行取舍、计算。
(5)本系统有广泛的适用范围,除了计算机软、硬件实现之外,还可迁移至所有可迁移的范围,例如数据压缩处理、统计图表的制作、金融银行数据计算、促进统计数据的使用等。
(6)具有智能控制模块,可根据运算需要自行调整r等参数值大小,控制运算量及运算频率。
(7)具有多数字处理系统,能够在保证计算精度的同时尽量减小运算压力。
附图说明
图1是实施例1处理系统的模块结构图。
图2是实施例12处理系统的模块结构图。
图3是实施例12中针对多数字的处理系统的模块结构图。
图4是判断模块对于乘法的具体舍入判断流程图。
图5是判断模块对于除法的具体舍入判断流程图。
图6是判断模块对于乘除混合运算的具体舍入判断流程图。
图7是判断模块在给出有效数字位数时的具体舍入判断流程图。
具体实施方式
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明的实施例和附图,对本发明的技术方案进行清楚、完整地描述。显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
实施例1:
如:某证券交易所年交易8850137345774股,成交金额为112817375324213.24元。求平均每股成交金额为多少元(精确到小数点后5位)。
如图1所示,包括输入模块、判断模块、智能取舍模块、计算模块和输出模块;由输入模块向判断模块输入精度要求或有效数字位数,然后输入模块的原始数据经由智能取舍模块按照判断模块的要求处理,经由计算模块计算后由输出模块输出;
其中,输入模块为输入原始数据、精度要求或有效数字位数,然后由判断模块判断舍入位数;或直接由操作者输入原始数据及舍入要求,直接进入智能取舍模块,并根据输入情况,选择返回原始值至智能取舍模块,返回精度要求至判断模块;判断模块根据操作者提供的精度要求,判断需要进行何种舍入操作;智能取舍模块为对输入数据进行预处理、按照取舍要求对数字进行取舍;计算模块调用计算功能对保留后的数字进行计算;输出模块按照精度要求对计算结果进行取舍,接着输出计算结果。
其中,判断模块对于乘法的舍入判断如下,精度要求结果精确至小数点后n d位,将原数字按照科学计数法记作A 1×10 x1、A 2×10 x2、...、A i×10 xi,判断n j=0时,n k=x1+x2...+xi+n d+i+r;判断n j≠0,保留位数=x1+x2...+xi+n d+i+n j+r;
对于乘除混合的舍入判断如图6所示,若精度要求结果精确至n d位,将乘数、被除数按科学计数法记作m 1×10 x1、m 2×10 x2...m i×10 xi,除数记作d 1×10 Y1、d 2×10 Y2...d j×10 Yj; 判断n j=0时,n k=x1+x2...+xi-Y1-Y2...-Yj+i+n d+r;判断n j≠0,n k=x1+x2...+xi-Y1-Y2...-Yj+i+n d+n j+r;
进一步的,若输入有效数字位数,判断模块对于乘法的具体舍入判断如图7所示,若要求计算结果前n x位为精确值,判断n j=0时,n k=n x+r;判断n j≠0,n k=n x+n j+r。
进一步的,若参与运算的为加减乘除混合运算时,可按上述方式求得每组乘除运算的n k,并取其中的某个值(n ki),接着返回n k=n ki或按照(64)进行判断;也可按照上述方式分别求得每组乘除运算的n k,并对每组运算分开取舍。
其中n ki的取值可根据需要固定也可变化,如存在减法时可取其中最大值等。
进一步的,若参与运算的原始数字中存在近似值,可按上述方式进行判断,或在按照上述方式判断出n k之后,若n k≤N y+r,正常返回n k,否则返回n k=N y+r。
在加法运算中n k=n max+r。
其中,r为可变值,可根据计算精度的要求取值(可为正值负值或零)。如:在启用精确校验模块,为保证计算精确无误,r初始值可取为r=2,并根据319-320步骤或人为进行合理化调整;在进行近似计算时,根据精度要求,取r=1或r=2等;在专门针对多数字乘除的处理系统中,r初始值可取为r=2,同时可引入算数个数对r的影响,如r=C+{[log o1N] 取整/o 2} 取整(其中o1、o2为涉及到多数字运算时的纠正参数,C为根据运算需要确定的参数,如当o1、o2较小时C可取为1,这三个参数均可根据计算误差进行人为规定),或根据具体运算步骤与需要给r赋值,如一个计算分为M个步骤,则r可赋值为r=1+M/o 2,在加法运算中r=C+[lgN]等,并在必要时进行调整(见319-320)。在复杂加减乘除混合运算中r可根据需要固定为某值。
其中N y为所有近似值中有效数字位数最少的数字的有效数字位数。
如:根据本例开头所给数据,列式为:平均每股=112817375324213.24÷8850137345774元/股,取r=1,n d=5,n k=14-12+1+n d+r=9,原式保留前9位估算112817375000000÷8850137340000=12.74753元/股。
如:若按每组运算分开取舍,75.3201×42.1312+885.0131×37.34712,取r=1,n d=0,n k1=1+1+2+n d+r=5,n k2=2+1+2+n d+r=6,则原式转化为75.320×42.131+885.013×37.3471。
实施例2:
如:若给定运算1000个,thr1=0.02,thr2=0,n j返回次数为100,r初始值为1。
在实施例1的基础上,智能取舍模块包括排序模块、存储模块和高精度取舍模块,排序模块对数字按照数字前几位的大小进行排序(以下以从小到大排序为例);存储模块接收返回的原始值;原始数据经存储模块按照判断模块的要求处理后进入高精度取舍模块处 理,高精度取舍模块处理后的数据进入计算模块;存储模块处理过程如下:
(311)将输入模块输入的信息可在加减算法中正常存储原数字或取舍后再存储;
(312)在两数乘除法运算中,根据舍入位数的要求,将需要保留位数以内的数字及更低位的数字进行分别存储,如对123456保留至万位,即将原数字拆分为120000与3456,并进一步的根据科学计数法,以保留位数为单位,存储两数,即120000记作12×10^4,3456记作0.3456×10^4,将两数分别标记为a i×10^n,b i×10^n(b i<1);
(313)需要时可记录运算中出现的数量级最高的数字所对应的数量级(n max)等数据。
(314)两数相乘中,求得两数b i的和,并将该和按照给定的舍入上下限取整(如四舍五入、四舍六入等),记作n
(315)两数相除中,求得两数b i的差,并将该差按照给定的舍入上下限取整,记作n
进一步的,存储模块在多步计算中,根据步骤逐步满足或求得总数进而予以判断,
进一步的,为后续操作方便,可在存储模块中存入算数的个数、运算步骤数,可分别记作N、M,
进一步的,若参与运算的数字存在近似值,记录近似值中有效位数最低的数字的有效位数为N y
(316)在多步乘除法运算中,根据舍入位数的要求及运算法则,将需要保留位数以内的数字及更低位的数字进行拆分,如对354321×123456÷234567保留至万位,即将原数字分别拆分为350000与4321,120000与3456,230000与4567,并进一步的根据科学计数法,以保留位数为单位,存储各数,并利用符号/字母等方式分别标记乘数(被除数)及除数,如350000记作35×10^4,4321记作0.4321×10^4;120000记作12×10^4,3456记作0.3456×10^4;230000与4567分别记作23×10^4与0.4567×10^4,并按照运算法则标记各数字,如标记为mi×10^n,mti×10^n(乘数或被除数)及dj×10^n,dtj×10^n(除数);
注:拆分主要是为本说明方便进行描述,在实践中可在排序、取舍等环节再进行拆分。
(317)在多步乘除法运算中,按照mi或dj的大小进行排序,如对354321×123456÷234567排序后,顺序为12(3456),23(4567),35(4321);
(317)在多步乘除法运算中,若采取先乘后除的运算结合方式,则先按照运算法则进行分类,接着对其中的乘数(被除数)、除数分别排序,如对354321×123456÷234567排序后,顺序为m1=12,m2=35,d1=23;
(318)在多步加减乘除混合运算中,按照运算优先级,先按316-317步骤对其中乘除法进行取舍,接着对其中加减法进行取舍,或对其中加减法进行精确计算。
进一步的,可以对舍入位数进行合理化调整,调整方式包括但不限于如下步骤:
(319)记录返回nj>0次数或运算次数为count1,总的计算次数或运算次数为count2。当count2大于或等于某一给定值时,若count1÷count2>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值或校验频率,且令count1=0,count2=0;若count1÷count2≤thr2时令r=r-1或调整o 2、o 1等一个或多个参数值或校验频率,且令count1=0,count2=0;
其中:thr1/2为根据工作实际确定的阈值,当超过/低于这一阈值,保留精度进行适当提高或降低,以减小返回n j次数或降低单次运算量。
如本实施例开头:若给定运算1000个,即count2=1000,thr1=0.02,thr2=0,n j返回次数为100,即count1=100,r初始值为1,则count1÷count2=0.1>thr1,则r=r+1=2。
实施例3:
在实施例1的基础上,智能取舍模块包括排序模块、存储模块和高精度取舍模块,排序模块对数字按照数字前几位的大小进行排序(以下以从小到大排序为例);存储模块接收返回的原始值;原始数据经存储模块照判断模块的要求处理后进入高精度取舍模块处理,高精度取舍模块处理后的数据进入计算模块;存储模块处理过程如下:
(311)将输入模块输入的信息可在加减算法中正常存储原数字或取舍后再存储;
(312)在两数乘除法运算中,根据舍入位数的要求,将需要保留位数以内的数字及更低位的数字进行分别存储;
(313)需要时可记录运算中出现的数量级最高的数字所对应的数量级(n max)等数据。
(314)两数相乘中,求得两数字b i的和,并取整,记作n
(315)两数相除中,求得两数字b i的差,并取整,记作n
进一步的,存储模块在多步计算中,根据步骤逐步满足或求得总数进而予以判断,
进一步的,为后续操作方便,可在存储模块中存入算数的个数、运算步骤数,可分别记作N、M,
进一步的,若参与运算的数字存在近似值,记录近似值中有效位数最低的数字的有效位数为N y
(316)在多步乘除法运算中,根据舍入位数的要求及运算法则,将需要保留位数以内的数字及更低位的数字进行拆分,并进一步的根据科学计数法,以保留位数为单位,存储各数,并利用符号/字母等方式分别标记乘数(被除数)及除数,并按照运算法则标记各数字,如标记为mi×10^n,mti×10^n(乘数或被除数)及dj×10^n,dtj×10^n(除数);
(317)在多步乘除法运算中,按照mi或dj的大小进行排序;
(317)在多步乘除法运算中,若采取先乘后除的运算结合方式,则先按照运算法则进 行分类,接着对其中的乘数(被除数)、除数分别排序;
(318)在多步加减乘除混合运算中,按照运算优先级,先按316-317步骤对其中乘除法进行取舍,接着对其中加减法进行取舍,或对其中加减法进行精确计算。
进一步的,可以对舍入位数进行合理化调整,调整方式包括但不限于如下步骤:
(319)记录总的计算时间为T1,不返回n j>0的计算时间为T2,当T1大于或等于某一给定值时。若T1÷T2>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值或校验频率,且令T1=0,T2=0;若T1÷T2<=thr2时令r=r-1或调整o 2、o 1等一个或多个参数值或校验频率,且令T1=0,T2=0;
其中:thr1/2为根据工作实际确定的阈值,当超过/低于这一阈值,保留精度进行适当提高或降低,以减小返回n j次数或降低单次运算量。
实施例4:
在实施例1的基础上,智能取舍模块包括排序模块、存储模块和高精度取舍模块,排序模块对数字按照数字前几位的大小进行排序(以下以从小到大排序为例);存储模块接收返回的原始值;原始数据经存储模块照判断模块的要求处理后进入高精度取舍模块处理,高精度取舍模块处理后的数据进入计算模块;存储模块处理过程如下:
(311)将输入模块输入的信息可在加减算法中正常存储原数字或取舍后再存储;
(312)在两数乘除法运算中,根据舍入位数的要求,将需要保留位数以内的数字及更低位的数字进行分别存储;
(313)需要时可记录运算中出现的数量级最高的数字所对应的数量级(n max)等数据;
(314)两数相乘中,求得两数字b i的和,并取整,记作n
(315)两数相除中,求得两数字b i的差,并取整,记作n
进一步的,存储模块在多步计算中,根据步骤逐步满足或求得总数进而予以判断,
进一步的,为后续判断误差方便,在存储模块中存入算数的个数,记作N,
进一步的,若参与运算的数字存在近似值,记录近似值中有效位数最低的数字的有效位数为N y
(316)在多步乘除法运算中,根据舍入位数的要求及运算法则,将需要保留位数以内的数字及更低位的数字进行拆分,并进一步的根据科学计数法,以保留位数为单位,存储各数,并利用符号/字母等方式分别标记乘数(被除数)及除数,并按照运算法则标记标记各数字,如标记为mi×10^n,mti×10^n(乘数或被除数)及dj×10^n,dtj×10^n(除数);
(317)在多步乘除法运算中,按照mi或dj的大小进行排序;
(317)在多步乘除法运算中,若采取先乘后除的运算结合方式,则先按照运算法则进 行分类,接着对其中的乘数(被除数)、除数分别排序;
(318)在多步加减乘除混合运算中,按照运算优先级,先按316-317步骤对其中乘除法进行取舍,接着对其中加减法进行取舍,或对其中加减法进行精确计算。
进一步的,若需要对r、o 2、o 1进行精确调整,可开启自适应模式:
(320)以原始数据进行计算并完成取舍,若取舍结果与本系统计算结果不同,则修改标记+1,在给定数据的计算中,当标记数>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值;若标记数<=thr2时令r=r-1或调整o 2、o 1等一个或多个参数值。
实施例5:
在实施例2、3或4的基础上,高精度取舍模块处理两数字运算时对原始数字根据舍入要求舍入,处理过程如下:
(321)加减法运算直接跳入计算模块进行精确计算,或取舍后进入计算模块;
(322)在两数相乘中,若n =0,则将两数保留为a i×10^n进行计算;
(323)在两数相乘中,若n =2,则将两数保留为(a i+1)×10^n进行计算;
(324)在两数相乘中,若n =1,接着比较两数a i的大小,a i小的数字正常舍入,另一个数字反向取舍;
如:对131241×241431保留前3位进行计算,n =[0.241+0.431] 取整=1,则131241正常舍入转化为131000,241431反向取舍转化为242000,原式转化为131000×242000。
(325)在两数相除中,若n =0,接着比较两数a i的大小,a i小的数字正常舍入,另一个数字同向取舍;
(326)在两数相除中,若n ≠0,进行正常舍入。
如:对31231÷54865保留前3位进行计算,n =[0.65-0.31] 取整=0,则31231正常舍入转化为31200,54865同向取舍转化为54800,原式转化为31200÷54800。
实施例6:
在实施例2、3或4的基础上,高精度取舍模块为了提高乘除法计算的精度,处理过程如下:
(321)加减法运算直接跳入计算模块进行精确计算,或取舍后进入计算模块;
(322)在两数相乘中,若n =1,接着比较两数a i的大小,a i小的数字正常舍入,另一个数字反向取舍;
(323)在两数相乘中,若n ≠1,进行正常舍入。
(324)在两数相除中,若n =0,接着比较两数a i的大小,a i小的数字正常舍入,另一个数字同向取舍;
(325)在两数相除中,若n ≠0,进行正常舍入。
如:对31231×54835保留前3位进行计算,n =[0.35+0.31] 取整=1,则31231正常舍入转化为31200,54835反向取舍转化为54900,原式转化为31200×54900。
实施例7:
在实施例2、3或4的基础上,高精度取舍模块处理在多数字运算时对原始数字根据舍入要求舍入,处理过程如下:
(331)在多数字乘除运算中,若数字未分类,首先求得
Figure PCTCN2020104885-appb-000003
注:其中|no|为需要进行调整数字的个数,其他数字均保留为m i×10^n及d i×10^n。
若no=0,则所有数字均保留为m i×10^n及d i×10^n。
若no>0,且该数字为乘数(被除数),则原数保留为(m i+1)×10^n,若原数为除数,则原数保留为(d i-1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中no个乘数(被除数),将其保留为(m i+1)×10^n,或no个除数,保留为(d i-1)×10^n,其他数字保留为m i×10^n或d j×10^n。
若no<0,且该数字为乘数(被除数),则原数保留为(m i-1)×10^n,若原数为除数,则原数保留为(d i+1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中|no|个乘数(被除数),将其保留为(m i-1)×10^n,或|no|个除数,保留为(d i+1)×10^n,其他数字保留为m i×10^n或d j×10^n。
(332)在多数字乘除运算中,若未按照运算法则对数字分类,若从中间开始取舍,求得fr=(i+j-|no|)/2+1。在(i+j-|no|)/2非整数时可根据需要进行取整。
注:这里主要列举了从中间开始取舍,除从中间开始进行取舍之外,也可从两端进行取舍,甚至可以包括跳跃式取舍。
(333)按m i及d j的大小顺序,若从中间开始取舍,对m i×10^n、d j×10^n中的数字进行舍入:按照排序自小到大,对其中第fr往后|no|个数字做出调整;若从两头开始,则分别从序列最小/最大两端向中间进行取整;若采取跳跃式取舍,则将需要调整的数字相对均匀的分布在所有数字中:
(334)若从中间开始调整,如
1201000010007×0.0001202×12.0300010×0.0001204÷120500072÷0.0000000012060031×0.12070001÷120.8×0.1209≈173.81,若保留前三位,其no=1则原式将转化为:
1200000000000×0.00012×12×0.000120÷119000000÷0.0000000012×0.12÷120×0.12≈174.25。
(334)若从两头调整,如
1196000010007×0.0001202×12.0300010×0.0001204÷120500072÷0.0000000012010031×0.12070001÷120.8×0.1209≈173.81,若保留前三位,其no=2则只对其中两个数字进行调整,原式将转化为(调整头尾两个数字):
1200000000000×0.00012×12×0.00012÷120000000÷0.0000000012×0.12÷120×0.121≈174.24。
(334)若采取跳跃取舍方式,如
1196000010007×0.0001202×12.0300010×0.0001204÷120500072÷0.0000000012010031×0.12070001÷120.8×0.1209≈173.81,若保留前三位,其no=2则只对其中两个数字进行调整,原式将转化为(调整其中两个数字):
1190000000000×0.000121×12.0×0.00012÷120000000÷0.00000000119×0.12÷120×0.12≈174.24。
(334)若只调整其中乘数(被除数),如
1196000010007×0.0001202×12.0300010×0.0001204÷120500072÷0.0000000012010031×0.12070001÷120.8×0.1209≈173.81,若保留前三位,其no=2则只对其中两个乘数(被除数)进行调整,原式将转化为:
1190000000000×0.00012×12.1×0.000121÷120000000÷0.0000000012×0.120÷120×0.12≈174.23。
(334)若只调整其中除数,如
1196000010007×0.0001202×12.0300010×0.0001204÷120500072÷0.0000000012010031×0.12070001÷120.8×0.1209≈173.81,若保留前三位,其no=2则只对其中两个乘数(被除数)进行调整,原式将转化为:
1190000000000×0.000120×12×0.00012÷119000000÷0.0000000012×0.12÷119×0.12≈174.25。
(334)这种取舍方式同样适合于加减法,如
1196+1202+1203+1204-1205-1201+1207-1208+1209,若保留前三位,其no=2则只对其中两个数字进行调整,原式将转化为:1200+1210+1200+1200-1200-1200+1200-1200+1200。
实施例8:
在实施例2、3或4的基础上,高精度取舍模块处理在多数字运算时对原始数字根据舍入要求舍入,处理过程如下:
(331)在多数字乘除运算中,若数字未分类,则依次(按m i及d j的大小从小到大)求得mt i、(-dt j)的加和,并将该结果按照设定的舍入上下限进行舍入(此处以四舍五入为例,下同)取整,若取整结果与先前不同,则对应将m i×10^n保留为(m i+1)×10^n,或将d j×10^n保留为(d j+1)×10^n。
(332)如
120100001001×0.001202×12.0300010×0.0001204÷120500072÷0.0000000012060031×0.12070001÷120.8×0.1209≈173.81,若保留前三位原式将转化为:
120000000000×0.0012×12.1×0.00012÷120000000÷0.00000000121×0.121÷121×0.121≈174.24。
实施例9:
在实施例2、3或4的基础上,高精度取舍模块处理在多数字运算时对原始数字根据舍入要求舍入,处理过程如下:
(331)在多数字乘除运算中,若按照运算法则等对数字分类,首先求得每组分类中
Figure PCTCN2020104885-appb-000004
(332)对其中|no|个数字进行调整,其他数字均保留为m i×10^n,或d j×10^n。
若no=0,则所有数字均保留为m i×10^n及d i×10^n。
若no>0,且该数字为乘数(被除数),则原数保留为(m i+1)×10^n,若原数为除数,则原数保留为(d i-1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中no个乘数(被除数),将其保留为(m i+1)×10^n,或no个除数,保留为(d i-1)×10^n,其他数字保留为m i×10^n或d j×10^n。
若no<0,且该数字为乘数(被除数),则原数保留为(m i-1)×10^n,若原数为除数,则原数保留为(d i+1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中|no|个乘数(被除数),将其保留为(m i-1)×10^n,或|no|个除数,保留为(d i+1)×10^n,其他数字保留为m i×10^n或d j×10^n。
(332)同样,此时调整可从中间开始取舍;也可从两头开始,则分别从序列最小/最大两端向中间进行取整;还可采取跳跃式取舍,则将需要调整的数字相对均匀的分布在所有数字中:
(333)若从中间开始调整,如
1201000010007×0.0001202×12.0300010×0.0001204×120500072×0.0000000012060031÷0.12070001÷120.8÷0.1209≈17237.52,中no=0,若保留前三位原式将转化为:
1200000000000×0.000120×12.0×0.000120×120000000×0.00000000120÷0.120÷120÷0.120≈17280。其他方式类似实施例7。
实施例10:
在实施例2、3或4的基础上,高精度取舍模块处理在多数字运算时对原始数字根据舍入要求舍入,处理过程如下:
(331)在多数字乘除运算中,若按照运算法则等对数字分类,则在每组分类中依次(按 m i及d j的大小从小到大)求得mt i、(-dt j)的加和,并将该结果按照设定的舍入上下限取整,若取整结果与先前不同,则对应将m i×10^n保留为(m i+1)×10^n,或将d j×10^n保留为(d j+1)×10^n。
(332)如
1201000010007×0.0001202×12.0300010×0.0001204×120500072×0.0000000012060031÷0.12070001÷120.8÷0.1209≈17237.52,若保留前三位原式将转化为:
1200000000000×0.000120×12.1×0.000120×121000000×0.00000000120÷0.121÷121÷0.120≈17280。
实施例11:
在实施例7-10的基础上,在多数字运算时,可采用不同的计算思路来提高运算效率,处理过程包括但不限于如下方式:
一、按照上述流程将算式直接计算,从而求出最终值。
(41)按照计算法则直接计算,求得结果。其优点是简单易实现,缺点是随着计算的进行,位数会不断加大,运算量会增加。
二、为了保证计算精度,可以按照如下做法:
(41)由于除法运算不易控制计算精度,因此可以采取先乘后除的计算结合方式进行计算。如要计算64718264×2131241÷72357283×2431231÷54835787,则可先将原式乘除分开结合,原式转化为
Figure PCTCN2020104885-appb-000005
(42)将计算结果传入误差分析模块,进一步判断如何进行舍入以满足计算精度要求。
(43)若计算结果不满足对于精度的控制要求,则根据误差分析判断确定舍入方式,进而进行计算。
三、分组计算,然后求出最终结果。
(41)以r=C+{[log o1N] 向下取整/o 2} 向上取整为例,按数字分组计算。如要计算14718×21312÷32351×44312÷54835×63124÷78298×81241÷93212,设C=1,o 1=o 2=2,n k=4,则r=1+[log 29] 向下取整/2=1+2=3。
(42)求得[log o1N] 向下取整/o 2=s...rm。[log o1N] 向下取整/o 2=3/2=1...1。
(43)取舍后将参与运算的数字每o 1个数字为一组,计算出每组数字的结果。由于14718×21312÷32351×44312÷54835×63124÷78298×81241÷93212中no=(8+2-1+2-5+4-8+1-2) /10=0,所以原式保留为14710×21310÷32350×44310÷54830×63120÷78290×81240÷93210,每组o 1=2个算式,即原式转化为(14710×21310)(÷32350×44310)(÷54830×63120)(÷78290×81240)÷93210。
(44)对每组数字计算出的结果重新进行取舍,并重复上述操作,反复进行rm次后,令r=r-o 3,或n k=n k-o 3,再次进行取舍,并令rm=o 2
令o 3=1,原式≈(14710×21310)(÷32350×44310)(÷54830×63120)(÷78290×81240)÷93210=(14710×21310)×(44310÷32350)×(63120÷54830)×(81240÷78290)÷93210=313470100×1.3697063369397×1.1511946014955×1.0376804189552÷93210,r=r-1=3-1=2,即n k=3,原式转化为
Figure PCTCN2020104885-appb-000006
Figure PCTCN2020104885-appb-000007
(如不调整顺序,则原式转化为314000000×1.37×1.15×1.03÷93200)...
(45)反复进行上述部分操作,直至计算出最终结果。
实施例12:
在实施例7-10的基础上,在多数字运算时,可采用不同的计算思路来提高运算效率,处理过程包括但不限于如下方式:
三、分组计算,然后求出最终结果。
(41)以r=C+[log o1N] 向下取整/o 2为例,按数字分组计算。
(42)取舍后将参与运算的数字每o 1个数字为一组,计算出每组数字的结果;
(44)对每组数字计算出的结果重新进行取舍,并重复上述操作,反复进行o 2次后,令r=r-o 3,或n k=n k-o 3,再次进行取舍;
(45)反复进行上述部分操作,直至计算出最终结果。
注:当o 3=0时,该方式每次进行取舍时r值不变,即n k为一定值。除此之外,也可按照运算步骤进行分组,或混合分组计算。
如按步骤分组计算:14710×21310÷32350×44310-54830×63120÷78290×81240÷93210,按照运算结合方式,原式分为两步运算(先算乘除法,接着算其中的加减法),保留3位计算,原式转化为
Figure PCTCN2020104885-appb-000008
Figure PCTCN2020104885-appb-000009
实施例13:
如图2、3所示,在实施例2-12的基础上,计算模块和输出模块之间还包括误差分析模 块;
误差分析模块为可关闭模块,若该模块关闭,则计算结果将直接进入输出模块,若需要对计算结果进行校验,则进入误差分析模块,误差分析模块分为粗略误差分析模式或精确误差分析模式:
其中,粗略误差分析模式处理过程如下:
误差分析模块为可关闭模块,若该模块关闭,则计算结果将直接进入输出模块,若需要对计算结果进行校验,则后置误差分析模块可有但不限于如下实现方式:
一、粗略误差分析模式:
(51)对于加减法,直接通过。
(52)对于多步乘除,取计算结果的前n位,记作c 1
(53)判断c 1×10^(-n)×Q的大小,若c 1×10^(-n)×Q<1,则校验通过。
(54)Q为校正参数,可以根据工作实际选取恰当的值。比如,当两数相乘/除时,若保留位数为1位时Q可取值为Q=0.6×10^(1-r)等。
(55)进一步的,若c 1×10^(-n)×Q≥1,且10^n j>c 1×10^(-n)×Q≥10^(n j-1),则返回n j(n j≥1)。
二、精确误差分析模式:
(51)对于乘除法,取计算结果的前n位,记作c 1
(52)判断c 1×10^(-n)×Q的大小,若c 1×10^(-n)×Q≥1,且10^n j>c 1×10^(-n)×Q≥10^(n j-1),则返回n j(n j≥1)。
(53)若c 1×10^(-n)×Q<1,对于乘除法,判断计算结果需要保留的精确位的下一位,若计算结果需要保留的精确位的下一位为舍入上下限分别对应的数值(以4、5为例),进行下一步校验,若不是,校验通过。
(541)若两数计算结果需要保留的精确位的下一位为4,则取计算结果的前n位,记作c 1
求得c 1×10^(1-n)×Q的大小,接着在计算结果第N k(N k的取值,在多数情况下N k=n k,在涉及减法的运算中若计算结果的数量级为L,且L<n max,则N k可取值为N k=n k-n max+L或最终保留位的下r位等,下同)位加上c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
R为精确校验参数,当精确校验不通过时人为规定的校验值,比如可直接令R=1。
对于多步乘除法,取计算结果的前n位,记作c 1
若c 1×10^(1-n)×Q<1。在计算结果第N k位加上c 1×10^(1-n)×Q,若该操作不会改变 取舍结果,则校验通过,否则返回n j=R。
(542)若两数计算结果需要保留的精确位的下一位为5,则取计算结果的前n位,记作c 1
求得c 1×10^(1-n)×Q的大小,接着在计算结果第N k位减去c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
(55)对于多步乘除法,取计算结果的前n位,记作c 1
(56)若c 1×10^(1-n)×Q<1。在计算结果第N k位减去c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
显然,本领域的技术人员应当理解,为避免进入死循环,建议只进行一次或两次校验。
如,要校验实施例1,平均每股=112817375324213.24÷8850137345774元/股,取r=1,n d=5,n k=14-12+1+n d+r=9,原式保留前9位估算112817375000000÷8850137340000=12.747528元/股,取计算结果前2位,Q取值Q=0.5×10^(1-r),则c 1×10^(-n)×Q=12×0.01×0.5<1,且小数点后第6位为8,校验通过。
实施例14:
在实施例13的基础上,误差分析模块还包括前置误差分析模块:
(61)核对已计算出的数据:当需要对已计算出的数据进行核对时,若要校验计算结果的前n x位是否正确,则按照高精度取舍方式保留原数据的前n x+1位进行分析。如,A报表统计出1.2535×5.3621≈6.721,要核对计算结果前2位是否正确,则对应保留其前3位进行校验,即原式可保留为1.25×5.37≈6.71。
且借助高精度取舍方式保留n x+1位计算出的两数乘除结果可保证前n x位误差极小,前n x+1位的误差小于等于计算结果首位的一半,其直观感受就是保留n x+1位求得的带误差的最大最小值的前n x+1位的误差小于等于计算结果首位,前n x位的误差不大于1。
(62)避免计算完毕后返回n j,造成运算资源浪费:当需要降低运算压力时,可人为确定保留算式中的前n y位进行估算,并根据计算结果的前n y位返回n j值。
(63)避免保留位数过多带来过大运算压力:当需要降低运算压力时,可人为确定保留算式中的前n y位进行估算,设计算结果可写为rt×10^x,且需要保留计算结果至小数点后n d位,则保留位数为n k=x+n d+1+r。
(64)加减乘除混合运算:当参与运算的为加减乘除混合运算时,可返回n k=n ki进行取舍。可估计运算结果数量级进行判断。也可人为确定保留算式中的前n y位进行估算,若计算结果可写为rt×10^x 1,若n y>|x 1-n max|,且x 1≠n max时,返回n j=|x 1-n max|+h,若x 1=n max时,返回n j=h(若rt首位为1,则h可取值为h=1,否则可取值为h=0);若n y≤|x 1-n max|,则返回 n j=|x 1-n max|+Cr,或令n y=n y+Cr,再次进行验证(其中Cr为混合运算校正参数,为人为规定的一个参数)。
4274838.343211×14898274.434213÷41927.21324-37281749.4123×1232198.43231÷48937.43331中,设n y=3,则14800000÷41800×4270000≈1511866028.71≈1.51×10^10,则n max=10,则原式转化为14800000÷41800×4270000-1230000×37300000÷48900≈573645169.81≈5.74×10^8,则返回n j=10-8=2。
实施例15:
一种基于高精度取舍方式的误差可控的数据处理方法,采用实施例1-14任一的数据处理系统对数据进行精度判断、计算、取舍和输出。
本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件、硬件方面的实施例甚至可以包含借助本系统进行笔算或心算等形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器和光学存储器等)上实施的计算机程序产品的形式。
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框和/或多个方框中指定的功能。这些计算机程序指令也可装载到计算机和/或其他可编程数据处理设备上,从而在计算机和/或其他可编程设备上执行的指令提供用于实现在流程图一个流程和/或多个流程和/或方框图一个方框和/或多个方框中指定的功能的步骤。
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。

Claims (13)

  1. 一种基于高精度取舍方式的误差可控的数据处理系统,其特征在于:包括输入模块、判断模块、智能取舍模块、计算模块和输出模块;由输入模块向判断模块输入精度要求:即最终需要精确到小数点前/后第几位,有效数字位数:即最终需要几位精确值,然后输入模块的原始数据经由智能取舍模块按照判断模块的要求处理,经由计算模块计算后由输出模块输出;
    其中,输入模块为输入原始数据、精度要求或有效数字位数,然后由判断模块判断舍入位数;或直接由操作者输入原始数据及舍入要求,直接进入智能取舍模块,并根据输入情况,选择返回原始值至智能取舍模块,返回精度要求或有效数字位数至判断模块;判断模块根据操作者提供的精度要求或有效数字位数,判断需要进行何种舍入操作;智能取舍模块为对输入数据进行标记、排序等预处理、按照取舍要求对数字进行取舍;计算模块调用计算功能对保留后的数字进行计算;输出模块按照精度要求对计算结果进行取舍,接着输出计算结果。
  2. 如权利要求1所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:判断模块对于乘法的舍入判断如下,若精度要求需要结果精确至n d位,若n d为正值表示精确至小数点后n d位,若n d为负值则表示精确至小数点前|n d|位,若n d=0则表示精确至整数部分,将原数字按照科学计数法记作A 1×10 x1、A 2×10 x2、...、A i×10 xi,判断n j=0时,保留位数n k=x1+x2...+xi+n d+i+r;判断n j≠0,n k=x1+x2...+xi+n d+i+n j+r;
    对于乘除混合的舍入判断如下,若精度要求结果精确至n d位,将乘数、被除数按科学计数法记作m 1×10 x1、m 2×10 x2...m i×10 xi,除数记作d 1×10 Y1、d 2×10 Y2...d j×10 Yj;判断n j=0时,n k=x1+x2...+xi-Y1-Y2...-Yj+i+n d+r;判断n j≠0,n k=x1+x2...+xi-Y1-Y2...-Yj+i+n d+n j+r;
    若输入有效数字位数,要求计算结果前n x位为精确值,判断n j=0时,n k=n x+r;判断n j≠0,n k=n x+n j+r;
    若参与运算的为加减乘除混合运算时,求得每组乘除运算的n k,并取其中的某个值n ki,接着返回n k=n ki或按照(64)进行判断;也可按照上述方式分别求得每组乘除运算的n k,并对每组运算分开取舍;
    其中n ki的取值可根据需要固定也可变化,如存在减法时可取其中最大值等;
    若参与运算的原始数字中存在近似值,可按上述方式进行判断,或在按照上述方式判断出n k之后,若n k≤N y+r,正常返回n k,否则返回n k=N y+r;
    在加法运算中n k=n max+r;
    其中,r为可变值,根据计算精度的要求、运算法则、算数个数取值;
    其中N y为所有近似值中有效数字位数最少的数字的有效数字位数。
  3. 如权利要求1所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:智能取舍模块包括排序模块、存储模块和高精度取舍模块;两数运算中原始数据经存储模块按照判断模块的要求处理后进入高精度取舍模块处理,处理过程如下:
    (311)将输入模块输入的信息可在加减算法中正常存储原数字或取舍后存储;
    (312)在乘除法运算中,根据舍入位数的要求,将需要保留位数以内的数字及更低位的数字进行分别存储,将两数分别标记为a i×10^n,b i×10^n;
    (313)需要时可记录运算中出现的数量级最高的数字所对应的数量级n max等数据;
    (314)两数相乘中,求得两数字b i的和,并将该和按照给定的舍入上下限取整(如舍入上下限分别设定为4、5时即四舍五入,若舍入上下限分别为4、6时即四舍六入等),记作n
    (315)两数相除中,求得两数字b i的差,并将该差按照给定的舍入上下限取整,记作n
    存储模块在多步计算中,根据步骤逐步满足或求得总数进而予以判断,为后续操作方便,可在存储模块中存入算数的个数、运算步骤数,可分别记作N、M;
    若参与运算的数字存在近似值,记录近似值中有效位数最低的数字的有效数字位数为N y
    多数字运算中,原始数据可先经排序模块按照运算法则分类或不分类排序,排序方式如下:
    (316)在多步乘除法运算中,根据舍入位数的要求及运算法则,将需要保留位数以内的数字及更低位的数字进行拆分,并进一步的根据科学计数法,以保留位数为单位,存储各数,并利用符号/字母等方式分别标记乘数、被除数与除数,并按照运算法则标记各数字,如标记乘数或被除数为mi×10^n,mti×10^n及除数为dj×10^n,dtj×10^n;
    注:拆分主要是为本说明方便进行描述,在实践中可在排序、取舍等环节再进行拆分。
    (317)在多步乘除法运算中,按照m i或d j的大小进行排序;
    (317)在多步乘除法运算中,若采取先乘后除的运算结合方式,则先按照运算法 则进行分类,接着对其中的乘数或被除数、除数分别排序;
    (318)在多步加减乘除混合运算中,按照运算优先级,先按316-317步骤对其中乘除法进行取舍,接着对其中加减法进行取舍,或对其中加减法进行精确计算。
  4. 如权利要求3所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:存储模块在多步计算中,根据步骤逐步满足或求得总数进而予以判断,判断时将在存储模块中存入算数的个数,记作N;对舍入位数进行调整的步骤如下:
    (319)记录返回n j>0次数或运算次数为count1,总的计算次数或运算次数为count2;当count2大于或等于某一给定值时,若count1÷count2>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值或校验频率,且令count1=0,count2=0;若count1÷count2≤thr2时令r=r-1或调整o 2、o 1等一个或多个参数值或校验频率,且令count1=0,count2=0;
    其中:thr1/2为根据工作实际确定的阈值,当超过/低于这一阈值,保留精度进行适当提高或降低,以减小返回n j次数或降低单次运算量,下同;
    或者,(319)记录总的计算时间为T1,不返回n j>0的计算时间为T2,当T1大于或等于某一给定值时。若T1÷T2>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值或校验频率,且令T1=0,T2=0;若T1÷T2<=thr2时令r=r-1或调整o 2、o 1等一个或多个参数值或校验频率,且令T1=0,T2=0;
    或者,(320)在取舍模块以原始数据进行计算并完成取舍,若取舍结果与本系统计算结果不同,则修改标记+1,在给定数据的计算中,当标记数>thr1时令r=r+1或调整o 2、o 1等一个或多个参数值;若标记数<=thr2时令r=r-1或调整o 2、o 1等一个或多个参数值。
  5. 如权利要求3所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:在两数字运算时,高精度取舍模块为了提高乘除法计算的精度,处理过程如下:
    (321)加减法运算直接跳入计算模块进行精确计算,或取舍后进入计算模块;
    (322)在两数相乘中,若n =0,则将两数保留为a i×10^n进行计算即可;
    (323)在两数相乘中,若n =2,则将两数保留为(a i+1)×10^n进行计算即可;
    (324)在两数相乘中,若n =1,接着比较两数a i的大小,a i小的数字按照舍入上下限正常舍入,另一个数字反向取舍;
    (325)在两数相除中,若n =0,接着比较两数a i的大小,a i小的数字按照舍入 上下限正常舍入,另一个数字同向取舍;
    (326)在两数相除中,若n ≠0,进行正常舍入。
    或者,(321)加减法运算直接跳入计算模块进行精确计算,或取舍后进入计算模块;
    (322)在两数相乘中,若n =1,接着比较两数a i的大小,a i小的数字按照舍入上下限正常舍入,另一个数字反向取舍;
    (323)在两数相乘中,若n ≠1,进行正常舍入;
    (324)在两数相除中,若n =0,接着比较两数a i的大小,a i小的数字按照舍入上下限正常舍入,另一个数字同向取舍;
    (325)在两数相除中,若n ≠0,进行正常舍入。
  6. 如权利要求3所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:在多数字运算时,高精度取舍模块为了提高乘除法计算的精度,处理过程如下:
    (331)在多数字乘除运算中,若数字未分类,首先求得
    Figure PCTCN2020104885-appb-100001
    注:其中|no|为需要进行调整数字的个数,其他数字均保留为m i×10^n及d i×10^n;
    若no=0,则所有数字保留为m i×10^n及d i×10^n;
    若no>0,且该数字为乘数或被除数,则原数保留为(m i+1)×10^n,若原数为除数,则原数保留为(d i-1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中no个乘数(被除数),将其保留为(m i+1)×10^n,或no个除数,保留为(d i-1)×10^n,其他数字保留为m i×10^n或d j×10^n;
    若no<0,且该数字为乘数或被除数,则原数保留为(m i-1)×10^n,若原数为除数,则原数保留为(d i+1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中|no|个乘数(被除数),将其保留为(m i-1)×10^n,或|no|个除数,保留为(d i+1)×10^n,其他数字保留为m i×10^n或d j×10^n。
    (332)在多数字乘除运算中,若未按照运算法则对数字分类,若从中间开始取舍,求得fr=(i+j-|no|)/2+1;在(i+j-|no|)/2非整数时可根据需要进行取整;从中间开始取舍,可按照大小顺序,对其中第fr往后|no|个数字做出调整;
    (333)若按m i及d j的大小顺序,从两头开始,则分别从序列最小/最大两端向中 间进行取整;
    (334)除此之外,还可进行跳跃式取舍。
    注:上述取舍方式同样适用于加减法,在加减法中除数对应减数,乘数或被除数对应其他数字,且需要对齐小数点。排序主要是为了降低运算产生的极限误差,如不进行排序,可被认为是一种特殊的跳跃取舍方式。
  7. 如权利要求3所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:在多数字运算时,高精度取舍模块为了提高乘除法计算的精度,处理过程如下:
    (331)在多数字乘除运算中,若数字未分类,则按m i及d j的大小顺序,如从小到大依次求得mt i、(-dt j)的加和,并将该结果按照设定的舍入上下限进行取整,若取整结果与先前不同,则对应将m i×10^n保留为(m i+1)×10^n,或将d j×10^n保留为(d j+1)×10^n。
  8. 如权利要求3所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:在多数字运算时,高精度取舍模块为了提高乘除法计算的精度,处理过程如下:
    (331)在多数字乘除运算中,若按照运算法则等对数字分类,首先求得分类中每组数字的
    Figure PCTCN2020104885-appb-100002
    (332)对其中|no|个数字进行调整,其他数字均保留为m i×10^n,或d j×10^n;
    若no=0,则所有数字保留为m i×10^n及d i×10^n;
    若no>0,且该数字为乘数、被除数,则原数保留为(m i+1)×10^n,若原数为除数,则原数保留为(d i-1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中no个乘数、被除数,将其保留为(m i+1)×10^n,或no个除数,保留为(d i-1)×10^n,其他数字保留为m i×10^n或d j×10^n;
    若no<0,且该数字为乘数、被除数,则原数保留为(m i-1)×10^n,若原数为除数,则原数保留为(d i+1)×10^n,除此之外其他数字均保留为m i×10^n或d j×10^n。或只调整其中|no|个乘数、被除数,将其保留为(m i-1)×10^n,或|no|个除数,保留为(d i+1)×10^n,其他数字保留为m i×10^n或d j×10^n;
    (332)同样,此时调整可按照m i或d i的大小排序,从中间开始取舍;也可从两头开始,可分别从序列最小/最大两端向中间进行取整;还可采取跳跃式取舍,可将需要调整的数字相对均匀的分布在所有数字中。
  9. 如权利要求3所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:在多数字运算时,高精度取舍模块为了提高乘除法计算的精度,处理过程如下:
    (331)在多数字乘除运算中,若按照分类,则按m i及d j的大小从小到大在每组数字中依次求得mt i、(-dt j)的加和,并将该结果按照设定的舍入上下限进行取整,若取整结果与先前不同,则对应将m i×10^n保留为(m i+1)×10^n,或将d j×10^n保留为(d j+1)×10^n;
  10. 如权利要求1-9任一项所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:计算模块可根据参与运算的数字多少,采取合理操作,在保证计算精度的同时有效降低运算量:
    一、直接计算,从而求出最终值;
    (41)按照计算法则直接计算,求得结果;
    二、为了保证计算精度,可以按照如下做法:
    (41)由于除法运算不易控制计算精度,因此可以采取先乘后除的计算结合方式进行计算;
    (42)将计算结果传入误差分析模块,并进一步判断如何进行舍入以满足计算精度要求;
    (43)若计算结果不满足对于精度的控制要求,则根据误差分析判断确定舍入方式,进而进行计算;
    三、分组计算,然后求出最终结果;
    (41)以r=1+{[log o1N] 向下取整/o 2} 向上取整为例,按数字分组计算;
    (42)求得[log o1N] 向下取整/o 2=s...rm;
    (43)取舍后将参与运算的数字每o 1个数字为一组,计算出每组数字的计算结果;
    (44)对每组数字计算出的结果重新进行取舍,并重复上述操作,反复进行rm次后,令r=r-o 3,或n k=n k-o 3,再次进行取舍,并令rm=o 2
    其中o 3为与o 1、o 2相关的参数,当o 1、o 2不大时可令o 3=1。
    (45)反复进行上述部分操作,直至计算出最终结果;
    (41)以r=1+{[log o1N] 向下取整/o 2} 向上取整为例,按数字分组计算;
    (42)取舍后将参与运算的数字每o 1个数字为一组,计算出每组数字的结果;
    (44)对每组数字计算出的结果重新进行取舍,并重复上述操作,反复进行o 2次 后,令r=r-o 3,或n k=n k-o 3,再次进行取舍;
    (45)反复进行上述操作,直至计算出最终结果。
    除此之外,也可按照运算步骤进行分组,或数字与步骤混合分组计算。
  11. 如权利要求1-10任一项所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:计算模块和输出模块之间还包括误差分析模块;误差分析模块为可关闭模块,若该模块关闭,则计算结果将直接进入输出模块,若需要对计算结果进行校验,则进入误差分析模块,后置误差分析模块分为粗略误差分析模式或精确误差分析模式:
    其中,粗略误差分析模式:
    (51)对于加减法,直接通过;
    (52)对于多步乘除,取计算结果的前n位,记作c 1
    (53)判断c 1×10^(-n)×Q的大小,若c 1×10^(-n)×Q<1,则校验通过;
    (54)Q为校正参数,可以根据工作实际选取恰当的值。比如,当两数相乘/除时,若保留位数为1位时Q可取值为Q=0.6×10^(1-r);
    (55)进一步的,若c 1×10^(-n)×Q≥1,且10^n j>c 1×10^(-n)×Q≥10^(n j-1),则返回n j(n j≥1);
    精确误差分析模式:
    (51)对于乘除法,取计算结果的前n位,记作c 1
    (52)判断c 1×10^(-n)×Q的大小,若c 1×10^(-n)×Q>=1,
    且10^n j>c 1×10^(-n)×Q≥10^(n j-1),则返回n j(n j≥1);
    (53)若c 1×10^(-n)×Q<1,对于乘除法,判断计算结果需要保留的精确位的下一位,若计算结果需要保留的精确位的下一位为舍入上下限分别对应的数值:如以四舍五入为例,则舍入上下限分别为4或5,进行下一步校验,若不是,校验通过;
    (541)若两数计算结果需要保留的精确位的下一位为4,则取计算结果的前n位,记作c 1
    求得c 1×10^(1-n)×Q的大小,接着在计算结果第N k(N k的取值,在多数情况下N k=n k,在涉及减法的运算中若计算结果的数量级为L,且L<n max,则N k可取值为N k=n k-n max+L或最终保留位的下r位等,下同)位加上c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R;
    R为精确校验参数,当精确校验不通过时人为规定的校验值,比如可直接令R=1;
    对于多步乘除法,取计算结果的前n位,记作c 1
    若c 1×10^(1-n)×Q<1;在计算结果第N k位加上c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R;
    (542)若两数计算结果需要保留的精确位的下一位为5,则取计算结果的前n位,记作c 1
    求得c 1×10^(1-n)×Q的大小,接着在计算结果第N k位减去c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R;
    (55)对于多步乘除法,取计算结果的前n位,记作c 1
    (56)若c 1×10^(1-n)×Q<1。在计算结果第N k位减去c 1×10^(1-n)×Q,若该操作不会改变取舍结果,则校验通过,否则返回n j=R。
  12. 如权利要求11所述的基于高精度取舍方式的误差可控的数据处理系统,其特征在于:误差分析模块还包括前置误差分析模式:
    (61)核对已计算出的数据:
    当需要对已计算出的数据进行核对时,若要校验计算结果的前n x位是否正确,则按照高精度取舍方式保留原数据的前n k=n x+1位进行分析;
    且借助高精度取舍方式保留n x+1位计算出的两数乘除结果可保证前n x位误差极小,前n x+1位的误差小于等于计算结果首位的一半,其直观感受就是保留n x+1位求得的带误差的最大最小值的前n x+1位的误差小于等于计算结果首位,且前n x位的误差不大于1。
    (62)避免计算完毕后返回n j,造成运算资源浪费:
    当需要降低运算压力时,可人为确定保留算式中的前n y位进行估算,并根据计算结果的前n y位返回n j值;
    (63)避免保留位数过多带来过大的运算压力:
    当需要降低运算压力时,可人为确定保留算式中的前n y位进行估算,若计算结果可写为rt×10^x,且需要保留计算结果至小数点后n d位,则保留位数为n k=x+n d+1+r;
    (64)加减乘除混合运算:
    当参与运算的为加减乘除混合运算时,可返回n k=n ki进行取舍。可估计运算结果数量级进行判断。也可人为确定保留算式中的前n y位进行估算,若计算结果可写为 rt×10^x 1,若n y>|x 1-n max|,且x 1≠n max时,返回n j=|x 1-n max|+h,若x 1=n max时,返回n j=h,若rt首位为1,则h可取值为h=1,否则可取值为h=0。;若n y≤|x 1-n max|,则返回n j=|x 1-n max|+Cr,或令n y=n y+Cr,再次进行验证;
    其中Cr为混合运算校正参数,为人为规定的一个参数。
  13. 一种基于高精度取舍方式的误差可控的数据处理方法,其特征在于:采用权利要求1-12任一项的数据处理系统对数据进行精度判断、计算、取舍和输出。
PCT/CN2020/104885 2019-10-18 2020-07-27 基于高精度取舍方式的误差可控的数据处理系统及方法 WO2021073196A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910993935.7 2019-10-18
CN201910993935.7A CN110908975A (zh) 2019-10-18 2019-10-18 基于高精度取舍方式的误差可控的数据处理系统及方法

Publications (1)

Publication Number Publication Date
WO2021073196A1 true WO2021073196A1 (zh) 2021-04-22

Family

ID=69814602

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/104885 WO2021073196A1 (zh) 2019-10-18 2020-07-27 基于高精度取舍方式的误差可控的数据处理系统及方法

Country Status (2)

Country Link
CN (1) CN110908975A (zh)
WO (1) WO2021073196A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116822253A (zh) * 2023-08-29 2023-09-29 山东省计算中心(国家超级计算济南中心) 适用于masnum海浪模式的混合精度实现方法及系统

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110908975A (zh) * 2019-10-18 2020-03-24 汪浩 基于高精度取舍方式的误差可控的数据处理系统及方法
CN111486888A (zh) * 2020-04-14 2020-08-04 新石器慧通(北京)科技有限公司 误差校正方法、装置及无人车辆
CN111639929B (zh) * 2020-05-29 2023-10-27 浙江百世技术有限公司 离线收银系统

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1359064A (zh) * 2001-10-18 2002-07-17 何惠昭 水平放置圆形罐体标尺的设计制作方法
CN101794412A (zh) * 2009-12-29 2010-08-04 金蝶软件(中国)有限公司 一种物料数值信息输出方法及系统
CN101907985A (zh) * 2010-08-06 2010-12-08 上海交通大学 信息定点化处理装置及其处理方法
CN110908975A (zh) * 2019-10-18 2020-03-24 汪浩 基于高精度取舍方式的误差可控的数据处理系统及方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1359064A (zh) * 2001-10-18 2002-07-17 何惠昭 水平放置圆形罐体标尺的设计制作方法
CN101794412A (zh) * 2009-12-29 2010-08-04 金蝶软件(中国)有限公司 一种物料数值信息输出方法及系统
CN101907985A (zh) * 2010-08-06 2010-12-08 上海交通大学 信息定点化处理装置及其处理方法
CN110908975A (zh) * 2019-10-18 2020-03-24 汪浩 基于高精度取舍方式的误差可控的数据处理系统及方法

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116822253A (zh) * 2023-08-29 2023-09-29 山东省计算中心(国家超级计算济南中心) 适用于masnum海浪模式的混合精度实现方法及系统
CN116822253B (zh) * 2023-08-29 2023-12-08 山东省计算中心(国家超级计算济南中心) 适用于masnum海浪模式的混合精度实现方法及系统

Also Published As

Publication number Publication date
CN110908975A (zh) 2020-03-24

Similar Documents

Publication Publication Date Title
WO2021073196A1 (zh) 基于高精度取舍方式的误差可控的数据处理系统及方法
CN108701250B (zh) 数据定点化方法和装置
KR101735677B1 (ko) 부동 소수점의 복합 연산장치 및 그 연산방법
CN110363281A (zh) 一种卷积神经网络量化方法、装置、计算机和存储介质
CN106126189A (zh) 微处理器中的方法
CN106909970A (zh) 一种基于近似计算的二值权重卷积神经网络硬件加速器计算模块
CN106951211B (zh) 一种可重构定浮点通用乘法器
CN102393839B (zh) 并行数据处理系统及方法
WO2022017167A1 (zh) 一种信息处理方法、系统、电子设备及存储介质
CN105930128B (zh) 一种利用浮点数计算指令实现大整数乘法计算加速方法
CN107305485A (zh) 一种用于执行多个浮点数相加的装置及方法
CN104616029A (zh) 数据分类方法及装置
CN105139282A (zh) 一种电网指标数据处理方法、装置以及计算设备
CN109325530A (zh) 基于少量无标签数据的深度卷积神经网络的压缩方法
CN110704424B (zh) 一种应用于数据库的排序方法、装置及相关设备
CN112906865A (zh) 神经网络架构搜索方法、装置、电子设备及存储介质
CN116596095A (zh) 基于机器学习的碳排放量预测模型的训练方法及装置
Meng et al. Learning-based multi-objective evolutionary algorithm for batching decision problem
WO2017185203A1 (zh) 一种用于执行多个浮点数相加的装置及方法
Lu et al. Consensus reaching with minimum adjustment and consistency management in group decision making with intuitionistic multiplicative preference relations
CN106997284A (zh) 实现浮点运算操作的方法和装置
CN112329822A (zh) 一种提高支持向量机分类精度的方法、系统、设备及介质
CN202838322U (zh) 并行数据处理系统
CN106649203A (zh) 一种提高大数据处理质量的方法
CN110489077A (zh) 一种神经网络加速器的浮点乘法运算电路和方法

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20877547

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20877547

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 20877547

Country of ref document: EP

Kind code of ref document: A1