Welcome to resampling’s documentation!

Contents:

The module resampling can be used for estimating errors of of non-linear functions of random measurements.

It can be used mainly for the analysis of Markov chain Monte Carlo methods.

resampling.bootstrap(a, iterations, func=<function identity at 0x37f1938>, func_axis=None, dtype=None)[source]

Compute the bootstrap mean and error of an array with respect to a given function.

Parameters :

a : array_like

Array containing numbers whose jackknife mean and error is desired. If a is not an array, a conversion is attempted.

iterations: int

Number of bootstrap iterations to execute.

func: callable function

(Ususally non-linear) Function that maps a scalar to a scalar (or number to a number), whichs is applied to each jackknife mean value.

func_axis: integer, optional

Axis of the array that is used to seperate different independent measurements for usage in a function with more than one argument. The shape of this axis must match the number of arguments of the given function func.

dtype : data-type, optional

Type to use in computing the jackknife mean and error. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.

Examples

>>> a = numpy.random.normal(loc=5.0, scale=2.0, size=1000)
>>> mean_a, error_a = bootstrap(a, 100)
>>> (mean_a > 4.9, mean_a < 5.1)
(True, True)
>>> (error_a > 2.0/math.sqrt(1000 - 1) - 0.01, error_a < 2.0/math.sqrt(1000 - 1) + 0.01)
(True, True)
resampling.identity(x)[source]

Identity function used as default function in the resampling methods.

resampling.jackknife(a, func=<function identity at 0x37f1938>, func_axis=None, dtype=None)[source]

Compute the jackknife mean and error of an array (with \(N\) values) with respect to a given function \(f\).

Parameters :

a : array_like

Array containing numbers whose jackknife mean and error is desired. If a is not an array, a conversion is attempted.

func: callable function, optional

(Ususally non-linear) Function that maps a scalar to a scalar (or number to a number), whichs is applied to each jackknife mean value. (The default is the identity function.)

func_axis: integer, optional

Axis of the array that is used to seperate different independent measurements for usage in a function with more than one argument. The shape of this axis must match the number of arguments of the given function func.

dtype : data-type, optional

Type to use in computing the jackknife mean and error. (For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.)

Returns :

jackknife_mean : dtype

Mean value \(\overline f\) of the function applied to the data set.

jackknife_error: dtype

Error \(\sigma_{\overline f}\) of the function applied to the data set.

Notes

The single jackknife values are calculated by

\[\overline{x_i} = \frac{1}{N} \sum_{j \neq i} x_j,\]

and the mean \(\overline f\) and the error \(\sigma_{\overline f}\) of the function \(f\) are calculated using

\[\begin{split}\overline f &= \frac{1}{N} \sum_i f(\overline{x_i}) \\ \sigma_{\overline f} &= \sqrt{\frac{N - 1}{N}} \cdot \sqrt{\sum_i \left( f(\overline{x_i})^2 - \overline f ^2 \right) }\end{split}\]

References

[R1]
    1. Quenouille: Notes on bias in estimation. Biometrika, 43, S.353ff (1956)
[R2]
    1. Tukey: Bias and confidence in not quite large samples. Annls. Math. Stat. 29, S. 614 (1958)

Examples

>>> a = numpy.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> jackknife(a)
(3.0, 0.70710678118654757)
>>> jackknife(a, func=lambda x: x**2)
(9.125, 4.247793544888923)
>>> b = numpy.array([[1.0, 2.0, 3.0, 4.0, 5.0], [1.0, 3.0, 5.0, 7.0, 9.0]])
>>> jackknife(b, func=lambda x,y: x*y, func_axis=0)
resampling.subsampling(a, samples, iterations, func=<function identity at 0x37f1938>, func_axis=None, dtype=None)[source]

Compute the subsampling mean and error of an array with respect to a given function.

Parameters :

a : array_like

Array containing numbers whose jackknife mean and error is desired. If a is not an array, a conversion is attempted.

iterations: int

Number of subsampling iterations to execute.

samples: int

Number of samples from the data set to include into the subsampling

func: callable function

(Ususally non-linear) Function that maps a scalar to a scalar (or number to a number), whichs is applied to each jackknife mean value.

func_axis: integer, optional

Axis of the array that is used to seperate different independent measurements for usage in a function with more than one argument. The shape of this axis must match the number of arguments of the given function func.

dtype : data-type, optional

Type to use in computing the jackknife mean and error. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.

Examples

>>> a = numpy.random.normal(loc=5.0, scale=2.0, size=1000)
>>> mean_a, error_a = subsampling(a, 100, 50)
>>> (mean_a > 4.9, mean_a < 5.1)
(True, True)
>>> (error_a > 2.0/math.sqrt(1000 - 1) - 0.01, error_a < 2.0/math.sqrt(1000 - 1) + 0.01)
(True, True)

Indices and tables

Table Of Contents

This Page