Skip to content

Commit e05241c

Browse files
authored
Merge pull request #9 from RonanLegin/bootstrap_bugfix
Fixed replacement sampling and alpha range.
2 parents bc8ea9e + d0e1731 commit e05241c

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "tarp"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
authors = [
55
{name = "Adam Coogan", email = "dr.adam.coogan@gmail.com"},
66
{name = "Pablo Lemos", email = "plemos91@gmail.com"},

src/tarp/drp.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _get_tarp_coverage_single(
124124
f = np.sum((samples_distances < theta_distances), axis=0) / num_samples
125125

126126
# Compute expected coverage
127-
h, alpha = np.histogram(f, density=True, bins=num_alpha_bins)
127+
h, alpha = np.histogram(f, density=True, bins=num_alpha_bins, range=(0,1))
128128
dx = alpha[1] - alpha[0]
129129
ecp = np.cumsum(h) * dx
130130
return np.concatenate([[0], ecp]), alpha
@@ -168,15 +168,14 @@ def _get_tarp_coverage_bootstrap(samples: np.ndarray,
168168

169169
boot_ecp = np.empty(shape=(num_bootstrap, num_alpha_bins+1))
170170
for i in tqdm(range(num_bootstrap)):
171-
idx_remove = np.random.randint(num_sims)
172-
idx_add = np.random.randint(num_sims)
173-
174-
# Replacing one simulation and its samples by another and its associated samples
175-
samples[:, idx_remove, :] = samples[:, idx_add, :]
176-
theta[idx_remove, :] = theta[idx_add, :]
177-
178-
boot_ecp[i, :], alpha = _get_tarp_coverage_single(samples,
179-
theta,
171+
idx = np.random.randint(low=0, high=num_sims, size=num_sims)
172+
173+
# Sample with replacement from the full set of simulations
174+
boot_samples = samples[:, idx, :]
175+
boot_theta = theta[idx, :]
176+
177+
boot_ecp[i, :], alpha = _get_tarp_coverage_single(boot_samples,
178+
boot_theta,
180179
references=references,
181180
metric=metric,
182181
num_alpha_bins=num_alpha_bins,

0 commit comments

Comments
 (0)