Contains the Value class.
A Value represents a numerical measurement of some kind, with its associated uncertainty/error.
For example a value of 23 ± 0.2 would be
Values mostly support the same operators that numbers do - you can add them, divide them, raise them to powers, compare them etc. There are a few important differences however. Firstly, the error values of the resultant operations will be derived from the standard guidelines for combining uncertainties. Specifically, values will be assumed to be independent, and so errors will be summed etc. in quadrature.
Secondly, comparing two values with
<etc. will compare the values only - the error values will not be taken into account. I thought it would be too confusing otherwise. However, all values have a
consistent_with()method which will look at the error values. If two values are consistent, then one should not be considered larger than the other, regardless of what
The intention behind the Value class was that if you wanted to, you could forget that it was anything other than an
float, and only access the error associated with it if you need it.
You can create a Value from a value, and the argument will be treated exactly like an
float. That is, unless you also supply an error value, the resultant Value will have an error of 0. I considered having the error of the Value passed in become the new error, but decided it would become too easy to lose track of the errors. So,
Value(Value(23, 0.2))would produce a Value with an error of 0 (and a value of 23).
One final note on terminology - I know it is confusing that the Value class has a property called
value(), but that is the terminology in use as of this version.
- value – The value.
- error – The uncertainty associated with the value. By default this is zero.
- TypeError – if either the value or its error is not numeric.
- ValueError – if the error is negative.
This is a static method, and serves as an alternate constructor for Values. It tries to convert some value to an actual Value, and if it can’t because it is the wrong type, it just sends the object back unaltered.
- value – The value to convert.
- error – The error associated with the value.
Either the converted
Valueor the original object.
Returns the value’s… value. That is, the measurement itself, without its associated error.
Returns the value’s associated error.
Returns the value’s associated error as a proportion of the value. If the value is 0, the relative error will be 0 too.
Returns the range of possible values implied by the uncertainty.
Checks if the value is consistent with another value. Two values are considered consistent if the difference between them is less than or equal to the sum of their uncertainties/errors.
If two values are consistent, there cannot be said to be a difference between them, whereas if they are not consistent, there is a meaningful difference between them.
You can also provide an
float, which will be assumed to have an error of zero.
Parameters: other (Value) – The other value to check against. Raises: TypeError – if the other value given is not a