@mailwoman/core 8.1.0 → 8.2.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 (406) hide show
  1. package/api/APIClient.ts +3 -4
  2. package/api/responses.ts +6 -3
  3. package/coarse-placer/coarse-placer.ts +26 -11
  4. package/coarse-placer/featurize.ts +25 -16
  5. package/coarse-placer/tools/build-dataset.ts +42 -18
  6. package/coarse-placer/tools/build-outlier-exposure.ts +51 -18
  7. package/coarse-placer/tools/build-outlier-latin.ts +48 -22
  8. package/coarse-placer/tools/build-outlier-oa.ts +52 -20
  9. package/coarse-placer/tools/eval-latin-offmap.ts +37 -12
  10. package/coarse-placer/tools/eval-openset.ts +104 -37
  11. package/coarse-placer/tools/eval-quant-compare.ts +41 -11
  12. package/coarse-placer/tools/eval.ts +51 -13
  13. package/coarse-placer/tools/fnv-hash.ts +5 -3
  14. package/coarse-placer/tools/probe-frontier.ts +63 -32
  15. package/coarse-placer/tools/quantize.ts +30 -8
  16. package/coarse-placer/tools/train.ts +63 -17
  17. package/collections.ts +2 -2
  18. package/decoder/build-tree.ts +16 -3
  19. package/decoder/calibration.ts +23 -7
  20. package/decoder/containment.ts +3 -1
  21. package/decoder/proposals-to-tree.ts +2 -0
  22. package/decoder/resolve-proposal-overlaps.ts +5 -1
  23. package/decoder/serialize-json.ts +8 -2
  24. package/decoder/serialize-tuples.ts +7 -2
  25. package/decoder/serialize-xml.ts +29 -11
  26. package/decoder/types.ts +34 -12
  27. package/decoder/unknown-spans.ts +14 -5
  28. package/decoder/validate-tree.ts +6 -1
  29. package/env/index.ts +1 -1
  30. package/env/load.ts +1 -1
  31. package/env/paths.ts +1 -1
  32. package/env/schema.ts +12 -4
  33. package/errors/schema.ts +1 -1
  34. package/fs/node.ts +9 -10
  35. package/identifiers.ts +3 -3
  36. package/kysley/adapter.ts +1 -1
  37. package/layers/manifest.ts +22 -8
  38. package/layers/schema.ts +59 -19
  39. package/locale/locale.ts +6 -2
  40. package/locale/profiles/en-us.ts +3 -0
  41. package/locale/profiles/fr-fr.ts +3 -0
  42. package/locale/profiles/ja-jp.ts +3 -0
  43. package/locale/registry.ts +3 -1
  44. package/logging/shared.ts +1 -0
  45. package/logging/utils.ts +1 -1
  46. package/objects.ts +7 -2
  47. package/out/api/APIClient.d.ts +1 -1
  48. package/out/api/APIClient.d.ts.map +1 -1
  49. package/out/api/APIClient.js +3 -2
  50. package/out/api/APIClient.js.map +1 -1
  51. package/out/api/responses.d.ts.map +1 -1
  52. package/out/api/responses.js +3 -3
  53. package/out/api/responses.js.map +1 -1
  54. package/out/coarse-placer/coarse-placer.d.ts +19 -9
  55. package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
  56. package/out/coarse-placer/coarse-placer.js +6 -4
  57. package/out/coarse-placer/coarse-placer.js.map +1 -1
  58. package/out/coarse-placer/featurize.d.ts.map +1 -1
  59. package/out/coarse-placer/featurize.js +20 -16
  60. package/out/coarse-placer/featurize.js.map +1 -1
  61. package/out/coarse-placer/tools/build-dataset.d.ts +15 -5
  62. package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -1
  63. package/out/coarse-placer/tools/build-dataset.js +19 -14
  64. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  65. package/out/coarse-placer/tools/build-outlier-exposure.d.ts +21 -7
  66. package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -1
  67. package/out/coarse-placer/tools/build-outlier-exposure.js +24 -12
  68. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  69. package/out/coarse-placer/tools/build-outlier-latin.d.ts +18 -6
  70. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
  71. package/out/coarse-placer/tools/build-outlier-latin.js +27 -17
  72. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  73. package/out/coarse-placer/tools/build-outlier-oa.d.ts +18 -6
  74. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
  75. package/out/coarse-placer/tools/build-outlier-oa.js +29 -15
  76. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  77. package/out/coarse-placer/tools/eval-latin-offmap.d.ts +18 -6
  78. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  79. package/out/coarse-placer/tools/eval-latin-offmap.js +13 -7
  80. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  81. package/out/coarse-placer/tools/eval-openset.d.ts +24 -8
  82. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
  83. package/out/coarse-placer/tools/eval-openset.js +52 -31
  84. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  85. package/out/coarse-placer/tools/eval-quant-compare.d.ts +30 -10
  86. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
  87. package/out/coarse-placer/tools/eval-quant-compare.js +4 -2
  88. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  89. package/out/coarse-placer/tools/eval.d.ts +24 -8
  90. package/out/coarse-placer/tools/eval.d.ts.map +1 -1
  91. package/out/coarse-placer/tools/eval.js +16 -6
  92. package/out/coarse-placer/tools/eval.js.map +1 -1
  93. package/out/coarse-placer/tools/fnv-hash.d.ts +3 -1
  94. package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
  95. package/out/coarse-placer/tools/fnv-hash.js +5 -3
  96. package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
  97. package/out/coarse-placer/tools/probe-frontier.d.ts +18 -6
  98. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  99. package/out/coarse-placer/tools/probe-frontier.js +39 -23
  100. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  101. package/out/coarse-placer/tools/quantize.d.ts +15 -5
  102. package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
  103. package/out/coarse-placer/tools/quantize.js +11 -4
  104. package/out/coarse-placer/tools/quantize.js.map +1 -1
  105. package/out/coarse-placer/tools/train.d.ts +24 -8
  106. package/out/coarse-placer/tools/train.d.ts.map +1 -1
  107. package/out/coarse-placer/tools/train.js +24 -10
  108. package/out/coarse-placer/tools/train.js.map +1 -1
  109. package/out/collections.js +2 -2
  110. package/out/collections.js.map +1 -1
  111. package/out/decoder/build-tree.d.ts.map +1 -1
  112. package/out/decoder/build-tree.js +9 -3
  113. package/out/decoder/build-tree.js.map +1 -1
  114. package/out/decoder/calibration.d.ts +17 -3
  115. package/out/decoder/calibration.d.ts.map +1 -1
  116. package/out/decoder/calibration.js +12 -4
  117. package/out/decoder/calibration.js.map +1 -1
  118. package/out/decoder/containment.d.ts +3 -1
  119. package/out/decoder/containment.d.ts.map +1 -1
  120. package/out/decoder/containment.js +3 -1
  121. package/out/decoder/containment.js.map +1 -1
  122. package/out/decoder/proposals-to-tree.d.ts.map +1 -1
  123. package/out/decoder/proposals-to-tree.js.map +1 -1
  124. package/out/decoder/resolve-proposal-overlaps.d.ts.map +1 -1
  125. package/out/decoder/resolve-proposal-overlaps.js +5 -1
  126. package/out/decoder/resolve-proposal-overlaps.js.map +1 -1
  127. package/out/decoder/serialize-json.d.ts +6 -2
  128. package/out/decoder/serialize-json.d.ts.map +1 -1
  129. package/out/decoder/serialize-json.js.map +1 -1
  130. package/out/decoder/serialize-tuples.d.ts +6 -2
  131. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  132. package/out/decoder/serialize-tuples.js.map +1 -1
  133. package/out/decoder/serialize-xml.d.ts +21 -7
  134. package/out/decoder/serialize-xml.d.ts.map +1 -1
  135. package/out/decoder/serialize-xml.js +7 -5
  136. package/out/decoder/serialize-xml.js.map +1 -1
  137. package/out/decoder/types.d.ts +34 -12
  138. package/out/decoder/types.d.ts.map +1 -1
  139. package/out/decoder/types.js +1 -1
  140. package/out/decoder/types.js.map +1 -1
  141. package/out/decoder/unknown-spans.d.ts +9 -3
  142. package/out/decoder/unknown-spans.d.ts.map +1 -1
  143. package/out/decoder/unknown-spans.js +4 -2
  144. package/out/decoder/unknown-spans.js.map +1 -1
  145. package/out/decoder/validate-tree.d.ts +3 -1
  146. package/out/decoder/validate-tree.d.ts.map +1 -1
  147. package/out/decoder/validate-tree.js +3 -1
  148. package/out/decoder/validate-tree.js.map +1 -1
  149. package/out/env/index.js +0 -1
  150. package/out/env/index.js.map +1 -1
  151. package/out/env/load.js +1 -1
  152. package/out/env/load.js.map +1 -1
  153. package/out/env/paths.js +1 -1
  154. package/out/env/paths.js.map +1 -1
  155. package/out/env/schema.d.ts.map +1 -1
  156. package/out/env/schema.js +12 -4
  157. package/out/env/schema.js.map +1 -1
  158. package/out/errors/schema.js +1 -1
  159. package/out/errors/schema.js.map +1 -1
  160. package/out/fs/node.d.ts +1 -2
  161. package/out/fs/node.d.ts.map +1 -1
  162. package/out/fs/node.js +7 -8
  163. package/out/fs/node.js.map +1 -1
  164. package/out/identifiers.js +3 -3
  165. package/out/identifiers.js.map +1 -1
  166. package/out/kysley/adapter.d.ts +1 -1
  167. package/out/kysley/adapter.d.ts.map +1 -1
  168. package/out/kysley/adapter.js +1 -1
  169. package/out/kysley/adapter.js.map +1 -1
  170. package/out/layers/manifest.d.ts +18 -6
  171. package/out/layers/manifest.d.ts.map +1 -1
  172. package/out/layers/manifest.js +8 -4
  173. package/out/layers/manifest.js.map +1 -1
  174. package/out/layers/schema.d.ts +57 -19
  175. package/out/layers/schema.d.ts.map +1 -1
  176. package/out/layers/schema.js +24 -8
  177. package/out/layers/schema.js.map +1 -1
  178. package/out/locale/locale.d.ts +6 -2
  179. package/out/locale/locale.d.ts.map +1 -1
  180. package/out/locale/profiles/en-us.d.ts +3 -0
  181. package/out/locale/profiles/en-us.d.ts.map +1 -1
  182. package/out/locale/profiles/en-us.js +3 -0
  183. package/out/locale/profiles/en-us.js.map +1 -1
  184. package/out/locale/profiles/fr-fr.d.ts +3 -0
  185. package/out/locale/profiles/fr-fr.d.ts.map +1 -1
  186. package/out/locale/profiles/fr-fr.js +3 -0
  187. package/out/locale/profiles/fr-fr.js.map +1 -1
  188. package/out/locale/profiles/ja-jp.d.ts +3 -0
  189. package/out/locale/profiles/ja-jp.d.ts.map +1 -1
  190. package/out/locale/profiles/ja-jp.js +3 -0
  191. package/out/locale/profiles/ja-jp.js.map +1 -1
  192. package/out/locale/registry.d.ts +3 -1
  193. package/out/locale/registry.d.ts.map +1 -1
  194. package/out/locale/registry.js +3 -1
  195. package/out/locale/registry.js.map +1 -1
  196. package/out/logging/shared.d.ts.map +1 -1
  197. package/out/logging/shared.js +1 -0
  198. package/out/logging/shared.js.map +1 -1
  199. package/out/logging/utils.js +1 -1
  200. package/out/logging/utils.js.map +1 -1
  201. package/out/objects.d.ts.map +1 -1
  202. package/out/objects.js +2 -2
  203. package/out/objects.js.map +1 -1
  204. package/out/pipeline/index.d.ts +2 -2
  205. package/out/pipeline/index.d.ts.map +1 -1
  206. package/out/pipeline/index.js +1 -1
  207. package/out/pipeline/index.js.map +1 -1
  208. package/out/pipeline/reconcile-lookups.d.ts.map +1 -1
  209. package/out/pipeline/reconcile-lookups.js.map +1 -1
  210. package/out/pipeline/reconcile.d.ts +30 -10
  211. package/out/pipeline/reconcile.d.ts.map +1 -1
  212. package/out/pipeline/reconcile.js +12 -9
  213. package/out/pipeline/reconcile.js.map +1 -1
  214. package/out/pipeline/runtime-pipeline.d.ts +18 -0
  215. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  216. package/out/pipeline/runtime-pipeline.js +73 -46
  217. package/out/pipeline/runtime-pipeline.js.map +1 -1
  218. package/out/pipeline/span-logit-aggregation.d.ts.map +1 -1
  219. package/out/pipeline/span-logit-aggregation.js +5 -2
  220. package/out/pipeline/span-logit-aggregation.js.map +1 -1
  221. package/out/pipeline/span-proposer.d.ts +19 -9
  222. package/out/pipeline/span-proposer.d.ts.map +1 -1
  223. package/out/pipeline/span-proposer.js +42 -22
  224. package/out/pipeline/span-proposer.js.map +1 -1
  225. package/out/pipeline/types.d.ts +77 -19
  226. package/out/pipeline/types.d.ts.map +1 -1
  227. package/out/pipeline/types.js +16 -0
  228. package/out/pipeline/types.js.map +1 -1
  229. package/out/policy/proposal-collection.d.ts +1 -1
  230. package/out/policy/proposal-collection.d.ts.map +1 -1
  231. package/out/policy/proposal-collection.js +2 -3
  232. package/out/policy/proposal-collection.js.map +1 -1
  233. package/out/policy/registry.d.ts +9 -3
  234. package/out/policy/registry.d.ts.map +1 -1
  235. package/out/policy/registry.js +9 -3
  236. package/out/policy/registry.js.map +1 -1
  237. package/out/resolver/index.d.ts.map +1 -1
  238. package/out/resolver/types.d.ts +94 -30
  239. package/out/resolver/types.d.ts.map +1 -1
  240. package/out/resolver/types.js +7 -1
  241. package/out/resolver/types.js.map +1 -1
  242. package/out/resources/LocaleIndex.d.ts +1 -1
  243. package/out/resources/LocaleIndex.d.ts.map +1 -1
  244. package/out/resources/LocaleIndex.js +1 -2
  245. package/out/resources/LocaleIndex.js.map +1 -1
  246. package/out/resources/ResourceMapCache.d.ts.map +1 -1
  247. package/out/resources/ResourceMapCache.js +1 -1
  248. package/out/resources/ResourceMapCache.js.map +1 -1
  249. package/out/resources/collections.d.ts.map +1 -1
  250. package/out/resources/collections.js +3 -1
  251. package/out/resources/collections.js.map +1 -1
  252. package/out/resources/languages/index.d.ts +1 -1
  253. package/out/resources/languages/index.d.ts.map +1 -1
  254. package/out/resources/languages/index.js +1 -1
  255. package/out/resources/languages/index.js.map +1 -1
  256. package/out/resources/libpostal.d.ts +1 -1
  257. package/out/resources/libpostal.d.ts.map +1 -1
  258. package/out/resources/libpostal.js +7 -5
  259. package/out/resources/libpostal.js.map +1 -1
  260. package/out/resources/set.js +6 -6
  261. package/out/resources/set.js.map +1 -1
  262. package/out/resources/whosonfirst/DataSourceCache.d.ts +1 -4
  263. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
  264. package/out/resources/whosonfirst/DataSourceCache.js +1 -20
  265. package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
  266. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +1 -1
  267. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  268. package/out/resources/whosonfirst/PlacetypeDataSource.js +2 -2
  269. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  270. package/out/resources/whosonfirst/backoff.d.ts +19 -0
  271. package/out/resources/whosonfirst/backoff.d.ts.map +1 -0
  272. package/out/resources/whosonfirst/backoff.js +35 -0
  273. package/out/resources/whosonfirst/backoff.js.map +1 -0
  274. package/out/resources/whosonfirst/loader.d.ts +1 -1
  275. package/out/resources/whosonfirst/loader.d.ts.map +1 -1
  276. package/out/resources/whosonfirst/loader.js +0 -1
  277. package/out/resources/whosonfirst/loader.js.map +1 -1
  278. package/out/resources/whosonfirst/placetypes/Placetype.d.ts +4 -1
  279. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  280. package/out/resources/whosonfirst/placetypes/Placetype.js +8 -6
  281. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  282. package/out/resources/whosonfirst/placetypes/admin.d.ts +6 -4
  283. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  284. package/out/resources/whosonfirst/placetypes/admin.js +8 -4
  285. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  286. package/out/resources/whosonfirst/placetypes/definition.d.ts +5 -6
  287. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  288. package/out/resources/whosonfirst/placetypes/definition.js +3 -0
  289. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  290. package/out/resources/whosonfirst/placetypes/graph.d.ts +4 -2
  291. package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
  292. package/out/resources/whosonfirst/placetypes/graph.js +0 -0
  293. package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
  294. package/out/resources/whosonfirst/placetypes/mermaid.d.ts +4 -2
  295. package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
  296. package/out/resources/whosonfirst/placetypes/mermaid.js +0 -1
  297. package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
  298. package/out/resources/whosonfirst/placetypes/tree.d.ts +1 -1
  299. package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
  300. package/out/resources/whosonfirst/placetypes/tree.js +0 -1
  301. package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
  302. package/out/routing/index.d.ts.map +1 -1
  303. package/out/routing/index.js +1 -1
  304. package/out/routing/index.js.map +1 -1
  305. package/out/scripting/utils/index.d.ts +3 -1
  306. package/out/scripting/utils/index.d.ts.map +1 -1
  307. package/out/scripting/utils/index.js +3 -1
  308. package/out/scripting/utils/index.js.map +1 -1
  309. package/out/tokenization/Span.js.map +1 -1
  310. package/out/tokenization/normalizer.js +11 -11
  311. package/out/tokenization/normalizer.js.map +1 -1
  312. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  313. package/out/tools/download-libpostal-resources.js.map +1 -1
  314. package/out/tools/download-ssl-address.d.ts +9 -3
  315. package/out/tools/download-ssl-address.d.ts.map +1 -1
  316. package/out/tools/download-ssl-address.js +8 -4
  317. package/out/tools/download-ssl-address.js.map +1 -1
  318. package/out/tools/generate-language-types.d.ts +12 -4
  319. package/out/tools/generate-language-types.d.ts.map +1 -1
  320. package/out/tools/generate-language-types.js +3 -1
  321. package/out/tools/generate-language-types.js.map +1 -1
  322. package/out/types/Classification.d.ts.map +1 -1
  323. package/out/types/Classification.js.map +1 -1
  324. package/out/types/classifier.d.ts +27 -9
  325. package/out/types/classifier.d.ts.map +1 -1
  326. package/out/types/component.d.ts +6 -2
  327. package/out/types/component.d.ts.map +1 -1
  328. package/out/types/component.js.map +1 -1
  329. package/out/utils/data-root.d.ts +3 -1
  330. package/out/utils/data-root.d.ts.map +1 -1
  331. package/out/utils/data-root.js +3 -1
  332. package/out/utils/data-root.js.map +1 -1
  333. package/out/utils/hash.d.ts +6 -2
  334. package/out/utils/hash.d.ts.map +1 -1
  335. package/out/utils/hash.js +6 -2
  336. package/out/utils/hash.js.map +1 -1
  337. package/out/utils/jsonl.d.ts +9 -3
  338. package/out/utils/jsonl.d.ts.map +1 -1
  339. package/out/utils/jsonl.js +9 -3
  340. package/out/utils/jsonl.js.map +1 -1
  341. package/out/utils/python-json.d.ts +6 -2
  342. package/out/utils/python-json.d.ts.map +1 -1
  343. package/out/utils/python-json.js +9 -3
  344. package/out/utils/python-json.js.map +1 -1
  345. package/out/utils/python-random.d.ts +15 -5
  346. package/out/utils/python-random.d.ts.map +1 -1
  347. package/out/utils/python-random.js +17 -7
  348. package/out/utils/python-random.js.map +1 -1
  349. package/out/utils/repo.d.ts +4 -0
  350. package/out/utils/repo.d.ts.map +1 -1
  351. package/out/utils/repo.js +4 -0
  352. package/out/utils/repo.js.map +1 -1
  353. package/out/utils/sealed-db.d.ts +6 -2
  354. package/out/utils/sealed-db.d.ts.map +1 -1
  355. package/out/utils/sealed-db.js +6 -2
  356. package/out/utils/sealed-db.js.map +1 -1
  357. package/out/utils/stats.d.ts +9 -3
  358. package/out/utils/stats.d.ts.map +1 -1
  359. package/out/utils/stats.js +11 -5
  360. package/out/utils/stats.js.map +1 -1
  361. package/package.json +2 -2
  362. package/pipeline/index.ts +5 -1
  363. package/pipeline/reconcile-lookups.ts +3 -0
  364. package/pipeline/reconcile.ts +65 -24
  365. package/pipeline/runtime-pipeline.ts +95 -46
  366. package/pipeline/span-logit-aggregation.ts +7 -2
  367. package/pipeline/span-proposer.ts +95 -34
  368. package/pipeline/types.ts +88 -19
  369. package/policy/proposal-collection.ts +4 -3
  370. package/policy/registry.ts +13 -3
  371. package/resolver/index.ts +1 -0
  372. package/resolver/types.ts +95 -30
  373. package/resources/LocaleIndex.ts +2 -2
  374. package/resources/ResourceMapCache.ts +3 -2
  375. package/resources/collections.ts +4 -1
  376. package/resources/languages/index.ts +2 -1
  377. package/resources/libpostal.ts +6 -3
  378. package/resources/set.ts +6 -6
  379. package/resources/whosonfirst/DataSourceCache.ts +2 -24
  380. package/resources/whosonfirst/PlacetypeDataSource.ts +2 -2
  381. package/resources/whosonfirst/backoff.ts +39 -0
  382. package/resources/whosonfirst/loader.ts +2 -1
  383. package/resources/whosonfirst/placetypes/Placetype.ts +9 -6
  384. package/resources/whosonfirst/placetypes/admin.ts +12 -7
  385. package/resources/whosonfirst/placetypes/definition.ts +6 -6
  386. package/resources/whosonfirst/placetypes/graph.ts +0 -0
  387. package/resources/whosonfirst/placetypes/mermaid.ts +5 -2
  388. package/resources/whosonfirst/placetypes/tree.ts +1 -1
  389. package/routing/index.ts +5 -1
  390. package/scripting/utils/index.ts +3 -1
  391. package/tokenization/Span.ts +1 -1
  392. package/tokenization/normalizer.ts +11 -11
  393. package/tools/download-libpostal-resources.ts +1 -0
  394. package/tools/download-ssl-address.ts +19 -7
  395. package/tools/generate-language-types.ts +12 -4
  396. package/types/Classification.ts +5 -0
  397. package/types/classifier.ts +27 -9
  398. package/types/component.ts +6 -2
  399. package/utils/data-root.ts +3 -1
  400. package/utils/hash.ts +6 -2
  401. package/utils/jsonl.ts +11 -3
  402. package/utils/python-json.ts +13 -4
  403. package/utils/python-random.ts +17 -7
  404. package/utils/repo.ts +8 -0
  405. package/utils/sealed-db.ts +10 -2
  406. package/utils/stats.ts +11 -5
@@ -30,6 +30,9 @@
30
30
  * Run: `mailwoman placer eval openset [--model <dir>] [--out-md <path>]`
31
31
  */
32
32
 
33
+ /* oxlint-disable sister-software/prefer-region-over-marks -- these markers label steps inside one
34
+ procedure, not sections of declarations. A region there folds nothing a reader wants folded. */
35
+
33
36
  import { readFileSync, writeFileSync } from "node:fs"
34
37
  import * as path from "node:path"
35
38
 
@@ -38,6 +41,16 @@ import { repoRootPath } from "../../utils/repo.ts"
38
41
  import type { CoarsePlacerMeta } from "../coarse-placer.ts"
39
42
  import { COARSE_CLASSES, featurize } from "../featurize.ts"
40
43
 
44
+ /**
45
+ * Steps in the threshold sweep; finer than the reporting precision so the knee is not missed.
46
+ */
47
+ const QUANTILE_SWEEP_STEPS = 200
48
+
49
+ /**
50
+ * Percentage both held-out catch and in-map accuracy must clear for an operating point to qualify.
51
+ */
52
+ const TARGET_PERCENT = 90
53
+
41
54
  type ScoreKey = "maxprob" | "p_inmap" | "energy" | "maxlogit" | "maha"
42
55
 
43
56
  interface DataRow {
@@ -59,21 +72,35 @@ interface ParetoPoint {
59
72
  heldCaught: number
60
73
  }
61
74
 
62
- /** Options for {@linkcode evalOpenSet}. */
75
+ /**
76
+ * Options for {@linkcode evalOpenSet}.
77
+ */
63
78
  export interface EvalOpenSetOptions {
64
- /** Model artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`. */
79
+ /**
80
+ * Model artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
81
+ */
65
82
  model?: string
66
- /** Dataset dir. Default `<repo>/data/coarse-placer`. */
83
+ /**
84
+ * Dataset dir. Default `<repo>/data/coarse-placer`.
85
+ */
67
86
  data?: string
68
- /** Mahalanobis fit rows per class. Default 2000. */
87
+ /**
88
+ * Mahalanobis fit rows per class. Default 2000.
89
+ */
69
90
  fitPerClass?: number
70
- /** Also write the markdown report here. */
91
+ /**
92
+ * Also write the markdown report here.
93
+ */
71
94
  outMd?: string
72
95
  }
73
96
 
74
- /** Result of {@linkcode evalOpenSet}. */
97
+ /**
98
+ * Result of {@linkcode evalOpenSet}.
99
+ */
75
100
  export interface EvalOpenSetResult {
76
- /** Best score by the honest dev→test balanced min. */
101
+ /**
102
+ * Best score by the honest dev→test balanced min.
103
+ */
77
104
  winner: ScoreKey
78
105
  honestMin: number
79
106
  clears90: boolean
@@ -87,6 +114,7 @@ function logsumexp(xs: number[]): number {
87
114
  if (x > m) {
88
115
  m = x
89
116
  }
117
+
90
118
  let s = 0
91
119
 
92
120
  for (const x of xs) {
@@ -96,7 +124,9 @@ function logsumexp(xs: number[]): number {
96
124
  return m + Math.log(s)
97
125
  }
98
126
 
99
- /** Per-class softmax prob over ALL 12 classes. */
127
+ /**
128
+ * Per-class softmax prob over ALL 12 classes.
129
+ */
100
130
  function softmax(z: Float64Array): Float64Array {
101
131
  const m = Math.max(...z)
102
132
  const e = z.map((x) => Math.exp(x - m))
@@ -105,15 +135,19 @@ function softmax(z: Float64Array): Float64Array {
105
135
  return e.map((x) => x / s)
106
136
  }
107
137
 
108
- /** Invert a symmetric positive-definite matrix via Gauss-Jordan. */
138
+ /**
139
+ * Invert a symmetric positive-definite matrix via Gauss-Jordan.
140
+ */
109
141
  function inverse(M: Float64Array[]): number[][] {
110
142
  const n = M.length
143
+
111
144
  const A = M.map((row, i) => {
112
145
  const r = new Float64Array(2 * n)
113
146
 
114
147
  for (let j = 0; j < n; j++) {
115
148
  r[j] = row[j]!
116
149
  }
150
+
117
151
  r[n + i] = 1
118
152
 
119
153
  return r
@@ -126,6 +160,7 @@ function inverse(M: Float64Array[]): number[][] {
126
160
  if (Math.abs(A[r]![col]!) > Math.abs(A[piv]![col]!)) {
127
161
  piv = r
128
162
  }
163
+
129
164
  ;[A[col], A[piv]] = [A[piv]!, A[col]!]
130
165
  const d = A[col]![col]!
131
166
 
@@ -146,7 +181,9 @@ function inverse(M: Float64Array[]): number[][] {
146
181
  return A.map((r) => Array.from(r.slice(n)))
147
182
  }
148
183
 
149
- /** Coarse-placer post-hoc open-set score comparison — see the module doc. Emits the markdown report to stdout. */
184
+ /**
185
+ * Coarse-placer post-hoc open-set score comparison — see the module doc. Emits the markdown report to stdout.
186
+ */
150
187
  export async function evalOpenSet(
151
188
  options: EvalOpenSetOptions = {},
152
189
  report?: (line: string) => void
@@ -166,7 +203,9 @@ export async function evalOpenSet(
166
203
 
167
204
  if (W.length !== C * D) throw new Error(`weights ${W.length} ≠ ${C}×${D}`)
168
205
 
169
- /** Raw logits (PRE-temperature) for the 12 classes. OOD scores use the geometry, not calibration. */
206
+ /**
207
+ * Raw logits (PRE-temperature) for the 12 classes. OOD scores use the geometry, not calibration.
208
+ */
170
209
  function logits(raw: string): Float64Array {
171
210
  const feats = featurize(raw)
172
211
  const z = new Float64Array(C)
@@ -178,13 +217,16 @@ export async function evalOpenSet(
178
217
  for (const i of feats) {
179
218
  s += W[base + i]!
180
219
  }
220
+
181
221
  z[c] = s
182
222
  }
183
223
 
184
224
  return z
185
225
  }
186
226
 
187
- /** In-map logit sub-vector (length nIn), in IN order. */
227
+ /**
228
+ * In-map logit sub-vector (length nIn), in IN order.
229
+ */
188
230
  const inVec = (z: Float64Array): number[] => IN.map((c) => z[c]!)
189
231
 
190
232
  function load(file: string): DataRow[] {
@@ -194,10 +236,8 @@ export async function evalOpenSet(
194
236
  .map((l) => JSON.parse(l) as DataRow)
195
237
  }
196
238
 
197
- // ---------------------------------------------------------------------------
198
239
  // Fit the Mahalanobis params on IN-MAP TRAIN logits (no test leak): per-class
199
240
  // mean in the nIn-dim in-map-logit space + a tied (shared) covariance.
200
- // ---------------------------------------------------------------------------
201
241
  report?.("fitting Mahalanobis on in-map train logits…")
202
242
  const trainRows = load("train.jsonl")
203
243
  const byClass = new Map<string, string[]>(COARSE_CLASSES.map((c): [string, string[]] => [c, []]))
@@ -210,12 +250,13 @@ export async function evalOpenSet(
210
250
  arr.push(r.raw)
211
251
  }
212
252
  }
253
+
213
254
  const means = new Map<string, Float64Array>() // country -> Float64Array(nIn)
214
255
  const counts = new Map<string, number>()
215
256
 
216
257
  // Accumulate per-class means.
217
258
  for (const [country, raws] of byClass) {
218
- if (raws.length === 0) continue
259
+ if (!raws.length) continue
219
260
  const mu = new Float64Array(nIn)
220
261
 
221
262
  for (const raw of raws) {
@@ -229,9 +270,11 @@ export async function evalOpenSet(
229
270
  for (let k = 0; k < nIn; k++) {
230
271
  mu[k] = mu[k]! / raws.length
231
272
  }
273
+
232
274
  means.set(country, mu)
233
275
  counts.set(country, raws.length)
234
276
  }
277
+
235
278
  // Tied covariance over centered in-map train logits.
236
279
  const Sigma = Array.from({ length: nIn }, () => new Float64Array(nIn))
237
280
  let nTot = 0
@@ -254,6 +297,7 @@ export async function evalOpenSet(
254
297
  Sigma[a]![b] = Sigma[a]![b]! + d[a]! * d[b]!
255
298
  }
256
299
  }
300
+
257
301
  nTot++
258
302
  }
259
303
  }
@@ -271,7 +315,9 @@ export async function evalOpenSet(
271
315
 
272
316
  const SigmaInv = inverse(Sigma)
273
317
 
274
- /** -min_c Mahalanobis² to any in-map class mean (higher = closer to the in-map manifold). */
318
+ /**
319
+ * -min_c Mahalanobis² to any in-map class mean (higher = closer to the in-map manifold).
320
+ */
275
321
  function mahaScore(z: Float64Array): number {
276
322
  const v = inVec(z)
277
323
  let best = Infinity
@@ -282,6 +328,7 @@ export async function evalOpenSet(
282
328
  for (let k = 0; k < nIn; k++) {
283
329
  d[k] = v[k]! - mu[k]!
284
330
  }
331
+
285
332
  let q = 0
286
333
 
287
334
  for (let a = 0; a < nIn; a++) {
@@ -290,6 +337,7 @@ export async function evalOpenSet(
290
337
  for (let b = 0; b < nIn; b++) {
291
338
  row += SigmaInv[a]![b]! * d[b]!
292
339
  }
340
+
293
341
  q += d[a]! * row
294
342
  }
295
343
 
@@ -301,17 +349,19 @@ export async function evalOpenSet(
301
349
  return -best
302
350
  }
303
351
 
304
- // ---------------------------------------------------------------------------
305
- // Score the in-map test (11 countries) + the off-map heldout families.
306
- // ---------------------------------------------------------------------------
352
+ // MARK: Score both splits
353
+
307
354
  report?.("scoring in-map test + off-map heldout…")
308
355
  const SCORES: ScoreKey[] = ["maxprob", "p_inmap", "energy", "maxlogit", "maha"]
309
356
 
310
- /** All open-set scores for one raw string + whether argmax-in-map routes to `trueCountry`. */
357
+ /**
358
+ * All open-set scores for one raw string + whether argmax-in-map routes to `trueCountry`.
359
+ */
311
360
  function scoreRow(raw: string, trueCountry: string | undefined): ScoredRow {
312
361
  const z = logits(raw)
313
362
  const probs = softmax(z)
314
363
  const zin = inVec(z)
364
+
315
365
  // argmax over in-map classes (the FIXED routing).
316
366
  let amIdx = 0,
317
367
  am = -Infinity
@@ -321,6 +371,7 @@ export async function evalOpenSet(
321
371
  am = zin[k]!
322
372
  amIdx = k
323
373
  }
374
+
324
375
  const routedCountry = COARSE_CLASSES[IN[amIdx]!]!
325
376
  const inmapProbMax = Math.max(...IN.map((c) => probs[c]!))
326
377
 
@@ -350,7 +401,9 @@ export async function evalOpenSet(
350
401
  const heldDev = heldoutScored.filter((_, i) => i % 2 === 0)
351
402
  const heldTest = heldoutScored.filter((_, i) => i % 2 === 1)
352
403
 
353
- /** (inMapAcc, heldCaught) at threshold t over a given in-map/heldout split. */
404
+ /**
405
+ * (inMapAcc, heldCaught) at threshold t over a given in-map/heldout split.
406
+ */
354
407
  function pointAt(scoreKey: ScoreKey, t: number, inSplit: ScoredRow[], heldSplit: ScoredRow[]): ParetoPoint {
355
408
  let keepCorrect = 0
356
409
 
@@ -358,6 +411,7 @@ export async function evalOpenSet(
358
411
  if (o.s[scoreKey] >= t && o.correctRoute) {
359
412
  keepCorrect++
360
413
  }
414
+
361
415
  let caught = 0
362
416
 
363
417
  for (const o of heldSplit)
@@ -374,15 +428,17 @@ export async function evalOpenSet(
374
428
  const inVals = inmapScored.map((o) => ({ v: o.s[scoreKey], ok: o.correctRoute }))
375
429
  const heldVals = heldoutScored.map((o) => o.s[scoreKey])
376
430
  // Candidate thresholds: quantiles of the union of scores.
377
- const all = [...inVals.map((x) => x.v), ...heldVals].sort((a, b) => a - b)
431
+ const all = [...inVals.map((x) => x.v), ...heldVals].toSorted((a, b) => a - b)
378
432
  const ts: number[] = []
379
433
 
380
- for (let q = 0; q <= 200; q++) {
434
+ for (let q = 0; q <= QUANTILE_SWEEP_STEPS; q++) {
381
435
  ts.push(all[Math.min(all.length - 1, Math.floor((q / 200) * (all.length - 1)))]!)
382
436
  }
437
+
383
438
  const uniq = [...new Set(ts)]
384
439
  const nInVals = inVals.length
385
440
  const nHeld = heldVals.length
441
+
386
442
  const pts: ParetoPoint[] = uniq.map((t) => {
387
443
  let keepCorrect = 0
388
444
 
@@ -390,6 +446,7 @@ export async function evalOpenSet(
390
446
  if (x.v >= t && x.ok) {
391
447
  keepCorrect++
392
448
  }
449
+
393
450
  let caught = 0
394
451
 
395
452
  for (const v of heldVals)
@@ -399,6 +456,7 @@ export async function evalOpenSet(
399
456
 
400
457
  return { t, inMapAcc: (100 * keepCorrect) / nInVals, heldCaught: (100 * caught) / nHeld }
401
458
  })
459
+
402
460
  // Summaries.
403
461
  let balanced: { val: number; pt: ParetoPoint | null } = { val: -1, pt: null } // max of min(inMapAcc, heldCaught) on the FULL probe
404
462
  let atHeld90: ParetoPoint | null = null // highest inMapAcc with heldCaught >= 90
@@ -412,11 +470,11 @@ export async function evalOpenSet(
412
470
  balanced = { val: m, pt: p }
413
471
  }
414
472
 
415
- if (p.heldCaught >= 90 && (!atHeld90 || p.inMapAcc > atHeld90.inMapAcc)) {
473
+ if (p.heldCaught >= TARGET_PERCENT && (!atHeld90 || p.inMapAcc > atHeld90.inMapAcc)) {
416
474
  atHeld90 = p
417
475
  }
418
476
 
419
- if (p.inMapAcc >= 90 && (!atIn90 || p.heldCaught > atIn90.heldCaught)) {
477
+ if (p.inMapAcc >= TARGET_PERCENT && (!atIn90 || p.heldCaught > atIn90.heldCaught)) {
420
478
  atIn90 = p
421
479
  }
422
480
  }
@@ -432,6 +490,7 @@ export async function evalOpenSet(
432
490
  devBest = { val: m, t: p.t }
433
491
  }
434
492
  }
493
+
435
494
  const heldoutTestPt = pointAt(scoreKey, devBest.t!, inTest, heldTest)
436
495
 
437
496
  return { balanced, atHeld90, atIn90, devThreshold: devBest.t, honest: heldoutTestPt, pts }
@@ -440,20 +499,20 @@ export async function evalOpenSet(
440
499
  type Pareto = ReturnType<typeof paretoFor>
441
500
  const results = Object.fromEntries(SCORES.map((k) => [k, paretoFor(k)])) as Record<ScoreKey, Pareto>
442
501
 
443
- // ---------------------------------------------------------------------------
444
- // Report.
445
- // ---------------------------------------------------------------------------
502
+ // MARK: Report.
503
+
446
504
  const f = (x: number | null | undefined): string => (x == null ? "—" : x.toFixed(1))
447
- const lines: string[] = []
448
- lines.push(`# Coarse-placer M2 Phase 1 — post-hoc open-set score comparison (#244)`)
449
- lines.push("")
450
- lines.push(
505
+
506
+ const lines: string[] = [
507
+ `# Coarse-placer M2 Phase 1 — post-hoc open-set score comparison (#244)`,
508
+ "",
451
509
  `_Frozen shipped model (\`${path.basename(modelDir)}\`), NO retrain. In-map test ${inmapTest.length} rows ` +
452
510
  `(11 countries); off-map HELDOUT ${heldout.length} rows (never-trained families: baltic/oceania/middle-east). ` +
453
511
  `Mahalanobis fit on ≤${fitPerClass}/class in-map train logits. The 11-way routing is fixed; each score only ` +
454
- `changes the reject decision._`
455
- )
456
- lines.push("")
512
+ `changes the reject decision._`,
513
+ "",
514
+ ]
515
+
457
516
  function atStr(p: ParetoPoint | null): string {
458
517
  if (!p) return "— (unreachable)"
459
518
 
@@ -468,10 +527,12 @@ export async function evalOpenSet(
468
527
  for (const k of SCORES) {
469
528
  const r = results[k]
470
529
  const h = r.honest
530
+
471
531
  lines.push(
472
532
  `| \`${k}\` | ${f(h.inMapAcc)} | ${f(h.heldCaught)} | **${f(Math.min(h.inMapAcc, h.heldCaught))}** | ${f(r.balanced.val)} |`
473
533
  )
474
534
  }
535
+
475
536
  lines.push("")
476
537
  lines.push(`## Full-probe corners (the achievable Pareto), per score`)
477
538
  lines.push("")
@@ -481,33 +542,39 @@ export async function evalOpenSet(
481
542
  for (const k of SCORES) {
482
543
  const r = results[k]
483
544
  const bal = r.balanced.pt
545
+
484
546
  lines.push(
485
547
  `| \`${k}\` | **${f(r.balanced.val)}** (in ${f(bal?.inMapAcc)}, held ${f(bal?.heldCaught)}) | ` +
486
548
  `${atStr(r.atHeld90)} | ${atStr(r.atIn90)} |`
487
549
  )
488
550
  }
551
+
489
552
  lines.push("")
490
553
 
491
554
  // Winner by the HONEST dev→test balanced min (not the full-probe number).
492
555
  const ranked = SCORES.map((k) => ({
493
556
  k,
494
557
  honestMin: Math.min(results[k].honest.inMapAcc, results[k].honest.heldCaught),
495
- })).sort((a, b) => b.honestMin - a.honestMin)
558
+ })).toSorted((a, b) => b.honestMin - a.honestMin)
559
+
496
560
  const winner = ranked[0]!
497
- const clears90 = winner.honestMin >= 90
561
+ const clears90 = winner.honestMin >= TARGET_PERCENT
498
562
  lines.push(`## Verdict`)
499
563
  lines.push("")
564
+
500
565
  lines.push(
501
566
  `Best score (honest dev→test): **\`${winner.k}\`** at min(in-map, heldout) = **${f(winner.honestMin)}** on the frozen test half. ` +
502
567
  (clears90
503
568
  ? `**Clears 90/90 post-hoc** — wire it into CoarsePlacer as the open-set reject rule; no retrain needed (Phase 2 reject-head unnecessary).`
504
569
  : `Below the 90/90 bar — the best post-hoc score reaches ${f(winner.honestMin)}. Escalate to Phase 2 (explicit binary reject head).`)
505
570
  )
571
+
506
572
  lines.push("")
507
573
  lines.push(`Ranking (honest dev→test min): ${ranked.map((r) => `\`${r.k}\` ${f(r.honestMin)}`).join(" · ")}`)
508
574
  lines.push("")
509
575
 
510
576
  const md = lines.join("\n")
577
+
511
578
  console.log(md)
512
579
 
513
580
  if (options.outMd) {
@@ -23,30 +23,50 @@ interface TestRow {
23
23
  country: string
24
24
  }
25
25
 
26
- /** Options for {@linkcode evalQuantCompare}. */
26
+ /**
27
+ * Options for {@linkcode evalQuantCompare}.
28
+ */
27
29
  export interface EvalQuantCompareOptions {
28
- /** Fp32 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`. */
30
+ /**
31
+ * Fp32 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
32
+ */
29
33
  fp32?: string
30
- /** Int8 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model-int8`. */
34
+ /**
35
+ * Int8 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model-int8`.
36
+ */
31
37
  int8?: string
32
- /** Abstention threshold. Default 0.5. */
38
+ /**
39
+ * Abstention threshold. Default 0.5.
40
+ */
33
41
  abstain?: number
34
- /** Dataset dir (`test.jsonl`). Default `<repo>/data/coarse-placer`. */
42
+ /**
43
+ * Dataset dir (`test.jsonl`). Default `<repo>/data/coarse-placer`.
44
+ */
35
45
  data?: string
36
46
  }
37
47
 
38
- /** Result of {@linkcode evalQuantCompare}. */
48
+ /**
49
+ * Result of {@linkcode evalQuantCompare}.
50
+ */
39
51
  export interface EvalQuantCompareResult {
40
52
  n: number
41
- /** Fp32 overall accuracy in percent. */
53
+ /**
54
+ * Fp32 overall accuracy in percent.
55
+ */
42
56
  accFp32: number
43
- /** Int8 overall accuracy in percent. */
57
+ /**
58
+ * Int8 overall accuracy in percent.
59
+ */
44
60
  accInt8: number
45
- /** Whether int8 is within 1pp of fp32 (the gate). */
61
+ /**
62
+ * Whether int8 is within 1pp of fp32 (the gate).
63
+ */
46
64
  pass: boolean
47
65
  }
48
66
 
49
- /** Coarse-placer int8-vs-fp32 comparison — see the module doc. Emits the report to stdout. */
67
+ /**
68
+ * Coarse-placer int8-vs-fp32 comparison — see the module doc. Emits the report to stdout.
69
+ */
50
70
  export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): Promise<EvalQuantCompareResult> {
51
71
  const fp32Dir = options.fp32 || dataRootPath("coarse-placer", "model")
52
72
  const int8Dir = options.int8 || dataRootPath("coarse-placer", "model-int8")
@@ -61,6 +81,7 @@ export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): P
61
81
 
62
82
  return new CoarsePlacer({ ...meta, weights }, { abstainBelow })
63
83
  }
84
+
64
85
  function loadInt8(dir: string): CoarsePlacer {
65
86
  const meta = JSON.parse(readFileSync(path.join(dir, "meta.json"), "utf8")) as CoarsePlacerMeta
66
87
  const buf = readFileSync(path.join(dir, "weights.bin"))
@@ -103,28 +124,34 @@ export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): P
103
124
  const pf = fp32.predict(r.raw)
104
125
  const pi = int8.predict(r.raw)
105
126
  const cf = pf.country ?? "(abstain)"
127
+
106
128
  const ci = pi.country ?? "(abstain)"
107
129
  ;(perF[r.country] ??= { n: 0, ok: 0 }).n++
108
130
  ;(perI[r.country] ??= { n: 0, ok: 0 }).n++
109
131
 
110
132
  if (cf === r.country) {
111
133
  okF++
134
+
112
135
  perF[r.country]!.ok++
113
136
  }
114
137
 
115
138
  if (ci === r.country) {
116
139
  okI++
140
+
117
141
  perI[r.country]!.ok++
118
142
  }
119
143
 
120
144
  if (cf === ci) {
121
145
  agree++
122
146
  }
147
+
123
148
  confMae += Math.abs(pf.confidence - pi.confidence)
124
149
  }
150
+
125
151
  const N = test.length
126
152
  const accF = (100 * okF) / N
127
153
  const accI = (100 * okI) / N
154
+
128
155
  console.log(`coarse-placer int8 vs fp32 — test n=${N} (abstain ${abstainBelow})`)
129
156
  console.log(
130
157
  ` overall accuracy: fp32 ${accF.toFixed(2)}% int8 ${accI.toFixed(2)}% Δ ${(accI - accF >= 0 ? "+" : "") + (accI - accF).toFixed(2)}pp`
@@ -140,11 +167,14 @@ export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): P
140
167
  if (!f) continue
141
168
  const rf = (100 * f.ok) / f.n
142
169
  const ri = (100 * i.ok) / i.n
170
+
143
171
  console.log(
144
172
  ` ${c.padEnd(6)} ${rf.toFixed(1)}% → ${ri.toFixed(1)}% (Δ ${(ri - rf >= 0 ? "+" : "") + (ri - rf).toFixed(1)}pp, n=${f.n})`
145
173
  )
146
174
  }
147
- const pass = Math.abs(accI - accF) <= 1.0
175
+
176
+ const pass = Math.abs(accI - accF) <= 1
177
+
148
178
  console.log(` gate: ${pass ? "PASS (within 1pp)" : "FAIL (>1pp drop)"}`)
149
179
 
150
180
  return { n: N, accFp32: accF, accInt8: accI, pass }