Struct set_genome::Genome
source · pub struct Genome {
pub inputs: Genes<Node>,
pub hidden: Genes<Node>,
pub outputs: Genes<Node>,
pub feed_forward: Genes<Connection>,
pub recurrent: Genes<Connection>,
}
Expand description
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§
source§impl Genome
impl Genome
sourcepub fn new(structure: &Structure) -> Self
pub fn new(structure: &Structure) -> Self
Creates a new genome according to the Structure
it is given.
It generates all necessary identities based on an RNG seeded from a hash of the I/O configuration of the structure.
This allows genomes of identical I/O configuration to be crossed over in a meaningful way.
sourcepub fn nodes(&self) -> impl Iterator<Item = &Node>
pub fn nodes(&self) -> impl Iterator<Item = &Node>
Returns an iterator over references to all node genes (input + hidden + output) in the genome.
pub fn contains(&self, id: Id) -> bool
sourcepub fn connections(&self) -> impl Iterator<Item = &Connection>
pub fn connections(&self) -> impl Iterator<Item = &Connection>
Returns an iterator over references to all connection genes (feed-forward + recurrent) in the genome.
sourcepub fn init(&mut self, structure: &Structure)
pub fn init(&mut self, structure: &Structure)
Initializes a genome, i.e. connects the in the Structure
configured percent of inputs to all outputs by creating connection genes with random weights.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the sum of connection genes inside the genome (feed-forward + recurrent).
sourcepub fn cross_in(&self, other: &Self) -> Self
pub fn cross_in(&self, other: &Self) -> Self
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
.
sourcepub fn would_form_cycle(&self, start_node: &Node, end_node: &Node) -> bool
pub fn would_form_cycle(&self, start_node: &Node, end_node: &Node) -> bool
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
?
sourcepub fn has_alternative_input(&self, node: Id, exclude: Id) -> bool
pub fn has_alternative_input(&self, node: Id, exclude: Id) -> bool
Check if a node gene has more than one connection gene pointing to it.
sourcepub fn has_alternative_output(&self, node: Id, exclude: Id) -> bool
pub fn has_alternative_output(&self, node: Id, exclude: Id) -> bool
Check if a node gene has more than one connection gene leaving it.
source§impl Genome
impl Genome
sourcepub fn uninitialized(parameters: &Parameters) -> Self
pub fn uninitialized(parameters: &Parameters) -> Self
Initialization connects the configured percent of inputs nodes to output nodes, i.e. it creates connection genes with random weights.
pub fn initialized(parameters: &Parameters) -> Self
sourcepub fn mutate(&mut self, parameters: &Parameters) -> MutationResult
pub fn mutate(&mut self, parameters: &Parameters) -> MutationResult
Apply all mutations listed in the Parameters
with respect to their chance of happening.
If a mutation is listed multiple times it is applied multiple times.
This will probably be the most common way to apply mutations to a genome.
Examples
use set_genome::{Genome, Parameters};
// Create parameters, usually read from a configuration file.
let parameters = Parameters::default();
// Create an initialized `Genome`.
let mut genome = Genome::initialized(¶meters);
// Randomly mutate the genome according to the available mutations listed in the parameters of the context and their corresponding chances .
genome.mutate(¶meters);
Trait Implementations§
source§impl<'de> Deserialize<'de> for Genome
impl<'de> Deserialize<'de> for Genome
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl NetworkLike<Node, Connection> for Genome
impl NetworkLike<Node, Connection> for Genome
source§impl PartialEq<Genome> for Genome
impl PartialEq<Genome> for Genome
source§impl Recurrent<Node, Connection> for Genome
impl Recurrent<Node, Connection> for Genome
fn recurrent_edges(&self) -> Vec<&Connection>
impl Eq for Genome
impl StructuralEq for Genome
impl StructuralPartialEq for Genome
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.