Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
503c374968 | ||
|
|
3ef8868ffa |
No files matched your search
+11
-3
@@ -16,9 +16,17 @@ class AffectiveCPPN(nn.Module):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.l1 = nn.Linear(coord_dim + n_edge_types + context_dim, hidden)
|
self.l1 = nn.Linear(coord_dim + n_edge_types + context_dim, hidden)
|
||||||
self.l2 = nn.Linear(hidden, out_dim)
|
self.l2 = nn.Linear(hidden, out_dim)
|
||||||
# omega scales the sine pre-activation and sets the kernel bandwidth; it is
|
# omega scales the sine pre-activation and sets the kernel bandwidth. This was
|
||||||
# a calibration knob that wants tuning against the domain's length scale
|
# documented as "a calibration knob that wants tuning against the domain's length
|
||||||
# (the particles domain's sigma). l1 deliberately keeps PyTorch's default init.
|
# scale"; experiments/results/omega.md measured that and it is FALSE over the range
|
||||||
|
# tested -- the best omega sits at 2-4 for a domain bandwidth varying 4.7x, and 8 is
|
||||||
|
# an optimisation cliff for every domain tried. What the domain changes is the
|
||||||
|
# penalty for being under-banded, not where the optimum is.
|
||||||
|
# The default of 10.0 is OUTSIDE that plateau and every chess result was produced at
|
||||||
|
# it. It is left alone rather than silently changed: those results are comparisons at
|
||||||
|
# a fixed omega and stay fair, and one synthetic teacher family is not enough to move
|
||||||
|
# a library default. Pass omega explicitly, and measure it for a new domain.
|
||||||
|
# l1 deliberately keeps PyTorch's default init.
|
||||||
self.omega = omega
|
self.omega = omega
|
||||||
|
|
||||||
def forward(self, r: Tensor, edge_onehot: Tensor, context: Tensor) -> Tensor:
|
def forward(self, r: Tensor, edge_onehot: Tensor, context: Tensor) -> Tensor:
|
||||||
|
|||||||
@@ -179,3 +179,38 @@ def test_detach_memory_cuts_graph():
|
|||||||
_, mem = org(attrs, r, ids, (0.0, 0.0), {})
|
_, mem = org(attrs, r, ids, (0.0, 0.0), {})
|
||||||
assert all(m.requires_grad for m in mem.values())
|
assert all(m.requires_grad for m in mem.values())
|
||||||
assert not any(m.requires_grad for m in detach_memory(mem).values())
|
assert not any(m.requires_grad for m in detach_memory(mem).values())
|
||||||
|
|
||||||
|
|
||||||
|
# --- Property card rows: what the RP is, asserted rather than assumed. -------------------
|
||||||
|
# These two are not experiments and must never become them. They state properties that hold
|
||||||
|
# by construction, and exist so a future change cannot remove one silently. Both were checked
|
||||||
|
# against a deliberately broken RP (see results/rp_properties.md) and both failed there.
|
||||||
|
|
||||||
|
|
||||||
|
def test_rp_same_parameters_any_n():
|
||||||
|
"""One parameter set serves any entity count. A fixed-weight layer over N entities is
|
||||||
|
not worse here, it is undefined: its input dimension is N (or N^2) and has to be chosen."""
|
||||||
|
rp = RelationalPerceptron(D_ATTR, K, E, C, hidden_dim=H)
|
||||||
|
before = [p.clone() for p in rp.parameters()]
|
||||||
|
for n in (2, 7, 32):
|
||||||
|
attrs, coords = torch.randn(n, D_ATTR), torch.rand(n, K)
|
||||||
|
edge = torch.zeros(n, n, E); edge[..., 0] = 1.0
|
||||||
|
h = rp(attrs, flat_diff(coords), edge, torch.ones(n, n), torch.tensor([0.1, 0.2]))
|
||||||
|
assert h.shape == (n, H)
|
||||||
|
assert all(torch.equal(a, b) for a, b in zip(before, rp.parameters())) # no shape adapted
|
||||||
|
|
||||||
|
|
||||||
|
def test_organism_permutation_equivariance_with_memory():
|
||||||
|
"""The RP-level test uses positional tensors; the Organism keys memory by entity id, which
|
||||||
|
is a second place the order could leak in."""
|
||||||
|
org = make_org(memory=True)
|
||||||
|
attrs, coords, _, _, _ = make_inputs()
|
||||||
|
r, ids = flat_diff(coords), list(range(N))
|
||||||
|
mem = {i: torch.randn(H) for i in ids}
|
||||||
|
y0, m0 = org(attrs, r, ids, (0.0, 0.0), mem)
|
||||||
|
|
||||||
|
perm = torch.randperm(N)
|
||||||
|
ids_p = [ids[k] for k in perm.tolist()]
|
||||||
|
y1, m1 = org(attrs[perm], flat_diff(coords[perm]), ids_p, (0.0, 0.0), mem)
|
||||||
|
assert torch.allclose(y0[perm], y1, atol=1e-5)
|
||||||
|
assert all(torch.allclose(m0[i], m1[i], atol=1e-5) for i in ids)
|
||||||
Reference in new issue
Block a user