Skip to main content

stresampling

license pypi python

The aim of the package

The Python package stresampling implements resampling methods applicable to stationary timeseries, especially the stationary bootstrap (Politis, D. N. and Romano, J. P.) method for estimating statistical properties of stationary timeseries, using the bootstrap percentile, the bias-corrected, or the bootstrap-t methods, with an optimal choice of the parameter (Politis, D.N. and White, H., Patton, A., Politis, D.N. and White, H.) from a single time series.

The aim of the package is to provide an easy and intuitive interface to calculate statistics of desired quantities using single one timeseries, with minimal dependencies on other packages.

Authors

Yoshihiko Nishikawa (Tohoku University), Jun Takahashi (University of New Mexico), and Takashi Takahashi (University of Tokyo)

Requirements

  • Python>=3.6
  • numpy>=1.13.3
  • scipy>=0.19.1
  • psutil>=5.9.0

Usage

The stresampling package is very simple and intuitive to use. What you need are the timeseries you wish to analyze, a quantity of interest, and the coverage probability for the output confidence interval.

The following is a simple example showing how to use the package:

import numpy as np
from stresampling import stationary_bootstrap as sbm

def phys(timeseries): # Kurtosis of the distribution
    return np.mean(timeseries**4.0) / np.mean(timeseries**2.0)**2.0

def main():
    file = 'data/timeseries.dat'
    timeseries = np.loadtxt(file)
    print(timeseries.shape) # (10000,)
    print(timeseries)

    alpha = 0.68
    stat = sbm.conf_int(timeseries, phys, alpha)
    print('Mean:', stat.mean, 'Standard error:', stat.se, 'Lower and upper confidence limits:', stat.low, stat.up)

if __name__ == "__main__":
    main()

Detail of the conf_int function

stresampling.stationary_bootstrap.conf_int(seq, phys, alpha, number_bsamples, parallel=True, method='percentile')
  • parameters

    • seq: ndarray

      Input timeseries of shape (timeseries length, *)

    • phys: Function

      A method to calculate the desired quantity

      Note that the conf_int function currently supports only a scalar output

    • alpha: Real number in [0, 1]

      The coverage probability of the output confidence interval

    • number_bsamples: Integer value, optional

      The number of bootstrap samples to be built

      The default value is 1000

    • parallel: Bool, optional

      Build bootstrap samples using multiple cores if True

      The default is True

    • method: {'percentile', 'bt', 'symbt', 'bc'}, optional

      Specify which method will be used to estimate the confidence limits

      The default is 'percentile'

  • Return: Stat: a class including

    • mean: The estimate of the quantity
    • se: The standard error of the estimate
    • low and up: The lower and upper confidence limits
    • prob: The estimated optimal probability for the stationary bootstrap method
    • dist: ndarray of the sorted bootstrap samples of the quantity
    • autocorr: ndarray for the unnormalized autocorrelation function of the timeseries

Installation

You can easily install the package via pypi as

pip install stresampling

or, by cloning the repository,

git clone https://github.com/YoshihikoNishikawa/stresampling.git
cd stresampling
pip install .

Future development

We will implement other resampling methods such as the circular bootstrap and the subsampling method in the future updates.

Citation

If you use this package or find it useful, please cite arXiv:2112.11837.

Contributing

If you wish to contribute, please submit a pull request.

If you find an issue or a bug, please contact us or raise an issue.

Metadata

Release files for stresampling 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stresampling 1.0.2
File Size Uploaded
stresampling-1.0.2.tar.gz 21.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stresampling 1.0.2
File Interpreter ABI Platform
stresampling-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 43.4 kB

Release files / stresampling-1.0.2.tar.gz

Download URL stresampling-1.0.2.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4e155d7d2965b46f820157720e0cfe3c6f0aa35a7441a3928920ee9dc7468dde
BLAKE2b-256 checksum
How to use checksums
a2d5deba25f4fecc3a48bfc40b739af2e6bea3b28ef2be3f552b1e7dfef890be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.2

Release files / stresampling-1.0.2-py3-none-any.whl

Download URL stresampling-1.0.2-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e33209f89827643bdd5145b6bacf4f2b6f3bc012c8af65b02878b5865b2b3e1
BLAKE2b-256 checksum
How to use checksums
444e2a8b5f063e7f66f34cf21e4a6d28a42d58212525bca0ca4f884e4fb268d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.2

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page