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>§hidden: Genes<Node>§outputs: Genes<Node>§feed_forward: Genes<Connection>§recurrent: Genes<Connection>

Implementations§

source§

impl Genome

source

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.

source

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

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

source

pub fn contains(&self, id: Id) -> bool

source

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

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

source

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.

source

pub fn len(&self) -> usize

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

source

pub fn is_empty(&self) -> bool

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

source

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.

source

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?

source

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.

source

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

pub fn dot(genome: &Self) -> String

Get the encoded neural network as a string in DOT format.

The output can be visualized here for example.

source§

impl Genome

source

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.

source

pub fn initialized(parameters: &Parameters) -> Self

source

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(&parameters);

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

Trait Implementations§

source§

impl Clone for Genome

source§

fn clone(&self) -> Genome

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Genome

source§

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

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

impl Default for Genome

source§

fn default() -> Genome

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Genome

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Hash for Genome

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl NetworkLike<Node, Connection> for Genome

source§

fn nodes(&self) -> Vec<&Node>

source§

fn edges(&self) -> Vec<&Connection>

source§

fn inputs(&self) -> Vec<&Node>

source§

fn outputs(&self) -> Vec<&Node>

source§

fn hidden(&self) -> Vec<&Node>

source§

impl PartialEq<Genome> for Genome

source§

fn eq(&self, other: &Genome) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Recurrent<Node, Connection> for Genome

source§

impl Serialize for Genome

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Genome

source§

impl StructuralEq for Genome

source§

impl StructuralPartialEq for Genome

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

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

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,