Skip to main content

Module boolean

Module boolean 

Source
Expand description

Boolean problems: Koza’s multiplexer and even-parity functions, learned from their whole truth tables.

Each is a fitness function for trees of its paper’s primitives, Logic, in the set its primitives gives: the number of cases of the truth table that a tree gets wrong, minimized, 0 at the optimum (Koza’s standardized fitness). The trees are evaluated on 64 cases at once, a bit per case in a u64, with Tree::evaluate.

use genoxide::gp::boolean::Multiplexer;
use genoxide::gp::{Gp, SubtreeCrossover, SubtreeMutation};
use genoxide::prelude::*;

// the 6-multiplexer: 2 address bits select one of 4 data bits
let problem = Multiplexer::new(2)?;
let gp = Gp::builder(problem.primitives().clone()).build()?;
let ga = Ga::builder(gp)
    .population_size(500)
    .select(Tournament::new(7)?)
    .crossover(SubtreeCrossover::new())
    .mutate(SubtreeMutation::new())
    .mutation_rate(0.1)
    .minimize()
    .seed(1)
    .build()?;
let outcome = Engine::new(ga, problem)
    .stop_when(Stop::target(0.0).or(Stop::generations(50)))
    .run()?;
assert_eq!(outcome.best_fitness(), Fitness::new(0.0)); // all 64 cases right

They are among the problems that McDermott et al. (2012, Genetic programming needs better benchmarks, GECCO 2012: 791-798) found overused; they stay GP’s classic tests with an exact optimum.

Structs§

EvenParity
The even-parity function of Koza (1992): true when an even number of the n inputs are true. Even-3 to even-5 parity are the usual sizes; each input more doubles the cases and makes it much harder.
Multiplexer
The Boolean multiplexer of Koza (1992): k address bits select one of 2^k data bits, which is the output. The 11-multiplexer (k = 3, 2048 cases) is Koza’s; the 6-multiplexer (k = 2) is a smaller version.

Enums§

Logic
The primitives of the Boolean problems: Koza’s (1992) functions, and the inputs.