Skip to main content

Multiplexer

Struct Multiplexer 

Source
pub struct Multiplexer { /* private fields */ }
Expand description

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.

Its primitives are Koza’s: the functions and, or, not and if (of three arguments), and the inputs a0 to a{k-1} (the address, a0 its least significant bit), then d0 to d{2^k-1} (the data). One type: the untyped genetic programming of the paper.

use genoxide::gp::boolean::Multiplexer;

let problem = Multiplexer::new(3)?; // Koza's 11-multiplexer
assert_eq!((problem.inputs(), problem.cases()), (11, 2048));
let set = problem.primitives();
// the right output everywhere: the data bit that the address selects
let tree = set.parse(
    "if(a2, if(a1, if(a0, d7, d6), if(a0, d5, d4)), if(a1, if(a0, d3, d2), if(a0, d1, d0)))",
)?;
assert_eq!(problem.errors(&tree), 0);
// one data bit is right in the cases that select it, and in half the others
assert_eq!(problem.errors(&set.parse("d0")?), 896);

Implementations§

Source§

impl Multiplexer

Source

pub fn new(address_bits: usize) -> Result<Self>

The multiplexer of address_bits address bits, 1 to 4: the 3-, 6-, 11- and 20-multiplexer.

§Errors

Error::InvalidSetting (setting address_bits) for 0 or more than 4 address bits.

Source

pub fn address_bits(&self) -> usize

The number of address bits.

Source

pub fn reference(&self) -> &'static str

Koza (1992), the source of the problem and its primitives.

Source§

impl Multiplexer

Source

pub fn primitives(&self) -> &PrimitiveSet<Logic>

The primitive set of the paper, over Logic: build a Gp from it, so the trees’ primitives are the problem’s.

Source

pub fn inputs(&self) -> usize

The number of inputs.

Source

pub fn cases(&self) -> u64

The number of cases of the truth table, 2^inputs. In case c, input i (in the order of the set’s terminals) is bit i of c.

Source

pub fn targets(&self) -> &[u64]

The right outputs, 64 cases per word: case c at bit c % 64 of word c / 64.

Source

pub fn outputs(&self, tree: &Tree) -> Vec<u64>

The tree’s outputs, as targets lays them out.

§Panics

If the tree has primitives that aren’t the problem’s.

Source

pub fn errors(&self, tree: &Tree) -> u64

The number of cases the tree gets wrong: the fitness, 0 at the optimum.

§Panics

If the tree has primitives that aren’t the problem’s.

Trait Implementations§

Source§

impl Clone for Multiplexer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Multiplexer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FitnessFunction<Tree> for Multiplexer

Source§

fn evaluate(&self, tree: &Tree) -> f64

The number of cases the tree gets wrong, minimized.

Source§

type Output = f64

The type of a score.
Source§

fn is_batch(&self) -> bool

Whether the engine evaluates a generation with one call of evaluate_batch (true) rather than one call of evaluate per genome, in parallel if asked (false, the default). See Batch.
Source§

fn evaluate_batch(&self, genomes: &[&G]) -> Vec<Self::Output>

The scores of genomes, in their order: one evaluate each by default. Override it, and is_batch, to evaluate a generation at once, e.g. on a GPU.
Source§

fn provides(&self) -> Provided

What the function gives besides the fitness, such as the gradient of the score: nothing by default. An algorithm that needs an extra checks it once per run in Algorithm::prepare. Declare an extra here, and write it in evaluate_with.
Source§

fn evaluate_with(&self, genome: &G, extras: &mut Extras<'_>) -> Self::Output

The score of genome, with the extras that extras has buffers for (only ones that provides declares). The engine calls it instead of evaluate when the algorithm wants extras. The score must be the same as evaluate’s, to the bit. By default, evaluate(genome). Read more
Source§

fn evaluate_batch_with( &self, genomes: &[&G], extras: &mut BatchExtras<'_>, ) -> Vec<Self::Output>

The scores of genomes, in their order, with the extras that extras has buffers for, a row per genome. The engine calls it instead of evaluate_batch for a batch function when the algorithm wants extras. By default, evaluate_batch(genomes) without extras, and one evaluate_with each otherwise.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more