exp: chess attack adjacency is a measured null, and the oracle still does not pay

Mean degree falls 30 -> 3.3. Accuracy falls with it (0.414 -> 0.381): the mask removes
board information the model was using. The dilution hypothesis is not supported -- the
history oracle reads -0.0003 +/- 0.0019 on 4/8 seeds, ambiguous, same as under all-ones.
grp - rp_wide is +0.0023 +/- 0.0026 on 4/8, so the earlier -0.0057 dissolves too.

Twice-controlled: per-entity history does not pay under contract A with an MSE readout,
in either adjacency.
This commit is contained in:
chrnx committed 2026-09-02 17:54:10 -05:00
1 parent 8ea61f9617
commit 1c28987649
1 file changed
+26 -10
+26 -10
View File
@@ -57,6 +57,7 @@ class Ply:
dests: np.ndarray # (L, 2) displacement of every legal move from its square
true_dest: int # index into dests
past: np.ndarray # (N, 2*hist) each entity's previous squares, as displacements
mask: np.ndarray # (N, N) the attack/defend graph, symmetric, self-loops on
def advance_ids(board: chess.Board, move: chess.Move, piece: chess.Piece,
@@ -105,6 +106,15 @@ def plies(game: chess.pgn.Game, hist: int = 3) -> list[Ply]:
mover = squares.index(move.from_square)
attrs[mover, 7] = 1.0
# the spec's optional adjacency input (§2), which chess actually has: i sees j when
# either attacks the other's square. With the all-ones default an entity's own
# attributes reach it only through the diagonal term and are divided by deg ~= 30.
sq = np.array(squares, dtype=np.uint64)
bb = np.array([int(board.attacks(int(t))) for t in squares], dtype=np.uint64)
att = ((bb[:, None] >> sq[None, :]) & np.uint64(1)).astype(np.float32)
mask = np.maximum(att, att.T)
np.fill_diagonal(mask, 1.0)
# each entity's own past, relative to where it stands now. Absent history is zero,
# which is also "I am where I was" -- the ambiguity costs the oracle, never the model.
past = np.zeros((len(squares), 2 * hist), dtype=np.float32)
@@ -120,8 +130,8 @@ def plies(game: chess.pgn.Game, hist: int = 3) -> list[Ply]:
(chess.square_rank(t) - chess.square_rank(move.from_square)) / SCALE]
for t in legal], dtype=np.float32)
j = legal.index(move.to_square)
out.append(Ply([id_at[sq] for sq in squares], attrs, coords, mover, dests[j], dests, j,
past))
out.append(Ply([id_at[s] for s in squares], attrs, coords, mover, dests[j], dests, j,
past, mask))
seen.setdefault(id_at[move.from_square], []).append(move.from_square)
advance_ids(board, move, piece, id_at)
@@ -160,7 +170,7 @@ def match_width(hidden: int, cppn_hidden: int) -> int:
def _stream(org: Organism, game: list[Ply], affect: Affect, acfg: AffectConfig,
opt: torch.optim.Optimizer | None, bptt: int, use_affect: bool,
oracle: bool):
oracle: bool, adjacency: bool):
"""One game as one continuous stream. Memory starts empty: new game, new pieces."""
memory: dict[int, torch.Tensor] = {}
pending: list[torch.Tensor] = []
@@ -170,7 +180,8 @@ def _stream(org: Organism, game: list[Ply], affect: Affect, acfg: AffectConfig,
coords = torch.from_numpy(ply.coords)
attrs = np.concatenate([ply.attrs, ply.past], 1) if oracle else ply.attrs
pred, memory = org(torch.from_numpy(attrs), flat_diff(coords), ply.ids,
affect.axes, memory)
affect.axes, memory,
mask=torch.from_numpy(ply.mask) if adjacency else None)
p = pred[ply.mover]
loss = ((p - torch.from_numpy(ply.target)) ** 2).mean() # masked to the mover
if use_affect:
@@ -214,7 +225,8 @@ def run_constant(games: list[list[Ply]], seed: int) -> dict:
def run(games: list[list[Ply]], memory: bool, hidden: int, cppn_hidden: int, seed: int,
lr: float, bptt: int, kappa: float, use_affect: bool, oracle: bool = False) -> dict:
lr: float, bptt: int, kappa: float, use_affect: bool, oracle: bool = False,
adjacency: bool = False) -> dict:
torch.manual_seed(seed)
attr_dim = ATTR_DIM + (games[0][0].past.shape[1] if oracle else 0)
org = Organism(attr_dim, 2, 2, hidden_dim=hidden, cppn_hidden=cppn_hidden,
@@ -226,12 +238,12 @@ def run(games: list[list[Ply]], memory: bool, hidden: int, cppn_hidden: int, see
order = np.random.default_rng(seed).permutation(len(games))
cut = max(1, len(games) // 4)
for gi in order[cut:]:
affect, *_ = _stream(org, games[gi], affect, acfg, opt, bptt, use_affect, oracle)
affect, *_ = _stream(org, games[gi], affect, acfg, opt, bptt, use_affect, oracle, adjacency)
mse, hits, chance = [], [], []
for gi in order[:cut]:
affect, l, h, c = _stream(org, games[gi], affect, acfg, None, bptt, use_affect, oracle)
affect, l, h, c = _stream(org, games[gi], affect, acfg, None, bptt, use_affect, oracle, adjacency)
mse += l; hits += h; chance += c
return dict(seed=seed, hidden=hidden, memory=memory, oracle=oracle,
return dict(seed=seed, hidden=hidden, memory=memory, oracle=oracle, mask=adjacency,
params=sum(p.numel() for p in org.parameters()), plies=len(mse),
mse=statistics.fmean(mse), acc=statistics.fmean(hits),
chance=statistics.fmean(chance))
@@ -250,6 +262,8 @@ def main() -> None:
ap.add_argument("--affect", default="neutral", choices=("neutral", "stream"),
help="neutral holds psi at (0,0); stream runs the real EMA chain")
ap.add_argument("--arms", default="rp,grp,rp_wide,rp_oracle")
ap.add_argument("--mask", default="all", choices=("all", "attack"),
help="all is the spec default; attack is the domain's own adjacency")
ap.add_argument("--out", default="results/chess.json")
a = ap.parse_args()
@@ -262,15 +276,17 @@ def main() -> None:
"rp_wide": (False, wide, False), "rp_oracle": (False, wide, True),
"constant": (False, 0, False)}
arms = {k: all_arms[k] for k in a.arms.split(",")}
deg = statistics.fmean(float(p.mask.sum(1).mean()) for g in games for p in g)
print(f"{len(games)} games, {sum(len(g) for g in games)} plies; "
f"width-matched memoryless arm at hidden={wide}\n")
f"width-matched memoryless arm at hidden={wide}; mask={a.mask}, "
f"mean degree {deg if a.mask == 'attack' else statistics.fmean(len(p.ids) for g in games for p in g):.1f}\n")
results = []
for name, (mem, h, orc) in arms.items():
for seed in (int(s) for s in a.seeds.split(",")):
r = (run_constant(games, seed) if name == "constant" else
run(games, mem, h, a.cppn_hidden, seed, a.lr, a.bptt, a.kappa,
a.affect == "stream", orc)) | {"arm": name}
a.affect == "stream", orc, a.mask == "attack")) | {"arm": name}
print(f"{name:<8} seed={seed} params={r['params']:<6} "
f"mse={r['mse']:.5f} acc={r['acc']:.4f}", flush=True)
results.append(r)