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

Dev #20

Merged
merged 36 commits into from
Jun 19, 2024
Merged

Dev #20

Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f60ffa9
solve minor issues
edadaltocg Jun 1, 2023
99a0332
implement Beyond AUROC \& Co.
edadaltocg Jun 7, 2023
9e8c52d
small changes
edadaltocg Jul 3, 2023
628de5c
improve aggregations
edadaltocg Jul 3, 2023
9626764
fix typo
edadaltocg Jul 3, 2023
3acf527
ninco ssb clean benchmark
edadaltocg Aug 21, 2023
14c7541
update imagenet benchmarks
edadaltocg Aug 21, 2023
8e83cdb
small changes
edadaltocg Aug 23, 2023
3888942
p-value combining method
edadaltocg Sep 13, 2023
40bda81
small changes
edadaltocg Sep 13, 2023
89928e7
update doi
edadaltocg Sep 25, 2023
14aa3b2
update some datasets to hf hub
edadaltocg Oct 31, 2023
8e8a773
crop_pct bug
edadaltocg Nov 2, 2023
f147ea8
Ensembling + SC
edadaltocg Dec 14, 2023
40ec8d6
fix pipelines
edadaltocg Dec 14, 2023
4887663
docs
edadaltocg Jan 2, 2024
260596e
fix docstrings
edadaltocg Jan 2, 2024
802ec63
remove requirements.txt
edadaltocg Jan 2, 2024
251ed22
remove ba
edadaltocg Jan 2, 2024
db10b31
remove ba
edadaltocg Jan 2, 2024
fe9ea60
bump version
edadaltocg Jan 2, 2024
0bb1123
remove reqs
edadaltocg Jan 2, 2024
c1c04a3
bump actions
edadaltocg Jan 2, 2024
79ee723
minor fix
edadaltocg Jan 2, 2024
00c0dc1
minor fix
edadaltocg Jan 2, 2024
17beb4a
update pypi workflow
edadaltocg Jan 2, 2024
30b9861
fix typo
edadaltocg Jan 2, 2024
e7a67c3
download imagenet models
edadaltocg Jan 15, 2024
64c0e7b
Improvements to pipelines
edadaltocg Jun 19, 2024
e815c58
Code + docs cleaning
edadaltocg Jun 19, 2024
20ffb04
Combine and conquer score aggregation
edadaltocg Jun 19, 2024
eb9a811
helpful scripts
edadaltocg Jun 19, 2024
dac1ec3
Merge branch 'master' of https://github.com/edadaltocg/detectors into…
edadaltocg Jun 19, 2024
362f697
remove requirements.txt
edadaltocg Jun 19, 2024
46bba8a
Format
edadaltocg Jun 19, 2024
f6229f1
Simplify tests
edadaltocg Jun 19, 2024
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
Prev Previous commit
Next Next commit
p-value combining method
edadaltocg committed Sep 13, 2023
commit 388894228c0f6b8931d858786d4a394d0257359b
52 changes: 52 additions & 0 deletions src/detectors/ensemble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np


def p_value_fn(test_statistic: np.ndarray, X: np.ndarray):
"""Compute the p-value of a test statistic given a sample X.

Args:
test_statistic (np.ndarray): test statistic (n,m)
X (np.ndarray): sample (N,m)

Returns:
np.ndarray: p-values (n,m)
"""
mult_factor_min = np.where(X.min(0) > 0, np.array(1 / len(X)), np.array(len(X)))
mult_factor_max = np.where(X.max(0) > 0, np.array(len(X)), np.array(1 / len(X)))
lower_bound = X.min(0) * mult_factor_min
upper_bound = X.max(0) * mult_factor_max
X = np.concatenate((lower_bound.reshape(1, -1), X, upper_bound.reshape(1, -1)), axis=0)
X = np.sort(X, axis=0)
y_ecdf = np.concatenate([np.arange(1, X.shape[0] + 1).reshape(-1, 1) / X.shape[0]] * X.shape[1], axis=1)
return np.concatenate(list(map(lambda xx: np.interp(*xx).reshape(-1, 1), zip(test_statistic.T, X.T, y_ecdf.T))), 1)


# Fisher
def fisher_method(p_values: np.ndarray):
"""Combine p-values using Fisher's method

Args:
p_values (np.ndarray): p-values (n,m)

Returns:
np.ndarray (n,): combined p-values
"""
tau = -2 * np.sum(np.log(p_values), axis=1).reshape(-1, 1)
group_p_value = p_value_fn(tau, np.random.chisquare(2 * p_values.shape[1], (1000, 1)))
# or
# group_p_value = stats.chi2.cdf(tau, 2 * p_values.shape[1])
return group_p_value


# Fisher
def fisher_tau_method(p_values: np.ndarray):
"""Combine p-values using Fisher's method

Args:
p_values (np.ndarray): p-values (n,m)

Returns:
np.ndarray (n,): combined p-values
"""
tau = -2 * np.sum(np.log(p_values), axis=1)
return tau