/rustneat

Rust Neat - NeuroEvolution of Augmenting Topologies

Primary LanguageRustMIT LicenseMIT

Rust NEAT

travis-ci Gitter

Implementation of NeuroEvolution of Augmenting Topologies NEAT http://nn.cs.utexas.edu/downloads/papers/stanley.ec02.pdf

This implementations uses a CTRNN based onOn the Dynamics of Small Continuous-Time Recurrent Neural Network (Beer, 1995) http://www.cs.uvm.edu/~jbongard/2014_CS206/Beer_CTRNNs.pdf

telemetry

Run test

To speed up tests, run them with --release (XOR classification/simple_sample should take less than a minute)

cargo test --release

Run example

cargo run --release --example simple_sample --features=telemetry

then go to http://localhost:3000 to see how neural network evolves

telemetry

Run openai tests

telemetry

Install python dependencies

sudo apt install python3
sudo apt install python3-pip
sudo apt install libpython3.5-dev
sudo pip3 install gym
sudo apt install nvidia-384
sudo apt install python3-opengl

Run test

cargo run --release --example openai --features=openai,telemetry

Windows Openai

openai/gym#11 (comment)

Update to the latest version of Windows (>version 1607, "Anniversary Update")
Enable Windows Subsystem for Linux (WSL)
Open cmd, run bash
Install python & gym (using sudo, and NOT PIP to install gym). So by now you should probably be able to run things and get really nasty graphics related errors. This is because WSL doesn't support any displays, so we need to fake it.
Install vcXsrv, and run it (you should just have a little tray icon)
In bash run "export DISPLAY=:0" Now when you run it you should get a display to pop-up, there may be issues related to graphics drivers. Sadly, this is where the instructions diverge if you don't have an NVIDIA graphics card.
Get the drivers: "sudo apt-get install nvidia-319 nvidia-settings-319 nvidia-prime"
Run!

Sample usage

Create a new cargo project:

Add rustneat to Cargo.toml

[dependencies]
rustneat = "0.2.1"

Then use the library i.e. to implement the above example, use the library as follows:

extern crate rustneat;
use rustneat::Environment;
use rustneat::Organism;
use rustneat::Population;

struct XORClassification;

impl Environment for XORClassification {
    fn test(&self, organism: &mut Organism) -> f64 {
        let nn = organism.make_network();
        let mut output = vec![0f64];
        let mut distance: f64;
        nn.activate(&vec![0f64, 0f64], &mut output);
        distance = (0f64 - output[0]).abs();
        nn.activate(&vec![0f64, 1f64], &mut output);
        distance += (1f64 - output[0]).abs();
        nn.activate(&vec![1f64, 0f64], &mut output);
        distance += (1f64 - output[0]).abs();
        nn.activate(&vec![1f64, 1f64], &mut output);
        distance += (0f64 - output[0]).abs();
        (4f64 - distance).powi(2)
    }
}

fn main() {
    let mut population = Population::create_population(150);
    let mut environment = XORClassification;
    let mut champion: Option<Organism> = None;
    while champion.is_none() {
        population.evolve();
        population.evaluate_in(&mut environment);
        for organism in &population.get_organisms() {
            if organism.fitness > 15.9f64 {
                champion = Some(organism.clone());
            }
        }
    }
    println!("{:?}", champion.unwrap().genome);
}

Develop

Check style guidelines with:

rustup component add rustfmt-preview cargo fmt -- --write-mode=diff

Thanks

Thanks for the icon nerves by Delwar Hossain from the Noun Project