From 515bee2f013ed744d7138346dffa1108eab55996 Mon Sep 17 00:00:00 2001 From: lhj <403133128@qq.com> Date: Thu, 3 Dec 2026 18:33:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(spatial):=20=E8=A7=82=E6=B5=8B=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E8=87=AA=E5=B7=B1=E7=9A=84=E7=9B=B2=E5=8C=BA=EF=BC=88?= =?UTF-8?q?=E6=8C=89=E7=B1=BB=E5=88=AB=E8=AE=A1=E6=95=B0=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E5=90=AB=E8=BA=AB=E4=BB=BD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cond.p1 从 0.602 到 1.000 证实了这一点:缺的不是容量,是"我看不到什么"这个输入。 剩下 area.sup2h / dof.c6h 弃权率仍为 0,是同一个病在另两个域——生成器把底座/配合 藏起来了,却不让观测声明。 schema 增加 Observation.hidden:{entity: {kind: 数量}, edge: {kind: 数量}}, 由 _observe 从"全状态减可见"自动导出,所以新增遮挡物不可能忘记声明。 只记数量不记身份:"少了一条接触"是能据以行动的事实,"少的是 kPT"是泄题。 scene 特征扩到 17 维:隐藏层指示、未见面的数量、各实体类别缺失数、各边类别缺失数、 是否有任何缺失、场景规模。 --- spatial/data.py | 14 ++++++++++++-- spatial/generator.py | 9 +++++++++ spatial/model.py | 9 +++++---- spatial/schema.py | 12 +++++++++++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/spatial/data.py b/spatial/data.py index 2958353..58ae0bb 100644 --- a/spatial/data.py +++ b/spatial/data.py @@ -115,14 +115,24 @@ def scene_features(sc: Scenario) -> list: the model as the same input with opposite labels. That is not an under-fitting problem; it is information the contract promised and the tensorisation dropped. + + Counts by kind, not identities: "one contact is missing" is a fact the + agent can act on, "kPT is missing" would be a leak of the answer. """ f = [0.0] * SCENE_DIM for layer in sc.obs.hidden_layers: if 1 <= layer <= 3: f[layer - 1] = 1.0 f[3] = min(1.0, len(sc.obs.hidden_faces) / 6.0) - f[4] = 1.0 if (sc.obs.hidden_layers or sc.obs.hidden_faces) else 0.0 - f[5] = len(sc.obs.entities) / 32.0 + hidden = sc.obs.hidden or {} + for kind, cnt in (hidden.get("entity") or {}).items(): + if kind in ENTITY_KINDS: + f[4 + ENTITY_KINDS.index(kind)] = min(1.0, cnt / 2.0) + for kind, cnt in (hidden.get("edge") or {}).items(): + if kind in EDGE_KINDS: + f[4 + len(ENTITY_KINDS) + EDGE_KINDS.index(kind)] = min(1.0, cnt / 3.0) + f[-2] = 1.0 if (hidden.get("entity") or hidden.get("edge")) else 0.0 + f[-1] = len(sc.obs.entities) / 32.0 return f diff --git a/spatial/generator.py b/spatial/generator.py index 1ca6077..abaf54f 100644 --- a/spatial/generator.py +++ b/spatial/generator.py @@ -12,6 +12,7 @@ restricting the full state to what the observation shows. from __future__ import annotations import random +from collections import Counter from dataclasses import replace from . import checker @@ -39,12 +40,20 @@ DOMAIN_OF = {f: spec["domain"] for f, spec in FAMILIES.items()} def _observe(entities, edges, visible_edges, visible_ents, hidden_layers, cameras, units): vis_e = [e for e in edges if e.eid in visible_edges] keep = set(visible_ents) | {e.a for e in vis_e} | {e.b for e in vis_e} + # derived, not hand-written: the gap between the full state and this view is + # exactly what an agent has to know in order to decide it cannot decide. + # Computing it here means a new occluder cannot silently go undeclared. + hidden = { + "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)), + } return Observation( entities=[e for e in entities if e.eid in keep], edges=vis_e, cameras=list(cameras), units=dict(units), hidden_layers=sorted(hidden_layers), + hidden=hidden, ) diff --git a/spatial/model.py b/spatial/model.py index b54428d..8f7f7c4 100644 --- a/spatial/model.py +++ b/spatial/model.py @@ -46,10 +46,11 @@ QUERY_KINDS = ("connection", "stability", "freedom") HOP_MAX = 4 # longer paths collapse into one bucket FAR = HOP_MAX + 1 # unreachable, or "involves the query token" # what the observation admits it is missing: hidden layer markers, unseen faces, -# and one bit for "something was withheld at all". Without this the two worlds -# "no hidden branch exists" and "a hidden branch exists off-view" are literally -# the same tensor, and no amount of reasoning can separate them. -SCENE_DIM = 6 +# one count per entity kind and per edge kind, an "anything withheld" bit, and +# the scene size. Without this the two worlds "no hidden branch exists" and "a +# hidden branch exists off-view" are literally the same tensor, and no amount of +# reasoning can separate them. +SCENE_DIM = 4 + N_KIND + N_EDGE + 2 def hop_distance(edge_index, edge_mask, edge_removed, n_ent: int) -> torch.Tensor: diff --git a/spatial/schema.py b/spatial/schema.py index 027a8be..989bd0d 100644 --- a/spatial/schema.py +++ b/spatial/schema.py @@ -84,7 +84,15 @@ class Edge: @dataclass class Observation: - """What the model sees. Only visible items are stored here.""" + """What the model sees. Only visible items are stored here. + + ``hidden`` is the one thing here that is not visible, and it is deliberate: + it counts what the full state contains that this view does not. Without it + "nothing is there" and "it is behind the part" are the same input, and the + two have different answers -- no reasoning can recover a distinction that + the input never carried. It records counts by kind, never identities, so it + says *that* a support is missing, not *which* one. + """ entities: list = field(default_factory=list) edges: list = field(default_factory=list) @@ -92,6 +100,7 @@ class Observation: units: dict = field(default_factory=lambda: {"length": "mm", "per_unit": 1}) hidden_layers: list = field(default_factory=list) hidden_faces: list = field(default_factory=list) + hidden: dict = field(default_factory=lambda: {"entity": {}, "edge": {}}) def entity_ids(self) -> set: return {e.eid for e in self.entities} @@ -104,6 +113,7 @@ class Observation: "units": dict(self.units), "hidden_layers": sorted(self.hidden_layers), "hidden_faces": sorted(self.hidden_faces), + "hidden": {k: dict(sorted(v.items())) for k, v in sorted(self.hidden.items())}, }