本文整理汇总了Python中arch.bootstrap.IIDBootstrap.seed方法的典型用法代码示例。如果您正苦于以下问题:Python IIDBootstrap.seed方法的具体用法?Python IIDBootstrap.seed怎么用?Python IIDBootstrap.seed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arch.bootstrap.IIDBootstrap
的用法示例。
在下文中一共展示了IIDBootstrap.seed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bca
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)
示例2: test_conf_int_bias_corrected
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)
示例3: test_pandas_integer_index
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [as 别名]
def test_pandas_integer_index(self):
x = self.x
x_int = self.x_df.copy()
x_int.index = 10 + np.arange(x.shape[0])
bs = IIDBootstrap(x, x_int)
bs.seed(23456)
for pdata, kwdata in bs.bootstrap(10):
assert_equal(pdata[0], pdata[1].values)
示例4: test_conf_int_bca_scaler
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [as 别名]
def test_conf_int_bca_scaler(self):
num_bootstrap = 100
bs = IIDBootstrap(self.y)
bs.seed(23456)
ci = bs.conf_int(np.mean, reps=num_bootstrap, method='bca')
msg = 'conf_int(method=\'bca\') scalar input regression. Ensure ' \
'output is at least 1D with numpy.atleast_1d().'
assert ci.shape == (2, 1), msg
示例5: test_apply
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)
示例6: test_extra_kwargs
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)
示例7: test_conf_int_bca_scaler
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [as 别名]
def test_conf_int_bca_scaler(self):
num_bootstrap = 100
bs = IIDBootstrap(self.y)
bs.seed(23456)
try:
ci = bs.conf_int(np.mean, reps=num_bootstrap, method='bca')
assert(ci.shape == (2, 1))
except IndexError:
pytest.fail('conf_int(method=\'bca\') scaler input regression. '
'Ensure output is at least 1D with '
'numpy.atleast_1d().')
示例8: test_mixed_types
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [as 别名]
def test_mixed_types(self):
x, y, z = self.x_df, self.y_series, self.z
bs = IIDBootstrap(y, x=x, z=z)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(data), 1)
assert_equal(len(kwdata.keys()), 2)
assert_frame_equal(x.iloc[index], kwdata['x'])
assert_frame_equal(x.iloc[index], bs.x)
assert_series_equal(y.iloc[index], data[0])
assert_equal(z[index], kwdata['z'])
assert_equal(z[index], bs.z)
示例9: test_state
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [as 别名]
def test_state(self):
bs = IIDBootstrap(np.arange(100))
bs.seed(23456)
state = bs.get_state()
for data, kwdata in bs.bootstrap(10):
final = data[0]
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
final_seed = data[0]
bs.set_state(state)
for data, kwdata in bs.bootstrap(10):
final_state = data[0]
assert_equal(final, final_seed)
assert_equal(final, final_state)
示例10: test_apply_series
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)
示例11: test_extra_kwargs
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)
示例12: test_conf_int_parametric
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)
示例13: test_pandas
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [as 别名]
def test_pandas(self):
x, y, z = self.x_df, self.y_series, self.z_df
bs = IIDBootstrap(y)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(kwdata.keys()), 0)
assert_series_equal(y.iloc[index], data[0])
# Ensure no changes to original data
assert_series_equal(bs._args[0], y)
bs = IIDBootstrap(y=y)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(data), 0)
assert_series_equal(y.iloc[index], kwdata['y'])
assert_series_equal(y.iloc[index], bs.y)
# Ensure no changes to original data
assert_series_equal(bs._kwargs['y'], y)
bs = IIDBootstrap(x, y, z)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(data), 3)
assert_equal(len(kwdata.keys()), 0)
assert_frame_equal(x.iloc[index], data[0])
assert_series_equal(y.iloc[index], data[1])
assert_frame_equal(z.iloc[index], data[2])
bs = IIDBootstrap(x, y=y, z=z)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(data), 1)
assert_equal(len(kwdata.keys()), 2)
assert_frame_equal(x.iloc[index], data[0])
assert_series_equal(y.iloc[index], kwdata['y'])
assert_frame_equal(z.iloc[index], kwdata['z'])
assert_series_equal(y.iloc[index], bs.y)
assert_frame_equal(z.iloc[index], bs.z)
示例14: test_numpy
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [as 别名]
def test_numpy(self):
x, y, z = self.x, self.y, self.z
bs = IIDBootstrap(y)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(kwdata.keys()), 0)
assert_equal(y[index], data[0])
# Ensure no changes to original data
assert_equal(bs._args[0], y)
bs = IIDBootstrap(y=y)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(data), 0)
assert_equal(y[index], kwdata['y'])
assert_equal(y[index], bs.y)
# Ensure no changes to original data
assert_equal(bs._kwargs['y'], y)
bs = IIDBootstrap(x, y, z)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(data), 3)
assert_equal(len(kwdata.keys()), 0)
assert_equal(x[index], data[0])
assert_equal(y[index], data[1])
assert_equal(z[index], data[2])
bs = IIDBootstrap(x, y=y, z=z)
bs.seed(23456)
for data, kwdata in bs.bootstrap(10):
index = bs.index
assert_equal(len(data), 1)
assert_equal(len(kwdata.keys()), 2)
assert_equal(x[index], data[0])
assert_equal(y[index], kwdata['y'])
assert_equal(z[index], kwdata['z'])
assert_equal(y[index], bs.y)
assert_equal(z[index], bs.z)
示例15: test_studentized
# 需要导入模块: from arch.bootstrap import IIDBootstrap [as 别名]
# 或者: from arch.bootstrap.IIDBootstrap import seed [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)