Skip to content

Species: select parents on shifted fitness (ref #98) - #115

Merged
TLmaK0 merged 1 commit into
developfrom
issue-98-within-species-shift
Nov 25, 2026
Merged

TLmaK0 merged 1 commit into
developfrom
issue-98-within-species-shift

Conversation

@TLmaK0

@TLmaK0 TLmaK0 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What changes

  • Roulette parent selection inside a species now works on shifted adjusted fitness, reusing shift_to_non_negative from the between-species share (Fitness negativo, NaN, élite sin evaluar y campeón histórico #66, now pub(crate)): if any value is negative, each weight is its distance to the worst organism (the worst gets 0); non-negative fitness is used as is; non-finite fitness gets 0 (as before).
    • Before: all fitness ≤ 0 → uniform selection over the parent half; mixed signs → every negative organism weight 0.
  • The roulette is extracted into Specie::select_parents(count, rng) (same RNG draws, same order) so it can be tested directly.

Verification

  • New unit tests in src/specie.rs (ChaCha8 seed 1), red on develop before the fix:
    • selection_favours_the_fittest_when_all_fitness_is_negative: fitness −90…−100, 6000 draws. Develop: [997, 1052, 992, 995, 991, 973] (uniform). Now: fittest > worst, fittest > 1/4 of draws, worst = 0.
    • selection_ranks_negative_fitness_with_mixed_signs: [5, -1, -5]. Develop: [6000, 0, 0]. Now strictly ordered.
    • selection_keeps_proportions_of_non_negative_fitness: [3, 1, 0] keeps the 3:1 ratio and 0 for the zero.
  • Gates: cargo fmt -- --check OK; cargo clippy --release --all-targets 56 warnings (same as develop); cargo build --release --examples OK; cargo test --release --no-fail-fast all green.

Closing criterion

Met: in a species with fitness in [−100, −90], the fittest is selected more often than the worst over 6000 draws with a fixed seed (worst is never selected).

Banco A (xor_bench 50 500 init reset=1 seed=S), seeds 1/101/201/301: 50/50 solved each, medians 52/53/53/51, same as develop 0d78b05. XOR fitness is non-negative, so the output is bit-identical: all 200 RunResult lines (sorted, secs stripped) match develop exactly.

ref #98
Part of epic #55

🤖 Generated with Claude Code

Roulette selection inside a species now uses the same shift as the
offspring shares between species (#66): if any adjusted fitness is
negative, every weight is its distance to the worst, so the fittest is
favoured whatever the sign. Before, all-negative fitness made selection
uniform and, with mixed signs, every negative organism got weight 0.
Non-negative fitness is used unchanged (bit-identical XOR bench).

The roulette is extracted into Specie::select_parents and tested with a
fixed seed: fitness in [-100, -90], mixed signs, and plain proportions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TLmaK0
TLmaK0 merged commit 8f7c5ff 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