Block Bootstrap

class tsbootstrap.block_bootstrap.BartlettsBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, bootstrap_type: str = 'moving', rng=None, **kwargs)[source]

Bartlett’s Bootstrap class for time series data.

This class is a specialized bootstrapping class that uses Bartlett’s window for tapered weights.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Bartlett window is defined as:

\[\begin{split}w(n) = 1 - \\frac{|n - (N - 1) / 2|}{(N - 1) / 2}\end{split}\]

where \(N\) is the block length.

References

class tsbootstrap.block_bootstrap.BaseBlockBootstrap(bootstrap_type: str = 'moving', **kwargs)[source]

Base class for block bootstrapping.

Parameters:
  • bootstrap_type (str, default="moving") – The type of block bootstrap to use. Must be one of “nonoverlapping”, “moving”, “stationary”, or “circular”.

  • kwargs – Additional keyword arguments to pass to the BaseBlockBootstrapConfig class. See the documentation for BaseBlockBootstrapConfig for more information.

class tsbootstrap.block_bootstrap.BlackmanBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, bootstrap_type: str = 'moving', rng=None, **kwargs)[source]

Blackman Bootstrap class for time series data.

This class is a specialized bootstrapping class that uses Blackman window for tapered weights.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Blackman window is defined as:

\[\begin{split}w(n) = 0.42 - 0.5 \\cos\\left(\\frac{2\\pi n}{N - 1}\\right) + 0.08 \\cos\\left(\\frac{4\\pi n}{N - 1}\\right)\end{split}\]

where \(N\) is the block length.

References

class tsbootstrap.block_bootstrap.BlockBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, rng=None)[source]

Block Bootstrap base class for time series data.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is automatically set to the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Raises:

ValueError – If block_length is not greater than 0.

class tsbootstrap.block_bootstrap.CircularBlockBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, rng=None, **kwargs)[source]

Circular Block Bootstrap class for time series data.

This class functions similarly to the base BlockBootstrap class, with the following modifications to the default behavior: * overlap_flag is always set to True, meaning that blocks can overlap. * wrap_around_flag is always set to True, meaning that the data will wrap around when generating blocks. * block_length_distribution is always None, meaning that the block length distribution is not utilized. * combine_generation_and_sampling_flag is always False, meaning that the block generation and resampling are performed separately.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Circular Block Bootstrap is defined as:

\[\begin{split}\\hat{X}_t = \\frac{1}{L}\\sum_{i=1}^L X_{t + \\lfloor U_i \\rfloor}\end{split}\]

where \(L\) is the block length, \(U_i\) is a uniform random variable on \([0, 1]\), and \(\\lfloor \\cdot \\rfloor\) is the floor function.

References

class tsbootstrap.block_bootstrap.HammingBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, bootstrap_type: str = 'moving', rng=None, **kwargs)[source]

Hamming Bootstrap class for time series data.

This class is a specialized bootstrapping class that uses Hamming window for tapered weights.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Hamming window is defined as:

\[\begin{split}w(n) = 0.54 - 0.46 \\cos\\left(\\frac{2\\pi n}{N - 1}\\right)\end{split}\]

where \(N\) is the block length.

References

class tsbootstrap.block_bootstrap.HanningBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, bootstrap_type: str = 'moving', rng=None, **kwargs)[source]

Hanning Bootstrap class for time series data.

This class is a specialized bootstrapping class that uses Hanning window for tapered weights.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • bootstrap_type (str, default="moving") – The type of block bootstrap to use. Must be one of “nonoverlapping”, “moving”, “stationary”, or “circular”.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Hanning window is defined as:

\[\begin{split}w(n) = 0.5 - 0.5 \\cos\\left(\\frac{2\\pi n}{N - 1}\\right)\end{split}\]

where \(N\) is the block length.

References

class tsbootstrap.block_bootstrap.MovingBlockBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, rng=None, **kwargs)[source]

Moving Block Bootstrap class for time series data.

This class functions similarly to the base BlockBootstrap class, with the following modifications to the default behavior: * overlap_flag is always set to True, meaning that blocks can overlap. * wrap_around_flag is always set to False, meaning that the data will not wrap around when generating blocks. * block_length_distribution is always None, meaning that the block length distribution is not utilized. * combine_generation_and_sampling_flag is always False, meaning that the block generation and resampling are performed separately.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Moving Block Bootstrap is defined as:

\[\begin{split}\\hat{X}_t = \\frac{1}{L}\\sum_{i=1}^L X_{t + \\lfloor U_i \\rfloor}\end{split}\]

where \(L\) is the block length, \(U_i\) is a uniform random variable on \([0, 1]\), and \(\\lfloor \\cdot \\rfloor\) is the floor function.

References

class tsbootstrap.block_bootstrap.NonOverlappingBlockBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, rng=None, **kwargs)[source]

Non-Overlapping Block Bootstrap class for time series data.

This class functions similarly to the base BlockBootstrap class, with the following modifications to the default behavior: * overlap_flag is always set to False, meaning that blocks cannot overlap. * wrap_around_flag is always set to False, meaning that the data will not wrap around when generating blocks. * block_length_distribution is always None, meaning that the block length distribution is not utilized. * combine_generation_and_sampling_flag is always False, meaning that the block generation and resampling are performed separately.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Raises:

ValueError – If block_length is not greater than 0.

Notes

The Non-Overlapping Block Bootstrap is defined as:

\[\begin{split}\\hat{X}_t = \\frac{1}{L}\\sum_{i=1}^L X_{t + i}\end{split}\]

where \(L\) is the block length.

References

class tsbootstrap.block_bootstrap.StationaryBlockBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, rng=None, **kwargs)[source]

Stationary Block Bootstrap class for time series data.

This class functions similarly to the base BlockBootstrap class, with the following modifications to the default behavior: * overlap_flag is always set to True, meaning that blocks can overlap. * wrap_around_flag is always set to False, meaning that the data will not wrap around when generating blocks. * block_length_distribution is always “geometric”, meaning that the block length distribution is geometrically distributed. * combine_generation_and_sampling_flag is always False, meaning that the block generation and resampling are performed separately.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Stationary Block Bootstrap is defined as:

\[\begin{split}\\hat{X}_t = \\frac{1}{L}\\sum_{i=1}^L X_{t + \\lfloor U_i \\rfloor}\end{split}\]

where \(L\) is the block length, \(U_i\) is a uniform random variable on \([0, 1]\), and \(\\lfloor \\cdot \\rfloor\) is the floor function.

References

class tsbootstrap.block_bootstrap.TukeyBootstrap(n_bootstraps: Integral = 10, block_length: Integral | None = None, block_length_distribution: str | None = None, wrap_around_flag: bool = False, overlap_flag: bool = False, combine_generation_and_sampling_flag: bool = False, block_weights=None, tapered_weights: Callable | None = None, overlap_length: Integral | None = None, min_block_length: Integral | None = None, bootstrap_type: str = 'moving', rng=None, **kwargs)[source]

Tukey Bootstrap class for time series data.

This class is a specialized bootstrapping class that uses Tukey window for tapered weights.

Parameters:
  • n_bootstraps (Integral, default=10) – The number of bootstrap samples to create.

  • block_length (Integral, default=None) – The length of the blocks to sample. If None, the block length is the square root of the number of observations.

  • block_length_distribution (str, default=None) – The block length distribution function to use. If None, the block length distribution is not utilized.

  • wrap_around_flag (bool, default=False) – Whether to wrap around the data when generating blocks.

  • overlap_flag (bool, default=False) – Whether to allow blocks to overlap.

  • combine_generation_and_sampling_flag (bool, default=False) – Whether to combine the block generation and sampling steps.

  • block_weights (array-like of shape (n_blocks,), default=None) – The weights to use when sampling blocks.

  • tapered_weights (callable, default=None) – The tapered weights to use when sampling blocks.

  • overlap_length (Integral, default=None) – The length of the overlap between blocks.

  • min_block_length (Integral, default=None) – The minimum length of the blocks.

  • rng (Integral or np.random.Generator, default=np.random.default_rng()) – The random number generator or seed used to generate the bootstrap samples.

Notes

The Tukey window is defined as:

\[\begin{split}w(n) = \\begin{cases} 0.5\\left[1 + \\cos\\left(\\frac{2\\pi n}{\\alpha(N - 1)}\\right)\\right], & \\text{if } n < \\frac{\\alpha(N - 1)}{2}\\\\ 1, & \\text{if } \\frac{\\alpha(N - 1)}{2} \\leq n \\leq (N - 1)\\left(1 - \\frac{\\alpha}{2}\\right)\\\\ 0.5\\left[1 + \\cos\\left(\\frac{2\\pi n}{\\alpha(N - 1)}\\right)\\right], & \\text{if } n > (N - 1)\\left(1 - \\frac{\\alpha}{2}\\right) \\end{cases}\end{split}\]

where \(N\) is the block length and \(\\alpha\) is the parameter controlling the shape of the window.

References