def test(self, xtest, x, type_='smaller', alpha=0.05):
"""
Parameters
----------
type_: in ['smaller', 'equality']
type of comparison to perform
alpha: float
significance level
"""
# call function to make sure it has been evaluated a sufficient number of times
if type_ not in ['smaller', 'equality']:
raise NotImplementedError(type_)
ftest, ftestse = self(xtest)
f, fse = self(x)
# get function values
fxtest = np.array(self.cache[tuple(xtest)])
fx = np.array(self.cache[tuple(x)])
if np.mean(fxtest-fx) == 0.0:
if type_ == 'equality':
return True
if type_ == 'smaller':
return False
if self.paired:
# if values are paired then test on distribution of differences
statistic, pvalue = stats.ttest_rel(fxtest, fx, axis=None)
else:
statistic, pvalue = stats.ttest_ind(fxtest, fx, equal_var=False, axis=None)
if type_ == 'smaller':
# if paired then df=N-1, else df=N1+N2-2=2*N-2
df = self.N-1 if self.paired else 2*self.N-2
pvalue = stats.t.cdf(statistic, df)
# return true if null hypothesis rejected
return pvalue < alpha
if type_ == 'equality':
# return true if null hypothesis not rejected
return pvalue > alpha
评论列表
文章目录