Ejemplo n.º 1
0
 def test_bootstrap_simple_mean(self):
     data = np.ones(10)
     results = statistics.bootstrap(
         data,
         np.mean,
         bootstrap_iterations=5,
     )
     self.assertListEqual(results, [1 for _ in range(5)])
Ejemplo n.º 2
0
 def test_bootstrap_sample_size_fraction(self):
     data = np.ones(10)
     results = statistics.bootstrap(
         data,
         len,
         bootstrap_sample_size=0.5,
         bootstrap_iterations=2,
     )
     for i in range(2):
         self.assertTrue(results[i] == 5, f"{i} has length {results[i]}")
Ejemplo n.º 3
0
 def test_bootstrap_min_sample_size_integer(self):
     data = np.ones(100)
     results = statistics.bootstrap(
         data,
         len,
         bootstrap_min_sample_size=3,
         bootstrap_iterations=10,
         sample_method="integer",
     )
     for i in range(10):
         self.assertTrue(results[i] >= 3, f"{i} has length {results[i]}")
Ejemplo n.º 4
0
    def test_bootstrap_null(self):
        def func(_, a, b=1):
            return a + b

        data = np.ones(10)
        results = statistics.bootstrap(
            data,
            func,
            func_args=(1,),
            func_kws={"b": 1},
            bootstrap_iterations=5,
        )
        self.assertListEqual(results, [2 for _ in range(5)])
Ejemplo n.º 5
0
    def test_bootstrap_custom_sampler(self):
        data = np.arange(10)

        def sample_method(_, number):
            return np.arange(0, number)

        results = statistics.bootstrap(
            data,
            np.mean,
            bootstrap_sample_size=5,  # select first 5 every time
            bootstrap_iterations=4,  # number of iteractions
            sample_method=sample_method,
        )
        # first three are [0, 1, 2, 3, 4] so mean is 2
        self.assertListEqual(results, [2 for _ in range(4)])