Skip to content

Close the XOR gap with the NEAT paper: tuned survival threshold and weight sigma, mate-only and mate selection options (ref #108) - #125

Merged
TLmaK0 merged 1 commit into
developfrom
issue-108-xor-paper-gap
Nov 25, 2026
Merged

TLmaK0 merged 1 commit into
developfrom
issue-108-xor-paper-gap

Conversation

@TLmaK0

@TLmaK0 TLmaK0 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What changes

  • Defaults (measured improvement on both seed sets, details below): survival_threshold 0.5 → 0.2 and weight_mutate_power 1.0 → 2.0.
  • New opt-in MutationConfig::mate_only_probability (NEAT mate_only_prob, Some algorithm considerations #38 point 3) and MutationConfig::mate_selection / MateSelection::{Uniform, FitnessProportional} (Selection inside a species ignores negative fitness #98). Both default to the old behaviour and draw no extra random numbers.
  • xor_bench: new keys mateonly, matesel and round=1. With round=1 a run counts as solved by the NEAT paper criterion (every output on the right side of 0.5).
  • The lunar lander keeps its survival threshold of 0.5 (LANDER_SURVIVAL_THRESHOLD) and its own σ, so its config is unchanged.
  • Results change on purpose, so the long_run_identity_tests digest is re-recorded (0xb085f2fe3578d4a4 → 0xacac1eb362c6aa78). The test also checks that the two old values reproduce the old digest.

How it was verified

  • TDD: unit tests for mate-only (unmutated crossover children; a crossover with itself is always mutated), for fitness-proportional mate choice, for the new defaults, and for the bench keys and rounding criterion. Each was seen failing first.
  • cargo fmt -- --check OK; cargo clippy --release --all-targets -- -D warnings OK; with --all-features and with --features telemetry (pyo3 stub) OK; cargo build --release --examples OK; cargo check --release --features openai --examples OK; cargo test --release --no-fail-fast: 245 passed, 0 failed (including the README doc-tests).
  • function_approximation and simple_sample still run.

#108 results: XOR gap with the NEAT paper

Method. Bench A: xor_bench 50 500 init reset=1 seed=S [keys], with S = 1/101/201/301 (runs S..S+49, so 200 runs per config). Each config was measured under three success criteria, each in its own run:

  • target 15.5: the usual bench criterion, fitness 16/(1+Σerr²) > 15.5 (Σerr² < 0.032).
  • target 13: the audit's stand-in for the paper (Σerr² < 0.23). It is stricter than the paper: it guarantees every output is on the right side of 0.5.
  • rounding (paper): new key round=1. A run is solved when every output is on the right side of 0.5 (out < 0.5 for 0, ≥ 0.5 for 1), which is the check in Stanley's code.

The last column is the champion check still_solved_reversed_no_reset: the champion still scores above 15.5 with the patterns in reverse order and no state reset. It measures how much a CTRNN's answer depends on the patterns it saw before. I tracked it so that no default would buy speed with less robust champions.

Each key is set on top of the develop defaults (mutp=0.4 surv=0.5 champ=2 tspec=10 wpow=1 wgene=0.5 addc=0.05 addn=0.03 tau=0.01 step=0.1 xavg=0.4). In total: 54 configs on the main seeds, 6 on the validation seeds 401/501/601/701, and 8 on other XOR variants. Every one of them solved 200/200.

Key finding: most of the gap is the success criterion

With the develop defaults, judged by the paper's own criterion (rounding), XOR is solved in mean 18.2 generations (medians 17/18/20/16; validation seeds mean 18.6). The paper reports 32. The 52–54 generation medians come from our much stricter target of 15.5. Even the audit's target 13 gives a mean of 33.6, which is about the paper's number.

Chosen change (defaults)

  • survival_threshold 0.5 → 0.2 (the survival_thresh in Stanley's NEAT code).
  • weight_mutate_power (gaussian σ) 1.0 → 2.0.
develop new defaults
seeds 1/101/201/301, target 15.5 medians (mean) 52/53/53/51 (52.15) 30/31/31/30 (31.43)
seeds 401/501/601/701, target 15.5 medians (mean) 53/54/54/53 (54.38) 30/29/28/31 (30.20)
seeds 1/101/201/301, target 13 mean 33.60 21.45
seeds 401/501/601/701, target 13 mean 35.05 20.65
seeds 1/101/201/301, rounding (paper) mean 18.18 14.68
seeds 401/501/601/701, rounding (paper) mean 18.60 13.95
reversed_no_reset (main / validation) 160 / 157 of 200 157 / 162 of 200
no-reset training (reset=0), target 15.5 medians, main / validation 50/54/56/52, 55/54/53/53 30/28/31/32, 29/28/28/30
no-reset training, all_orders_reset_each main / validation 182 / 172 of 200 178 / 172 of 200
signed inputs (inlo=-1 splitlo=-1), target 15.5 medians 54/61/58/56 36/36/34/38
signed inputs, rounding mean 22.85 23.27 (≈ unchanged)

Rejected after measuring

  • The fastest combinations included addc=0.3 (the paper's rate for large populations): surv=0.2 wpow=2 addc=0.3 mutp=0.25 reaches medians 27 and a rounding mean of 11.0–11.3. But they cut reversed_no_reset from 160 to about 120 of 200 on both seed sets, and with no-reset training they cut all_orders from 182 to about 163. More connections give more recurrent and self loops, so the answer depends more on earlier patterns.
  • mutp=0.25 on top of the chosen pair measured 30/30/30/30 vs 30/31/31/30 (validation 29/28/27/30 vs 30/29/28/31), with equal rounding means. That is within the noise, so mutation_probability stays 0.4.
  • wgene=1 on top of the pair is faster at target 15.5 (26.75) but slower by the paper criterion (mean 16.2 vs 14.7).

Other examples

  • The lunar lander config is unchanged. It already sets its own σ (0.87), and it now pins LANDER_SURVIVAL_THRESHOLD = 0.5 because the new library default was measured on XOR only.
  • function_approximation still runs. Neither the old nor the new defaults reach its 96 target within 600 generations (24 seeds). The average best fitness was 69.2 with the old defaults and 71.2 with the new.
  • simple_sample still runs and finishes.

Hash. Because the defaults change, the digest in long_run_identity_tests changes too (0xb085f2fe3578d4a4 → 0xacac1eb362c6aa78). The test also checks that setting the two old values back gives the old digest, which proves the new options change nothing by default. The README doc-tests pass unchanged.

New opt-in options (#38 point 3, #98)

  • MutationConfig::mate_only_probability (NEAT mate_only_prob): the probability that a crossover child is not mutated. A crossover of an organism with itself is always mutated. Default 0, which means every crossover child is mutated, as before.
  • MutationConfig::mate_selection: MateSelection::Uniform (default, as before) or FitnessProportional (roulette, like the first parent).
  • xor_bench keys mateonly, matesel and round.

Neither option helped (tables below), so both stay off by default.

Full tables

Baseline (develop b0cc678), seeds 1/101/201/301

config solved target 15.5: medians (avg) mean target 13: medians (avg) rounding (paper): medians (avg) rounding: mean champion reversed_no_reset
develop defaults (surv=0.5 wpow=1) 200/200 52/53/53/51 (52.25) 52.15 32/34/35/33 (33.50) 17/18/20/16 (17.75) 18.18 160/200

Single candidates, seeds 1/101/201/301

config solved target 15.5: medians (avg) mean target 13: medians (avg) rounding (paper): medians (avg) rounding: mean champion reversed_no_reset
mutp=0.25 200/200 53/55/53/55 (54.00) 54.98 34/35/34/36 (34.75) 16/19/18/18 (17.75) 18.07 153/200
mutp=0.6 200/200 51/52/55/50 (52.00) 52.35 34/33/33/33 (33.25) 18/18/18/19 (18.25) 19.15 148/200
mutp=0.8 200/200 53/55/52/53 (53.25) 53.17 36/36/36/35 (35.75) 20/22/20/21 (20.75) 21.85 144/200
mateonly=0.2 200/200 56/57/59/54 (56.50) 56.17 35/36/39/33 (35.75) 17/17/19/16 (17.25) 18.23 147/200
mateonly=0.5 200/200 60/59/60/60 (59.75) 60.58 37/36/36/35 (36.00) 20/18/17/17 (18.00) 18.73 146/200
mutp=0 mateonly=0.75 200/200 93/92/92/94 (92.75) 95.00 51/50/53/56 (52.50) 18/18/19/20 (18.75) 20.62 124/200
mutp=0 200/200 60/60/56/56 (58.00) 57.88 38/36/35/36 (36.25) 18/17/16/18 (17.25) 18.70 148/200
matesel=1 200/200 55/54/51/55 (53.75) 53.55 35/33/31/34 (33.25) 18/17/15/19 (17.25) 18.10 157/200
surv=0.2 200/200 37/38/38/39 (38.00) 38.58 25/25/25/25 (25.00) 13/14/14/13 (13.50) 13.95 156/200
surv=0.3 200/200 44/42/41/41 (42.00) 42.65 26/27/27/27 (26.75) 14/14/15/16 (14.75) 15.47 146/200
surv=0.7 200/200 70/69/68/69 (69.00) 68.67 44/41/40/46 (42.75) 21/21/20/19 (20.25) 21.88 152/200
champ=1 200/200 52/53/53/51 (52.25) 52.15 32/34/35/33 (33.50) 17/18/20/16 (17.75) 18.18 160/200
champ=6 200/200 52/53/53/53 (52.75) 52.62 31/34/34/34 (33.25) 17/18/20/17 (18.00) 18.20 153/200
champ=inf 200/200 68/68/66/64 (66.50) 67.78 39/43/40/40 (40.50) 20/20/19/19 (19.50) 20.60 156/200
tspec=5 200/200 55/55/54/54 (54.50) 55.70 35/36/35/36 (35.50) 17/20/21/18 (19.00) 19.50 161/200
tspec=15 200/200 52/55/55/55 (54.25) 54.38 32/34/35/34 (33.75) 17/17/18/18 (17.50) 17.85 156/200
tspec=20 200/200 53/53/57/56 (54.75) 54.88 32/33/35/33 (33.25) 17/17/18/17 (17.25) 17.95 148/200
tspec=0 thr=3 200/200 67/60/65/61 (63.25) 64.62 39/36/41/40 (39.00) 22/21/23/20 (21.50) 22.50 153/200
wpow=0.5 200/200 83/79/79/79 (80.00) 80.53 50/50/51/52 (50.75) 22/23/20/22 (21.75) 22.10 132/200
wpow=2 200/200 39/40/39/39 (39.25) 40.15 26/26/25/26 (25.75) 18/18/15/18 (17.25) 18.38 162/200
wgene=0.2 200/200 70/74/74/75 (73.25) 72.97 46/45/47/44 (45.50) 19/19/21/22 (20.25) 21.10 133/200
wgene=1 200/200 45/43/45/45 (44.50) 44.58 29/26/30/27 (28.00) 17/17/16/17 (16.75) 17.60 163/200
addc=0.1 200/200 51/51/53/50 (51.25) 50.75 32/32/33/32 (32.25) 17/16/17/17 (16.75) 16.50 149/200
addc=0.3 200/200 48/46/48/47 (47.25) 46.80 31/30/30/30 (30.25) 15/14/15/15 (14.75) 14.75 118/200
addn=0.01 200/200 53/51/54/53 (52.75) 52.10 34/33/32/33 (33.00) 17/18/19/18 (18.00) 18.02 147/200
addn=0.06 200/200 56/54/54/57 (55.25) 55.60 36/34/35/37 (35.50) 17/19/18/19 (18.25) 19.35 144/200
taurate=0.1 200/200 53/55/55/55 (54.50) 54.38 34/35/35/34 (34.50) 18/18/19/19 (18.50) 18.65 140/200
tau=0.1 200/200 98/105/105/99 (101.75) 102.33 61/69/68/65 (65.75) 29/32/30/28 (29.75) 30.50 1/200
step=0.05 200/200 56/59/57/55 (56.75) 56.08 37/37/37/35 (36.50) 17/19/20/20 (19.00) 19.30 69/200
xavg=0 200/200 51/53/50/51 (51.25) 51.35 32/34/33/34 (33.25) 17/18/16/19 (17.50) 18.25 152/200
surv=0.1 200/200 33/33/32/34 (33.00) 34.10 23/22/22/22 (22.25) 13/14/12/13 (13.00) 13.12 150/200
wpow=1.5 200/200 42/43/45/44 (43.50) 43.92 26/29/30/29 (28.50) 15/18/18/18 (17.25) 17.30 148/200
wpow=3 200/200 35/37/35/38 (36.25) 39.27 25/26/25/29 (26.25) 20/17/20/21 (19.50) 22.43 161/200
addc=0.5 200/200 46/46/49/48 (47.25) 46.90 30/29/32/30 (30.25) 14/13/14/15 (14.00) 14.12 115/200

Combinations, seeds 1/101/201/301

config solved target 15.5: medians (avg) mean target 13: medians (avg) rounding (paper): medians (avg) rounding: mean champion reversed_no_reset
surv=0.2 wpow=1.5 200/200 33/32/33/32 (32.50) 32.67 20/22/22/21 (21.25) 13/13/14/13 (13.25) 13.55 165/200
surv=0.2 wpow=2 200/200 30/31/31/30 (30.50) 31.43 19/22/21/20 (20.50) 13/13/13/14 (13.25) 14.68 157/200
surv=0.2 wgene=1 200/200 31/31/33/31 (31.50) 31.23 21/21/23/20 (21.25) 13/13/15/12 (13.25) 13.22 163/200
surv=0.2 addc=0.3 200/200 36/35/36/36 (35.75) 36.35 24/23/24/24 (23.75) 12/13/12/13 (12.50) 12.40 112/200
surv=0.2 wpow=2 addc=0.3 200/200 29/29/28/29 (28.75) 28.15 18/19/18/19 (18.50) 12/12/12/12 (12.00) 11.78 130/200
surv=0.2 wpow=1.5 addc=0.3 200/200 31/31/32/30 (31.00) 31.07 21/21/20/20 (20.50) 12/12/12/11 (11.75) 12.00 124/200
surv=0.2 wpow=2 wgene=1 200/200 25/28/28/26 (26.75) 28.00 18/21/20/18 (19.25) 12/16/14/15 (14.25) 16.15 159/200
surv=0.2 wpow=2 addc=0.3 mutp=0.25 200/200 27/27/27/27 (27.00) 27.32 17/18/18/18 (17.75) 11/11/12/11 (11.25) 11.25 124/200
surv=0.2 wpow=2 addc=0.3 matesel=1 200/200 29/26/28/27 (27.50) 27.65 19/18/18/17 (18.00) 12/10/12/10 (11.00) 11.22 121/200
surv=0.2 wpow=2 addc=0.3 mateonly=0.2 200/200 28/27/28/29 (28.00) 28.20 17/16/17/19 (17.25) 11/10/11/14 (11.50) 11.62 121/200
surv=0.1 wpow=2 addc=0.3 200/200 25/26/25/28 (26.00) 26.12 16/18/17/17 (17.00) 12/12/11/10 (11.25) 11.15 135/200
surv=0.1 wpow=2 addc=0.3 mutp=0.25 200/200 25/26/26/25 (25.50) 25.38 16/17/17/17 (16.75) 10/11/9/11 (10.25) 10.47 122/200
surv=0.2 wpow=2.5 addc=0.3 mutp=0.25 200/200 26/25/26/24 (25.25) 25.27 18/17/16/17 (17.00) 12/11/12/12 (11.75) 11.97 125/200
surv=0.2 wpow=2 addc=0.3 mutp=0.25 matesel=1 200/200 28/28/28/27 (27.75) 27.93 19/18/18/19 (18.50) 11/10/11/11 (10.75) 11.28 138/200
surv=0.2 wpow=2 addc=0.3 mutp=0.25 tspec=15 200/200 27/29/29/30 (28.75) 28.88 17/19/19/20 (18.75) 11/11/13/11 (11.50) 11.65 118/200
surv=0.2 wpow=2 addc=0.3 mutp=0.25 champ=6 200/200 28/27/27/28 (27.50) 27.25 17/16/18/19 (17.50) 11/11/11/12 (11.25) 11.07 119/200
surv=0.2 wpow=2 mutp=0.25 200/200 30/30/30/30 (30.00) 30.52 19/18/21/19 (19.25) 13/12/13/13 (12.75) 13.82 166/200
surv=0.2 wpow=2 wgene=1 mutp=0.25 200/200 25/25/27/27 (26.00) 27.02 18/19/19/18 (18.50) 14/14/13/14 (13.75) 15.10 162/200
surv=0.2 wpow=2 addc=0.1 200/200 29/29/29/27 (28.50) 28.60 19/20/20/19 (19.50) 12/14/13/13 (13.00) 13.03 139/200
surv=0.2 wpow=2 wgene=1 addc=0.1 200/200 24/25/26/24 (24.75) 25.52 15/17/20/17 (17.25) 11/13/15/14 (13.25) 13.70 145/200

Validation on other seeds 401/501/601/701

config solved target 15.5: medians (avg) mean target 13: medians (avg) rounding (paper): medians (avg) rounding: mean champion reversed_no_reset
develop defaults 200/200 53/54/54/53 (53.50) 54.38 35/34/35/34 (34.50) 18/18/19/17 (18.00) 18.60 157/200
surv=0.2 wpow=2 addc=0.3 mutp=0.25 200/200 27/28/28/26 (27.25) 27.25 17/18/17/18 (17.50) 10/12/11/12 (11.25) 11.00 112/200
surv=0.2 wpow=2 addc=0.3 200/200 27/26/28/28 (27.25) 27.52 19/17/19/19 (18.50) 12/10/12/12 (11.50) 11.65 130/200
surv=0.1 wpow=2 addc=0.3 mutp=0.25 200/200 26/28/25/27 (26.50) 26.70 16/17/16/16 (16.25) 12/11/10/10 (10.75) 10.90 126/200
surv=0.2 wpow=2 200/200 30/29/28/31 (29.50) 30.20 20/19/19/23 (20.25) 13/12/14/14 (13.25) 13.95 162/200
surv=0.2 wpow=2 mutp=0.25 200/200 29/28/27/30 (28.50) 29.73 20/22/18/20 (20.00) 14/14/11/14 (13.25) 13.97 168/200
reset=0 200/200 55/54/53/53 (53.75) 53.90 35/34/34/32 (33.75) 19/17/17/19 (18.00) 18.45 142/200
reset=0 surv=0.2 wpow=2 200/200 29/28/28/30 (28.75) 30.65 18/19/20/22 (19.75) 14/11/14/14 (13.25) 14.53 144/200

Other XOR variants, seeds 1/101/201/301 (no-regression check)

config solved target 15.5: medians (avg) mean target 13: medians (avg) rounding (paper): medians (avg) rounding: mean champion reversed_no_reset
reset=0 200/200 50/54/56/52 (53.00) 53.45 33/34/35/33 (33.75) 17/17/20/17 (17.75) 17.77 150/200
reset=0 surv=0.2 wpow=2 addc=0.3 mutp=0.25 200/200 27/26/27/26 (26.50) 26.95 18/17/17/18 (17.50) 12/11/12/11 (11.50) 11.10 111/200
inlo=-1 splitlo=-1 200/200 54/61/58/56 (57.25) 58.55 37/38/39/36 (37.50) 21/21/22/21 (21.25) 22.85 175/200
inlo=-1 splitlo=-1 surv=0.2 wpow=2 addc=0.3 mutp=0.25 200/200 29/29/29/27 (28.50) 28.73 20/22/20/19 (20.25) 14/14/14/15 (14.25) 14.72 156/200
reset=0 surv=0.2 wpow=2 mutp=0.25 200/200 31/28/29/29 (29.25) 30.85 21/18/19/20 (19.50) 12/13/14/14 (13.25) 13.78 144/200
inlo=-1 splitlo=-1 surv=0.2 wpow=2 mutp=0.25 200/200 36/35/35/35 (35.25) 37.65 25/27/27/24 (25.75) 20/22/23/17 (20.50) 22.05 168/200
reset=0 surv=0.2 wpow=2 200/200 30/28/31/32 (30.25) 31.38 20/19/21/20 (20.00) 13/14/14/15 (14.00) 14.20 147/200
inlo=-1 splitlo=-1 surv=0.2 wpow=2 200/200 36/36/34/38 (36.00) 38.90 27/28/26/25 (26.50) 20/21/20/22 (20.75) 23.27 162/200

champ=1 gives results identical to champ=2 because no species gets exactly one offspring there.
Reproduce any row: cargo run --release --example xor_bench -- 50 500 init reset=1 seed=S <keys> [target=13 | round=1].

ref #108
Part of epic #55. Also relates to #38 (points 3, 5, 6 measured; see the comment there).

🤖 Generated with Claude Code

…ions, ref #108

Measured on bench A (xor_bench 50 500 init reset=1) over seeds
1/101/201/301 and validated on 401/501/601/701 (200 runs each, all solved):

- survival_threshold default 0.5 -> 0.2 (Stanley's NEAT survival_thresh)
- weight_mutate_power default 1.0 -> 2.0
  Medians 52/53/53/51 -> 30/31/31/30 (validation 53/54/54/53 ->
  30/29/28/31); by the paper criterion (every output on the right side of
  0.5) mean 18.2 -> 14.7 generations (validation 18.6 -> 14.0). Champion
  robustness to the pattern order unchanged (reversed_no_reset 160 -> 157
  of 200, validation 157 -> 162). The lunar lander keeps the fittest half
  (LANDER_SURVIVAL_THRESHOLD = 0.5) and its own sigma.

- MutationConfig::mate_only_probability (default 0, NEAT mate_only_prob):
  a crossover child is left unmutated with this probability (#38 point 3).
- MutationConfig::mate_selection / MateSelection::{Uniform (default),
  FitnessProportional}: how the crossover mate is chosen (#98).
  Neither helped on the bench, so both are opt-in; with them at their
  defaults the random sequence is unchanged.
- xor_bench: keys mateonly, matesel and round=1 (solved by the NEAT paper
  criterion instead of a fitness target).

The long_run_identity digest changes because the defaults change on
purpose; the test now also checks that with the old two values the old
digest (0xb085_f2fe_3578_d4a4) is reproduced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TLmaK0
TLmaK0 merged commit 34950c4 into develop Nov 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant