当前位置: 首页>>代码示例>>Python>>正文


Python IIDBootstrap.reset方法代码示例

本文整理汇总了Python中arch.bootstrap.IIDBootstrap.reset方法的典型用法代码示例。如果您正苦于以下问题:Python IIDBootstrap.reset方法的具体用法?Python IIDBootstrap.reset怎么用?Python IIDBootstrap.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arch.bootstrap.IIDBootstrap的用法示例。


在下文中一共展示了IIDBootstrap.reset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_bca

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_bca(self):
        num_bootstrap = 20
        bs = IIDBootstrap(self.x)
        bs.seed(23456)

        def func(y):
            return y.mean(axis=0)

        ci_direct = bs.conf_int(func, reps=num_bootstrap, method='bca')
        bs.reset()
        base, results = bs._base, bs._results
        p = np.zeros(2)
        p[0] = np.mean(results[:, 0] < base[0])
        p[1] = np.mean(results[:, 1] < base[1])
        b = stats.norm.ppf(p)
        b = b[:, None]
        q = stats.norm.ppf(np.array([0.025, 0.975]))

        base = func(self.x)
        nobs = self.x.shape[0]
        jk = _loo_jackknife(func, nobs, [self.x], {})
        u = (nobs - 1) * (jk - base)
        u2 = np.sum(u * u, 0)
        u3 = np.sum(u * u * u, 0)
        a = u3 / (6.0 * (u2 ** 1.5))
        a = a[:, None]
        percentiles = 100 * stats.norm.cdf(b + (b + q) / (1 - a * (b + q)))

        ci = np.zeros((2, 2))
        for i in range(2):
            ci[i] = np.percentile(results[:, i], list(percentiles[i]))
        ci = ci.T
        assert_allclose(ci_direct, ci)
开发者ID:jkr2110,项目名称:arch,代码行数:35,代码来源:test_bootstrap.py

示例2: test_conf_int_bias_corrected

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_conf_int_bias_corrected(self):
        num_bootstrap = 20
        bs = IIDBootstrap(self.x)
        bs.seed(23456)

        def func(y):
            return y.mean(axis=0)

        ci = bs.conf_int(func, reps=num_bootstrap, method='bc')
        bs.reset()
        ci_db = bs.conf_int(func, reps=num_bootstrap, method='debiased')
        assert_equal(ci, ci_db)
        base, results = bs._base, bs._results
        p = np.zeros(2)
        p[0] = np.mean(results[:, 0] < base[0])
        p[1] = np.mean(results[:, 1] < base[1])
        b = stats.norm.ppf(p)
        q = stats.norm.ppf(np.array([0.025, 0.975]))
        q = q[:, None]
        percentiles = 100 * stats.norm.cdf(2 * b + q)

        ci = np.zeros((2, 2))
        for i in range(2):
            ci[i] = np.percentile(results[:, i], list(percentiles[:, i]))
        ci = ci.T
        assert_allclose(ci_db, ci)
开发者ID:jkr2110,项目名称:arch,代码行数:28,代码来源:test_bootstrap.py

示例3: test_reset

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
 def test_reset(self):
     bs = IIDBootstrap(np.arange(100))
     state = bs.get_state()
     for data, kwdata in bs.bootstrap(10):
         final = data[0]
     bs.reset()
     state_reset = bs.get_state()
     for data, kwdata in bs.bootstrap(10):
         final_reset = data[0]
     assert_equal(final, final_reset)
     assert_equal(state, state_reset)
开发者ID:jkr2110,项目名称:arch,代码行数:13,代码来源:test_bootstrap.py

示例4: test_apply

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_apply(self):
        bs = IIDBootstrap(self.x)
        bs.seed(23456)

        results = bs.apply(self.func, 1000)
        bs.reset(23456)
        direct_results = []
        for pos, _ in bs.bootstrap(1000):
            direct_results.append(self.func(*pos))
        direct_results = np.array(direct_results)
        assert_equal(results, direct_results)
开发者ID:bashtage,项目名称:arch,代码行数:13,代码来源:test_bootstrap.py

示例5: test_apply_series

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_apply_series(self):
        bs = IIDBootstrap(self.y_series)
        bs.seed(23456)

        def func(y):
            return y.mean(0)

        results = bs.apply(func, 1000)
        bs.reset(23456)
        direct_results = []
        for pos, kw in bs.bootstrap(1000):
            direct_results.append(func(*pos))
        direct_results = np.array(direct_results)
        direct_results = direct_results[:, None]
        assert_equal(results, direct_results)
开发者ID:jkr2110,项目名称:arch,代码行数:17,代码来源:test_bootstrap.py

示例6: test_cov

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_cov(self):
        bs = IIDBootstrap(self.x)
        num_bootstrap = 10
        cov = bs.cov(func=self.func, reps=num_bootstrap, recenter=False)
        bs.reset()

        results = np.zeros((num_bootstrap, 2))
        count = 0
        for data, _ in bs.bootstrap(num_bootstrap):
            results[count] = data[0].mean(axis=0)
            count += 1
        errors = results - self.x.mean(axis=0)
        direct_cov = errors.T.dot(errors) / num_bootstrap
        assert_allclose(cov, direct_cov)

        bs.reset()
        cov = bs.cov(func=self.func, recenter=True, reps=num_bootstrap)
        errors = results - results.mean(axis=0)
        direct_cov = errors.T.dot(errors) / num_bootstrap
        assert_allclose(cov, direct_cov)

        bs = IIDBootstrap(self.x_df)
        cov = bs.cov(func=self.func, reps=num_bootstrap, recenter=False)
        bs.reset()
        var = bs.var(func=self.func, reps=num_bootstrap, recenter=False)
        bs.reset()
        results = np.zeros((num_bootstrap, 2))
        count = 0
        for data, _ in bs.bootstrap(num_bootstrap):
            results[count] = data[0].mean(axis=0)
            count += 1
        errors = results - self.x.mean(axis=0)
        direct_cov = errors.T.dot(errors) / num_bootstrap
        assert_allclose(cov, direct_cov)
        assert_allclose(var, np.diag(direct_cov))

        bs.reset()
        cov = bs.cov(func=self.func, recenter=True, reps=num_bootstrap)
        errors = results - results.mean(axis=0)
        direct_cov = errors.T.dot(errors) / num_bootstrap
        assert_allclose(cov, direct_cov)
开发者ID:bashtage,项目名称:arch,代码行数:43,代码来源:test_bootstrap.py

示例7: test_conf_int_norm

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_conf_int_norm(self):
        num_bootstrap = 200
        bs = IIDBootstrap(self.x)

        def func(y):
            return y.mean(axis=0)

        ci = bs.conf_int(func, reps=num_bootstrap, size=0.90,
                         method='norm')
        bs.reset()
        ci_u = bs.conf_int(func, tail='upper', reps=num_bootstrap, size=0.95,
                           method='var')
        bs.reset()
        ci_l = bs.conf_int(func, tail='lower', reps=num_bootstrap, size=0.95,
                           method='cov')
        bs.reset()
        cov = bs.cov(func, reps=num_bootstrap)
        mu = func(self.x)
        std_err = np.sqrt(np.diag(cov))
        upper = mu + stats.norm.ppf(0.95) * std_err
        lower = mu + stats.norm.ppf(0.05) * std_err
        assert_allclose(lower, ci[0, :])
        assert_allclose(upper, ci[1, :])

        assert_allclose(ci[1, :], ci_u[1, :])
        assert_allclose(ci[0, :], ci_l[0, :])
        inf = np.empty_like(ci_l[0, :])
        inf.fill(np.inf)
        assert_equal(inf, ci_l[1, :])
        assert_equal(-1 * inf, ci_u[0, :])
开发者ID:jkr2110,项目名称:arch,代码行数:32,代码来源:test_bootstrap.py

示例8: test_conf_int_percentile

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_conf_int_percentile(self):
        num_bootstrap = 200
        bs = IIDBootstrap(self.x)

        def func(y):
            return y.mean(axis=0)

        ci = bs.conf_int(func, reps=num_bootstrap, size=0.90,
                         method='percentile')
        bs.reset()
        ci_u = bs.conf_int(func, tail='upper', reps=num_bootstrap, size=0.95,
                           method='percentile')
        bs.reset()
        ci_l = bs.conf_int(func, tail='lower', reps=num_bootstrap, size=0.95,
                           method='percentile')
        bs.reset()
        results = np.zeros((num_bootstrap, 2))
        count = 0
        for pos, kw in bs.bootstrap(num_bootstrap):
            results[count] = func(*pos)
            count += 1

        upper = np.percentile(results, 95, axis=0)
        lower = np.percentile(results, 5, axis=0)

        assert_allclose(lower, ci[0, :])
        assert_allclose(upper, ci[1, :])

        assert_allclose(ci[1, :], ci_u[1, :])
        assert_allclose(ci[0, :], ci_l[0, :])
        inf = np.empty_like(ci_l[0, :])
        inf.fill(np.inf)
        assert_equal(inf, ci_l[1, :])
        assert_equal(-1 * inf, ci_u[0, :])
开发者ID:jkr2110,项目名称:arch,代码行数:36,代码来源:test_bootstrap.py

示例9: test_conf_int_basic

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_conf_int_basic(self):
        num_bootstrap = 200
        bs = IIDBootstrap(self.x)

        ci = bs.conf_int(self.func, reps=num_bootstrap, size=0.90, method='basic')
        bs.reset()
        ci_u = bs.conf_int(self.func, tail='upper', reps=num_bootstrap, size=0.95,
                           method='basic')
        bs.reset()
        ci_l = bs.conf_int(self.func, tail='lower', reps=num_bootstrap, size=0.95,
                           method='basic')
        bs.reset()
        results = np.zeros((num_bootstrap, 2))
        count = 0
        for pos, _ in bs.bootstrap(num_bootstrap):
            results[count] = self.func(*pos)
            count += 1
        mu = self.func(self.x)
        upper = mu + (mu - np.percentile(results, 5, axis=0))
        lower = mu + (mu - np.percentile(results, 95, axis=0))

        assert_allclose(lower, ci[0, :])
        assert_allclose(upper, ci[1, :])

        assert_allclose(ci[1, :], ci_u[1, :])
        assert_allclose(ci[0, :], ci_l[0, :])
        inf = np.empty_like(ci_l[0, :])
        inf.fill(np.inf)
        assert_equal(inf, ci_l[1, :])
        assert_equal(-1 * inf, ci_u[0, :])
开发者ID:bashtage,项目名称:arch,代码行数:32,代码来源:test_bootstrap.py

示例10: test_conf_int_parametric

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_conf_int_parametric(self):
        def param_func(x, params=None, state=None):
            if state is not None:
                mu = params
                e = state.standard_normal(x.shape)
                return (mu + e).mean(0)
            else:
                return x.mean(0)

        def semi_func(x, params=None):
            if params is not None:
                mu = params
                e = x - mu
                return (mu + e).mean(0)
            else:
                return x.mean(0)

        reps = 100
        bs = IIDBootstrap(self.x)
        bs.seed(23456)

        ci = bs.conf_int(func=param_func, reps=reps, sampling='parametric')
        assert len(ci) == 2
        assert np.all(ci[0] < ci[1])
        bs.reset()
        results = np.zeros((reps, 2))
        count = 0
        mu = self.x.mean(0)
        for pos, _ in bs.bootstrap(100):
            results[count] = param_func(*pos, params=mu,
                                        state=bs.random_state)
            count += 1
        assert_equal(bs._results, results)

        bs.reset()
        ci = bs.conf_int(func=semi_func, reps=100, sampling='semi')
        assert len(ci) == 2
        assert np.all(ci[0] < ci[1])
        bs.reset()
        results = np.zeros((reps, 2))
        count = 0
        for pos, _ in bs.bootstrap(100):
            results[count] = semi_func(*pos, params=mu)
            count += 1
        assert_allclose(bs._results, results)
开发者ID:bashtage,项目名称:arch,代码行数:47,代码来源:test_bootstrap.py

示例11: test_studentized

# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import reset [as 别名]
    def test_studentized(self):
        num_bootstrap = 20
        bs = IIDBootstrap(self.x)
        bs.seed(23456)

        def func(y):
            return y.mean(axis=0)

        def std_err_func(mu, y):
            errors = y - mu
            var = (errors ** 2.0).mean(axis=0)
            return np.sqrt(var / y.shape[0])

        ci = bs.conf_int(func, reps=num_bootstrap, method='studentized',
                         std_err_func=std_err_func)
        bs.reset()
        base = func(self.x)
        results = np.zeros((num_bootstrap, 2))
        stud_results = np.zeros((num_bootstrap, 2))
        count = 0
        for pos, kwdata in bs.bootstrap(reps=num_bootstrap):
            results[count] = func(*pos)
            std_err = std_err_func(results[count], *pos)
            stud_results[count] = (results[count] - base) / std_err
            count += 1

        assert_allclose(results, bs._results)
        assert_allclose(stud_results, bs._studentized_results)
        errors = results - results.mean(0)
        std_err = np.sqrt(np.mean(errors ** 2.0, axis=0))
        ci_direct = np.zeros((2, 2))
        for i in range(2):
            ci_direct[0, i] = base[i] - std_err[i] * np.percentile(
                stud_results[:, i], 97.5)
            ci_direct[1, i] = base[i] - std_err[i] * np.percentile(
                stud_results[:, i], 2.5)
        assert_allclose(ci, ci_direct)

        bs.reset()
        ci = bs.conf_int(func, reps=num_bootstrap, method='studentized',
                         studentize_reps=50)

        bs.reset()
        base = func(self.x)
        results = np.zeros((num_bootstrap, 2))
        stud_results = np.zeros((num_bootstrap, 2))
        count = 0
        for pos, kwdata in bs.bootstrap(reps=num_bootstrap):
            results[count] = func(*pos)
            inner_bs = IIDBootstrap(*pos)
            seed = bs.random_state.randint(2 ** 31 - 1)
            inner_bs.seed(seed)
            cov = inner_bs.cov(func, reps=50)
            std_err = np.sqrt(np.diag(cov))
            stud_results[count] = (results[count] - base) / std_err
            count += 1

        assert_allclose(results, bs._results)
        assert_allclose(stud_results, bs._studentized_results)
        errors = results - results.mean(0)
        std_err = np.sqrt(np.mean(errors ** 2.0, axis=0))

        ci_direct = np.zeros((2, 2))
        for i in range(2):
            ci_direct[0, i] = base[i] - std_err[i] * np.percentile(
                stud_results[:, i], 97.5)
            ci_direct[1, i] = base[i] - std_err[i] * np.percentile(
                stud_results[:, i], 2.5)
        assert_allclose(ci, ci_direct)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            bs.conf_int(func, reps=num_bootstrap, method='studentized',
                        std_err_func=std_err_func, reuse=True)
            assert_equal(len(w), 1)
开发者ID:jkr2110,项目名称:arch,代码行数:77,代码来源:test_bootstrap.py


注:本文中的arch.bootstrap.IIDBootstrap.reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。