Answer stability round 1: each US place's draw is seeded by its GEOID, so a changed source moves only the places near the cut; item 78 leaves the plan and the multi-county fetch is filed

This commit is contained in:
2026-10-11 16:33:23 +02:00
committed by Lillem4n
parent 121f9549f2
commit 66b5d699fa
9 changed files with 60976 additions and 57434 deletions
+6 -6
View File
@@ -128,12 +128,12 @@ def localities(cache, counties):
def drawn(places, share):
"""The share of the places with people, each drawn with odds by its population, the same set on every run:
Efraimidis and Spirakis's weighted sampling without replacement."""
rng = random.Random(0)
peopled = sorted(code for code, p in places.items() if p["population"] > 0)
key = {code: math.log(1 - rng.random()) / places[code]["population"] for code in peopled}
return {code: places[code] for code in sorted(peopled, key=key.get, reverse=True)[:round(len(peopled) * share)]}
"""The share of the places with people, each drawn with odds by its population: Efraimidis and Spirakis's weighted
sampling without replacement. Each place's random number is seeded by its code, so a place added or dropped from
the sources moves only the places near the cut."""
peopled = [code for code, p in places.items() if p["population"] > 0]
key = {code: math.log(1 - random.Random(code).random()) / places[code]["population"] for code in peopled}
return {code: places[code] for code in sorted(peopled, key=lambda c: (key[c], c), reverse=True)[:round(len(peopled) * share)]}
def zcta_localities(cache, localities):