feat(spatial): 悬空关系与未知槽位,让"缺哪一段"落到位置而不是计数

此前"少了一条接触"只是全局计数,模型只能说"我在猜";它无法区分"目标根本没支撑"
和"目标的那条支撑被挡住了"。现在:
- Observation.dangling:一端可见、另一端不可见的关系,锚在可见那一端,不带身份。
  它说的是无知挂在哪儿,不是答案是什么。
- 模型多一个未知槽位(位置 1),悬空边的远端指向它;有悬空关系的锚定实体与它
  相距一跳。一条链走到它上面,就是一条链走进了问题。
- 悬空边不参与连通计算、不进入实体的入射边求和、边特征里带 dangling 标志。
- 新增 area.free 家族:T 的唯一接触连到一个自身悬空的块,什么也没藏、什么也不悬空,
  所以"没有支撑"是事实而非缺口,正确答案是 false,弃权才是错的。
  它与 area.sup2h 构成最小对:同样是一条接触,一个通到未知、一个通到死路。
This commit is contained in:
liuhuajie committed 2026-12-03 18:49:45 +08:00
1 parent 68380900ce
commit 40f6bb52fa
8 files changed
+251 -141

No files matched your search

+34 -2
View File
@@ -29,6 +29,7 @@ FAMILIES = {
"area.sup2": {"domain": "stability", "n_blocks": 2, "hidden": 0},
"area.sup3": {"domain": "stability", "n_blocks": 3, "hidden": 0},
"area.sup2h": {"domain": "stability", "n_blocks": 2, "hidden": 1},
"area.free": {"domain": "stability", "n_blocks": 2, "hidden": 0, "free": 1},
"dof.c6": {"domain": "freedom", "n_cons": 6, "hidden": 0},
"dof.c6r": {"domain": "freedom", "n_cons": 7, "hidden": 0},
"dof.c6h": {"domain": "freedom", "n_cons": 6, "hidden": 1},
@@ -47,6 +48,19 @@ def _observe(entities, edges, visible_edges, visible_ents, hidden_layers, camera
"entity": dict(Counter(e.kind for e in entities if e.eid not in keep)),
"edge": dict(Counter(e.kind for e in edges if e.eid not in visible_edges)),
}
# a hidden relation with one visible end becomes a dangling edge anchored on
# that visible end. Both ends hidden leaves no mouth to report, so it stays
# a bare count. The anchor is always something already in view: this says
# where the ignorance attaches, never where it leads.
dangling = []
for e in edges:
if e.eid in visible_edges:
continue
anchor = e.a if e.a in keep else (e.b if e.b in keep else None)
if anchor is None:
continue
dangling.append(Edge(f"d{len(dangling)}", e.kind, anchor, "",
layer=e.layer, source="inferred"))
return Observation(
entities=[e for e in entities if e.eid in keep],
edges=vis_e,
@@ -54,6 +68,7 @@ def _observe(entities, edges, visible_edges, visible_ents, hidden_layers, camera
units=dict(units),
hidden_layers=sorted(hidden_layers),
hidden=hidden,
dangling=dangling,
)
@@ -107,7 +122,23 @@ def _build_connection(rng, n_paths: int, hidden: int):
# stability: stacked blocks, optional hidden pedestal
def _build_stability(rng, n_blocks: int, hidden: int):
def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0):
if free:
# the minimal pair against area.sup2h: here T has exactly one contact and
# that contact leads to a block which itself hangs in the air. Nothing
# dangles and nothing is hidden, so "no support" is a fact rather than a
# gap -- the answer is legitimately false and abstaining would be wrong.
ents = [Entity("G", "ground", attrs={"plane": 0}),
Entity("T", "block", attrs={"box": [42, 42, 20, 58, 58, 36]}),
Entity("Q", "block", attrs={"box": [44, 44, 8, 56, 56, 20]}),
Entity("D", "block", attrs={"box": [80, 40, 0, 100, 60, 16]})]
edges = [Edge("kTQ", "contact", "Q", "T"), Edge("kDG", "contact", "D", "G")]
query = Query(kind="stability", a="T")
if rng.random() < 0.6:
query.edit = {"op": "remove_entity", "entity": "Q"}
return (ents, edges, query, {e.eid for e in edges}, {e.eid for e in ents},
set(), ["front", "iso"], {"length": "mm", "per_unit": 1})
# D is a decoy: it rests on the ground next to the stack and carries
# nothing. Without it "something was removed" and "the target lost support"
# are the same event on every sample, and a one-bit rule fits the whole
@@ -180,7 +211,8 @@ def _build_freedom(rng, n_cons: int, hidden: int):
_BUILDERS = {
"connection": lambda rng, spec: _build_connection(rng, spec["n_paths"], spec["hidden"]),
"stability": lambda rng, spec: _build_stability(rng, spec["n_blocks"], spec["hidden"]),
"stability": lambda rng, spec: _build_stability(rng, spec["n_blocks"], spec["hidden"],
spec.get("free", 0)),
"freedom": lambda rng, spec: _build_freedom(rng, spec["n_cons"], spec["hidden"]),
}