本文整理汇总了Python中arch.bootstrap.IIDBootstrap.cov方法的典型用法代码示例。如果您正苦于以下问题:Python IIDBootstrap.cov方法的具体用法?Python IIDBootstrap.cov怎么用?Python IIDBootstrap.cov使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arch.bootstrap.IIDBootstrap
的用法示例。
在下文中一共展示了IIDBootstrap.cov方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extra_kwargs
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import cov [as 别名]
def test_extra_kwargs(self):
extra_kwargs = {'axis': 0}
bs = IIDBootstrap(self.x)
bs.seed(23456)
num_bootstrap = 100
bs.cov(self.func, reps=num_bootstrap, extra_kwargs=extra_kwargs)
bs = IIDBootstrap(axis=self.x)
bs.seed(23456)
with pytest.raises(ValueError):
bs.cov(self.func, reps=num_bootstrap, extra_kwargs=extra_kwargs)
示例2: test_extra_kwargs
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import cov [as 别名]
def test_extra_kwargs(self):
extra_kwargs = {'axis': 0}
bs = IIDBootstrap(self.x)
bs.seed(23456)
num_bootstrap = 100
def func(y, axis=0):
return y.mean(axis=axis)
bs.cov(func, reps=num_bootstrap, extra_kwargs=extra_kwargs)
bs = IIDBootstrap(axis=self.x)
bs.seed(23456)
assert_raises(ValueError, bs.cov, func,
reps=num_bootstrap, extra_kwargs=extra_kwargs)
示例3: test_conf_int_norm
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import cov [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, :])
示例4: test_cov
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import cov [as 别名]
def test_cov(self):
def func(y):
return y.mean(axis=0)
bs = IIDBootstrap(self.x)
num_bootstrap = 10
cov = bs.cov(func=func, reps=num_bootstrap, recenter=False)
bs.reset()
results = np.zeros((num_bootstrap, 2))
count = 0
for data, kw 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=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=func, reps=num_bootstrap, recenter=False)
bs.reset()
results = np.zeros((num_bootstrap, 2))
count = 0
for data, kw 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=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)
示例5: test_studentized
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import cov [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)