Repository navigation
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_providerlocking - performance, performance, performance.
Added
- Built-in datasets.
DataSet(Rust) andrd.DataSet(Python) come with ready-made problems: classification (iris,xor,parity,moons,circles,spirals,simple_memory) and regression (cubic,koza1,nguyen7,pagie1;friedman1is Rust only). Random datasets respect the global seed.DataSetmoved fromradiate_gptoradiate_utilsand is re-exported fromradiate.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).SubtreeMutatorfor trees. Python:Mutate.subtree().TreeDistancefor 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.
Regressionnow 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(). PackedBitChromosomefor large bit strings. Stores 64 bits peru64word (BitWordGene), using 8× less memory thanBitChromosome. Comes withPackedBitCodec, bit-level operators (BitFlipMutator,PackedBitCrossover,PackedBitMultiPointCrossover) andPackedBitHammingDistance. The generic crossovers, mutators andHammingDistancealso 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)andPackedBitCodec. By default the fitness function gets bits, exactly likeEngine.bit. Withwords=Trueit gets the packed 64-bit words instead. Paired withuse_numpy=True, that runs up to ~10× faster thanEngine.bitat 100k bits. Prefer this for large bit strings. - Novelty search works with any descriptor type.
Novelty<T, D>andNoveltySearch<T, D>take a descriptor typeD(defaultVec<f32>), compared by anyDistance<D>. For example, packed bit strings can use their raw words with a bit-level distance:NoveltySearch::new(|w: &Vec<u64>| w.clone(), PackedBitHammingDistance).PackedBitHammingDistancenow also measures raw[u64]/Vec<u64>words (normalized bywords * 64, assuming cleared tail bits asPackedBitCodecproduces).PackedBitChromosome::to_words()returns those words.
Changed
- One
fitness_fnto rule them all. The builder infers single, batch, or raw-genotype evaluation from the function's signature.batch_fitness_fn,raw_fitness_fnandraw_batch_fitness_fnare deprecated. Closures no longer implementFitnessFunction/BatchFitnessFunctiondirectly. 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:
Generationgetters are properties (breaking).result.value(),result.score(),result.index()etc. becomeresult.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).
weight2is renamed todot,linearis replaced bysum,Op::constanttakes a name, and the bool opseq,ne,leandiffare removed. Saved graphs or trees that use the old names will no longer deserialize. Op outputs are now clamped to ±1e7 forf32(was ±1e10). - GP graph API (breaking). Node indices are
NodeIdxinstead ofusize,NodeStoreis renamed toNodeSet, and graph andGraphCodecconstructors returnResult.set_cycles()no longer takes arguments. GraphMutatorno longer adds recurrent edges by default. Use.allow_recurrent()(Python:Mutate.graph(allow_recurrent=True)) to restore the old behavior.- GP trees (breaking).
TreeChromosomeholds a single root, andTreeCodec'sconstraint/with_treeare replaced bymax_size(default 200 nodes). - Python:
GraphCodecandTreeCodecno longer fill in default ops. Passvertex,edge,output/rootexplicitly. I would flag this as a bug fix in reality - OPs should be explicit. Scoreis now an enum (Single/Multi, breaking). Its arithmetic operators,Sumand 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):
StochasticUniversalSamplingSelectoris nowSUSSelector(Python:Select.sus()),CompositeFitnessFnobjectives must returnf32,pareto::entropyis replaced bypareto::spacing_entropy,EngineExt::runis removed, andEventStream::attatchis nowattach. - 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. Diversitymerged intoDistance(breaking). Speciation now takes anyDistance<Phenotype<C>>, so one trait covers both speciation and novelty search. Replaceimpl Diversity<C> for X { fn measure(...) }withimpl Distance<Phenotype<C>> for X { fn calculate(...) }. Thediversitymodule is renamed todistance, andDistanceis exported from the crate root and prelude. The builder's.diversity(...)method is unchanged.NoveltySearchalways takes an explicit distance (breaking).NoveltySearch::new(behavior)becomesNoveltySearch::new(behavior, distance), and.cosine_distance()/.euclidean_distance()/.hamming_distance()are replaced by.distance_fn(d).from_batch_fnand batch evaluation ofNoveltySearchare removed.HammingDistance,EuclideanDistanceandCosineDistanceno longer implementNovelty; when the decoded value is the descriptor, pass|v: &Vec<f32>| v.clone(). Note: the oldNoveltySearch::new(CosineDistance)ornew(HammingDistance)used the distance type only as the descriptor and actually ran with Euclidean distance. To keep the same results, migrate it toNoveltySearch::new(|v: &Vec<f32>| v.clone(), EuclideanDistance). Python is unaffected.- Seeded runs produce different results for
JitterMutator,PolynomialMutator,SwapMutatorandOperationMutator, which now pick genes withbernoulli_indices, and for the fixes below.
Fixed
EdgeRecombinationCrossoverdidn'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.LinearRankSelectorignoredpressure. It now uses standard linear ranking, andpressuremust be in[1.0, 2.0].HoistMutatorignored its rate and hoisted every chromosome.- GP
Accuracyevaluated 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()andAlter.alter()assumed a fixed dtype per gene type, mishandling e.g.float32orint32populations. - Python:
TreeCodecignored itsleafargument. GaussianMutatorignored a gene'sbounds. Mutated values were clamped to the gene's sampling range (value_range) instead of itsbounds, 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 tobounds. 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
- clamping gaussian by bounds by @pkalivas in #31
- Feature/rd packed.01 by @pkalivas in #32
- PackedBitChromosomes initial build by @pkalivas in #33
- Feature/rd docs gene compats.01 by @pkalivas in #34
- Develop by @pkalivas in #35
- Feature/rd merge div dis.01 by @pkalivas in #37
- Develop by @pkalivas in #38
- Feature/rd cleaning.01 by @pkalivas in #39
Full Changelog: v1.3.2...v1.3.3