This Scripts is capable of calculating the Gaussian Error Propagation and create simple statistics for datasets.
This was created out of the frustration with the module Fehlerrechnung (engl. Error-Propagation) at my university and the ability to reliably cross check my results.
Although this library is built around the concept of accepting all numeric data types (float, int, Decimal), it is highly encouraged to use strings (str) to represent numbers. This recommendation stems from the inherent rounding errors associated with floating-point data types. The library performs all calculations using the built-in decimal module, ensuring the best accuracy when using string inputs.
In the following documentation number_like refers to Decimal | int | float | str
(all trigonometric functions currently only support arguments in radians)
argument x is of type Value | number_like. All following functions return a Value instance
exp( x )log( argument [, base:x defaults to Euler-e ] )sin( x )cos( x )tan( x )arcsin( x )arccos( x )arctan( x )sinh( x )cosh( x )tanh( x )arsinh( x )arcosh( x )artanh( x )
Following classes and functions that are relevant for you:
-
-
-
Value( best_value: number_like, error: number_like [, scale_exponent: int=0 ] [, precision: int=2 ] [, id:str ] )
-
operation symbol example negate --apositive ++aaddition +a+b1+aa+1subtraction -a-b2-aa-2multiplication *a*b3*aa*3division /a/b4/aa/4exponentiation **a**b5**aa**5Compare Equal ==a==b6==aa==6Compare Unequal !=a!=b7!=aa!=7
-
-
-
Measurement( data: Sequence[number_like] [, scale_exponent: int=0] [, precision: int=2 ] [, id:str ] )
-
-
The following classes assume that only the
Y-Component of the (X,Y)-Point-cloud is erroneous.-
simple linear Regression (all
Y-Values have the same absolute error)Regression_linear_simple( x_data: Sequence[number_like], y_data: Sequence[number_like] )
-
general linear Regression (
Y-Values can have different absolute errors)Regression_linear( x_data:Sequence[number_like], y_data:Sequence[Value] )
-
-
Converting data from one unit-scale to an other specific unit-scale.
PF employs Decimal-Prefixes or Pre-factors to denote the magnitude or scale of units( i.e kilometers (km), microfarad (µF) etc ).
example:
>>> # creating a mass `Value` in units of milligram that are converted to kilograms >>> Value( '100', '3.5', exp=PF.m.to(PF.k) ) (100 ± 3.5)e-6 δe= 0.035 >>> # creating a distance `Value` in units of kilometers that are converted to meters >>> Value( '3.21', '0.11', exp=PF.k.to(PF.NONE) ) (3.21 ± 0.11)e+3 δe= 0.034
-
predefined class-variables
name alias factor PETAPE+15TERATE+12GIGAGE+9MEGAME+6KILOkE+3HECTOhE+2DECAdaE+1NONE_1DEZIdE-1CENTIcE-2MILLImE-3MICROµE-6NANOnE-9PICOpE-12FEMTOfE-15
-
-
>>> # creating statistics to a set of measurements, the supplied data is scaled by the Pre-factor `PF.m` same as `exp=-3`
>>> length = Measurement( [1.249, 1.234, 1.252, 1.238, 1.235, 1.246, 1.262, 1.255, 1.243], PF.m, id='d' ) # data is in millimeter
Measurement:
+----------------------------------------------------+
| N: 9 |
| Spanwidth: 0.028 * 10^-3 |
| -------------------------------------------------- |
| Average: (1246 ± 3.2)e-6 δe= 0.0025 |
| Median: (1.2 ± 0)e-3 δe= 0E+27 |
| -------------------------------------------------- |
| σ²: (80 ± 4.4)e-9 δe= 0.056 |
| σ: (8.9 ± 2.1)e-6 δe= 0.24 |
| s²: (90 ± 5.6)e-9 δe= 0.062 |
| s: (9.5 ± 2.4)e-6 δe= 0.25 |
+----------------------------------------------------+
>>> # defining erroneous values
>>> # id is optional and does not alter results of your calculations
>>> # it is mainly there to be a placeholder in the .print_info_equation() output (example is below)
>>> a = Value( '1.630' , '0.021' , prec=2, id='a' )
>>> b = Value( '0.6649', '0.0040', prec=3, id='b' )
>>> x = Value( '1.376' , '0.037' , prec=2, id='x' )
>>> a.v # alias for a.value
1.63
>>> a.error # alias for a.e
0.021
>>> a.re # alias for a.relative_error
0.013
>>> # examples displaying the syntax of different calculations
>>> y1 = 13*a*x + 14*a*b*x**2 + 21*a*b**3
67.947 ± 2.513 δe= 0.03699
>>> y2 = exp( ( a - x ) / x )
(1202.73 ± 42.48)e-3 δe= 0.03532
>>> y3 = b * sin( a * x )
(520.3 ± 27.86)e-3 δe= 0.05355
>>> y4 = ( x - a ) / ( x + b )
(-124.45 ± 22.84)e-3 δe= 0.1835
>>> y1.print_info_equation()
Equation : b**3 * a * 21 + x * a * 13 + x**2 * b * a * 14
Derivatives:
x: a * 13 + b * a * x * 28
b: a * b**2 * 63 + x**2 * a * 14
a: b**3 * 21 + x * 13 + x**2 * b * 14