Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new binomtest function #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions booltest/booltest_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down