fix(spatial): 近贴合家族不该声明那条接触边,假边才第一次真能骗到结论

This commit is contained in:
liuhuajie committed 2026-12-03 22:37:45 +08:00
1 parent 2ddba5843c
commit 9d449f2108
6 files changed
+191 -68

No files matched your search

+1
View File
@@ -31,6 +31,7 @@
python3 -m spatial.cli smoke # 契约测试,必须先过 python3 -m spatial.cli smoke # 契约测试,必须先过
python3 -m spatial.baselines 128 # 平凡规则基线 python3 -m spatial.baselines 128 # 平凡规则基线
python3 -m spatial.extract 24 # 几何→关系图的保真度 python3 -m spatial.extract 24 # 几何→关系图的保真度
python3 -m spatial.extract tol 8 # 接触判定对余隙的敏感度
python3 -m spatial.cli train --config spatial/configs/dangling.json --seed 0 python3 -m spatial.cli train --config spatial/configs/dangling.json --seed 0
python3 -m spatial.cli report --config spatial/configs/dangling.json --seed 0 --n 128 python3 -m spatial.cli report --config spatial/configs/dangling.json --seed 0 --n 128
python3 -m spatial.cli report --config spatial/configs/dangling.json --n 128 --ablate dangling,scene python3 -m spatial.cli report --config spatial/configs/dangling.json --n 128 --ablate dangling,scene
+54 -21
View File
@@ -3,16 +3,16 @@
M1 的全部结果都建立在一个从未验证的假设上:`Observation` 里的实体和关系是**给定** M1 的全部结果都建立在一个从未验证的假设上:`Observation` 里的实体和关系是**给定**
的。真实场景里没有这个"给定",所以这是 M2 的第一个问题,比任何模型改动都靠前。 的。真实场景里没有这个"给定",所以这是 M2 的第一个问题,比任何模型改动都靠前。
结论先说:**三类关系来自三种不同的地方,几何只能给出其中一类;而几何这一类的 结论先说:**三类关系来自三种不同的地方,几何只能给出其中一类。** 几何这一类
可靠性全押在一个距离容差上,容差错了会伪造出能通过校验的支撑。** 原先把可靠性全押在一个距离容差上,容差跨过余隙就会伪造出能通过校验的支撑;现已
改成共面精确匹配,那个参数退回数值噪声量级。剩下两类必须来自元数据。
## 一、实测:几何能给出多少 ## 一、实测:几何能给出多少
`python3 -m spatial.extract 24` `python3 -m spatial.extract 24`
做法不接 CAD、不引第三方库:把零件表面变成三角形,只从**三角形之间的距离**推接触 做法不接 CAD、不引第三方库:把盒子表面写成六张面,只按**两张面是不是同一张面**
关系(容差 0.5,即 0.125mm),完全不读 schema 里的答案,然后拿几何图去重算检查器 推接触关系,完全不读 schema 里的答案,然后拿几何图去重算检查器的结论。
的结论。
| family | 真边 | 提取 | 真阳率 | 真阴率 | 凭证有效 | 余隙 | | family | 真边 | 提取 | 真阳率 | 真阴率 | 凭证有效 | 余隙 |
|---|---|---|---|---|---|---| |---|---|---|---|---|---|---|
@@ -20,12 +20,15 @@ M1 的全部结果都建立在一个从未验证的假设上:`Observation` 里
| area.sup3 | 4 | 4 | 1.00 | 1.00 | 1.00 | 16 | | area.sup3 | 4 | 4 | 1.00 | 1.00 | 1.00 | 16 |
| area.sup2d | 3 | 3 | 1.00 | 1.00 | 1.00 | 10 | | area.sup2d | 3 | 3 | 1.00 | 1.00 | 1.00 | 10 |
| area.free | 2 | 2 | — | 1.00 | — | 22 | | area.free | 2 | 2 | — | 1.00 | — | 22 |
| area.gap1/2/4 | 2 | 2 | — | 1.00 | — | 1–4 |
| cond.p1 / p3 / p1h / p3h | 3–7 | **0** | **0.00** | — | 0.00 | — | | cond.p1 / p3 / p1h / p3h | 3–7 | **0** | **0.00** | — | 0.00 | — |
| dof.c6 / c6d / set | 6 | **0** | **0.00** | 1.00 | 0.00 | — | | dof.c6 / c6d / set | 6 | **0** | **0.00** | 1.00 | 0.00 | — |
两件事: 两件事:
* **接触关系可以 100% 从几何恢复**,连凭证都对得上(`area.*` 全列 1.00)。 * **接触关系可以 100% 从几何恢复**,连凭证都对得上(`area.*` 全列 1.00)。
`area.gap*` 这一行也一致:1–4 格的余隙下,几何说没有接触,schema 也真的没有
这条边,两边对得上——这是第三节那次夹具修复之后才成立的。
* **连通和自由度一条都提不出来**(提取 0 条,真阳率 0.00)。不是"差一点"。 * **连通和自由度一条都提不出来**(提取 0 条,真阳率 0.00)。不是"差一点"。
注意"真阴率 1.00"不是成绩:零关系的图对每一条都答 false,负类全是白送的。真阳率 注意"真阴率 1.00"不是成绩:零关系的图对每一条都答 false,负类全是白送的。真阳率
@@ -35,7 +38,7 @@ M1 的全部结果都建立在一个从未验证的假设上:`Observation` 里
| 关系 | 几何能不能给 | 真实来源 | 状态 | | 关系 | 几何能不能给 | 真实来源 | 状态 |
|---|---|---|---| |---|---|---|---|
| `contact` | **能**,100% | 表面距离 + 投影 footprint(`spatial/extract.py`) | 已实现并验证 | | `contact` | **能**,100% | 共面精确匹配(`spatial/extract.py`) | 已实现并验证 |
| `conduct` | 不能,0% | 材料、层定义、网表(PCB 的 netlist / 原理图) | 待接 | | `conduct` | 不能,0% | 材料、层定义、网表(PCB 的 netlist / 原理图) | 待接 |
| `constraint` | 不能,0% | 装配配合、要素树(CAD 的 mates / 约束定义) | 待接 | | `constraint` | 不能,0% | 装配配合、要素树(CAD 的 mates / 约束定义) | 待接 |
@@ -43,24 +46,55 @@ M1 的全部结果都建立在一个从未验证的假设上:`Observation` 里
理解结构"的路线,在这三类里只覆盖一类——而且覆盖的那一类还会对连通问题永远答 理解结构"的路线,在这三类里只覆盖一类——而且覆盖的那一类还会对连通问题永远答
false,看起来准确率还不错。 false,看起来准确率还不错。
## 三、容差:几何这一类的全部可靠性都押在它上面 ## 三、容差曾经是决定答案的参数(已改成共面精确匹配)
`python3 -m spatial.extract tol 8` `python3 -m spatial.extract tol 8`
`area.gap1/2/4` 把上块抬离底座 0/1/2/4 格(1 格 = 0.25mm),然后扫容差: `area.gap1/2/4` 把上块抬离底座 1/2/4 格,然后扫参数。两版判定并排跑,旧版留作
控制组:
| family | 间隙 | tol 0 | 0.5 | 1.0 | 2.0 | 4.0 | ```
|---|---|---|---|---|---|---| 距离阈值(第一版,tol 以格为单位扫)
| area.sup2 | 0 | ok | ok | ok | ok | ok | family 间隙 0.0 0.5 1.0 2.0 4.0
| area.gap1 | 1 | — | — | 8/8 x | 8/8 x | 8/8 x | area.sup2 0 8/8 ok 8/8 ok 8/8 ok 8/8 ok 8/8 ok
| area.gap2 | 2 | — | — | — | 8/8 x | 8/8 x | area.gap1 1 0/8 - 0/8 - 8/8 x 8/8 x 8/8 x
| area.gap4 | 4 | — | — | — | — | 8/8 x | area.gap2 2 0/8 - 0/8 - 0/8 - 8/8 x 8/8 x
area.gap4 4 0/8 - 0/8 - 0/8 - 0/8 - 8/8 x
`x` = 提取出了一条不存在的接触,但凭证校验按几何拒绝了它。 共面精确匹配(第二版,eps 以坐标单位扫)
family 间隙 0 1e-12 1e-9 1e-6 1e-3 1.0
area.sup2 0 8/8 ok 8/8 ok 8/8 ok 8/8 ok 8/8 ok 8/8 ok
area.gap1 1 0/8 - 0/8 - 0/8 - 0/8 - 0/8 - 8/8 x
area.gap2 2 0/8 - 0/8 - 0/8 - 0/8 - 0/8 - 0/8 -
area.gap4 4 0/8 - 0/8 - 0/8 - 0/8 - 0/8 - 0/8 -
```
**假边出现的条件恰好是 `容差 ≥ 间隙`。** 这条线很窄:真实装配的余隙是 0.2mm 级 `x` = 提取出了一条不存在的接触(这一步已经把答案 false 翻成 true),但凭证校验
(≈1 格),所以安全容差必须 **< 0.5 格 = 0.125mm**。用距离阈值做接触判定,在真实 自己复核几何后拒了它。`!` = 假边连校验都过了,现在不该出现。
数据上是站在刀刃上。
三件事:
* **距离法的假边条件恰好是 `容差 ≥ 间隙`。** 容差因此不是"精度参数",而是"决定
答案的参数":真实装配的余隙是 0.2mm 级,跨过去就凭空焊出一个支撑。
* **共面法里 eps 扫四个数量级(1e-12 → 1e-3)一格不动。** 因为贴合的两张面本来
就是同一张面,判定不涉及"多近算近"。eps 只盖浮点噪声。
* **滥用那一列说明了它为什么只能是数值兜底。** 把 eps 给到 1.0(设计容差量级),
`area.gap1` 立刻回到 `8/8`——旧坑一模一样。参数换了类别,坑还在原地,所以这条
不能被当成"可调"。
### 顺带修掉的夹具矛盾
近贴合家族原先一边把上块抬高 1/2/4 格,一边在 schema 里声明 T 和 P **接触**。这是
夹具自己和自己矛盾:几何上没碰上,就不存在这条边。现在 `clearance > 0` 不再生成
`kPT`,真边从 3 条降到 2 条,答案变成 false。
这一改动让这三个家族第一次变锋利:假接触不再只是"多画一条冗余边",而是**把结论
从 false 翻成 true**。
代价也要记清楚:它们现在是**单答案家族**(恒 false),常量规则就能拿 1.000
(`python3 -m spatial.baselines` 实测 majority share 1.00)。所以 `area.gap*`
**只做提取器的回归测试,不进任何 split**。`smoke` 每次都会打印"哪些家族没被任何
split 使用",这一条就是靠它守住的。
### 顺带发现的校验器漏洞(已修) ### 顺带发现的校验器漏洞(已修)
@@ -90,9 +124,8 @@ false,看起来准确率还不错。
## 五、下一步(按顺序) ## 五、下一步(按顺序)
1. **把接触判定从"距离阈值"换成"共面精确匹配"**:相邻零件的贴合面在 B-rep 里是 1. ~~把接触判定从"距离阈值"换成"共面精确匹配"~~ **已完成**(第三节)。顺带修掉
同一张面,可以精确判定,不需要容差。这样容差从"决定答案的参数"降级成"处理 近贴合家族的夹具矛盾,并把它们标成不进 split 的诊断家族。
数值噪声的兜底"。近贴合家族已就位,可以直接当回归测试。
2. **接一个真元数据 provider**:先做 PCB(KiCad 网表 → `conduct`),再做装配 2. **接一个真元数据 provider**:先做 PCB(KiCad 网表 → `conduct`),再做装配
(FreeCAD 配合 → `constraint`)。验收标准不是"能跑",而是端到端一致:同一批 (FreeCAD 配合 → `constraint`)。验收标准不是"能跑",而是端到端一致:同一批
样板,提取器 + 检查器给出的答案与人工确认的答案一致。 样板,提取器 + 检查器给出的答案与人工确认的答案一致。
+30 -1
View File
@@ -166,11 +166,40 @@ def check_cross_family_digest() -> bool:
return True return True
def check_extract_contacts(n: int = 8) -> bool:
"""The geometry provider must not invent a contact across a clearance.
``area.gap1/2/4`` place the same block 1, 2 and 4 units above its pedestal.
Contact is decided by coincident faces, not by distance, so at a numerical
epsilon the extractor has to report no T-P edge there -- and still report
the two contacts that are real. This is the regression gate for the
parameter that used to decide the answer by itself.
"""
from . import extract
bad = set()
for fam in ("area.gap1", "area.gap2", "area.gap4"):
for i in range(n):
sc = generator.make(fam, seed=0, index=i)
if any({e.a, e.b} == {"T", "P"}
for e in extract.extract_edges(sc.obs.entities, eps=1e-9)):
bad.add(fam)
break
if bad:
return _fail(f"extractor welded T to P across a clearance: {sorted(bad)}")
got = len(extract.extract_edges(
generator.make("area.sup2", seed=0, index=0).obs.entities, eps=1e-9))
if got != 3:
return _fail(f"area.sup2: extractor found {got} contacts, expected 3")
print("ok extractor: nothing welded across a clearance, 3/3 real contacts kept")
return True
def cmd_smoke(args) -> int: def cmd_smoke(args) -> int:
cfg = _load_config(args.config) cfg = _load_config(args.config)
print(f"config {args.config} out {cfg['out_dir']}") print(f"config {args.config} out {cfg['out_dir']}")
results = [check_splits(cfg), check_determinism(), check_labels(), results = [check_splits(cfg), check_determinism(), check_labels(),
check_insufficient(), check_invariances(), check_cross_family_digest()] check_insufficient(), check_invariances(), check_cross_family_digest(),
check_extract_contacts()]
# one update, then interrupt and resume: the step counter must advance # one update, then interrupt and resume: the step counter must advance
from . import train as trainer from . import train as trainer
+7
View File
@@ -11,6 +11,13 @@
| `setonly.json` | 只训 `dof.set`,隔离"六个轴是否全覆盖"这个子技能 | 1.000(用于定位读出缺陷) | | `setonly.json` | 只训 `dof.set`,隔离"六个轴是否全覆盖"这个子技能 | 1.000(用于定位读出缺陷) |
| `cross_oneshot.json` | 对照:第一版混合集,被一位规则完全可分 | 6 族与平凡规则逐位相同 | | `cross_oneshot.json` | 对照:第一版混合集,被一位规则完全可分 | 6 族与平凡规则逐位相同 |
## 不进 split 的家族
`area.gap1/gap2/gap4` 是**单答案家族**(恒 false),常量规则就能拿 1.000,加进任何
split 都会造出一个假满分。它们只做 `spatial.extract` 的回归测试:把上块抬离底座
1/2/4 格,问提取器会不会焊出一条不存在的接触。同理 `smoke` 每次都会打印"哪些家族
没被任何 split 使用",加家族时先看那行。
## 归档(`archive/`) ## 归档(`archive/`)
| 文件 | 当时的用途 | 留下它的理由 | | 文件 | 当时的用途 | 留下它的理由 |
+91 -44
View File
@@ -23,52 +23,74 @@ from __future__ import annotations
import sys import sys
import numpy as np
from . import checker, generator from . import checker, generator
from .schema import Edge, FullState, Query from .schema import Edge, FullState, Query
CONTACT = "contact" CONTACT = "contact"
TOLERANCES = (0.0, 0.5, 1.0, 2.0, 4.0)
def box_triangles(box) -> np.ndarray: def _sub(u, v):
"""(12,3,3) triangles for an axis-aligned box. Surface only, no interior.""" return (u[0] - v[0], u[1] - v[1], u[2] - v[2])
def _add(u, v):
return (u[0] + v[0], u[1] + v[1], u[2] + v[2])
def _mul(u, s):
return (u[0] * s, u[1] * s, u[2] * s)
def _dot(u, v):
return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]
def _len(u):
return _dot(u, u) ** 0.5
def box_triangles(box) -> list:
"""12 triangles for an axis-aligned box. Surface only, no interior.
Plain tuples on purpose: this module has to run on a machine that has no
third-party packages at all, and the arithmetic here is a few dots and
norms on four boxes. numpy would be the only dependency in the file.
"""
x0, y0, z0, x1, y1, z1 = (float(v) for v in box) x0, y0, z0, x1, y1, z1 = (float(v) for v in box)
c = np.array([(x0, y0, z0), (x1, y0, z0), (x1, y1, z0), (x0, y1, z0), c = [(x0, y0, z0), (x1, y0, z0), (x1, y1, z0), (x0, y1, z0),
(x0, y0, z1), (x1, y0, z1), (x1, y1, z1), (x0, y1, z1)]) (x0, y0, z1), (x1, y0, z1), (x1, y1, z1), (x0, y1, z1)]
faces = [(0, 2, 1), (0, 3, 2), (4, 5, 6), (4, 6, 7), (0, 1, 5), (0, 5, 4), faces = [(0, 2, 1), (0, 3, 2), (4, 5, 6), (4, 6, 7), (0, 1, 5), (0, 5, 4),
(1, 2, 6), (1, 6, 5), (2, 3, 7), (2, 7, 6), (3, 0, 4), (3, 4, 7)] (1, 2, 6), (1, 6, 5), (2, 3, 7), (2, 7, 6), (3, 0, 4), (3, 4, 7)]
return np.array([[c[i] for i in f] for f in faces]) return [tuple(c[i] for i in f) for f in faces]
def _pt_tri(p, tri) -> float: def _pt_tri(p, tri) -> float:
"""Distance from a point to a triangle (Ericson, clamped barycentric).""" """Distance from a point to a triangle (Ericson, clamped barycentric)."""
a, b, c = tri a, b, c = tri
ab, ac, ap = b - a, c - a, p - a ab, ac, ap = _sub(b, a), _sub(c, a), _sub(p, a)
d1, d2 = ab @ ap, ac @ ap d1, d2 = _dot(ab, ap), _dot(ac, ap)
if d1 <= 0 and d2 <= 0: if d1 <= 0 and d2 <= 0:
return float(np.linalg.norm(ap)) return _len(ap)
bp = p - b bp = _sub(p, b)
d3, d4 = ab @ bp, ac @ bp d3, d4 = _dot(ab, bp), _dot(ac, bp)
if d3 >= 0 and d4 <= d3: if d3 >= 0 and d4 <= d3:
return float(np.linalg.norm(bp)) return _len(bp)
vc = d1 * d4 - d3 * d2 vc = d1 * d4 - d3 * d2
if vc <= 0 <= d1 and d3 <= 0: if vc <= 0 <= d1 and d3 <= 0:
return float(np.linalg.norm(p - (a + ab * (d1 / (d1 - d3))))) return _len(_sub(p, _add(a, _mul(ab, d1 / (d1 - d3)))))
cp = p - c cp = _sub(p, c)
d5, d6 = ab @ cp, ac @ cp d5, d6 = _dot(ab, cp), _dot(ac, cp)
if d6 >= 0 and d5 <= d6: if d6 >= 0 and d5 <= d6:
return float(np.linalg.norm(cp)) return _len(cp)
vb = d5 * d2 - d1 * d6 vb = d5 * d2 - d1 * d6
if vb <= 0 <= d2 and d6 <= 0: if vb <= 0 <= d2 and d6 <= 0:
return float(np.linalg.norm(p - (a + ac * (d2 / (d2 - d6))))) return _len(_sub(p, _add(a, _mul(ac, d2 / (d2 - d6)))))
va = d3 * d6 - d5 * d4 va = d3 * d6 - d5 * d4
if va <= 0 and (d4 - d3) >= 0 and (d5 - d6) >= 0: if va <= 0 and (d4 - d3) >= 0 and (d5 - d6) >= 0:
w = (d4 - d3) / ((d4 - d3) + (d5 - d6)) w = (d4 - d3) / ((d4 - d3) + (d5 - d6))
return float(np.linalg.norm(p - (b + (c - b) * w))) return _len(_sub(p, _add(b, _mul(_sub(c, b), w))))
denom = 1.0 / (va + vb + vc) denom = 1.0 / (va + vb + vc)
return float(np.linalg.norm(p - (a + ab * (vb * denom) + ac * (vc * denom)))) return _len(_sub(p, _add(a, _add(_mul(ab, vb * denom), _mul(ac, vc * denom)))))
def _aabb_gap(a, b) -> float: def _aabb_gap(a, b) -> float:
@@ -136,10 +158,13 @@ def surface_gap(box_a, box_b) -> float:
the gap when two edges cross without a vertex near the contact. For the the gap when two edges cross without a vertex near the contact. For the
separation this benchmark actually has (>=16 grid units) it never matters -- separation this benchmark actually has (>=16 grid units) it never matters --
and that "never matters" is itself one of the findings. and that "never matters" is itself one of the findings.
Kept for the clearance column only. Contact is decided by ``contact_area``,
which needs no distance at all.
""" """
ta, tb = box_triangles(box_a), box_triangles(box_b) ta, tb = box_triangles(box_a), box_triangles(box_b)
va, vb = np.unique(ta.reshape(-1, 3), axis=0), np.unique(tb.reshape(-1, 3), axis=0) va, vb = _vertices(ta), _vertices(tb)
best = np.inf best = float("inf")
for tri in ta: for tri in ta:
for p in vb: for p in vb:
best = min(best, _pt_tri(p, tri)) best = min(best, _pt_tri(p, tri))
@@ -149,6 +174,16 @@ def surface_gap(box_a, box_b) -> float:
return best return best
def _vertices(tris) -> list:
seen, out = set(), []
for tri in tris:
for p in tri:
if p not in seen:
seen.add(p)
out.append(p)
return out
def extract_edges(entities, eps: float = 0.0) -> list: def extract_edges(entities, eps: float = 0.0) -> list:
"""Contacts implied by geometry alone: coincident faces. """Contacts implied by geometry alone: coincident faces.
@@ -231,7 +266,7 @@ def report(n: int = 32) -> None:
for fam in generator.FAMILIES: for fam in generator.FAMILIES:
n_true = n_false = hit_true = hit_false = cert_ok = 0 n_true = n_false = hit_true = hit_false = cert_ok = 0
got = truth = total = 0 got = truth = total = 0
gap = np.inf gap = float("inf")
for i in range(n): for i in range(n):
sc = generator.make(fam, seed=3, index=i) sc = generator.make(fam, seed=3, index=i)
if sc.query.edit is not None: if sc.query.edit is not None:
@@ -258,7 +293,7 @@ def report(n: int = 32) -> None:
rec = f"{hit_true / n_true:6.2f}" if n_true else " —" rec = f"{hit_true / n_true:6.2f}" if n_true else " —"
neg = f"{hit_false / n_false:6.2f}" if n_false else " —" neg = f"{hit_false / n_false:6.2f}" if n_false else " —"
cert = f"{cert_ok / n_true:5.2f}" if n_true else " —" cert = f"{cert_ok / n_true:5.2f}" if n_true else " —"
g = "—" if not np.isfinite(gap) else f"{gap:.0f}" g = "—" if gap == float("inf") else f"{gap:.0f}"
print(f"{fam:11s} {truth / max(1, total):5.1f} {got / max(1, total):5.1f} " print(f"{fam:11s} {truth / max(1, total):5.1f} {got / max(1, total):5.1f} "
f"{rec} {neg} {cert} {g:>5s}") f"{rec} {neg} {cert} {g:>5s}")
print() print()
@@ -277,17 +312,21 @@ DIST_TOLS = (0.0, 0.5, 1.0, 2.0, 4.0)
NUM_EPS = (0.0, 1e-12, 1e-9, 1e-6, 1e-3, 0.25) NUM_EPS = (0.0, 1e-12, 1e-9, 1e-6, 1e-3, 0.25)
def _panel(title: str, families, cols, extract, marks: bool, n: int) -> None: def _panel(title: str, families, cols, extract, n: int) -> None:
"""One sweep of the same four clearances under one extraction rule.""" """One sweep of the same four clearances under one extraction rule.
``cols`` is a list of (label, value): the label is what the header shows, the
value is what the rule is actually called with.
"""
print(title) print(title)
print(f" {'family':10s} {'间隙':>4s} " + " ".join(f"{c:>9s}" for c in cols)) print(f" {'family':10s} {'间隙':>4s} " + " ".join(f"{c[0]:>9s}" for c in cols))
for fam, gap in families: for fam, gap in families:
cells = [] cells = []
for col in cols: for _, val in cols:
got = forged = total = 0 got = forged = total = 0
for i in range(n): for i in range(n):
sc = generator.make(fam, seed=7, index=i) sc = generator.make(fam, seed=7, index=i)
edges = extract(sc.obs.entities, col) edges = extract(sc.obs.entities, val)
world = FullState(entities=list(sc.obs.entities), edges=edges) world = FullState(entities=list(sc.obs.entities), edges=edges)
tp = [e for e in edges if {e.a, e.b} == {"T", "P"}] tp = [e for e in edges if {e.a, e.b} == {"T", "P"}]
total += 1 total += 1
@@ -295,14 +334,12 @@ def _panel(title: str, families, cols, extract, marks: bool, n: int) -> None:
got += 1 got += 1
forged += int(checker.validate_evidence( forged += int(checker.validate_evidence(
world, Query(kind="stability", a="T"), [tp[0].eid])) world, Query(kind="stability", a="T"), [tp[0].eid]))
if not marks: if gap == 0:
cells.append(f"{got:2d}/{total}")
elif gap == 0:
cells.append(f"{got:2d}/{total} {'ok' if got else 'miss'}") cells.append(f"{got:2d}/{total} {'ok' if got else 'miss'}")
elif not got: elif not got:
cells.append(f"{got:2d}/{total} -") cells.append(f"{got:2d}/{total} -")
else: else:
cells.append(f"{got:2d}/{total} {'?' if not forged else '!'}") cells.append(f"{got:2d}/{total} {'x' if not forged else '!'}")
print(f" {fam:10s} {gap:4d} " + " ".join(f"{c:>9s}" for c in cells)) print(f" {fam:10s} {gap:4d} " + " ".join(f"{c:>9s}" for c in cells))
print() print()
@@ -317,20 +354,30 @@ def report_tolerance(n: int = 8) -> None:
turns a wrong graph into a wrong *proof*. turns a wrong graph into a wrong *proof*.
""" """
_panel("距离阈值(第一版,tol 以格为单位扫)", GAP_FAMILIES, _panel("距离阈值(第一版,tol 以格为单位扫)", GAP_FAMILIES,
[f"{t:.1f}" for t in DIST_TOLS], [(f"{t:.1f}", t) for t in DIST_TOLS],
lambda ents, t: extract_edges_by_distance(ents, tol=t), True, n) lambda ents, t: extract_edges_by_distance(ents, tol=t), n)
_panel("共面精确匹配(第二版,eps 以 mm 为单位扫)", GAP_FAMILIES, _panel("共面精确匹配(第二版,eps 以坐标单位扫)", GAP_FAMILIES,
["0", "1e-12", "1e-9", "1e-6", "1e-3", "0.25"], [("0", 0.0), ("1e-12", 1e-12), ("1e-9", 1e-9), ("1e-6", 1e-6),
lambda ents, e: extract_edges(ents, eps=e), True, n) ("1e-3", 1e-3), ("1.0", 1.0)],
lambda ents, e: extract_edges(ents, eps=e), n)
print("单元格 = 提取到 T-P 边的样本数 / 总数") print("单元格 = 提取到 T-P 边的样本数 / 总数")
print("ok = 间隙为 0,零件本来就贴着,提取到了") print("ok = 间隙为 0,零件本来就贴着,提取到了")
print("miss = 间隙为 0 却没提取到(该报的没报)") print("miss = 间隙为 0 却没提取到(该报的没报)")
print("- = 间隙 > 0,没有提取到边(正确)") print("- = 间隙 > 0,没有提取到边(正确)")
print("? = 间隙 > 0 却提取到边,但凭证校验按几何拒了它(图错了,校验器救了)") print("x = 间隙 > 0 却焊出一条接触(这一步就把答案 false 翻成了 true),但凭证")
print("! = 假边通过了凭证校验 —— 图错,而且这个错还能当证明用") print(" 校验自己复核几何后拒了它 —— 校验器只挡住了「错还能当证明用」")
print("间隙单位 0.25mm;真实装配的余隙是 0.2mm 级,即约 1 格") print("! = 假边连凭证校验都过了。现在不该出现,出现就是校验器回退了")
print("距离法在这一格上分辨不了;共面法只需要 eps 盖住浮点噪声,0.25 那列是把") print("间隙 = 上面那块被抬高的坐标单位数(夹具 per_unit=1,1 格即 1 单位)")
print("eps 当容差用的滥用,旧坑原样回来 —— 这也是为什么它只是数值兜底。") print()
print("两版差别就一条:距离法在 tol >= 间隙时必然焊出一个接触,容差因此是决定")
print("答案的参数;共面法只看两张面是不是同一张面,eps 只盖浮点噪声,扫描从 1e-12")
print("到 1e-3 一格都不动。最后一列 1.0 是把 eps 当容差用的滥用——旧坑原样回来,")
print("这正说明它只能是数值兜底,不能是设计容差。")
print()
print("顺带修掉夹具自己的矛盾:近贴合家族原先一边把上面那块抬高 1/2/4 格,一边")
print("还在 schema 里声明 T 和 P 接触。几何上没碰上就不存在这条边,所以现在只剩")
print("真边 2 条、答案 false。也正因为少了那条边,任何跨越间隙的假接触都会让答案")
print("从 false 变成 true —— 假边才第一次真的骗到了结论,而不只是画错了一条线。")
def main(argv=None) -> int: def main(argv=None) -> int:
+8 -2
View File
@@ -170,8 +170,14 @@ def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int
Entity("T", "block", attrs={"box": [42 + dx, 42 + dy, 20 + cl, Entity("T", "block", attrs={"box": [42 + dx, 42 + dy, 20 + cl,
58 + dx, 58 + dy, 36 + cl]}), 58 + dx, 58 + dy, 36 + cl]}),
Entity("D", "block", attrs={"box": [80, 40, 0, 100, 60, 16]})] Entity("D", "block", attrs={"box": [80, 40, 0, 100, 60, 16]})]
edges = [Edge("kPG", "contact", "P", "G"), Edge("kPT", "contact", "T", "P"), edges = [Edge("kPG", "contact", "P", "G"), Edge("kDG", "contact", "D", "G")]
Edge("kDG", "contact", "D", "G")] if cl == 0:
edges.append(Edge("kPT", "contact", "T", "P"))
# With a clearance there is no contact, so the fixture must not declare one:
# a kPT edge over a 1-unit gap would be the schema contradicting its own
# geometry. Dropping it is what makes the near-fit families sharp -- any
# spurious T-P edge now flips the answer false -> true instead of merely
# adding a redundant edge.
top = None top = None
if n_blocks >= 3: if n_blocks >= 3:
ents.append(Entity("U", "block", ents.append(Entity("U", "block",