Struct set_genome::GenomeContext[][src]

pub struct GenomeContext {
    pub id_gen: IdGenerator,
    pub rng: GenomeRng,
    pub parameters: Parameters,
    // some fields omitted
}

This struct simplifies operations on the Genome.

The GenomeContext wraps all required building blocks to create and initialize genomes while maintaining consistent identities of their parts across operations. It is used in a simplified API to perform operations on genomes, as it handles all necessary moving parts for you.

Examples

Creating a default genome context:

use set_genome::GenomeContext;

let genome_context = GenomeContext::default();

Creating the context like this is unusual as we most likely want to pass it parameters fitting our situation.

Suppose we know our task has ten inputs and two outputs, which translate to the input and output layer of our ANN. Further we want 100% of our inputs nodes to be initially connected to the outputs and the outputs shall use the activations::Activation::Tanh function. Also the weights of our connections are supposed to be capped between [-1, 1] and change by deltas sampled from a normal distribution with 0.1 standard deviation.

use set_genome::{GenomeContext, activations::Activation, Parameters, Structure};

let parameters = Parameters {
    seed: None,
    structure: Structure {
        // ten inputs
        inputs: 10,
        // 100% connected
        inputs_connected_percent: 1.0,
        // two outputs
        outputs: 2,
        // specified output activation
        outputs_activation: Activation::Tanh,
        // delta distribution
        weight_std_dev: 0.1,
        // intervall constraint, applies as [-weight_cap, weight_cap]
        weight_cap: 1.0,
    },
    mutations: vec![],
};

let genome_context = GenomeContext::new(parameters);

This allows us to ask this context for an initialized genome which conforms to our description above:

let genome_with_connections = genome_context.initialized_genome();

“Initialized” here means the configured percent of connections have been constructed with random weights. “Uninitialized” thereby implys no connections have been constructed, such a genome is also available:

let genome_without_connections = genome_context.uninitialized_genome();

Setting the inputs_connected_percent field in the parameters::Structure parameter to zero makes the “initialized” and “uninitialized” genome look the same.

So we got ourselves a genome, let’s mutate it: Genome::mutate_with_context.

The possible mutations:

To evaluate the function encoded in the genome check this crate.

Fields

id_gen: IdGeneratorrng: GenomeRngparameters: Parameters

Implementations

impl GenomeContext[src]

pub fn new(parameters: Parameters) -> Self[src]

Returns a new GenomeContext from the parameters.

pub fn initialized_genome(&self) -> Genome[src]

Returns an initialized genome, see Genome::init_with_context.

pub fn uninitialized_genome(&self) -> Genome[src]

Returns an uninitialized genome, see Genome::init_with_context.

Trait Implementations

impl Default for GenomeContext[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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