Uncertainty Module¶
You might read the user guide introduction of this module.
-
class
maabara.uncertainty.
Sheet
(equation='0', name='', data=[])[source]¶ Symbolic propagation of uncertainty
- equation : sympy equation string, optional
- See
set_equation()
- name : string, optional
- See
set_name()
- data : list
- See
set_data()
-
batch
(data, fields, mode='default')[source]¶ Batch process a set of values.
- data : array_like NxM or tuple of array_like
- A tuple will be stacked to columns. Columns represent
different variables indexed by
fields
. Rows will be iterated. - fields : string
- List of columns fields divided by
|
. Deviations columns must be suffix by%
. Use*
to ignore a column formdata
- mode : {‘default’, ‘ufloat’, or ‘exact’}, optional
- Specify
return
type
- out : ndarray
Depending on mode.
‘default’ will return Nx2 array. First column will hold nominal value, second its deviation. ‘exact’ like default but rounded to significant digits. ‘ufloat’ will return Nx1 array of ufloats
It is possible to set constant values or errors before calling batch method. The batch method will automaticly use the values if not given by the data array. See example below.
Retrieve a computation object and set equation
>>> stack = ma.uncertainty.Sheet('a*x**3')
Data array specifies the sets to compute row-by-row
>>> data = [ [0.5, 1. , 0.1], [0.3, 2. ,0.15] ]
Batch the data
>>> stack.set_value('a', error=0.05) # set constant error for a >>> stack.batch(data, 'a|x|x%') array([[ 0.5 , 0.15811388], [ 2.4 , 0.6720119 ]]) # line-by-line result with uncertainty
Try again with a constant value
>>> stack.set_value('a',1., 0.05) # define constant a value >>> stack.batch(data, '*|x|x%', 'ufloat') # rerun computation ignoring first data column array([[1.0+/-0.30000000000000004], [8.0+/-1.7999999999999998]], dtype=object)
-
eq
(equation, name='')[source]¶ Alias of
set_equation()
-
get_data
(line=False, element=False)[source]¶ Get data
- line : string, optional
- Variable name
- element : {‘val’, ‘dev’, or ‘tex’}, optional
- Return mode
- out : mixed
- If
line
andelement
are False complete data is returned. If foundline
will be returned as tuple. Ifelement
is specified value (val), deviation (dev) or Latex markup (tex) will be returned.
-
get_result
(mode='default')[source]¶ Get error propagation
mode : {‘default’, ‘exact’, ‘ufloat’, or ‘tex’}
out : mixed
-
n
(name)[source]¶ Alias of
set_name()
-
p
(mode='default', multiply='dot')[source]¶ Alias of
print_result()
-
print_result
(mode='default', multiply='dot')[source]¶ Print results of symbolic error propagation
- mode : {‘default’, or ‘short’}
- Specifies printing mode.
- multiply : string, optional
- Latex markup for multiply symbol. Use
None
to supress multipliers
- out : ufloat
- Result
-
run
(equation=False, data=[])[source]¶ Runs symbolic error propagation by specified data
- equation : string, optional
- See
set_equation()
- data : list, optional
- See
set_data()
out : sympy equation, sympy error_equation, ufloat result
-
set_data
(data)[source]¶ Set data manually.
- data : list of tuples
- [ ( string Variable, float Value, float Error = 0, tex = “”) ]
It is more recommend to use
set_value()
function to manipulate the data.- out : boolean
- True on success.
-
set_equation
(equation, name='')[source]¶ Set equation string
- equation : Sympy equation string
- Use fundamental functions like
sin, exp, sqrt, atan
etc. andRational(a,b)
to define a fraction a/b. Allowed variable names are alphanumeric and use_
only. They must be specifed byset_value()
. Please be aware thatI
will be interpreted as imaginary unit. - name : string, optional
- See
set_name()
- out : boolean
- True on success.
-
set_name
(name)[source]¶ Set a name
- name : string
- Name as Latex markup. It will appear in computation equations.
- out : boolean
- True on success.
-
set_value
(symbol, value=False, error=False, tex=False)[source]¶ Set uncertain value
- symbol : string
- Symbol string used in equation
- value : float, optional
- Value
- error : float, optional
- Deviation
- tex : string, optional
- Latex markup replace string. All symbol occurences will be replaced by this markup.
-
v
(symbol, value=False, error=False, tex=False)[source]¶ Alias of
set_value()