Skip to content

Need for speed

Latest

Choose a tag to compare

@pkalivas pkalivas released this 14 Nov 21:14
· 2 commits to master since this release

I feel the need, the need for speed.

Highlights

  • Built-in datasets for classification and regression.
  • New crossover and mutation operators for permutations, floats, and trees.
  • Batch evaluation for graphs and trees.
  • Packed bit chromosomes for large bit strings.
  • Novelty search now supports any descriptor type.
  • Less random_provider locking - performance, performance, performance.

Added

  • Built-in datasets. DataSet (Rust) and rd.DataSet (Python) come with ready-made problems: classification (iris, xor, parity, moons, circles, spirals, simple_memory) and regression (cubic, koza1, nguyen7, pagie1; friedman1 is Rust only). Random datasets respect the global seed. DataSet moved from radiate_gp to radiate_utils and is re-exported from radiate. standardize()/normalize() now take &mut self.
  • New operators:
    • OrderCrossover (OX1) for permutations. Python: Cross.order().
    • DifferentialCrossover (DE/rand/1/bin) for floats. Python: Cross.differential(rate, weight, crossover_rate).
    • SubtreeMutator for trees. Python: Mutate.subtree().
    • TreeDistance for speciating trees. Python: Dist.tree(). Tree speciation was previously unsupported in Python.
  • Batch graph and tree evaluation. Graphs compile to a reusable evaluation plan, and both graphs and trees can evaluate a whole dataset column-wise in one call. Regression now always evaluates this way. This is orders of magnitude faster, especially for larger datasets.
  • New GP ops: Op::erc() (ephemeral random constant), Op::dot(), Op::one()/two()/three().
  • PackedBitChromosome for large bit strings. Stores 64 bits per u64 word (BitWordGene), using 8× less memory than BitChromosome. Comes with PackedBitCodec, bit-level operators (BitFlipMutator, PackedBitCrossover, PackedBitMultiPointCrossover) and PackedBitHammingDistance. The generic crossovers, mutators and HammingDistance also compile against it but act on whole 64-bit words, so prefer the packed versions.
  • Python: Engine.packed_bit(num_bits, use_numpy=False, *, words=False) and PackedBitCodec. By default the fitness function gets bits, exactly like Engine.bit. With words=True it gets the packed 64-bit words instead. Paired with use_numpy=True, that runs up to ~10× faster than Engine.bit at 100k bits. Prefer this for large bit strings.
  • Novelty search works with any descriptor type. Novelty<T, D> and NoveltySearch<T, D> take a descriptor type D (default Vec<f32>), compared by any Distance<D>. For example, packed bit strings can use their raw words with a bit-level distance: NoveltySearch::new(|w: &Vec<u64>| w.clone(), PackedBitHammingDistance). PackedBitHammingDistance now also measures raw [u64]/Vec<u64> words (normalized by words * 64, assuming cleared tail bits as PackedBitCodec produces). PackedBitChromosome::to_words() returns those words.

Changed

  • One fitness_fn to rule them all. The builder infers single, batch, or raw-genotype evaluation from the function's signature. batch_fitness_fn, raw_fitness_fn and raw_batch_fitness_fn are deprecated. Closures no longer implement FitnessFunction/BatchFitnessFunction directly. A batch function returning the wrong number of scores is now an error instead of silently dropping individuals. In reality, this should be a relatively small change and a nice API cleanup.
  • Python: Generation getters are properties (breaking). result.value(), result.score(), result.index() etc. become result.value, result.score, result.index.
  • Python: numpy batch fitness gets a single array of shape (n, genes) (or (n, chromosomes, genes)) instead of a list of arrays, and may return a numpy array of scores. Decode errors and invalid limits, filters or distances now raise instead of being silently ignored.
  • GP op changes (breaking). weight2 is renamed to dot, linear is replaced by sum, Op::constant takes a name, and the bool ops eq, ne, le and iff are removed. Saved graphs or trees that use the old names will no longer deserialize. Op outputs are now clamped to ±1e7 for f32 (was ±1e10).
  • GP graph API (breaking). Node indices are NodeIdx instead of usize, NodeStore is renamed to NodeSet, and graph and GraphCodec constructors return Result. set_cycles() no longer takes arguments.
  • GraphMutator no longer adds recurrent edges by default. Use .allow_recurrent() (Python: Mutate.graph(allow_recurrent=True)) to restore the old behavior.
  • GP trees (breaking). TreeChromosome holds a single root, and TreeCodec's constraint/with_tree are replaced by max_size (default 200 nodes).
  • Python: GraphCodec and TreeCodec no longer fill in default ops. Pass vertex, edge, output/root explicitly. I would flag this as a bug fix in reality - OPs should be explicit.
  • Score is now an enum (Single/Multi, breaking). Its arithmetic operators, Sum and string conversions are removed. This is another micro-optimization that speeds up single objective and makes multi-objective more type aware.
  • Species offspring are shared out by normalized score. The weakest species no longer gets zero offspring. Seeded speciated runs will differ, but speciated runs should produce more reliable and better results.
  • Smaller removals and renames (breaking): StochasticUniversalSamplingSelector is now SUSSelector (Python: Select.sus()), CompositeFitnessFn objectives must return f32, pareto::entropy is replaced by pareto::spacing_entropy, EngineExt::run is removed, and EventStream::attatch is now attach.
  • Python: chromosome reprs are consistent across types, e.g. Chromosome(FloatGene, dtype=Float64, len=3, [0.5, 1.25, 2.0]), with long chromosomes truncated. Genotype, phenotype and population reprs use it. Graph and tree chromosomes are unchanged.
  • Diversity merged into Distance (breaking). Speciation now takes any Distance<Phenotype<C>>, so one trait covers both speciation and novelty search. Replace impl Diversity<C> for X { fn measure(...) } with impl Distance<Phenotype<C>> for X { fn calculate(...) }. The diversity module is renamed to distance, and Distance is exported from the crate root and prelude. The builder's .diversity(...) method is unchanged.
  • NoveltySearch always takes an explicit distance (breaking). NoveltySearch::new(behavior) becomes NoveltySearch::new(behavior, distance), and .cosine_distance()/.euclidean_distance()/.hamming_distance() are replaced by .distance_fn(d). from_batch_fn and batch evaluation of NoveltySearch are removed. HammingDistance, EuclideanDistance and CosineDistance no longer implement Novelty; when the decoded value is the descriptor, pass |v: &Vec<f32>| v.clone(). Note: the old NoveltySearch::new(CosineDistance) or new(HammingDistance) used the distance type only as the descriptor and actually ran with Euclidean distance. To keep the same results, migrate it to NoveltySearch::new(|v: &Vec<f32>| v.clone(), EuclideanDistance). Python is unaffected.
  • Seeded runs produce different results for JitterMutator, PolynomialMutator, SwapMutator and OperationMutator, which now pick genes with bernoulli_indices, and for the fixes below.

Fixed

  • EdgeRecombinationCrossover didn't follow edges. It picked the globally lowest-degree node instead of a neighbor of the current one. It now implements standard edge recombination, so permutation (e.g. TSP) results improve and differ.
  • LinearRankSelector ignored pressure. It now uses standard linear ranking, and pressure must be in [1.0, 2.0].
  • HoistMutator ignored its rate and hoisted every chromosome.
  • GP Accuracy evaluated the dataset twice, so recurrent graphs reported loss and accuracy from different predictions. Precision, recall and F1 are now macro-averaged per class.
  • Python: Select.select() and Alter.alter() assumed a fixed dtype per gene type, mishandling e.g. float32 or int32 populations.
  • Python: TreeCodec ignored its leaf argument.
  • GaussianMutator ignored a gene's bounds. Mutated values were clamped to the gene's sampling range (value_range) instead of its bounds, so a gene with wider bounds could never be moved past its initial range by Gaussian mutation, and a gene already outside it was pulled back in. Values are now clamped only to bounds. The noise is unchanged: the standard deviation is still 25% of the sampling range, so mutations stay local. Genes without explicit bounds behave exactly as before; seeded runs with bounds wider than the sampling range will produce different results.

What's Changed

Full Changelog: v1.3.2...v1.3.3