Fix RNG re-seeding per party and vectorize bootstrap loop
Move rng initialization before the party loop so each party gets a unique segment of the random stream instead of identical sequences. Replace Python bootstrap loop with vectorized numpy indexing.
This commit is contained in:
@@ -649,6 +649,7 @@ def compute_party_bootstrap_cis(
|
|||||||
lo_pct = alpha / 2.0
|
lo_pct = alpha / 2.0
|
||||||
hi_pct = 100.0 - lo_pct
|
hi_pct = 100.0 - lo_pct
|
||||||
|
|
||||||
|
rng = np.random.default_rng(seed)
|
||||||
result: Dict[str, Dict] = {}
|
result: Dict[str, Dict] = {}
|
||||||
|
|
||||||
for party, vectors in party_vectors.items():
|
for party, vectors in party_vectors.items():
|
||||||
@@ -670,12 +671,8 @@ def compute_party_bootstrap_cis(
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|
||||||
rng = np.random.default_rng(seed)
|
idx = rng.integers(0, n_mps, size=(n_boot, n_mps))
|
||||||
boot_centroids = np.empty((n_boot, mat.shape[1]))
|
boot_centroids = mat[idx].mean(axis=1) # (n_boot, dim)
|
||||||
|
|
||||||
for b in range(n_boot):
|
|
||||||
idx = rng.integers(0, n_mps, size=n_mps)
|
|
||||||
boot_centroids[b] = mat[idx].mean(axis=0)
|
|
||||||
|
|
||||||
ci_lower = np.percentile(boot_centroids, lo_pct, axis=0)
|
ci_lower = np.percentile(boot_centroids, lo_pct, axis=0)
|
||||||
ci_upper = np.percentile(boot_centroids, hi_pct, axis=0)
|
ci_upper = np.percentile(boot_centroids, hi_pct, axis=0)
|
||||||
|
|||||||
Reference in New Issue
Block a user