punpy.mc.mc_propagation module#

Use Monte Carlo to propagate uncertainties

class punpy.mc.mc_propagation.MCPropagation(steps, parallel_cores=0, dtype=None, verbose=False, MCdimlast=True)[source]#

Bases: object

add_repeated_outs(outs, i, out_i, yshapes, lenx, n_repeats, repeat_shape, repeat_dims, return_corr, return_samples, output_vars, refyvar)[source]#

Add the results for a single repeated measurement to the combined array

Parameters:
  • outs (list[array]) – array with outputs of the repeated measurements

  • i (int) – index of the individual measurements

  • out_i (list[array]) – array with outputs of the individual measurements

  • yshapes (tuple) – shape of the measurand

  • lenx (int) – number of input quantities

  • n_repeats (int) – number of repeated measurements

  • repeat_shape (tuple) – shape along which the measurements are repeated

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to True

  • return_Jacobian (bool, optional) – set to True to return Jacobian, defaults to False

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • refyvar (int) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

Returns:

combined outputs

Return type:

list[array]

combine_samples(MC_samples)[source]#
finish_repeated_outs(outs, yshapes, lenx, n_repeats, repeat_shape, repeat_dims, return_corr, return_samples, output_vars, refyvar)[source]#

Do final operations to output arrays with repeated measurements (e.g. dividing by number of repeats to take mean).

Parameters:
  • outs (array) – array of outputs of the repeated measurements

  • lenx (int) – number of input quantities

  • n_repeats (int) – number of repeated measurements

  • repeat_shape (tuple) – shape along which the measurements are repeated

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to True

  • return_Jacobian (bool, optional) – set to True to return Jacobian, defaults to False

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • refyvar (int) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

Returns:

finalised array of outputs of the repeated measurements

Return type:

array

generate_MC_sample(x, u_x, corr_x, corr_between=None, pdf_shape='gaussian', pdf_params=None, comp_list=False)[source]#

function to generate MC sample for input quantities

Parameters:
  • x (list[array]) – list of input quantities (usually numpy arrays)

  • u_x (list[array]) – list of systematic uncertainties on input quantities (usually numpy arrays)

  • corr_x (list[array]) – list of correlation matrices (n,n) along non-repeating axis. Can be set to “rand” (diagonal correlation matrix), “syst” (correlation matrix of ones) or a custom correlation matrix.

  • corr_between (array, optional) – correlation matrix (n,n) between input quantities, defaults to None

  • pdf_shape (str, optional) – string identifier of the probability density function shape, defaults to gaussian

  • pdf_params (dict, optional) – dictionaries defining optional additional parameters that define the probability density function, Defaults to None (gaussian does not require additional parameters)

  • comp_list (bool, optional) – boolean to define whether u_x and corr_x are given as a list or individual uncertainty components. Defaults to False, in which case a single combined uncertainty component is given per input quantity.

Returns:

MC sample for input quantities

Return type:

list[array]

generate_MC_sample_cov(x, cov_x, corr_between=None, pdf_shape='gaussian', pdf_params=None)[source]#

function to generate MC sample for input quantities from covariance matrix

Parameters:
  • x (list[array]) – list of input quantities (usually numpy arrays)

  • u_x (list[array]) – list of systematic uncertainties on input quantities (usually numpy arrays)

  • corr_x (list[array]) – list of correlation matrices (n,n) along non-repeating axis. Can be set to “rand” (diagonal correlation matrix), “syst” (correlation matrix of ones) or a custom correlation matrix.

  • corr_between (array, optional) – correlation matrix (n,n) between input quantities, defaults to None

  • pdf_shape (str, optional) – string identifier of the probability density function shape, defaults to gaussian

  • pdf_params (dict, optional) – dictionaries defining optional additional parameters that define the probability density function, Defaults to None (gaussian does not require additional parameters)

Returns:

MC sample for input quantities

Return type:

make_new_outs(out_0, yshapes, lenx, n_repeats, repeat_shape, repeat_dims, return_corr, return_samples, output_vars, refyvar)[source]#

Prepare arrays for storing the results from the individual repeated measurements.

Parameters:
  • out_0 (array) – output array of the first repeated measurement

  • lenx (int) – number of input quantities

  • n_repeats (int) – number of repeated measurements

  • repeat_shape (tuple) – shape along which the measurements are repeated

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to True

  • return_Jacobian (bool, optional) – set to True to return Jacobian, defaults to False

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • refyvar (int) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

Returns:

array of outputs of the repeated measurements

Return type:

array

perform_checks(func, x, u_x, corr_x, repeat_dims, corr_dims, separate_corr_dims, output_vars, fixed_corr_var, param_fixed, refyvar)[source]#

Perform checks on the input parameters and set up the appropriate keywords for further processing

Parameters:
  • func (function) – measurement function

  • x (list[array]) – list of input quantities (usually numpy arrays)

  • u_x (list[array]) – list of uncertainties/covariances on input quantities (usually numpy arrays)

  • corr_x (list[array], optional) – list of correlation matrices (n,n) along non-repeating axis, defaults to None. Can optionally be set to “rand” (diagonal correlation matrix), “syst” (correlation matrix of ones) or a custom correlation matrix.

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • corr_dims (integer or list, optional) – set to positive integer to select the axis used in the correlation matrix. The correlation matrix will then be averaged over other dimensions. Defaults to -99, for which the input array will be flattened and the full correlation matrix calculated. When the combined correlation of 2 or more (but not all) dimensions is required, they can be provided as a string containing the different dimension integers, separated by a dot (e.g. “0.2”). When multiple error_correlations should be calculated, they can be provided as a list.

  • separate_corr_dims (bool, optional) – When set to True and output_vars>1, corr_dims should be a list providing the corr_dims for each output variable, each following the format defined in the corr_dims description. Defaults to False

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • fixed_corr_var (bool or integer, optional) – set to integer to copy the correlation matrix of the dimiension the integer refers to. Set to True to automatically detect if only one uncertainty is present and the correlation matrix of that dimension should be copied. Defaults to False.

  • param_fixed (list of bools, optional) – when repeat_dims>=0, set to true or false to indicate for each input quantity whether it has repeated measurements that should be split (param_fixed=False) or whether the input is fixed (param fixed=True), defaults to None (no inputs fixed).

  • refyvar (int) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

Returns:

yshape,u_x,repeat_axis,repeat_dims,corr_dims,fixed_corr

Return type:

tuple, list[array], int, int, int, array

process_samples(MC_x, MC_y, return_corr=False, return_samples=False, yshapes=None, corr_dims=-99, separate_corr_dims=False, fixed_corr=None, PD_corr=True, output_vars=1)[source]#

Run the MC-generated samples of input quantities through the measurement function and calculate correlation matrix if required.

Parameters:
  • MC_x (array[array]) – MC-generated samples of input quantities

  • MC_y (array[array]) – MC sample of measurand

  • return_corr (bool) – set to True to return correlation matrix of measurand

  • return_samples (bool) – set to True to return generated samples

  • corr_dims (integer, optional) – set to positive integer to select the axis used in the correlation matrix. The correlation matrix will then be averaged over other dimensions. Defaults to -99, for which the input array will be flattened and the full correlation matrix calculated. When the combined correlation of 2 or more (but not all) dimensions is required, they can be provided as a string containing the different dimension integers, separated by a dot (e.g. “0.2”). When multiple error_correlations should be calculated, they can be provided as a list.

  • separate_corr_dims (bool, optional) – When set to True and output_vars>1, corr_dims should be a list providing the corr_dims for each output variable, each following the format defined in the corr_dims description. Defaults to False

  • fixed_corr (array) – correlation matrix to be copied without changing, defaults to None (correlation matrix is calculated rather than copied)

  • PD_corr (bool, optional) – set to True to make sure returned correlation matrices are positive semi-definite, default to True

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

Returns:

uncertainties on measurand

Return type:

array

propagate_cov(func, x, cov_x, param_fixed=None, corr_between=None, samples=None, return_corr=True, return_samples=False, repeat_dims=-99, corr_dims=-99, separate_corr_dims=False, fixed_corr_var=False, output_vars=1, PD_corr=True, refyvar=0, pdf_shape='gaussian', pdf_params=None, allow_some_nans=True)[source]#

Propagate uncertainties with given covariance matrix through measurement function with n input quantities. Input quantities can be floats, vectors (1d-array) or images (2d-array). The covariance matrix can represent the full covariance matrix between all measurements in all dimensions. Alternatively if there are repeated measurements specified in repeat_dims, the covariance matrix is given for the covariance along the dimension that is not one of the repeat_dims.

Parameters:
  • func (function) – measurement function

  • x (list[array]) – list of input quantities (usually numpy arrays)

  • cov_x (list[array]) – list of covariance matrices on input quantities (usually numpy arrays). In case the input quantity is an array of shape (m,o), the covariance matrix is typically given as an array of shape (m*o,m*o).

  • param_fixed (list of bools, optional) – when repeat_dims>=0, set to true or false to indicate for each input quantity whether it has repeated measurements that should be split (param_fixed=False) or whether the input is fixed (param fixed=True), defaults to None (no inputs fixed).

  • corr_between (array, optional) – covariance matrix (n,n) between input quantities, defaults to None

  • samples (list[array], optional) – allows to provide a Monte Carlo sample previously generated. This sample of input quantities will be used instead of generating one from the uncertainties and error-correlation. Defaults to None

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to True

  • return_samples (bool, optional) – set to True to return generated samples, defaults to False

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • corr_dims (integer, optional) – set to positive integer to select the axis used in the correlation matrix. The correlation matrix will then be averaged over other dimensions. Defaults to -99, for which the input array will be flattened and the full correlation matrix calculated. When the combined correlation of 2 or more (but not all) dimensions is required, they can be provided as a string containing the different dimension integers, separated by a dot (e.g. “0.2”). When multiple error_correlations should be calculated, they can be provided as a list.

  • separate_corr_dims (bool, optional) – When set to True and output_vars>1, corr_dims should be a list providing the corr_dims for each output variable, each following the format defined in the corr_dims description. Defaults to False

  • fixed_corr_var (bool or integer, optional) – set to integer to copy the correlation matrix of the dimiension the integer refers to. Set to True to automatically detect if only one uncertainty is present and the correlation matrix of that dimension should be copied. Defaults to False.

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • PD_corr (bool, optional) – set to True to make sure returned correlation matrices are positive semi-definite, default to True

  • refyvar (int, optional) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

  • pdf_shape (str, optional) – string identifier of the probability density function shape, defaults to gaussian

  • pdf_params (dict, optional) – dictionaries defining optional additional parameters that define the probability density function, Defaults to None (gaussian does not require additional parameters)

  • allow_some_nans (bool, optional) – set to False to ignore any MC sample which has any nan’s in the measurand. Defaults to True, in which case only MC samples with only nan’s are ignored.

Returns:

uncertainties on measurand

Return type:

array

propagate_cov_flattened(func, x, cov_x, param_fixed=None, corr_between=None, samples=None, return_corr=True, return_samples=False, repeat_dims=-99, corr_dims=-99, separate_corr_dims=False, fixed_corr_var=False, output_vars=1, PD_corr=True, refyvar=0, pdf_shape='gaussian', pdf_params=None)[source]#

Propagate uncertainties with given covariance matrix through measurement function with n input quantities. Input quantities can be floats, vectors (1d-array) or images (2d-array). The covariance matrix can represent the full covariance matrix between all measurements in all dimensions. Alternatively if there are repeated measurements specified in repeat_dims, the covariance matrix is given for the covariance along the dimension that is not one of the repeat_dims.

Parameters:
  • func (function) – measurement function

  • x (list[array]) – list of input quantities (usually numpy arrays)

  • cov_x (list[array]) – list of covariance matrices on input quantities (usually numpy arrays). In case the input quantity is an array of shape (m,o), the covariance matrix needs to be given as an array of shape (m*o,m*o).

  • param_fixed (list of bools, optional) – when repeat_dims>=0, set to true or false to indicate for each input quantity whether it has repeated measurements that should be split (param_fixed=False) or whether the input is fixed (param fixed=True), defaults to None (no inputs fixed).

  • corr_between (array, optional) – covariance matrix (n,n) between input quantities, defaults to None

  • samples (list[array], optional) – allows to provide a Monte Carlo sample previously generated. This sample of input quantities will be used instead of generating one from the uncertainties and error-correlation. Defaults to None

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to True

  • return_samples (bool, optional) – set to True to return generated samples, defaults to False

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • corr_dims (integer, optional) – set to positive integer to select the axis used in the correlation matrix. The correlation matrix will then be averaged over other dimensions. Defaults to -99, for which the input array will be flattened and the full correlation matrix calculated. When the combined correlation of 2 or more (but not all) dimensions is required, they can be provided as a string containing the different dimension integers, separated by a dot (e.g. “0.2”). When multiple error_correlations should be calculated, they can be provided as a list.

  • separate_corr_dims (bool, optional) – When set to True and output_vars>1, corr_dims should be a list providing the corr_dims for each output variable, each following the format defined in the corr_dims description. Defaults to False

  • fixed_corr_var (bool or integer, optional) – set to integer to copy the correlation matrix of the dimiension the integer refers to. Set to True to automatically detect if only one uncertainty is present and the correlation matrix of that dimension should be copied. Defaults to False.

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • PD_corr (bool, optional) – set to True to make sure returned correlation matrices are positive semi-definite, default to True

  • refyvar (int, optional) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

  • pdf_shape (str, optional) – string identifier of the probability density function shape, defaults to gaussian

  • pdf_params (dict, optional) – dictionaries defining optional additional parameters that define the probability density function, Defaults to None (gaussian does not require additional parameters)

Returns:

uncertainties on measurand

Return type:

array

propagate_random(func, x, u_x, corr_x=None, param_fixed=None, corr_between=None, samples=None, return_corr=False, return_samples=False, repeat_dims=-99, corr_dims=-99, separate_corr_dims=False, fixed_corr_var=False, output_vars=1, PD_corr=True, refyvar=0, pdf_shape='gaussian', pdf_params=None, allow_some_nans=True)[source]#

Propagate random uncertainties through measurement function with n input quantities. Input quantities can be floats, vectors (1d-array) or images (2d-array). Random uncertainties arise when there is no correlation between repeated measurements. It is possible (though rare) that there is a correlation in one of the dimensions that is not one of the repeat_dims.

Parameters:
  • func (function) – measurement function

  • x (list[array]) – list of input quantities (usually numpy arrays)

  • u_x (list[array]) – list of random uncertainties on input quantities (usually numpy arrays)

  • corr_x (list[array], optional) – list of correlation matrices (n,n) along non-repeating axis, defaults to None. Can optionally be set to “rand” (diagonal correlation matrix), “syst” (correlation matrix of ones) or a custom correlation matrix.

  • param_fixed (list of bools, optional) – when repeat_dims>=0, set to true or false to indicate for each input quantity whether it has repeated measurements that should be split (param_fixed=False) or whether the input is fixed (param fixed=True), defaults to None (no inputs fixed).

  • corr_between (array, optional) – correlation matrix (n,n) between input quantities, defaults to None

  • samples (list[array], optional) – allows to provide a Monte Carlo sample previously generated. This sample of input quantities will be used instead of generating one from the uncertainties and error-correlation. Defaults to None

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to False

  • return_samples (bool, optional) – set to True to return generated samples, defaults to False

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • corr_dims (integer, optional) – set to positive integer to select the axis used in the correlation matrix. The correlation matrix will then be averaged over other dimensions. Defaults to -99, for which the input array will be flattened and the full correlation matrix calculated. When the combined correlation of 2 or more (but not all) dimensions is required, they can be provided as a string containing the different dimension integers, separated by a dot (e.g. “0.2”). When multiple error_correlations should be calculated, they can be provided as a list.

  • separate_corr_dims (bool, optional) – When set to True and output_vars>1, corr_dims should be a list providing the corr_dims for each output variable, each following the format defined in the corr_dims description. Defaults to False

  • fixed_corr_var (bool or integer, optional) – set to integer to copy the correlation matrix of the dimiension the integer refers to. Set to True to automatically detect if only one uncertainty is present and the correlation matrix of that dimension should be copied. Defaults to False.

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • PD_corr (bool, optional) – set to True to make sure returned correlation matrices are positive semi-definite, default to True.

  • refyvar (int, optional) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims).

  • pdf_shape (str, optional) – string identifier of the probability density function shape, defaults to gaussian.

  • pdf_params (dict, optional) – dictionaries defining optional additional parameters that define the probability density function, Defaults to None (gaussian does not require additional parameters).

  • allow_some_nans (bool, optional) – set to False to ignore any MC sample which has any nan’s in the measurand. Defaults to True, in which case only MC samples with only nan’s are ignored.

Returns:

uncertainties on measurand

Return type:

array

propagate_standard(func, x, u_x, corr_x, param_fixed=None, corr_between=None, samples=None, return_corr=False, return_samples=False, repeat_dims=-99, corr_dims=-99, separate_corr_dims=False, fixed_corr_var=False, output_vars=1, PD_corr=True, refyvar=0, pdf_shape='gaussian', pdf_params=None, allow_some_nans=True)[source]#

Propagate uncertainties through measurement function with n input quantities. Correlations must be specified in corr_x. Input quantities can be floats, vectors (1d-array) or images (2d-array). Systematic uncertainties arise when there is full correlation between repeated measurements. There is a often also a correlation between measurements along the dimensions that is not one of the repeat_dims.

Parameters:
  • func (function) – measurement function

  • x (list[array]) – list of input quantities (usually numpy arrays)

  • u_x (list[array]) – list of systematic uncertainties on input quantities (usually numpy arrays)

  • corr_x (list[array]) – list of correlation matrices (n,n) along non-repeating axis. Can be set to “rand” (diagonal correlation matrix), “syst” (correlation matrix of ones) or a custom correlation matrix.

  • param_fixed (list of bools, optional) – when repeat_dims>=0, set to true or false to indicate for each input quantity whether it has repeated measurements that should be split (param_fixed=False) or whether the input is fixed (param fixed=True), defaults to None (no inputs fixed).

  • corr_between (array, optional) – correlation matrix (n,n) between input quantities, defaults to None

  • samples (list[array], optional) – allows to provide a Monte Carlo sample previously generated. This sample of input quantities will be used instead of generating one from the uncertainties and error-correlation. Defaults to None

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to False

  • return_samples (bool, optional) – set to True to return generated samples, defaults to False

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • corr_dims (integer, optional) – set to positive integer to select the axis used in the correlation matrix. The correlation matrix will then be averaged over other dimensions. Defaults to -99, for which the input array will be flattened and the full correlation matrix calculated. When the combined correlation of 2 or more (but not all) dimensions is required, they can be provided as a string containing the different dimension integers, separated by a dot (e.g. “0.2”). When multiple error_correlations should be calculated, they can be provided as a list.

  • separate_corr_dims (bool, optional) – When set to True and output_vars>1, corr_dims should be a list providing the corr_dims for each output variable, each following the format defined in the corr_dims description. Defaults to False

  • fixed_corr_var (bool or integer, optional) – set to integer to copy the correlation matrix of the dimension the integer refers to. Set to True to automatically detect if only one uncertainty is present and the correlation matrix of that dimension should be copied. Defaults to False.

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • PD_corr (bool, optional) – set to True to make sure returned correlation matrices are positive semi-definite, default to True

  • refyvar (int, optional) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

  • pdf_shape (str, optional) – string identifier of the probability density function shape, defaults to gaussian

  • pdf_params (dict, optional) – dictionaries defining optional additional parameters that define the probability density function, Defaults to None (gaussian does not require additional parameters)

  • allow_some_nans (bool, optional) – set to False to ignore any MC sample which has any nan’s in the measurand. Defaults to True, in which case only MC samples with only nan’s are ignored.

Returns:

uncertainties on measurand

Return type:

array

propagate_systematic(func, x, u_x, corr_x=None, param_fixed=None, corr_between=None, samples=None, return_corr=False, return_samples=False, repeat_dims=-99, corr_dims=-99, separate_corr_dims=False, fixed_corr_var=False, output_vars=1, PD_corr=True, refyvar=0, pdf_shape='gaussian', pdf_params=None, allow_some_nans=True)[source]#

Propagate systematic uncertainties through measurement function with n input quantities. Input quantities can be floats, vectors (1d-array) or images (2d-array). Systematic uncertainties arise when there is full correlation between repeated measurements. There is a often also a correlation between measurements along the dimensions that is not one of the repeat_dims.

Parameters:
  • func (function) – measurement function

  • x (list[array]) – list of input quantities (usually numpy arrays)

  • u_x (list[array]) – list of systematic uncertainties on input quantities (usually numpy arrays)

  • corr_x (list[array], optional) – list of correlation matrices (n,n) along non-repeating axis, defaults to None. Can optionally be set to “rand” (diagonal correlation matrix), “syst” (correlation matrix of ones) or a custom correlation matrix.

  • param_fixed (list of bools, optional) – when repeat_dims>=0, set to true or false to indicate for each input quantity whether it has repeated measurements that should be split (param_fixed=False) or whether the input is fixed (param fixed=True), defaults to None (no inputs fixed).

  • corr_between (array, optional) – correlation matrix (n,n) between input quantities, defaults to None

  • samples (list[array], optional) – allows to provide a Monte Carlo sample previously generated. This sample of input quantities will be used instead of generating one from the uncertainties and error-correlation. Defaults to None

  • return_corr (bool, optional) – set to True to return correlation matrix of measurand, defaults to False

  • return_samples (bool, optional) – set to True to return generated samples, defaults to False

  • repeat_dims (integer or list of 2 integers, optional) – set to positive integer(s) to select the axis which has repeated measurements. The calculations will be performed seperately for each of the repeated measurments and then combined, in order to save memory and speed up the process. Defaults to -99, for which there is no reduction in dimensionality..

  • corr_dims (integer, optional) – set to positive integer to select the axis used in the correlation matrix. The correlation matrix will then be averaged over other dimensions. Defaults to -99, for which the input array will be flattened and the full correlation matrix calculated. When the combined correlation of 2 or more (but not all) dimensions is required, they can be provided as a string containing the different dimension integers, separated by a dot (e.g. “0.2”). When multiple error_correlations should be calculated, they can be provided as a list.

  • separate_corr_dims (bool, optional) – When set to True and output_vars>1, corr_dims should be a list providing the corr_dims for each output variable, each following the format defined in the corr_dims description. Defaults to False

  • fixed_corr_var (bool or integer, optional) – set to integer to copy the correlation matrix of the dimiension the integer refers to. Set to True to automatically detect if only one uncertainty is present and the correlation matrix of that dimension should be copied. Defaults to False.

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • PD_corr (bool, optional) – set to True to make sure returned correlation matrices are positive semi-definite, default to True

  • refyvar (int, optional) – Index of output variable with reference shape (only relevant when output_vars>1; should be output variable with most dimensions; affects things like repeat_dims)

  • pdf_shape (str, optional) – string identifier of the probability density function shape, defaults to gaussian

  • pdf_params (dict, optional) – dictionaries defining optional additional parameters that define the probability density function, Defaults to None (gaussian does not require additional parameters)

  • allow_some_nans (bool, optional) – set to False to ignore any MC sample which has any nan’s in the measurand. Defaults to True, in which case only MC samples with only nan’s are ignored.

Returns:

uncertainties on measurand

Return type:

array

return_no_unc(return_corr, return_samples)[source]#

function to generate outputs in right format when there are no valid uncertainties

Parameters:
  • return_corr (bool) – set to True to return correlation matrix of measurand

  • return_samples (bool) – set to True to return generated samples

Returns:

outputs (None) in right format

run_samples(func, MC_x, output_vars=1, start=None, end=None, sli=None, allow_some_nans=True)[source]#

process all the MC samples of input quantities through the measurand function

Parameters:
  • func (function) – measurement function

  • MC_x (array[array]) – MC-generated samples of input quantities

  • output_vars (integer, optional) – number of output parameters in the measurement function. Defaults to 1.

  • start (integer, optional) – set this parameter to propagate the input quantities through the measurement function starting from a specfic index. All input quantities before this index are ignored. Defaults to None, in which case no input quantities are ignored.

  • end (integer, optional) – set this parameter to propagate the input quantities through the measurement function up until a specfic index. All input quantities after this index are ignored. Defaults to None, in which case no input quantities are ignored.

  • sli (slice, optional) – set this parameter to a slice to set which input quantities will be processed through the measurment function. All other input quantities are ignored. Can only be used if start and end are not set. Defaults to None, in which case no input quantities are ignored.

  • allow_some_nans (bool, optional) – set to False to ignore any MC sample which has any nan’s in the measurand. Defaults to True, in which case only MC samples with only nan’s are ignored.

Returns:

MC sample of measurand

Return type:

array[array]