@mailwoman/registry 9.4.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/README.md +10 -10
  2. package/lib/address-key.ts +14 -10
  3. package/lib/geocode-handler.ts +6 -4
  4. package/lib/geojson.ts +13 -17
  5. package/lib/ingest.ts +57 -83
  6. package/lib/learned-scorer.ts +38 -44
  7. package/lib/map-html.ts +24 -70
  8. package/lib/models/crosssource-gbt-en-us.ts +9 -7
  9. package/lib/models/dedup-gbt-en-us.ts +9 -8
  10. package/lib/models/org-crosssource-gbt-en-us.ts +10 -8
  11. package/lib/reconcile.ts +45 -55
  12. package/lib/resolve.ts +180 -124
  13. package/lib/types.ts +18 -12
  14. package/out/address-key.d.ts +14 -10
  15. package/out/address-key.d.ts.map +1 -1
  16. package/out/address-key.js +14 -10
  17. package/out/address-key.js.map +1 -1
  18. package/out/geocode-handler.d.ts +6 -4
  19. package/out/geocode-handler.d.ts.map +1 -1
  20. package/out/geocode-handler.js +6 -4
  21. package/out/geocode-handler.js.map +1 -1
  22. package/out/geojson.d.ts +9 -5
  23. package/out/geojson.d.ts.map +1 -1
  24. package/out/geojson.js +13 -15
  25. package/out/geojson.js.map +1 -1
  26. package/out/ingest.d.ts +46 -75
  27. package/out/ingest.d.ts.map +1 -1
  28. package/out/ingest.js +27 -54
  29. package/out/ingest.js.map +1 -1
  30. package/out/learned-scorer.d.ts +29 -26
  31. package/out/learned-scorer.d.ts.map +1 -1
  32. package/out/learned-scorer.js +31 -39
  33. package/out/learned-scorer.js.map +1 -1
  34. package/out/map-html.d.ts +13 -32
  35. package/out/map-html.d.ts.map +1 -1
  36. package/out/map-html.js +9 -62
  37. package/out/map-html.js.map +1 -1
  38. package/out/models/crosssource-gbt-en-us.d.ts +9 -7
  39. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
  40. package/out/models/crosssource-gbt-en-us.js +9 -7
  41. package/out/models/crosssource-gbt-en-us.js.map +1 -1
  42. package/out/models/dedup-gbt-en-us.d.ts +9 -8
  43. package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
  44. package/out/models/dedup-gbt-en-us.js +9 -8
  45. package/out/models/dedup-gbt-en-us.js.map +1 -1
  46. package/out/models/org-crosssource-gbt-en-us.d.ts +10 -8
  47. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
  48. package/out/models/org-crosssource-gbt-en-us.js +10 -8
  49. package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
  50. package/out/reconcile.d.ts +35 -50
  51. package/out/reconcile.d.ts.map +1 -1
  52. package/out/reconcile.js +19 -43
  53. package/out/reconcile.js.map +1 -1
  54. package/out/resolve.d.ts +150 -90
  55. package/out/resolve.d.ts.map +1 -1
  56. package/out/resolve.js +62 -63
  57. package/out/resolve.js.map +1 -1
  58. package/out/tools/coverage-reconciliation.d.ts +23 -23
  59. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  60. package/out/tools/coverage-reconciliation.js +15 -26
  61. package/out/tools/coverage-reconciliation.js.map +1 -1
  62. package/out/tools/cross/dataset-correlation.d.ts +58 -0
  63. package/out/tools/cross/dataset-correlation.d.ts.map +1 -0
  64. package/out/tools/{cross-dataset-correlation.js → cross/dataset-correlation.js} +10 -62
  65. package/out/tools/cross/dataset-correlation.js.map +1 -0
  66. package/out/tools/cross/source-threshold-sweep.d.ts +60 -0
  67. package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -0
  68. package/out/tools/{cross-source-threshold-sweep.js → cross/source-threshold-sweep.js} +15 -41
  69. package/out/tools/cross/source-threshold-sweep.js.map +1 -0
  70. package/out/tools/dedup-ceiling.d.ts +23 -26
  71. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  72. package/out/tools/dedup-ceiling.js +22 -41
  73. package/out/tools/dedup-ceiling.js.map +1 -1
  74. package/out/tools/eval-geocoder.d.ts +22 -15
  75. package/out/tools/eval-geocoder.d.ts.map +1 -1
  76. package/out/tools/eval-geocoder.js +5 -6
  77. package/out/tools/eval-geocoder.js.map +1 -1
  78. package/out/tools/geocoder/namesake-probe.d.ts +33 -0
  79. package/out/tools/geocoder/namesake-probe.d.ts.map +1 -0
  80. package/out/tools/{geocoder-namesake-probe.js → geocoder/namesake-probe.js} +7 -8
  81. package/out/tools/geocoder/namesake-probe.js.map +1 -0
  82. package/out/tools/geocoder/vs-provided-coords.d.ts +53 -0
  83. package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -0
  84. package/out/tools/{geocoder-vs-provided-coords.js → geocoder/vs-provided-coords.js} +31 -28
  85. package/out/tools/geocoder/vs-provided-coords.js.map +1 -0
  86. package/out/tools/gold-set-sample.d.ts +27 -18
  87. package/out/tools/gold-set-sample.d.ts.map +1 -1
  88. package/out/tools/gold-set-sample.js +18 -22
  89. package/out/tools/gold-set-sample.js.map +1 -1
  90. package/out/tools/learned/scorer/clustering-eval.d.ts +77 -0
  91. package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -0
  92. package/out/tools/{learned-scorer-clustering-eval.js → learned/scorer/clustering-eval.js} +29 -39
  93. package/out/tools/learned/scorer/clustering-eval.js.map +1 -0
  94. package/out/tools/learned/scorer/crossstate-eval.d.ts +65 -0
  95. package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -0
  96. package/out/tools/{learned-scorer-crossstate-eval.js → learned/scorer/crossstate-eval.js} +20 -26
  97. package/out/tools/learned/scorer/crossstate-eval.js.map +1 -0
  98. package/out/tools/learned/scorer/eval.d.ts +60 -0
  99. package/out/tools/learned/scorer/eval.d.ts.map +1 -0
  100. package/out/tools/{learned-scorer-eval.js → learned/scorer/eval.js} +12 -72
  101. package/out/tools/learned/scorer/eval.js.map +1 -0
  102. package/out/tools/matcher-scale.d.ts +12 -17
  103. package/out/tools/matcher-scale.d.ts.map +1 -1
  104. package/out/tools/matcher-scale.js +11 -29
  105. package/out/tools/matcher-scale.js.map +1 -1
  106. package/out/tools/nppes/dedup-benchmark.d.ts +81 -0
  107. package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -0
  108. package/out/tools/{nppes-dedup-benchmark.js → nppes/dedup-benchmark.js} +21 -67
  109. package/out/tools/nppes/dedup-benchmark.js.map +1 -0
  110. package/out/tools/nppes/org-name.d.ts +5 -4
  111. package/out/tools/nppes/org-name.d.ts.map +1 -1
  112. package/out/tools/nppes/org-name.js +2 -2
  113. package/out/tools/nppes/org-name.js.map +1 -1
  114. package/out/tools/nppes/overmerge-packet.d.ts +15 -11
  115. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
  116. package/out/tools/nppes/overmerge-packet.js +7 -8
  117. package/out/tools/nppes/overmerge-packet.js.map +1 -1
  118. package/out/tools/nppes/report.d.ts +17 -13
  119. package/out/tools/nppes/report.d.ts.map +1 -1
  120. package/out/tools/nppes/report.js +6 -14
  121. package/out/tools/nppes/report.js.map +1 -1
  122. package/out/tools/nppes/sample.d.ts +28 -17
  123. package/out/tools/nppes/sample.d.ts.map +1 -1
  124. package/out/tools/nppes/sample.js +23 -26
  125. package/out/tools/nppes/sample.js.map +1 -1
  126. package/out/tools/nppes/scoring.d.ts +7 -6
  127. package/out/tools/nppes/scoring.d.ts.map +1 -1
  128. package/out/tools/nppes/scoring.js +6 -5
  129. package/out/tools/nppes/scoring.js.map +1 -1
  130. package/out/tools/nppes/settings.d.ts +10 -7
  131. package/out/tools/nppes/settings.d.ts.map +1 -1
  132. package/out/tools/nppes/settings.js +16 -16
  133. package/out/tools/nppes/settings.js.map +1 -1
  134. package/out/tools/nppes/truth-grains.d.ts +36 -23
  135. package/out/tools/nppes/truth-grains.d.ts.map +1 -1
  136. package/out/tools/nppes/truth-grains.js +36 -20
  137. package/out/tools/nppes/truth-grains.js.map +1 -1
  138. package/out/tools/shared.d.ts +63 -59
  139. package/out/tools/shared.d.ts.map +1 -1
  140. package/out/tools/shared.js +49 -66
  141. package/out/tools/shared.js.map +1 -1
  142. package/out/tools/train/cross-gbt.d.ts +88 -0
  143. package/out/tools/train/cross-gbt.d.ts.map +1 -0
  144. package/out/tools/{train-cross-gbt.js → train/cross-gbt.js} +15 -26
  145. package/out/tools/train/cross-gbt.js.map +1 -0
  146. package/out/tools/train/gbt.d.ts +85 -0
  147. package/out/tools/train/gbt.d.ts.map +1 -0
  148. package/out/tools/{train-gbt.js → train/gbt.js} +28 -32
  149. package/out/tools/train/gbt.js.map +1 -0
  150. package/out/tools/train/org-cross-gbt.d.ts +84 -0
  151. package/out/tools/train/org-cross-gbt.d.ts.map +1 -0
  152. package/out/tools/{train-org-cross-gbt.js → train/org-cross-gbt.js} +19 -23
  153. package/out/tools/train/org-cross-gbt.js.map +1 -0
  154. package/out/tools/txhhsc-to-oarow.d.ts +14 -9
  155. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  156. package/out/tools/txhhsc-to-oarow.js +16 -15
  157. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  158. package/out/tools/viz/browser.d.ts +6 -5
  159. package/out/tools/viz/browser.d.ts.map +1 -1
  160. package/out/tools/viz/browser.js +6 -5
  161. package/out/tools/viz/browser.js.map +1 -1
  162. package/out/tools/viz/cross-dataset-map.d.ts +7 -4
  163. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  164. package/out/tools/viz/cross-dataset-map.js +9 -6
  165. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  166. package/out/tools/viz/geocode-first-surface.d.ts +10 -5
  167. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  168. package/out/tools/viz/geocode-first-surface.js +16 -11
  169. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  170. package/out/tools/viz/{render-map.d.ts → render/map.d.ts} +6 -6
  171. package/out/tools/viz/render/map.d.ts.map +1 -0
  172. package/out/tools/viz/{render-map.js → render/map.js} +7 -6
  173. package/out/tools/viz/render/map.js.map +1 -0
  174. package/out/tools/viz/render.d.ts +12 -8
  175. package/out/tools/viz/render.d.ts.map +1 -1
  176. package/out/tools/viz/render.js +8 -7
  177. package/out/tools/viz/render.js.map +1 -1
  178. package/out/tools/viz/source-provenance-map.d.ts +19 -7
  179. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  180. package/out/tools/viz/source-provenance-map.js +11 -8
  181. package/out/tools/viz/source-provenance-map.js.map +1 -1
  182. package/out/tools/viz/yardstick-figure.d.ts +2 -21
  183. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  184. package/out/tools/viz/yardstick-figure.js +3 -39
  185. package/out/tools/viz/yardstick-figure.js.map +1 -1
  186. package/out/types.d.ts +17 -11
  187. package/out/types.d.ts.map +1 -1
  188. package/out/types.js +2 -2
  189. package/out/types.js.map +1 -1
  190. package/package.json +41 -184
  191. package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
  192. package/{lib/tools/cross-dataset-correlation.ts → tools/cross/dataset-correlation.ts} +31 -72
  193. package/{lib/tools/cross-source-threshold-sweep.ts → tools/cross/source-threshold-sweep.ts} +29 -46
  194. package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
  195. package/tools/eval-geocoder.ts +74 -0
  196. package/{lib/tools/geocoder-namesake-probe.ts → tools/geocoder/namesake-probe.ts} +9 -8
  197. package/{lib/tools/geocoder-vs-provided-coords.ts → tools/geocoder/vs-provided-coords.ts} +39 -30
  198. package/{lib/tools → tools}/gold-set-sample.ts +35 -29
  199. package/{lib/tools/learned-scorer-clustering-eval.ts → tools/learned/scorer/clustering-eval.ts} +49 -45
  200. package/{lib/tools/learned-scorer-crossstate-eval.ts → tools/learned/scorer/crossstate-eval.ts} +34 -30
  201. package/{lib/tools/learned-scorer-eval.ts → tools/learned/scorer/eval.ts} +35 -78
  202. package/{lib/tools → tools}/matcher-scale.ts +21 -33
  203. package/{lib/tools/nppes-dedup-benchmark.ts → tools/nppes/dedup-benchmark.ts} +37 -82
  204. package/{lib/tools → tools}/nppes/org-name.ts +5 -4
  205. package/{lib/tools → tools}/nppes/overmerge-packet.ts +17 -13
  206. package/{lib/tools → tools}/nppes/report.ts +32 -25
  207. package/{lib/tools → tools}/nppes/sample.ts +41 -36
  208. package/{lib/tools → tools}/nppes/scoring.ts +7 -6
  209. package/{lib/tools → tools}/nppes/settings.ts +16 -16
  210. package/{lib/tools → tools}/nppes/truth-grains.ts +46 -26
  211. package/{lib/tools → tools}/shared.ts +73 -83
  212. package/{lib/tools/train-cross-gbt.ts → tools/train/cross-gbt.ts} +38 -34
  213. package/{lib/tools/train-gbt.ts → tools/train/gbt.ts} +55 -41
  214. package/{lib/tools/train-org-cross-gbt.ts → tools/train/org-cross-gbt.ts} +39 -30
  215. package/{lib/tools → tools}/txhhsc-to-oarow.ts +24 -18
  216. package/{lib/tools → tools}/viz/browser.ts +6 -5
  217. package/{lib/tools → tools}/viz/cross-dataset-map.ts +15 -9
  218. package/{lib/tools → tools}/viz/geocode-first-surface.ts +28 -17
  219. package/{lib/tools/viz/render-map.ts → tools/viz/render/map.ts} +7 -6
  220. package/{lib/tools → tools}/viz/render.ts +16 -11
  221. package/{lib/tools → tools}/viz/source-provenance-map.ts +30 -15
  222. package/{lib/tools → tools}/viz/yardstick-figure.ts +6 -43
  223. package/lib/tools/eval-geocoder.ts +0 -67
  224. package/lib/tools/index.ts +0 -31
  225. package/out/tools/cross-dataset-correlation.d.ts +0 -65
  226. package/out/tools/cross-dataset-correlation.d.ts.map +0 -1
  227. package/out/tools/cross-dataset-correlation.js.map +0 -1
  228. package/out/tools/cross-source-threshold-sweep.d.ts +0 -66
  229. package/out/tools/cross-source-threshold-sweep.d.ts.map +0 -1
  230. package/out/tools/cross-source-threshold-sweep.js.map +0 -1
  231. package/out/tools/geocoder-namesake-probe.d.ts +0 -32
  232. package/out/tools/geocoder-namesake-probe.d.ts.map +0 -1
  233. package/out/tools/geocoder-namesake-probe.js.map +0 -1
  234. package/out/tools/geocoder-vs-provided-coords.d.ts +0 -50
  235. package/out/tools/geocoder-vs-provided-coords.d.ts.map +0 -1
  236. package/out/tools/geocoder-vs-provided-coords.js.map +0 -1
  237. package/out/tools/index.d.ts +0 -31
  238. package/out/tools/index.d.ts.map +0 -1
  239. package/out/tools/index.js +0 -31
  240. package/out/tools/index.js.map +0 -1
  241. package/out/tools/learned-scorer-clustering-eval.d.ts +0 -74
  242. package/out/tools/learned-scorer-clustering-eval.d.ts.map +0 -1
  243. package/out/tools/learned-scorer-clustering-eval.js.map +0 -1
  244. package/out/tools/learned-scorer-crossstate-eval.d.ts +0 -59
  245. package/out/tools/learned-scorer-crossstate-eval.d.ts.map +0 -1
  246. package/out/tools/learned-scorer-crossstate-eval.js.map +0 -1
  247. package/out/tools/learned-scorer-eval.d.ts +0 -77
  248. package/out/tools/learned-scorer-eval.d.ts.map +0 -1
  249. package/out/tools/learned-scorer-eval.js.map +0 -1
  250. package/out/tools/nppes-dedup-benchmark.d.ts +0 -101
  251. package/out/tools/nppes-dedup-benchmark.d.ts.map +0 -1
  252. package/out/tools/nppes-dedup-benchmark.js.map +0 -1
  253. package/out/tools/train-cross-gbt.d.ts +0 -78
  254. package/out/tools/train-cross-gbt.d.ts.map +0 -1
  255. package/out/tools/train-cross-gbt.js.map +0 -1
  256. package/out/tools/train-gbt.d.ts +0 -69
  257. package/out/tools/train-gbt.d.ts.map +0 -1
  258. package/out/tools/train-gbt.js.map +0 -1
  259. package/out/tools/train-org-cross-gbt.d.ts +0 -71
  260. package/out/tools/train-org-cross-gbt.d.ts.map +0 -1
  261. package/out/tools/train-org-cross-gbt.js.map +0 -1
  262. package/out/tools/viz/render-map.d.ts.map +0 -1
  263. package/out/tools/viz/render-map.js.map +0 -1
@@ -3,12 +3,11 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Admin-tier wrong-region probe (#619 tail) — the geocoder-vs-provided-coords eval found an
7
- * admin-tier tail to 11143 km (p99 2189 km). Hypothesis: when no street extract covers the address,
8
- * the admin cascade resolves the locality by NAME and (when the region/postcode constraint is
9
- * weak) picks the population-dominant FOREIGN namesake — Paris→France, Athens→Greece — instead of
10
- * the in-state Texas city. This probes a curated set of TX namesake cities, with and without ZIP,
11
- * and flags any result outside the Texas bounding box.
6
+ * Admin-tier wrong-region probe. When no street extract covers an address, the admin cascade can
7
+ * resolve the locality by name and, when the region or postcode constraint is weak, pick the
8
+ * population-dominant foreign namesake instead of the in-state Texas city. This probes a curated
9
+ * set of TX namesake cities, with and without ZIP. It flags any result outside the Texas bounding
10
+ * box.
12
11
  *
13
12
  * Run: `mailwoman registry scorer-eval namesake-probe`
14
13
  */
@@ -23,7 +22,9 @@ import { inTXBBOX } from "#tools/shared"
23
22
  */
24
23
  export interface GeocoderNamesakeProbeOptions {
25
24
  /**
26
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
25
+ * The injected geocoder factory.
26
+ *
27
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
27
28
  */
28
29
  createGeocoder: EvalGeocoderFactory
29
30
  }
@@ -43,7 +44,7 @@ const CASES: Array<{ city: string; zip: string; tx: [number, number]; namesake:
43
44
  ]
44
45
 
45
46
  /**
46
- * Admin-tier wrong-region probe (#619 tail) — see the module doc. Prints one line per variant to stdout.
47
+ * Probe a curated set of TX namesake cities and print one line per variant to stdout.
47
48
  */
48
49
  export async function geocoderNamesakeProbe(
49
50
  options: GeocoderNamesakeProbeOptions,
@@ -3,18 +3,14 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Geocoder validation against provided coordinates (#619) — a free, honest, real-world accuracy
7
- * eval.
6
+ * Geocoder validation against provided coordinates. TX HHSC's nursing-facilities registry ships
7
+ * a `Geo Location` (`lat,lon`) per facility alongside its physical address. Geocode the address
8
+ * with mailwoman's parser and resolver, then measure the great-circle delta to the provided point,
9
+ * broken down by resolution tier.
8
10
  *
9
- * TX HHSC's nursing-facilities registry ships a `Geo Location` (`lat,lon`) per facility alongside
10
- * its physical address. We geocode the address with mailwoman's real parser + resolver and
11
- * measure the great-circle delta to the provided point — p50 / p90, broken down by the resolution
12
- * tier we assign (address_point / interpolated / admin). This is an independent check of the
13
- * geocoder on real facility addresses; it does not touch the matcher.
14
- *
15
- * The provided coordinate is treated as ground truth for _this_ eval, with the honest caveat that
16
- * it is itself a third-party geocode of unknown provenance — a large delta is a discrepancy to
17
- * inspect, not automatically our error.
11
+ * The provided coordinate is treated as ground truth for this eval, with the caveat that it is
12
+ * itself a third-party geocode of unknown provenance. A large delta is a discrepancy to inspect
13
+ * rather than automatically our error.
18
14
  *
19
15
  * Run: `mailwoman registry scorer-eval vs-provided-coords [--max 1176] [--wof <admin.db>]
20
16
  * [--data-root <dir>] [--out-md docs/articles/evals/resolver-geo/<date>-...md]`
@@ -25,6 +21,7 @@ import { writeLocalFile } from "@mailwoman/core/fs/writers"
25
21
  import { isPresent } from "@mailwoman/core/objects"
26
22
  import { percentile } from "@mailwoman/core/stats"
27
23
  import { haversineKm } from "@mailwoman/match"
24
+ import { TextSpliterator } from "spliterator"
28
25
 
29
26
  import { streamRows } from "#index"
30
27
  import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
@@ -45,15 +42,21 @@ const MAX_ABS_LONGITUDE = 180
45
42
  */
46
43
  export interface GeocoderVsProvidedCoordsOptions {
47
44
  /**
48
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
45
+ * The injected geocoder factory.
46
+ *
47
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
49
48
  */
50
49
  createGeocoder: EvalGeocoderFactory
51
50
  /**
52
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
51
+ * Record-matcher sources directory.
52
+ *
53
+ * Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
53
54
  */
54
55
  sources?: string
55
56
  /**
56
- * Facilities geocoded. Default 2000.
57
+ * Facilities geocoded.
58
+ *
59
+ * Default 2000.
57
60
  */
58
61
  max?: number
59
62
  /**
@@ -63,22 +66,28 @@ export interface GeocoderVsProvidedCoordsOptions {
63
66
  }
64
67
 
65
68
  /**
66
- * Parse a `lat,lon` string into a coordinate, or null if malformed / out of range.
69
+ * Parse a `lat,lon` string into a coordinate, or null if malformed or out of range.
70
+ *
71
+ * Deliberately strict and deliberately not `GeoPoint.from()`.
72
+ * The provided coordinate is this eval's ground truth, so a row that cannot be read exactly
73
+ * is dropped (counted in `noCoord`) rather than repaired into something plausible.
74
+ *
75
+ * A silently repaired coordinate lands in the delta distribution as geocoder error.
76
+ *
77
+ * This source writes `latitude,longitude`, while `GeoPoint` reads GeoJSON `[longitude, latitude]`,
78
+ * so `31.5,-89.5` is a Mississippi row here and a South-Atlantic point there.
79
+ * `GeoPoint.from` also maps 0,0 to null.
80
+ *
81
+ * This moves Null Island out of the measured outliers and into the skipped bucket.
82
+ *
83
+ * The report attributes part of its p99/max tail to malformed provided coordinates,
84
+ * so those rows have to stay rejected or measured as-is, never rewritten.
67
85
  *
68
- * Deliberately strict, and deliberately not `GeoPoint.from()`. The provided coordinate is this eval's ground truth, so
69
- * a row we cannot read exactly has to be _dropped_ (counted in `noCoord`) rather than repaired into something plausible
70
- * — a silently repaired coordinate lands in the delta distribution as geocoder error. Two of the three divergences that
71
- * originally justified this parser were defects in `GeoPoint` and were fixed on 2026-08-05: it no longer guesses axis
72
- * order from the magnitudes, and an out-of-range value is now rejected instead of accepted (`200,-97.74` used to become
73
- * a point). What remains is not a defect and not negotiable. This source writes `latitude,longitude`; `GeoPoint` reads
74
- * GeoJSON `[longitude, latitude]`, so `31.5,-89.5` is a Mississippi row here and a South-Atlantic point there — and
75
- * `GeoPoint.from` maps 0,0 to null, which moves Null Island out of the measured outliers and into the skipped bucket.
76
- * The report below attributes part of its p99/max tail to malformed provided coordinates, so those rows have to stay
77
- * rejected or measured as-is, never rewritten. Strictness is the measurement, not an unfinished migration.
86
+ * Strictness is the measurement rather than an unfinished migration.
78
87
  */
79
88
  function parseLatLon(raw: string | undefined): { latitude: number; longitude: number } | null {
80
89
  if (!raw) return null
81
- const [a, b] = raw.split(",").map((x) => Number(x.trim()))
90
+ const [a, b] = TextSpliterator.from(raw, { delimiter: "," }).map(Number).toArray()
82
91
 
83
92
  if (!Number.isFinite(a) || !Number.isFinite(b)) return null
84
93
 
@@ -87,12 +96,13 @@ function parseLatLon(raw: string | undefined): { latitude: number; longitude: nu
87
96
  return { latitude: a!, longitude: b! }
88
97
  }
89
98
 
90
- // The core nearest-rank `percentile` (q in [0,100]) replaces the retired local `quantile(sorted, q)`
91
- // — byte-identical semantics (floor index, clamped); `?? NaN` preserves the empty-sample behavior.
99
+ // The core nearest-rank `percentile` (q in [0,100]) uses a floor index and clamping.
100
+ // `?? NaN` returns NaN when the percentile helper returns null for an empty sample.
92
101
  const quantile = (xs: number[], q: number): number => percentile(xs, q * 100) ?? Number.NaN
93
102
 
94
103
  /**
95
- * Geocoder validation against provided coordinates (#619) — see the module doc. Emits the report to stdout.
104
+ * Geocode each facility's physical address and measure the delta to its provided
105
+ * coordinate, then emit the report to stdout.
96
106
  */
97
107
  export async function geocoderVsProvidedCoords(
98
108
  options: GeocoderVsProvidedCoordsOptions,
@@ -149,7 +159,6 @@ export async function geocoderVsProvidedCoords(
149
159
 
150
160
  geocoder[Symbol.dispose]()
151
161
 
152
- // Overall + per-tier percentiles.
153
162
  const all = results.map((r) => r.deltaM).toSorted((a, b) => a - b)
154
163
  const byTier = new Map<string, number[]>()
155
164
 
@@ -3,25 +3,25 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Gold-set P3 (#625) — sample the HARD slice for adjudication. The programmatic entity truth
7
- * (`nppes-dedup-benchmark.ts`) collapses only NPPES-FLAGGED subparts (Is-Subpart + parent
8
- * LBN/TIN); it can't settle the genuinely-ambiguous co-located collisions: distinct NPIs at one
9
- * address with near-identical names that are NOT flagged subparts of the same parent. Those are
10
- * where NPI-truth and any programmatic rule disagree — exactly the pairs a frozen adjudicated
11
- * gold set must cover.
6
+ * Gold-set sampling for adjudication. The programmatic entity truth
7
+ * (`nppes-dedup-benchmark.ts`) collapses only NPPES-flagged subparts (Is-Subpart plus parent
8
+ * LBN/TIN), so it cannot settle the genuinely ambiguous co-located collisions: distinct NPIs at
9
+ * one address with near-identical name text and no subpart flag for the same parent.
10
+ * NPI truth and programmatic rules may disagree on these pairs. A frozen
11
+ * adjudicated gold set must cover.
12
12
  *
13
- * This finds them (over the full TX registry, geocode-free — the shared co-location scan
14
- * `dedup-ceiling.ts` also runs) and writes each as a JSONL row carrying BOTH records' fields (org
15
- * name, address, authorized official, taxonomy, subpart/parent flags) plus the programmatic
16
- * verdict, so an adjudicator (human or LLM-as-judge, flagged as such) can label "same real-world
17
- * entity? yes/no" and we can MEASURE how often the programmatic truth matches judgment.
13
+ * This scans the full TX registry without geocoding and writes each pair as a JSONL row containing
14
+ * both records' fields (org name, address, authorized official, taxonomy, subpart and parent
15
+ * flags) plus the programmatic verdict. An adjudicator (human or LLM-as-judge, flagged as such)
16
+ * can then label same real-world entity or not.
18
17
  *
19
18
  * Run: `mailwoman registry gold-set-sample [--cap 200000] [--state TX] [--tau 0.7] [--n 300]
20
19
  * [--out-jsonl <path>]`
21
20
  */
22
21
 
23
22
  import { dataRootPath } from "@mailwoman/core/data-root"
24
- import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
23
+ import { writeLocalJSONLFile } from "@mailwoman/core/fs/writers"
24
+ import { stringifyJSON } from "@mailwoman/core/json"
25
25
  import { jaccard } from "@mailwoman/match"
26
26
 
27
27
  import { colocatedDistinctPairs, scanColocatedProviders, stateOption } from "#tools/shared"
@@ -31,27 +31,37 @@ import { colocatedDistinctPairs, scanColocatedProviders, stateOption } from "#to
31
31
  */
32
32
  export interface GoldSetSampleOptions {
33
33
  /**
34
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
34
+ * Record-matcher sources directory.
35
+ *
36
+ * Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
35
37
  */
36
38
  sources?: string
37
39
  /**
38
- * Providers sampled from the registry. Default 200000.
40
+ * Providers sampled from the registry.
41
+ *
42
+ * Default 200000.
39
43
  */
40
44
  cap?: number
41
45
  /**
42
- * State filter. Default TX.
46
+ * State filter.
47
+ *
48
+ * Default TX.
43
49
  */
44
50
  state?: string
45
51
  /**
46
- * Org-name Jaccard collision threshold. Default 0.7.
52
+ * Org-name Jaccard collision threshold.
53
+ *
54
+ * Default 0.7.
47
55
  */
48
56
  tau?: number
49
57
  /**
50
- * Adjudication sample size. Default 300.
58
+ * Adjudication sample size.
59
+ *
60
+ * Default 300.
51
61
  */
52
62
  n?: number
53
63
  /**
54
- * Write the sampled pairs here as JSONL (otherwise the first 10 print to stdout).
64
+ * Write the sampled pairs here as jsonl (otherwise the first 10 print to stdout).
55
65
  */
56
66
  outJSONL?: string
57
67
  }
@@ -67,11 +77,11 @@ interface HardPair {
67
77
  sameTaxonomy: boolean
68
78
  bothSubpartSameParent: boolean
69
79
  programmaticVerdict: "same-entity" | "distinct"
70
- adjudication: null // ← to be filled: "same-entity" | "distinct"
80
+ adjudication: null
71
81
  }
72
82
 
73
83
  /**
74
- * Gold-set P3 (#625) — sample the HARD co-located name-collision slice for adjudication.
84
+ * Sample the hard co-located name-collision stratum for adjudication.
75
85
  */
76
86
  export async function goldSetSample(
77
87
  options: GoldSetSampleOptions = {},
@@ -89,8 +99,6 @@ export async function goldSetSample(
89
99
  const { byAddr, kept } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
90
100
  report?.(` ${kept} providers at ${byAddr.size} addresses`)
91
101
 
92
- // Hard pairs: co-located, name-similar (≥τ), DISTINCT NPIs that programmatic truth can't confidently
93
- // collapse (NOT subparts of the same parent). Tag the programmatic verdict so adjudication can grade it.
94
102
  const hard: HardPair[] = []
95
103
 
96
104
  for (const { a, b } of colocatedDistinctPairs(byAddr)) {
@@ -99,7 +107,7 @@ export async function goldSetSample(
99
107
  if (sim < TAU) continue
100
108
  const sameParent = a.subpart && b.subpart && a.parent === b.parent && a.parent !== "|"
101
109
 
102
- if (sameParent) continue // programmatic truth already collapses these — not the hard slice
110
+ if (sameParent) continue
103
111
  const sameAuth = a.auth !== "" && a.auth === b.auth
104
112
  const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
105
113
 
@@ -113,9 +121,7 @@ export async function goldSetSample(
113
121
  sameAuthorizedOfficial: sameAuth,
114
122
  sameTaxonomy: sameTax,
115
123
  bothSubpartSameParent: false,
116
- // Programmatic heuristic verdict (what an entity-level rule WOULD say, beyond the flagged
117
- // subparts): same authorized official ⇒ likely one org; different official + different
118
- // specialty ⇒ likely distinct. The whole point is to ADJUDICATE whether this is right.
124
+ // The verdict records what an entity-level rule would say, so adjudication can grade it.
119
125
  programmaticVerdict: sameAuth ? "same-entity" : "distinct",
120
126
  adjudication: null,
121
127
  })
@@ -123,17 +129,17 @@ export async function goldSetSample(
123
129
 
124
130
  report?.(` ${hard.length} hard co-located name-collision pairs (non-flagged-subpart)`)
125
131
 
126
- // Deterministic spread sample of N (stride, not head — avoid file-order bias, the dedup-ceiling lesson).
132
+ // A deterministic stride sample avoids file-order bias in the adjudication set.
127
133
  const stride = Math.max(1, Math.floor(hard.length / N))
128
134
  const sample = hard.filter((_, i) => i % stride === 0).slice(0, N)
129
135
  report?.(` sampling ${sample.length} (stride ${stride}) for adjudication`)
130
136
 
131
137
  if (OUT) {
132
- await writeLocalTextFile(sample.map((p) => JSON.stringify(p)).join("\n") + "\n", OUT)
138
+ await writeLocalJSONLFile(sample, OUT)
133
139
  report?.(`[written] ${OUT}`)
134
140
  } else {
135
141
  for (const p of sample.slice(0, 10)) {
136
- console.log(JSON.stringify(p))
142
+ console.log(stringifyJSON(p))
137
143
  }
138
144
  }
139
145
 
@@ -3,26 +3,14 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Learned-scorer CLUSTERING A/B (#603 Tier 2) — the definitive test the pairwise probe
7
- * (`learned-scorer-eval.ts`) deferred. The probe showed a learned scorer ranks candidate pairs
8
- * better than Fellegi-Sunter (GBT +0.0177 AUC, +6.6pp pairwise F1); a better pairwise scorer need
9
- * NOT lift the assembled clustering F1 (clustering depends on the threshold +
10
- * connected-components). This measures the clustering F1 directly, leakage-free:
6
+ * Learned-scorer clustering A/B. A better pairwise scorer need not lift the assembled clustering F1,
7
+ * because that F1 depends on the threshold and connected components. This measures the clustering F1
8
+ * directly. It splits the NPIs into train and eval, trains a GBT and an LR on train pairs labeled by
9
+ * same NPI, then clusters the eval records three ways through the same `resolveEntities` pipeline
10
+ * (FS baseline, GBT scorer, LR scorer), sweeping the link threshold for each.
11
11
  *
12
- * 1. Sample NPI-keyed records (real registry + name-drift + address-variation), geocode once.
13
- * 2. Split the NPIs into TRAIN / EVAL. Train a GBT + an LR on pairs blocked among TRAIN records (label
14
- * = same-NPI). The eval NPIs' records are never seen in training.
15
- * 3. Cluster the EVAL records three ways via the SAME `resolveEntities` pipeline (block → score →
16
- * connected-components) — once with the FS baseline, once with the GBT as the link scorer
17
- * (the new `ResolveConfig.scorer` hook), once with the LR. Sweep the link threshold for
18
- * each; take best F1.
19
- * 4. Report the eval clustering F1 (the dedup benchmark's metric): does the learned scorer beat the FS
20
- * baseline on the ASSEMBLED output, not just pairwise ranking?
21
- *
22
- * The FS arm IS the benchmark's baseline (same model: address-frequency + collapsed spatial,
23
- * EM-fit), so the comparison is credible. Honest framing: in-domain (one state), a held-out-NPI
24
- * split (not a held-out STATE — generalization across states is the next axis), a compact
25
- * pure-Node GBT.
12
+ * The FS arm is the benchmark baseline (same model: address-frequency plus collapsed spatial,
13
+ * EM-fit), and the split is in-domain, held out by NPI rather than by state.
26
14
  *
27
15
  * Run: `mailwoman registry scorer-eval clustering [--npis 2000] [--split 0.67] [--seed 1]
28
16
  * [--out-md <md>]`
@@ -64,31 +52,45 @@ import {
64
52
  */
65
53
  export interface ScorerClusteringEvalOptions {
66
54
  /**
67
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
55
+ * The injected geocoder factory.
56
+ *
57
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
68
58
  */
69
59
  createGeocoder: EvalGeocoderFactory
70
60
  /**
71
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
61
+ * Record-matcher sources directory.
62
+ *
63
+ * Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
72
64
  */
73
65
  sources?: string
74
66
  /**
75
- * State filter. Default TX.
67
+ * State filter.
68
+ *
69
+ * Default TX.
76
70
  */
77
71
  state?: string
78
72
  /**
79
- * NPIs sampled. Default 2000.
73
+ * NPIs sampled.
74
+ *
75
+ * Default 2000.
80
76
  */
81
77
  npis?: number
82
78
  /**
83
- * Train fraction of the NPI split. Default 0.67.
79
+ * Train fraction of the NPI split.
80
+ *
81
+ * Default 0.67.
84
82
  */
85
83
  split?: number
86
84
  /**
87
- * Base PRNG seed. Default 1.
85
+ * Base prng seed.
86
+ *
87
+ * Default 1.
88
88
  */
89
89
  seed?: number
90
90
  /**
91
- * Held-out-NPI splits averaged. Default 4.
91
+ * Held-out-NPI splits averaged.
92
+ *
93
+ * Default 4.
92
94
  */
93
95
  seeds?: number
94
96
  /**
@@ -98,7 +100,8 @@ export interface ScorerClusteringEvalOptions {
98
100
  }
99
101
 
100
102
  /**
101
- * Learned-scorer clustering A/B (#603 Tier 2) — see the module doc. Emits the markdown report to stdout.
103
+ * Cluster the eval records with the FS baseline, GBT and LR.
104
+ * Emit the markdown report to stdout.
102
105
  */
103
106
  export async function scorerClusteringEval(
104
107
  options: ScorerClusteringEvalOptions,
@@ -114,8 +117,6 @@ export async function scorerClusteringEval(
114
117
  const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
115
118
  const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
116
119
 
117
- // --- Data-gen: the same NPI-keyed records as the dedup benchmark + the pairwise probe (the SHARED
118
- // sample builder). ---
119
120
  const {
120
121
  rows,
121
122
  keptNpis: kept,
@@ -128,8 +129,9 @@ export async function scorerClusteringEval(
128
129
  report?.("[C] geocoding…")
129
130
  const geocoder = await options.createGeocoder()
130
131
 
131
- // `auth`/`taxonomy` ride as attributes so the SHARED featurizer's #625 roll-up features can read the
132
- // authorized official; the FS arm ignores them (no discriminators configured).
132
+ // `auth` and `taxonomy` ride as attributes so the shared featurizer's roll-up
133
+ // features can read the authorized official.
134
+ // The FS arm ignores them, since no discriminators are configured.
133
135
  const mapping: ColumnMapping = {
134
136
  id: "npi",
135
137
  name: "name",
@@ -145,10 +147,9 @@ export async function scorerClusteringEval(
145
147
 
146
148
  geocoder[Symbol.dispose]()
147
149
 
148
- // --- The feature basis: address-frequency + collapsed-spatial model (the baseline). The agreement
149
- // pattern is EM-independent, so the same featurize() is consistent at train and inference time. ---
150
- // The featurizer is the SHARED production one (createMatchFeaturizer) — train ≡ eval ≡ inference, one
151
- // definition. Feed the collapsed-spatial + address-frequency comparison set (the benchmark baseline).
150
+ // The collapsed-spatial and address-frequency comparison set is the benchmark feature basis.
151
+ // The shared production featurizer keeps train, eval and inference on one definition.
152
+ // The agreement pattern is independent of EM, so features stay consistent at train and inference time.
152
153
  const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
153
154
  const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
154
155
 
@@ -164,10 +165,12 @@ export async function scorerClusteringEval(
164
165
  }
165
166
 
166
167
  /**
167
- * One held-out-NPI split: train the GBT + LR on TRAIN pairs, then cluster the EVAL records three ways (FS baseline,
168
- * GBT scorer, LR scorer) through the same `resolveEntities` pipeline, sweeping the link threshold finely for each and
169
- * taking best F1. The geocode is shared across seeds; only the split, the trained scorers, and the eval subset move
170
- * with the seed.
168
+ * One held-out-NPI split: train the GBT and LR on train pairs, then cluster
169
+ * the eval records three ways through the same `resolveEntities` pipeline,
170
+ * sweeping the link threshold for each and taking best F1.
171
+ *
172
+ * The geocode is shared across seeds.
173
+ * Only the split, trained scorers and the eval subset move with the seed.
171
174
  */
172
175
  function runSeed(seed: number): SeedResult {
173
176
  const rnd = makeLcg(seed || 1)
@@ -189,7 +192,7 @@ export async function scorerClusteringEval(
189
192
  const dim = trainX[0]?.length ?? 0
190
193
  const gbt = trainGBT(trainX, trainY, trainW, { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 })
191
194
 
192
- // LR (batch GD, class-balanced) — the SHARED trainer, same as the pairwise probe.
195
+ // LR (batch GD, class-balanced) through the shared trainer.
193
196
  const lrSc = trainLogisticRegression(trainX, trainY, trainW, dim)
194
197
 
195
198
  const gbtScorer = (a: SourceRecord, b: SourceRecord) => gbtScore(gbt, featurize(a, b))
@@ -201,14 +204,15 @@ export async function scorerClusteringEval(
201
204
  ): ArmScore =>
202
205
  bestOver(thresholds, (t) => toArmScore(scoreEntities(resolveEntities(evalRecords, cfg(t)).entities, npiLabel, N)))
203
206
 
204
- // FS baseline: EM-fit weights in bits, fine grid [0..25]. Learned scorers: a FINE sweep from each
205
- // scorer's own eval-pair score distribution, so a coarse grid can't understate them.
207
+ // The FS baseline uses EM-fit weights in bits over a fine grid.
208
+ // Each learned scorer sweeps its own eval-pair score distribution,
209
+ // so a coarse grid cannot understate it.
206
210
  const { pairs: evalPairs } = block(evalRecords, defaultBlockingKeys())
207
211
 
208
212
  const fs = armOver(
209
213
  Array.from({ length: 26 }, (_, i) => i),
210
- // learnedScorer:false — the FS baseline is the baseline this A/B measures against (the learned scorer
211
- // is now default-on, so without this the "FS arm" would silently BE the GBT).
214
+ // learnedScorer false keeps the FS baseline.
215
+ // The learned scorer is default-on, so without this the FS arm would silently be the GBT.
212
216
  (t) => ({ addressFrequency, collapseSpatial: true, trainEM: true, threshold: t, learnedScorer: false })
213
217
  )
214
218
 
@@ -326,7 +330,7 @@ export async function scorerClusteringEval(
326
330
  `fair. The GBT is a compact pure-Node implementation (120 rounds, depth 3), not a tuned XGBoost/LightGBM — a real ` +
327
331
  `GBM with more NPIs/features could move the number further. Thresholds are swept per scorer (FS in bits, learned ` +
328
332
  `scorers in logits), each at its own best operating point — note a 300-NPI smoke MISLED (FS ahead): too few ` +
329
- `co-located collisions to exhibit the over-merge, which only bites at scale, so trust the larger eval. NPI-as-truth ` +
333
+ `co-located collisions to exhibit the over-merge. It only bites at scale. Therefore, trust the larger eval. NPI-as-truth ` +
330
334
  `is conservative (a cross-NPI merge is a candidate, not necessarily an error)._`
331
335
  )
332
336
 
@@ -3,19 +3,14 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Learned-scorer CROSS-STATE generalization (#603 Tier 2, the next axis after the held-out-NPI A/B
7
- * in `learned-scorer-clustering-eval.ts`). The held-out-NPI A/B showed the GBT beats the FS
8
- * baseline on clustering by +5.2pp — but the GBT was trained and evaluated within ONE state (TX).
9
- * The production question is whether that win GENERALIZES: train on one state, evaluate the dedup
10
- * clustering F1 on a DIFFERENT state the model never saw. If it holds, the GBM is
11
- * production-worthy; if it collapses, the scorer is fitting state-specific structure and needs
12
- * per-state training (a finding either way).
6
+ * Learned-scorer cross-state generalization, the next axis after the held-out-NPI A/B. The
7
+ * within-state A/B showed the GBT beats the FS baseline on clustering, so this trains on one state and
8
+ * evaluates clustering F1 on a different state the model never saw.
13
9
  *
14
- * One registry pass builds the global address-frequency table + a TRAIN-state sample + an
15
- * EVAL-state sample (the SHARED multi-state sample builder); both are geocoded; the GBT + LR are
16
- * trained on the train state's pairs and used to cluster the eval state's records through the
17
- * same `resolveEntities` pipeline (FS baseline / GBT scorer / LR scorer), best F1 over a fine
18
- * per-scorer threshold sweep. The metric is the dedup benchmark's clustering F1.
10
+ * One registry pass builds the global address-frequency table, a train-state sample and an
11
+ * eval-state sample. Both samples are geocoded. The GBT and LR train on the train state's pairs and
12
+ * cluster the eval state's records through the same `resolveEntities` pipeline, with best F1 over a
13
+ * fine per-scorer threshold sweep.
19
14
  *
20
15
  * Run: `mailwoman registry scorer-eval cross-state [--train-state TX] [--eval-state CA]
21
16
  * [--npis 2000] [--out-md <md>]`
@@ -55,23 +50,33 @@ import {
55
50
  */
56
51
  export interface ScorerCrossStateEvalOptions {
57
52
  /**
58
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
53
+ * The injected geocoder factory.
54
+ *
55
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
59
56
  */
60
57
  createGeocoder: EvalGeocoderFactory
61
58
  /**
62
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
59
+ * Record-matcher sources directory.
60
+ *
61
+ * Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
63
62
  */
64
63
  sources?: string
65
64
  /**
66
- * State the GBT/LR train on. Default TX.
65
+ * State the GBT/LR train on.
66
+ *
67
+ * Default TX.
67
68
  */
68
69
  trainState?: string
69
70
  /**
70
- * Held-out state clustered. Default CA.
71
+ * Held-out state clustered.
72
+ *
73
+ * Default CA.
71
74
  */
72
75
  evalState?: string
73
76
  /**
74
- * NPIs sampled per state. Default 2000.
77
+ * NPIs sampled per state.
78
+ *
79
+ * Default 2000.
75
80
  */
76
81
  npis?: number
77
82
  /**
@@ -81,7 +86,8 @@ export interface ScorerCrossStateEvalOptions {
81
86
  }
82
87
 
83
88
  /**
84
- * Learned-scorer cross-state generalization (#603 Tier 2) — see the module doc. Emits the report to stdout.
89
+ * Train on one state and cluster a different state's records.
90
+ * Emit the report to stdout.
85
91
  */
86
92
  export async function scorerCrossStateEval(
87
93
  options: ScorerCrossStateEvalOptions,
@@ -96,8 +102,6 @@ export async function scorerCrossStateEval(
96
102
  const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
97
103
  const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
98
104
 
99
- // ONE registry pass fills BOTH state buckets (the SHARED multi-state sample builder): the global
100
- // address-frequency table + a TRAIN-state sample + an EVAL-state sample.
101
105
  const { byState, addressFrequency } = await buildNPPESStateSamples(
102
106
  {
103
107
  registryPath: REGISTRY,
@@ -114,8 +118,9 @@ export async function scorerCrossStateEval(
114
118
  report?.("[C] geocoding both states…")
115
119
  const geocoder = await options.createGeocoder()
116
120
 
117
- // `auth`/`taxonomy` ride as attributes so the SHARED featurizer's #625 roll-up features can read the
118
- // authorized official; the FS arm ignores them (no discriminators configured).
121
+ // `auth` and `taxonomy` ride as attributes so the shared featurizer's roll-up
122
+ // features can read the authorized official.
123
+ // The FS arm ignores them, since no discriminators are configured.
119
124
  const mapping: ColumnMapping = {
120
125
  id: "npi",
121
126
  name: "name",
@@ -129,8 +134,8 @@ export async function scorerCrossStateEval(
129
134
  const evalRecords = await ingestRows(evalSample.rows, mapping, { geocodeAddress: geocoder.geocodeAddress })
130
135
  geocoder[Symbol.dispose]()
131
136
 
132
- // Feature basis: the SHARED production featurizer (train ≡ eval ≡ inference, one definition) over the
133
- // collapsed-spatial + address-frequency comparison set (the baseline).
137
+ // The shared production featurizer keeps train, eval and inference on one definition,
138
+ // over the collapsed-spatial and address-frequency comparison set.
134
139
  const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
135
140
  const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
136
141
 
@@ -143,7 +148,7 @@ export async function scorerCrossStateEval(
143
148
  const dim = trainX[0]?.length ?? 0
144
149
  const gbt = trainGBT(trainX, trainY, trainW, { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 })
145
150
 
146
- // LR (batch GD, class-balanced) — the SHARED trainer.
151
+ // LR (batch GD, class-balanced) through the shared trainer.
147
152
  const lrSc = trainLogisticRegression(trainX, trainY, trainW, dim)
148
153
 
149
154
  const gbtScorer = (a: SourceRecord, b: SourceRecord) => gbtScore(gbt, featurize(a, b))
@@ -165,8 +170,8 @@ export async function scorerCrossStateEval(
165
170
 
166
171
  const fs = armOver(
167
172
  Array.from({ length: 26 }, (_, i) => i),
168
- // learnedScorer:false — the FS baseline is the baseline (the learned scorer is now default-on, so
169
- // without this the "FS arm" would silently BE the GBT).
173
+ // learnedScorer false keeps the FS baseline.
174
+ // The learned scorer is default-on, so without this the FS arm would silently be the GBT.
170
175
  (t) => ({ addressFrequency, collapseSpatial: true, trainEM: true, threshold: t, learnedScorer: false })
171
176
  )
172
177
 
@@ -184,9 +189,8 @@ export async function scorerCrossStateEval(
184
189
  threshold: t,
185
190
  }))
186
191
 
187
- // The SHIPPED model (the default-on candidate): the bundled DEDUP_GBT_MODEL, NOT a fresh per-run TX
188
- // fit. This is the arm that justifies flipping `learnedScorer` default-on — the actual artifact every
189
- // caller would get, evaluated on a state it never trained on.
192
+ // The bundled DEDUP_GBT_MODEL is the shipped artifact every caller receives,
193
+ // evaluated here on a state it never trained on.
190
194
  const bundledScorer = createGBTScorer({ model: DEDUP_GBT_MODEL, comparisons, addressFrequency })
191
195
 
192
196
  const bundledArm = armOver(quantileThresholds(evalPairs.map(([a, b]) => bundledScorer(a, b))), (t) => ({