Error Propagation

Error propagation is implemented as a child class of ExperimentalValue called DerivedValue. When working with QExPy, the result of all computations are stored as instances of this class.

The DerivedValue Object

class qexpy.data.data.DerivedValue(formula)[source]

Result of calculations performed with ExperimentalValue instances

This class is automatically instantiated when the user performs calculations with other ExperimentalValue instances. It is created with the properly propagated uncertainties and units. The two available methods for error propagation are the derivative method, and the Monte Carlo method.

Internally, a DerivedValue preserves information on how it is calculated, so the user is able to make use of that information. For example, the user can find the derivative of a DerivedValue with respect to another ExperimentalValue that this value is derived from.

Examples

>>> import qexpy as q
>>> # First let's create some standard measurements
>>> a = q.Measurement(5, 0.2)
>>> b = q.Measurement(4, 0.1)
>>> c = q.Measurement(6.3, 0.5)
>>> d = q.Measurement(7.2, 0.5)
>>> # Now we can perform operations on them
>>> result = q.sqrt(c) * d - b / q.exp(a)
>>> result
DerivedValue(18 +/- 1)
>>> result.value
18.04490478513969
>>> result.error
1.4454463754287323
>>> # By default, the standard derivative method is used, but it can be changed
>>> q.set_error_method(q.ErrorMethod.MONTE_CARLO)
>>> result.value
18.03203135268583
>>> result.error
1.4116412532654283
>>> # If we want this value to use a different error method from the global default
>>> result.error_method = "derivative" # this only affects this value alone
>>> result.error
1.4454463754287323
>>> # If we want to reset the error method for this value and use the global default
>>> result.reset_error_method()
>>> result.error
1.4116412532654283

Properties

DerivedValue.value
DerivedValue.error
DerivedValue.relative_error
DerivedValue.error_method

The default error method used for this value

QExPy currently supports two different methods of error propagation, the derivative method, and the Monte-Carlo method. The user can change the global default which applies to all values, or set the error method of this single quantity if it is to be different from the global settings.

Type:

ErrorMethod

DerivedValue.mc

The settings object for customizing Monte Carlo

Type:

dut.MonteCarloSettings

Methods

DerivedValue.reset_error_method()[source]

Resets the default error method for this value to follow the global settings

DerivedValue.recalculate()[source]

Recalculates the value

A DerivedValue instance preserves information on how the value was derived. If values of the original measurements are changed, and you wish to update the derived value using the exact same formula, this method can be used.

Examples

>>> import qexpy as q
>>> a = q.Measurement(5, 0.2)
>>> b = q.Measurement(4, 0.1)
>>> c = a + b
>>> c
DerivedValue(9.0 +/- 0.2)
>>> # Now we change the value of a
>>> a.value = 8
>>> c.recalculate()
>>> c
DerivedValue(12.0 +/- 0.2)
DerivedValue.show_error_contributions()[source]

Displays measurements’ contribution to the final uncertainty

The MonteCarloSettings Object

QExPy provides users with many options to customize Monte Carlo error propagation. Each DerivedValue object stores a MonteCarloSettings object that contains some settings for the Monte Carlo error propagation of this value.

class qexpy.data.utils.MonteCarloSettings(evaluator)[source]

The object for customizing the Monte Carlo error propagation process

Properties

MonteCarloSettings.sample_size

The Monte Carlo sample size

Type:

int

MonteCarloSettings.confidence

The confidence level for choosing the mode of a Monte Carlo distribution

Type:

float

MonteCarloSettings.xrange

The x-range of the simulation

This is really the y-range, which means it’s the range of the y-values to show, but also this is the x-range of the histogram.

Type:

tuple

Methods

MonteCarloSettings.set_xrange(*args)[source]

set the range for the monte carlo simulation

MonteCarloSettings.use_mode_with_confidence(confidence=None)[source]

Use the mode of the distribution with a confidence coverage for this value

MonteCarloSettings.use_mean_and_std()[source]

Use the mean and std of the distribution for this value

MonteCarloSettings.show_histogram(bins=100, **kwargs)[source]

Shows the distribution of the Monte Carlo simulated samples

MonteCarloSettings.samples()[source]

The raw samples generated in the Monte Carlo simulation

Sometimes when the distribution is not typical, you might wish to do your own analysis with the raw samples generated in the Monte Carlo simulation. This method allows you to access a copy of the raw data.

MonteCarloSettings.use_custom_value_and_error(value, error)[source]

Manually set the value and uncertainty for this quantity

Sometimes when the distribution is not typical, and you wish to see for yourself what the best approach is to choose the center value and uncertainty for this quantity, use this method to manually set these values.