Skip to content

Commit

Permalink
MAINT: Rename and move to clarify statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Sep 9, 2024
1 parent 047febc commit e88a2ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions asv/commands/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..util import human_value, load_json
from ..console import log
from ..environment import get_environments
from .. import util, statistics
from .. import util, _stats


def mean(values):
Expand Down Expand Up @@ -76,7 +76,7 @@ def _is_result_better(a, b, a_ss, b_ss, factor, use_stats=True):
# Special-case the situation with only one sample, in which
# case we do the comparison only based on `factor` as there's
# not enough data to do statistics.
if not statistics.is_different(a_ss[1], b_ss[1],
if not _stats.is_different(a_ss[1], b_ss[1],
a_ss[0], b_ss[0]):
return False

Expand Down
4 changes: 2 additions & 2 deletions asv/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from asv.repo import get_repo
from asv.results import iter_results
from asv.publishing import OutputPublisher
from asv import statistics, util
from asv import _stats, util


def check_benchmark_params(name, benchmark):
Expand Down Expand Up @@ -191,7 +191,7 @@ def copy_ignore(src, names):
b_params = b['params']

result = results.get_result_value(key, b_params)
weight = [statistics.get_weight(s)
weight = [_stats.get_weight(s)
for s in results.get_result_stats(key, b_params)]
if not b_params:
result = result[0]
Expand Down
24 changes: 12 additions & 12 deletions test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from asv_runner.statistics import (compute_stats, LaplacePosterior, quantile, quantile_ci,
binom_pmf, get_err)

from asv import statistics
from asv import _stats


def test_compute_stats():
Expand Down Expand Up @@ -51,8 +51,8 @@ def test_is_different():
samples_b = true_mean + 0.1 * np.random.rand(n)
_, stats_a = compute_stats(samples_a, 1)
_, stats_b = compute_stats(samples_b, 1)
assert statistics.is_different(None, None, stats_a, stats_b) == significant
assert statistics.is_different(samples_a, samples_b, stats_a, stats_b) == significant
assert _stats.is_different(None, None, stats_a, stats_b) == significant
assert _stats.is_different(samples_a, samples_b, stats_a, stats_b) == significant


def _check_ci(estimator, sampler, nsamples=300):
Expand Down Expand Up @@ -315,7 +315,7 @@ def check_table(m, tbl):
if p is None:
continue

p2 = statistics.mann_whitney_u_cdf(m, n, u, memo=memo)
p2 = _stats.mann_whitney_u_cdf(m, n, u, memo=memo)
assert p2 == pytest.approx(p, abs=1e-3, rel=0), (m, n, u, p2, p)

# Tables from Mann & Whitney, Ann. Math. Statist. 18, 50 (1947).
Expand Down Expand Up @@ -363,15 +363,15 @@ def test_mann_whitney_u_scipy():
def check(x, y):
u0, p0 = stats.mannwhitneyu(x, y, alternative='two-sided', use_continuity=False)

u, p = statistics.mann_whitney_u(x.tolist(), y.tolist(), method='normal')
u, p = _stats.mann_whitney_u(x.tolist(), y.tolist(), method='normal')
assert u == u0
assert p == pytest.approx(p0, rel=1e-9, abs=0)

u, p = statistics.mann_whitney_u(x.tolist(), y.tolist(), method='exact')
u, p = _stats.mann_whitney_u(x.tolist(), y.tolist(), method='exact')
assert u == u0
assert p == pytest.approx(p0, rel=5e-2, abs=5e-3)

u, p = statistics.mann_whitney_u(x.tolist(), y.tolist())
u, p = _stats.mann_whitney_u(x.tolist(), y.tolist())
assert u == u0
assert p == pytest.approx(p0, rel=5e-2, abs=5e-3)

Expand All @@ -388,19 +388,19 @@ def test_mann_whitney_u_basic():
# wilcox.test(a, b, exact=TRUE)
a = [1, 2, 3, 4]
b = [0.9, 1.1, 0.7]
u, p = statistics.mann_whitney_u(a, b, method='exact')
u, p = _stats.mann_whitney_u(a, b, method='exact')
assert u == 11
assert p == pytest.approx(0.11428571428571428, abs=0, rel=1e-10)

a = [1, 2]
b = [1.5]
u, p = statistics.mann_whitney_u(a, b, method='exact')
u, p = _stats.mann_whitney_u(a, b, method='exact')
assert u == 1
assert p == 1.0

a = [1, 2]
b = [2.5]
u, p = statistics.mann_whitney_u(a, b, method='exact')
u, p = _stats.mann_whitney_u(a, b, method='exact')
assert u == 0
assert p == pytest.approx(2 / 3, abs=0, rel=1e-10)

Expand All @@ -419,7 +419,7 @@ def test_mann_whitney_u_R():

for m in range(1, len(a) + 1):
for n in range(1, len(b) + 1):
u, p = statistics.mann_whitney_u(a[:m], b[:n])
u, p = _stats.mann_whitney_u(a[:m], b[:n])

r = wilcox_test(robjects.FloatVector(a[:m]),
robjects.FloatVector(b[:n]))
Expand All @@ -442,7 +442,7 @@ def test_mann_whitney_u_R():
def test_binom():
for n in range(10):
for k in range(10):
p = statistics.binom(n, k)
p = _stats.binom(n, k)
if 0 <= k <= n:
p2 = math.factorial(n) / math.factorial(k) / math.factorial(n - k)
else:
Expand Down

0 comments on commit e88a2ac

Please sign in to comment.