Block Resampler
- class tsbootstrap.block_resampler.BlockResampler(blocks: List[ndarray], X: ndarray, block_weights: Callable | ndarray | None = None, tapered_weights: Callable | ndarray | None = None, rng: Generator | Integral | None = None)[source]
A class to perform block resampling.
- resample_blocks()[source]
Resamples blocks and their corresponding tapered_weights with replacement to create a new list of blocks and tapered_weights with total length equal to n.
- resample_block_indices_and_data()[source]
Generate block indices and corresponding data for the input data array X.
- property X: ndarray
The input data array.
- property block_weights: ndarray
An array of normalized block_weights.
- property blocks: List[ndarray]
A list of numpy arrays where each array represents the indices of a block in the time series.
- resample_block_indices_and_data()[source]
Generate block indices and corresponding data for the input data array X.
- Returns:
A tuple containing a list of block indices and a list of corresponding modified data blocks.
- Return type:
Tuple[List[np.ndarray], List[np.ndarray]]
Example
>>> block_resampler = BlockResampler(blocks=blocks, X=data) >>> block_indices, block_data = block_resampler.resample_block_indices_and_data() >>> len(block_indices) == len(data) True
Notes
The block indices are generated using the following steps: 1. Generate block weights using the block_weights argument. 2. Resample blocks with replacement to create a new list of blocks with total length equal to n. 3. Apply tapered_weights to the data within the blocks if provided.
- resample_blocks()[source]
Resample blocks and corresponding tapered weights with replacement to create a new list of blocks and tapered weights with total length equal to n.
- Returns:
The newly generated list of blocks and their corresponding tapered_weights with total length equal to n.
- Return type:
Tuple[list of ndarray, list of ndarray]
Example
>>> block_resampler = BlockResampler(blocks=blocks, X=data) >>> new_blocks, new_tapered_weights = block_resampler.resample_blocks() >>> len(new_blocks) == len(data) True
- property rng: Generator
Generator for reproducibility.
- property tapered_weights
A list of normalized weights.