From 886120dd65ed534fe3d2a53a925a6ecfe4e45bed Mon Sep 17 00:00:00 2001 From: jirigav Date: Tue, 25 Jun 2024 16:19:27 +0200 Subject: [PATCH] use new binomtest function --- README.md | 2 +- booltest/booltest_main.py | 6 +++--- setup.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 84e99d04..622802ee 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ The best distinguisher results are essentially following Binomial distribution: `Bi(number_of_blocks, probability_of_dist_eval_to_1)`. To compute the p-value we run the Binomial test: -```scipy.stats.binom_test(observed_ones, n=ntrials, p=dist_probab, alternative='two-sided')``` +```scipy.stats.binomtest(observed_ones, n=ntrials, p=dist_probab, alternative='two-sided').pvalue``` This method eliminates a need to have a `pval_db.json` database computed with the reference data for given parameters. The benefit is the halving method gives directly a p-value, without a need to run reference computations. diff --git a/booltest/booltest_main.py b/booltest/booltest_main.py index dfca5385..75b83341 100644 --- a/booltest/booltest_main.py +++ b/booltest/booltest_main.py @@ -289,7 +289,7 @@ def analyse_input(self, num_evals, hws_input=None): for res in results: fail = 'x' if self.zscore_thresh and abs(res.zscore) > self.zscore_thresh else ' ' - indiv_pval = ' indiv-pval: %.5e,' % (stats.binom_test(res.obs_cnt, n=num_evals, p=res.expp, alternative='two-sided'),) if self.comp_indiv_pval else '' + indiv_pval = ' indiv-pval: %.5e,' % (stats.binomtest(res.obs_cnt, n=num_evals, p=res.expp, alternative='two-sided').pvalue,) if self.comp_indiv_pval else '' self.tprint(' - zscore[idx%02d]: %+05.5f, observed: %08d, expected: %08d %s idx: %6d,%s poly: %s' % (res.idx, res.zscore, res.obs_cnt, res.exp_cnt, fail, res.idx, indiv_pval, self.input_poly[res.idx])) @@ -533,7 +533,7 @@ def analyse(self, num_evals, hws=None, hws_input=None, ref_hws=None): for i in range(min(len(top_res), 30)): comb = top_res[i] - indiv_pval = ' indiv-pval: %.5e,' % (stats.binom_test(comb.obs_cnt, n=num_evals, p=comb.expp, alternative='two-sided'),) if self.comp_indiv_pval else '' + indiv_pval = ' indiv-pval: %.5e,' % (stats.binomtest(comb.obs_cnt, n=num_evals, p=comb.expp, alternative='two-sided').pvalue,) if self.comp_indiv_pval else '' self.tprint(' - best poly zscore %9.5f, expp: %.4e, exp: %7d, obs: %7d, diff: %10.7f %%,%s poly: %s' % (comb.zscore, comb.expp, comb.exp_cnt, comb.obs_cnt, 100.0 * (comb.exp_cnt - comb.obs_cnt) / comb.exp_cnt, indiv_pval, sorted(comb.poly))) @@ -1365,7 +1365,7 @@ def analyze_iobj(self, iobj, coffset=0, tvsize=None, jscres=None): jsres['halvings'] = [] for ix, cr in enumerate(self.sort_res_by_input_poly(rshort)): ntrials = (tvsize * 8) // self.blocklen - pval = stats.binom_test(cr.obs_cnt, n=ntrials, p=cr.expp, alternative='two-sided') + pval = stats.binomtest(cr.obs_cnt, n=ntrials, p=cr.expp, alternative='two-sided').pvalue jsresc = collections.OrderedDict() jsresc['nsamples'] = ntrials diff --git a/setup.py b/setup.py index 25b5a5df..da4a74ba 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ install_requires = [ 'pycryptodome', # pycrypto alternative, working also on Win 'bitarray_ph4>=1.6.4', - 'scipy', + 'scipy>=1.7.0', 'ufx', 'repoze.lru',