File: test_bootstrap.py

package info (click to toggle)
python-resample 1.10.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,228 kB
  • sloc: python: 1,542; makefile: 12
file content (53 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
import pytest

from resample.bootstrap import confidence_interval, resample


def run_resample(n, method):
    x = np.arange(n)
    r = []
    for b in resample(x, method=method):
        r.append(b)
    return r


@pytest.mark.benchmark(group="bootstrap-100")
@pytest.mark.parametrize("method", ("ordinary", "balanced", "normal"))
def test_resample_100(benchmark, method):
    benchmark(run_resample, 100, method)


@pytest.mark.benchmark(group="bootstrap-1000")
@pytest.mark.parametrize("method", ("ordinary", "balanced", "normal"))
def test_bootstrap_resample_1000(benchmark, method):
    benchmark(run_resample, 1000, method)


@pytest.mark.benchmark(group="bootstrap-10000")
@pytest.mark.parametrize("method", ("ordinary", "balanced", "normal"))
def test_bootstrap_resample_10000(benchmark, method):
    benchmark(run_resample, 10000, method)


def run_confidence_interval(n, ci_method):
    x = np.arange(n)
    confidence_interval(np.mean, x, ci_method=ci_method)


@pytest.mark.benchmark(group="confidence-interval-100")
@pytest.mark.parametrize("ci_method", ("percentile", "bca"))
def test_bootstrap_confidence_interval_100(benchmark, ci_method):
    benchmark(run_confidence_interval, 100, ci_method)


@pytest.mark.benchmark(group="confidence-interval-1000")
@pytest.mark.parametrize("ci_method", ("percentile", "bca"))
def test_bootstrap_confidence_interval_1000(benchmark, ci_method):
    benchmark(run_confidence_interval, 1000, ci_method)


@pytest.mark.benchmark(group="confidence-interval-10000")
@pytest.mark.parametrize("ci_method", ("percentile", "bca"))
def test_bootstrap_confidence_interval_10000(benchmark, ci_method):
    benchmark(run_confidence_interval, 10000, ci_method)