Skip to content

Commit

Permalink
Merge pull request #16 from TLmaK0/feature/telemetry
Browse files Browse the repository at this point in the history
Feature/telemetry
  • Loading branch information
TLmaK0 authored Jan 3, 2017
2 parents 6c9c95a + 4b18f0a commit 18b4fbf
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ Cargo.lock
# Vim
*.swp
*.swo

# Fmt
**/*.rs.bk
22 changes: 12 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
sudo: false
language: rust
rust:
- stable
- beta
- stable
- beta
os:
- linux
- osx
- linux
- osx
cache: cargo
before_cache:
- cargo prune
- cargo prune
env:
global:
- PATH=$PATH:$HOME/.cargo/bin
- RUST_BACKTRACE=1
before_script:
- |
(which cargo-install-update && cargo install-update cargo-update) || cargo install cargo-update &&
(which rustfmt && cargo install-update rustfmt) || cargo install rustfmt &&
(which cargo-prune && cargo install-update cargo-prune) || cargo install cargo-prune
- |
(which cargo-install-update && cargo install-update cargo-update) || cargo install cargo-update &&
(which rustfmt && cargo install-update rustfmt) || cargo install rustfmt &&
(which cargo-prune && cargo install-update cargo-prune) || cargo install cargo-prune
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export DEP_OPENSSL_INCLUDE=`brew --prefix openssl`/include; fi
script:
- if [ "${TRAVIS_RUST_VERSION}" = stable ]; then
(
Expand Down
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ lazy_static = "0.2.2"
num_cpus = "1.0"
rand = "0.3"
rulinalg = "0.3.4"
rusty_dashed = "0.1.2"
rustc-serialize = "0.3.21"

[dependencies.clippy]
optional = true
version = "0.0.103"

[features]
default = []
telemetry = []
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ To speed up tests, run them with `--release` (XOR classification/simple_sample s
```
## Run example

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

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

## Sample usage

Expand Down Expand Up @@ -70,3 +72,9 @@ fn main() {
}

```

# Develop
Check style guidelines with:

`cargo install rustfmt`
`cargo fmt -- --write-mode=diff`
22 changes: 21 additions & 1 deletion examples/simple_sample.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
extern crate rustneat;
#[macro_use]
extern crate rusty_dashed;

extern crate rand;

use rustneat::Environment;
use rustneat::Organism;
use rustneat::Population;
use rusty_dashed::Dashboard;


struct XORClassification;

Expand All @@ -17,11 +24,24 @@ impl Environment for XORClassification {
distance += (1f64 - output[0]).abs();
organism.activate(&vec![1f64, 1f64], &mut output);
distance += (0f64 - output[0]).abs();
(4f64 - distance).powi(2)

let fitness = (4f64 - distance).powi(2);

fitness
}
}

fn main() {
let mut dashboard = Dashboard::new();
dashboard.add_graph("fitness1", "fitness", 0, 0, 4, 4);
dashboard.add_graph("network1", "network", 4, 0, 4, 4);

rusty_dashed::Server::serve_dashboard(dashboard);


#[cfg(feature = "telemetry")]
println!("\nGo to http://localhost:3000 to see how neural network evolves\n");

let mut population = Population::create_population(150);
let mut environment = XORClassification;
let mut champion: Option<Organism> = None;
Expand Down
9 changes: 9 additions & 0 deletions graphs/fitness.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
svg {
width: 100%;
height: 100%;
}

svg path {
stroke: black;
fill: none;
}
51 changes: 51 additions & 0 deletions graphs/fitness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var fitnessAxis = {};
function fitness_init(id){
var svg = d3.select('#' + id).append('svg');
svg.append('path');

fitnessAxis[id+"y"] = svg.append("g");
fitnessAxis[id+"x"] = svg.append("g");
}

var fitnessData = {};

function fitness(id, value){
if (!fitnessData[id]){
fitnessData[id] = [];
for(i = 0; i < 100; i++){
fitnessData[id].push(0);
}
}

fitnessData[id].shift();
fitnessData[id].push(value);

var data = fitnessData[id];

var svg = d3.select('#' + id).select('svg');
var path = svg.select('path');

var width = $('#' + id).children().width(),
height = $('#' + id).children().height();

var y = d3.scaleLinear()
.range([height, 0])
.domain([-1, 17]);

var x = d3.scaleLinear()
.range([0, width])
.domain([data.length, 0]);


var lineChart = d3.line()
.x(function(d, i){ return x(i) })
.y(function(d){ return y(d) });

var yAxis = d3.axisLeft(y);
var xAxis = d3.axisBottom(x);

fitnessAxis[id+'y'].attr("transform", "translate(30,0)").call(yAxis);
fitnessAxis[id+'x'].attr("transform", "translate(30,"+ (height - 19) + ")").call(xAxis);

path.attr("transform", "translate(30,0)").attr("d", lineChart(data));
}
15 changes: 15 additions & 0 deletions graphs/network.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.links line {
stroke: #999;
stroke-opacity: 0.6;
}

.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}

svg {
width: 100%;
height: 100%;
}

Loading

0 comments on commit 18b4fbf

Please sign in to comment.