Struct set_genome::Genome[][src]

pub struct Genome {
    pub inputs: Genes<Node>,
    pub hidden: Genes<Node>,
    pub outputs: Genes<Node>,
    pub feed_forward: Genes<Connection>,
    pub recurrent: Genes<Connection>,
}

This is the core data structure this crate revoles around.

A genome can be changed by mutation (a random alteration of its structure) or by crossing in another genome (recombining their matching parts). A lot of additional information explaining details of the structure can be found in the thesis that developed this idea. More and more knowledge from there will find its way into this documentaion over time.

Fields

inputs: Genes<Node>hidden: Genes<Node>outputs: Genes<Node>feed_forward: Genes<Connection>recurrent: Genes<Connection>

Implementations

impl Genome[src]

pub fn new(id_gen: &mut IdGenerator, structure: &Structure) -> Self[src]

Creates a new genome according to the Structure it is given. It generates all necessary identities from the IdGenerator.

pub fn nodes(&self) -> impl Iterator<Item = &Node>[src]

Returns an iterator over references to all node genes (input + hidden + output) in the genome.

pub fn connections(&self) -> impl Iterator<Item = &Connection>[src]

Returns an iterator over references to all connection genes (feed-forward + recurrent) in the genome.

pub fn init(&mut self, rng: &mut GenomeRng, structure: &Structure)[src]

Initializes a genome, i.e. connects the in the Structure configured percent of inputs to all outputs by creating connection genes with random weights.

pub fn len(&self) -> usize[src]

Returns the sum of connection genes inside the genome (feed-forward + recurrent).

pub fn is_empty(&self) -> bool[src]

Is true when no connection genes are present in the genome.

pub fn cross_in(&self, other: &Self, rng: &mut impl Rng) -> Self[src]

Cross-in another genome. For connection genes present in both genomes flip a coin to determine the weight inside the new genome. For node genes present in both genomes flip a coin to determine the activation function inside the new genome. Any structure not present in other is taken over unchanged from self.

pub fn would_form_cycle(&self, start_node: &Node, end_node: &Node) -> bool[src]

Check if connecting start_node and end_node would introduce a circle into the ANN structure. Think about the ANN as a graph for this, if you follow the connection arrows, can you reach start_node from end_node?

pub fn has_alternative_input(&self, node: Id, exclude: Id) -> bool[src]

Check if a node gene has more than one connection gene pointing to it.

pub fn has_alternative_output(&self, node: Id, exclude: Id) -> bool[src]

Check if a node gene has more than one connection gene leaving it.

pub fn compatability_distance(
    genome_0: &Self,
    genome_1: &Self,
    factor_genes: f64,
    factor_weights: f64,
    factor_activations: f64,
    weight_cap: f64
) -> (f64, f64, f64, f64)
[src]

Defines a distance metric between genomes, useful for other evolutionary mechanisms such as speciation used in NEAT. Expects three factors to tune to importance of several aspects contributing to the distance metric, for details read here.

impl Genome[src]

pub fn init_with_context(&mut self, context: &mut GenomeContext)[src]

Initialization connects the configured percent of inputs nodes to output nodes, i.e. it creates connection genes with random weights.

pub fn mutate_with_context(&mut self, context: &mut GenomeContext)[src]

Apply all mutations listed in the parameters of the context with respect to their chance of happening.

This will probably be the most common way to apply mutations to a genome.

Examples

use set_genome::GenomeContext;

// Create a `GenomeContext`.
let mut genome_context = GenomeContext::default();

// Create an initialized `Genome`.
let mut genome = genome_context.initialized_genome();

// Randomly mutate the genome according to the available mutations listed in the parameters of the context and their corresponding chances .
genome.mutate_with_context(&mut genome_context);

pub fn add_node_with_context(&mut self, context: &mut GenomeContext)[src]

Calls Mutations::add_node with self, should Mutations::AddNode be listed in the context. It needs to be listed as it provides parameters.

pub fn remove_node_with_context(
    &mut self,
    context: &mut GenomeContext
) -> Result<(), &'static str>
[src]

Calls the Mutations::remove_node with self.

pub fn add_connection_with_context(
    &mut self,
    context: &mut GenomeContext
) -> Result<(), &'static str>
[src]

Calls the Mutations::add_connection with self.

pub fn add_recurrent_connection_with_context(
    &mut self,
    context: &mut GenomeContext
) -> Result<(), &'static str>
[src]

pub fn change_activation_with_context(&mut self, context: &mut GenomeContext)[src]

Calls Mutations::change_activation with self, should Mutations::ChangeActivation be listed in the context. It needs to be listed as it provides parameters.

pub fn change_weights_with_context(&mut self, context: &mut GenomeContext)[src]

Calls Mutations::change_weights with self, should Mutations::ChangeWeights be listed in the context. It needs to be listed as it provides parameters.

Trait Implementations

impl Clone for Genome[src]

impl Debug for Genome[src]

impl Default for Genome[src]

impl<'de> Deserialize<'de> for Genome[src]

impl Serialize for Genome[src]

Auto Trait Implementations

impl RefUnwindSafe for Genome

impl Send for Genome

impl Sync for Genome

impl Unpin for Genome

impl UnwindSafe for Genome

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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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>,