The regime decodes from a single M at 0.332 and the question was whether it is distributed across the 16 per-entity states rather than absent from them. Mean-pooling lifts M's gap above the measured shift null by +0.045 -- and lifts the memoryless h it is built from by +0.048, on more seeds. Difference -0.003, paired se 0.015, M ahead on 8/16. Concatenating all 16 adds nothing over the mean once it has samples to fit. The instrument is not blind: a synthetic representation whose regime code is genuinely split across entities gains +0.589 through the same probe, thirteen times the effect measured here, and test_the_power_check_can_fail breaks the pooling on purpose and confirms that control fails. Eight seeds would have reported +0.010 in M's favour on 5/8. Sixteen report -0.003 on 8/16, which is the spread this project keeps being warned about. No training loop and no architecture added: _build, _train, _frozen and probe come from frozen.py unchanged, and seeds 0-7 reproduce results/frozen.json bit-identically.
82 lines
3.2 KiB
Python
82 lines
3.2 KiB
Python
import numpy as np
|
|
import pytest
|
|
|
|
import frozen
|
|
import pooled
|
|
from pooled import power_check, run_one, views
|
|
|
|
|
|
def _labels(t: int = 4000, seed: int = 0):
|
|
"""A regime label sequence with the world's own 40-80 step block structure."""
|
|
rng = np.random.default_rng(seed)
|
|
lab, sw, g = [], [], 0
|
|
while len(lab) < t:
|
|
g = int(rng.choice([i for i in range(4) if i != g]))
|
|
n = int(rng.integers(40, 81))
|
|
sw += [True] + [False] * (n - 1)
|
|
lab += [g] * n
|
|
return np.array(lab[:t]), sw[:t]
|
|
|
|
|
|
def test_views_preserve_the_representation():
|
|
"""Pooling must aggregate the entities it claims to, in a stable order."""
|
|
rep = np.random.default_rng(0).normal(size=(50, 16, 32))
|
|
v = views(rep)
|
|
assert v["single"] is rep
|
|
assert v["mean"].shape == (50, 1, 32)
|
|
assert v["concat"].shape == (50, 1, 16 * 32)
|
|
assert np.allclose(v["mean"][:, 0], rep.mean(1))
|
|
for i in range(16): # concat block i is always particle i
|
|
assert np.array_equal(v["concat"][:, 0, i * 32:(i + 1) * 32], rep[:, i])
|
|
|
|
|
|
def test_single_view_reproduces_the_frozen_probe_exactly():
|
|
"""The `single` row must be the published baseline, not a re-implementation of it.
|
|
|
|
Same organism, same world, same estimator: bit-identical or the comparison this
|
|
file draws against `results/frozen.md` is not against anything.
|
|
"""
|
|
kw = dict(train_steps=300, frozen_steps=300)
|
|
mine = run_one(seed=0, **kw)["probes"]
|
|
theirs = frozen.run_one("grp_k0", seed=0, **kw)["probes"]
|
|
for tag in ("M", "h"):
|
|
assert mine[f"{tag}_single_lsq"]["acc_entity"] == theirs[f"{tag}_lsq"]["acc_entity"]
|
|
assert mine[f"{tag}_single_lsq"]["chance_shift"] == theirs[f"{tag}_lsq"]["chance_shift"]
|
|
|
|
|
|
def test_power_check_finds_a_code_that_is_only_in_the_pool():
|
|
"""The positive control: hypothesis (b) made true by construction.
|
|
|
|
In `distributed` no entity holds more than one of the regime's two bits, so a
|
|
per-entity probe caps near 0.5 while the pool holds both. If this pipeline could
|
|
not find that, a null on the real data would carry no information.
|
|
"""
|
|
lab, sw = _labels()
|
|
pc = power_check(lab, sw, seed=0)
|
|
gap = lambda k: pc[k]["acc_entity"] - pc[k]["chance_shift"]
|
|
assert gap("distributed_single") < 0.30
|
|
assert gap("distributed_mean") > 0.60
|
|
assert gap("distributed_concat") > 0.60
|
|
# and pooling lifts a merely redundant code too -- the confound the `h` row controls
|
|
assert gap("redundant_mean") - gap("redundant_single") > 0.20
|
|
|
|
|
|
def test_the_power_check_can_fail(monkeypatch):
|
|
"""Break the pooling on purpose; the positive control must notice.
|
|
|
|
`views` is replaced by one whose `mean` and `concat` read entity 0 alone -- the
|
|
shape of every downstream call is unchanged, only the aggregation is gone. A test
|
|
that still passed here would be defending nothing.
|
|
"""
|
|
def broken(rep):
|
|
t, n, d = rep.shape
|
|
one = rep[:, :1]
|
|
return {"single": rep, "mean": one, "concat": np.tile(one, (1, 1, n)).reshape(t, 1, n * d)}
|
|
|
|
monkeypatch.setattr(pooled, "views", broken)
|
|
lab, sw = _labels()
|
|
pc = power_check(lab, sw, seed=0)
|
|
gap = lambda k: pc[k]["acc_entity"] - pc[k]["chance_shift"]
|
|
with pytest.raises(AssertionError):
|
|
assert gap("distributed_mean") > 0.60
|