From dead27b7d417b47c3350459d13a23aff796da18f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:26:28 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/resample/__init__.py | 1 + src/resample/bootstrap.py | 6 ++++++ src/resample/empirical.py | 3 +++ src/resample/jackknife.py | 5 +++++ src/resample/permutation.py | 8 ++++++++ 5 files changed, 23 insertions(+) diff --git a/src/resample/__init__.py b/src/resample/__init__.py index 1b48108..36e9a21 100644 --- a/src/resample/__init__.py +++ b/src/resample/__init__.py @@ -11,6 +11,7 @@ - Permutation-based variants of traditional statistical tests (t-test, K-S test, etc.) - Tools for working with empirical distributions (CDF, quantile, etc.) """ + from importlib.metadata import version from resample import bootstrap, empirical, jackknife, permutation diff --git a/src/resample/bootstrap.py b/src/resample/bootstrap.py index 1a161a3..6732fde 100644 --- a/src/resample/bootstrap.py +++ b/src/resample/bootstrap.py @@ -143,6 +143,7 @@ def resample( replicated sample. This is a stricter constraint than that offered by the balanced bootstrap, which only guarantees that classes have the original proportions over all replicates, but not within each one replicate. + """ sample_np = np.atleast_1d(sample) n_sample = len(sample_np) @@ -278,6 +279,7 @@ def bootstrap( >>> fb = bootstrap(np.mean, x, size=10000, random_state=1) >>> print(f"f(x) = {fx:.1f} +/- {np.std(fb):.1f}") f(x) = 4.5 +/- 0.9 + """ gen = resample(sample, *args, **kwargs) if args: @@ -331,6 +333,7 @@ def bias( This function has special space requirements, it needs to hold `size` replicates of the original sample in memory at once. The balanced bootstrap is recommended over the ordinary bootstrap for bias estimation, it tends to converge faster. + """ thetas = [] if args: @@ -390,6 +393,7 @@ def bias_corrected( 8.2 >>> round(bias_corrected(np.var, x, size=10000, random_state=1), 1) 9.1 + """ return fn(sample, *args) - bias(fn, sample, *args, **kwargs) @@ -429,6 +433,7 @@ def variance( >>> x = np.arange(10) >>> round(variance(np.mean, x, size=10000, random_state=1), 1) 0.8 + """ thetas = bootstrap(fn, sample, *args, **kwargs) return np.var(thetas, ddof=1, axis=0) @@ -488,6 +493,7 @@ def confidence_interval( increases the number of function evaluations in a direct comparison to 'percentile'. However the increase in accuracy should compensate for this, with the result that less bootstrap replicas are needed overall to achieve the same accuracy. + """ if args and not isinstance(args[0], Collection): import warnings diff --git a/src/resample/empirical.py b/src/resample/empirical.py index 30afce3..ace4cc8 100644 --- a/src/resample/empirical.py +++ b/src/resample/empirical.py @@ -28,6 +28,7 @@ def cdf_gen(sample: "ArrayLike") -> Callable[[np.ndarray], np.ndarray]: ------- callable Empirical distribution function. + """ sample_np = np.sort(sample) n = len(sample_np) @@ -49,6 +50,7 @@ def quantile_function_gen( ------- callable Empirical quantile function. + """ class QuantileFn: @@ -89,6 +91,7 @@ def influence( ------- ndarray Empirical influence values. + """ sample = np.atleast_1d(sample) n = len(sample) diff --git a/src/resample/jackknife.py b/src/resample/jackknife.py index 00c36d5..8280bac 100644 --- a/src/resample/jackknife.py +++ b/src/resample/jackknife.py @@ -75,6 +75,7 @@ def resample( ... r2.append(x) # x is now a view into the same array in memory >>> print(r2) [array([1, 2]), array([1, 2]), array([1, 2])] + """ sample_np = np.atleast_1d(sample) n_sample = len(sample_np) @@ -174,6 +175,7 @@ def jackknife( >>> fb = jackknife(np.mean, x) >>> print(f"f(x) = {fx:.1f} +/- {np.std(fb):.1f}") f(x) = 4.5 +/- 0.3 + """ gen = resample(sample, *args, copy=False) if args: @@ -219,6 +221,7 @@ def bias( -0.9 >>> round(bias(lambda x: np.var(x, ddof=1), x), 1) 0.0 + """ sample = np.atleast_1d(sample) n = len(sample) @@ -266,6 +269,7 @@ def bias_corrected( 8.2 >>> round(bias_corrected(np.var, x), 1) 9.2 + """ sample = np.atleast_1d(sample) n = len(sample) @@ -307,6 +311,7 @@ def variance( >>> x = np.arange(10) >>> round(variance(np.mean, x), 1) 0.9 + """ # formula is (n - 1) / n * sum((fj - mean(fj)) ** 2) # = np.var(fj, ddof=0) * (n - 1) diff --git a/src/resample/permutation.py b/src/resample/permutation.py index c469a2f..06a5ce7 100644 --- a/src/resample/permutation.py +++ b/src/resample/permutation.py @@ -65,6 +65,7 @@ class TestResult: hypothesis. See https://en.wikipedia.org/wiki/P-value for details. samples: array Values of the test statistic from the permutated samples. + """ statistic: float @@ -142,6 +143,7 @@ def usp( Returns ------- TestResult + """ if size <= 0: raise ValueError("size must be positive") @@ -238,6 +240,7 @@ def same_population( Returns ------- TestResult + """ if size <= 0: raise ValueError("max_size must be positive") @@ -317,6 +320,7 @@ def anova( ----- https://en.wikipedia.org/wiki/One-way_analysis_of_variance https://en.wikipedia.org/wiki/F-test + """ kwargs["transform"] = None return same_population(_ANOVA(), x, y, *args, **kwargs) @@ -350,6 +354,7 @@ def kruskal( Notes ----- https://en.wikipedia.org/wiki/Kruskal%E2%80%93Wallis_one-way_analysis_of_variance + """ kwargs["transform"] = None return same_population(_kruskal, x, y, *args, **kwargs) @@ -377,6 +382,7 @@ def pearsonr(x: "ArrayLike", y: "ArrayLike", **kwargs: Any) -> TestResult: Returns ------- TestResult + """ if len(x) != len(y): raise ValueError("x and y must have have the same length") @@ -403,6 +409,7 @@ def spearmanr(x: "ArrayLike", y: "ArrayLike", **kwargs: Any) -> TestResult: Returns ------- TestResult + """ if len(x) != len(y): raise ValueError("x and y must have have the same length") @@ -432,6 +439,7 @@ def ttest(x: "ArrayLike", y: "ArrayLike", **kwargs: Any) -> TestResult: Returns ------- TestResult + """ kwargs["transform"] = np.abs return same_population(_ttest, x, y, **kwargs)