Crate set_genome

source ·
Expand description

This crate is supposed to act as the representation/reproduction aspect in neuroevolution algorithms and may be combined with arbitrary selection mechanisms.

What you can do with this crate

// Setup a genome context for networks with 10 inputs and 10 outputs.
let parameters = Parameters::basic(10, 10);

// Initialize a genome.
let mut genome = Genome::initialized(&parameters);

// Mutate a genome.
genome.mutate(&parameters);

// Get a phenotype of the genome.
let network = MatrixFeedforwardFabricator::fabricate(&genome).expect("Cool network.");

// Evaluate a network on an input.
let output = network.evaluate(dmatrix![0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]);

SET genome

SET stands for Set Encoded Topology and this crate implements a genetic data structure, the Genome, using this set encoding to describe artificial neural networks (ANNs). Further this crate defines operations on this genome, namely Mutations and crossover. Mutations alter a genome by adding or removing genes, crossover recombines two genomes. To have an intuitive definition of crossover for network structures the NEAT algorithm defined a procedure and has to be understood as a mental predecessor to this SET encoding, which very much is a formalization and progression of the ideas NEAT introduced regarding the genome. The thesis describing this genome and other ideas can be found here, a paper focusing just on the SET encoding will follow soon.

Getting started

We start by defining our parameters:

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::{activations::Activation, Parameters, Structure};

let parameters = Parameters {
    structure: Structure {
        // ten inputs
        number_of_inputs: 10,
        // two outputs
        number_of_outputs: 2,
        // 100% connected
        percent_of_connected_inputs: 1.0,
        // specified output activation
        outputs_activation: Activation::Tanh,
        // seed for initial genome construction
        seed: 42
    },
    mutations: vec![],
};

This allows us to create an initialized genome which conforms to our description above:

          // seed for initial genome construction
          seed: 42
let genome_with_connections = Genome::initialized(&parameters);

“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:

          // seed for initial genome construction
          seed: 42

let genome_without_connections = Genome::uninitialized(&parameters);

Setting the percent_of_connected_inputs 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.

The possible mutations:

//! # Features

This crate exposes the ‘favannat’ feature. favannat is a library to translate the genome into an executable form and also to execute it. It can be seen as a phenotype of the genome. The feature is enabled by default as probably you want to evaluate your evolved genomes, but disabling it is as easy as this:

[dependencies]
set-genome = { version = "x.x.x", default-features = false }

If you are interested how they connect, see here. favannat can be used to evaluate other data structures of yours, too, if they are favannat::network::NetworkLike. ;)

Modules

Structs

  • Mechanism to compute distances between genomes.
  • Struct describing a ANN connection.
  • This is the core data structure this crate revoles around.
  • Identity of ANN structure elements.
  • Struct describing a ANN node.
  • This struct captures configuration about the basic ANN structure and available mutations.
  • This struct describes the invariants of the ANN structure.

Enums

Type Definitions