Implement Phase 1 of fugue-evo library (TDD approach) - #1
Merged
alexnodeland merged 11 commits intoDec 12, 2025
Merged
Conversation
This commit implements the core foundation of the probabilistic genetic algorithm library following test-driven development practices. Components implemented: - Error types: GenomeError, OperatorError, CheckpointError, EvolutionError - Genome traits: EvolutionaryGenome, RealValuedGenome, BinaryGenome, PermutationGenome - Genome implementations: RealVector, BitString - Bounds system: Bounds, MultiBounds for search space definition - Fitness traits: FitnessValue, Fitness, ParetoFitness - Benchmark functions: Sphere, Rastrigin, Rosenbrock, Ackley, Griewank, Schwefel, OneMax, LeadingOnes - Selection operators: Tournament, Roulette, Rank, Truncation, Boltzmann - Crossover operators: SBX, BLX-alpha, Uniform, OnePoint, TwoPoint, Arithmetic - Mutation operators: Polynomial, Gaussian, Uniform, BitFlip, Swap, Scramble - Population management: Individual, Population with parallel evaluation - Termination criteria: MaxGenerations, MaxEvaluations, TargetFitness, FitnessStagnation, DiversityThreshold - Diagnostics: GenerationStats, EvolutionStats, EvolutionResult - SimpleGA algorithm with builder pattern All 184 unit tests pass.
- Add .github/workflows/ci.yml with jobs for: - check: cargo check - fmt: formatting verification - clippy: linting with warnings as errors - test: run all tests - doc: documentation generation - ci-success: summary job - Add Makefile with common development commands: - make ci: full CI pipeline - make test: run tests - make fmt/fmt-fix: format checking and fixing - make clippy/clippy-fix: linting - make doc/doc-open: documentation - make quick: fast development checks - Fix all clippy warnings: - Replace manual range contains with (0.0..=1.0).contains() - Replace map_or(false, ..) with is_some_and() - Add #[allow] for intentional patterns (module_inception, type_complexity) - Rename from_iter to collect_from to avoid trait confusion - Apply rustfmt formatting to all files
This commit adds the core Fugue integration required by the Phase 1 spec: EvolutionaryGenome trait changes: - Add `to_trace(&self) -> Trace` method for converting genomes to Fugue traces - Add `from_trace(trace: &Trace) -> Result<Self, GenomeError>` for reconstruction - Add `trace_prefix() -> &'static str` for customizable address prefixes RealVector implementation: - Genes stored at "gene#0", "gene#1", ... addresses - Full roundtrip support via Trace BitString implementation: - Bits stored at "bit#0", "bit#1", ... addresses - Full roundtrip support via Trace This enables trace-based evolutionary operators where Fugue's traces serve as genomes, allowing probabilistic operations like selective resampling for mutation and constraint-based crossover. Tests added for trace conversion and roundtrip verification.
Phase 2 features: - Permutation genome type with Fugue trace integration - PMX (Partially Mapped Crossover) for permutations - OX (Order Crossover) for permutations - CX (Cycle Crossover) for permutations - ERX (Edge Recombination Crossover) for permutations - Permutation mutation operators: swap, insert, inversion, scramble, displacement - Adaptive permutation mutation with operator weights - CMA-ES algorithm with full covariance matrix adaptation - Evolution paths (p_σ, p_c) - Step-size control (CSA) - Rank-1 and rank-μ covariance updates - Jacobi eigendecomposition - NSGA-II multi-objective optimization - Fast non-dominated sorting - Crowding distance calculation - Crowded comparison operator - Expanded benchmark suite: - ZDT1, ZDT2, ZDT3 multi-objective test problems - SchafferN1 bi-objective problem - Levy, Dixon-Price, Styblinski-Tang functions All 266 tests passing.
This commit adds deep integration with Fugue's probabilistic programming primitives and comprehensive hyperparameter adaptation mechanisms: Hyperparameter Module: - Parameter schedules (constant, linear, exponential, cosine, polynomial, cyclical) - Adaptive control (1/5 rule, adaptive operator selection, diversity-based) - Self-adaptive evolution strategies (isotropic, non-isotropic, correlated) - Bayesian hyperparameter learning (Beta, Gamma, LogNormal posteriors) Fugue Integration Module: - Trace-based mutation operators (uniform, single-site, multi-site selectors) - Trace-based crossover operators (uniform, single-point, two-point masks) - Effect handlers (logging, rate-limiting, conditional, composed handlers) - Evolution models (MCMC evolution, SMC, HBGA) Key features: - Treats evolution as Bayesian inference over solution spaces - Fitness as likelihood for probabilistic selection - Poutine-style effect handlers for intercepting/modifying operators - Sequential Monte Carlo (SMC) for evolutionary inference - Hierarchical Bayesian GA (HBGA) with automatic hyperparameter adaptation All 315 tests pass.
Add the following Phase 4 components: 1. Checkpointing with version compatibility: - Checkpoint state serialization (JSON, Binary, CompressedBinary) - CheckpointManager for automatic saving with rotation - Version checking for forward compatibility - RLE compression for binary format 2. Island model parallelism: - Multiple population islands with independent evolution - Migration topologies: Ring, FullyConnected, Random, Star - Migration policies: Best(k), Random(k), BestReplaceWorst(k) - Parallel evolution using rayon 3. Convergence detection suite: - ConvergenceDetector with configurable criteria - R-hat statistic for multi-run convergence - ESS (Effective Sample Size) for SMC - Fitness stagnation detection - Population diversity thresholds - TerminationCriteria builder pattern 4. Tree genomes for genetic programming: - Generic TreeNode<T, F> for Terminal/Function types - ArithmeticTerminal (Variable, Constant, ERC) - ArithmeticFunction (Add, Sub, Mul, Div, Sin, etc.) - Protected operations (div by zero, sqrt of negative) - Full, Grow, and Ramped Half-and-Half initialization - S-expression serialization 5. Adaptive operator selection (verified existing): - AdaptiveOperatorSelection with fitness-based credit - OneFifthRule for step-size adaptation - AdaptiveMutationRate - DiversityBasedAdaptation All 370 tests pass.
- Add comprehensive examples: - sphere_optimization: Basic continuous optimization - rastrigin_benchmark: Multimodal function optimization - cma_es_example: CMA-ES for Rosenbrock - island_model: Parallel island model - checkpointing: Save/restore evolution state - symbolic_regression: GP with tree genomes - hyperparameter_learning: Bayesian hyperparameter adaptation - Add README with: - Quick start guide - Feature overview - Algorithm descriptions - Example usage
Adds comprehensive property tests for: - RealVector: dimension preservation, bounds, trace roundtrip, distance - BitString: dimension, count consistency, trace roundtrip - Permutation: validity, element coverage, trace roundtrip - Bounds: clamping, containment, multi-bounds dimension - Operators: SBX crossover, tournament selection - Fitness: Sphere and Rastrigin optimum properties - Population: size maintenance, best fitness ordering
- Fix CMA-ES test: use seeded RNG for deterministic behavior - Fix checkpoint manager: sort by filename index instead of mtime - Add CHANGELOG.md documenting all v0.1.0 features
- Run cargo fmt on all code - Add clippy allows for intentional patterns in lib.rs - Fix doc comments with unescaped brackets (array syntax) - Fix test assertion with logic bug (|| true) - Auto-fix simple clippy suggestions
alexnodeland
deleted the
claude/tdd-prd-implementation-01LMu66uYzAvMSTAM3Jx7dXp
branch
December 12, 2025 17:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit implements the core foundation of the probabilistic genetic
algorithm library following test-driven development practices.
Components implemented:
All 184 unit tests pass.