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>
outputs: Genes<Node>
feed_forward: Genes<Connection>
recurrent: Genes<Connection>
Implementations
impl Genome
[src]
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]
genome_0: &Self,
genome_1: &Self,
factor_genes: f64,
factor_weights: f64,
factor_activations: f64,
weight_cap: f64
) -> (f64, f64, f64, f64)
impl Genome
[src]
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]
&mut self,
context: &mut GenomeContext
) -> Result<(), &'static str>
Calls the Mutations::remove_node
with self
.
pub fn add_connection_with_context(
&mut self,
context: &mut GenomeContext
) -> Result<(), &'static str>
[src]
&mut self,
context: &mut GenomeContext
) -> Result<(), &'static str>
Calls the Mutations::add_connection
with self
.
pub fn add_recurrent_connection_with_context(
&mut self,
context: &mut GenomeContext
) -> Result<(), &'static str>
[src]
&mut self,
context: &mut GenomeContext
) -> Result<(), &'static str>
Calls the Mutations::add_recurrent_connection
with self
.
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<'de> Deserialize<'de> for Genome
[src]
impl<'de> Deserialize<'de> for Genome
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl RefUnwindSafe for Genome
impl RefUnwindSafe for Genome
impl UnwindSafe for Genome
impl UnwindSafe for Genome