Skip to content

Update 1.0.0 #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
273b9fa
rename CONTRIBUTING
HyperCodec Apr 16, 2024
3f50d08
add flush_state to readme example
HyperCodec Apr 16, 2024
e6d1215
Merge pull request #47 from inflectrix/docfixes
HyperCodec Apr 16, 2024
a94198a
create basic log test
HyperCodec Apr 16, 2024
339b90b
create plotters example
HyperCodec Apr 16, 2024
5cddae7
small changes
HyperCodec Apr 16, 2024
728cbde
more configuration
HyperCodec Apr 16, 2024
91c3f9f
make plotting ng more generic
HyperCodec Apr 17, 2024
f6d0df0
fix test rayon feature
HyperCodec Apr 18, 2024
cc88ebf
cargo fmt
HyperCodec Apr 18, 2024
66391cc
Merge pull request #49 from inflectrix/41-write-more-tests
HyperCodec Apr 18, 2024
b95084d
create custom activations example
HyperCodec Apr 18, 2024
3586879
fix opposite high and low
HyperCodec Apr 18, 2024
27e972a
Update Cargo.toml
HyperCodec May 6, 2024
4b8cef0
use svgbackend (now it hangs for some reason)
HyperCodec May 15, 2024
6a7090a
fix arc::into_inner failure
HyperCodec May 15, 2024
945ea4a
fix data retrieval
HyperCodec May 15, 2024
0717843
make compatible with other features
HyperCodec May 15, 2024
6a98fb0
cargo fmt
HyperCodec May 15, 2024
ca58022
Merge pull request #50 from HyperCodec/plotters-example
HyperCodec May 15, 2024
d150af4
Merge pull request #55 from HyperCodec/HyperCodec-patch-1
HyperCodec May 15, 2024
44b7fdb
create progress bar for plotting example
HyperCodec May 15, 2024
6d17ec6
create progress bar for basic example
HyperCodec May 15, 2024
d3a9c40
cargo fmt
HyperCodec May 15, 2024
9c4daf4
Merge pull request #57 from HyperCodec/examples-indicatif
HyperCodec May 15, 2024
e45908c
add logic to prevent duplicated input neurons
HyperCodec Jun 1, 2024
1ca896b
Merge pull request #62 from HyperCodec/duped-inputs
HyperCodec Jun 1, 2024
7c31f30
cargo fmt
HyperCodec Jun 13, 2024
707c3e0
Merge pull request #54 from HyperCodec/activation-example
HyperCodec Jun 13, 2024
a32bfff
change activation function to one that doesn't return NaN
HyperCodec Jun 13, 2024
53f21e9
Merge pull request #66 from HyperCodec/activation-fixes
HyperCodec Jun 13, 2024
627830a
Update CONTRIBUTING.md
HyperCodec Sep 24, 2024
1295d3d
Merge pull request #77 from HyperCodec/HyperCodec-patch-1
HyperCodec Sep 24, 2024
1978058
Merge branch 'rewrite' into dev
HyperCodec Feb 4, 2025
31b6e7d
delete topology and some examples
HyperCodec Feb 4, 2025
0a958f9
solve clippy errors
HyperCodec Feb 4, 2025
1a8896b
Merge pull request #84 from HyperCodec/rewrite-temp
HyperCodec Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI-CD

on:
push:
branches: [main]
branches: [main, dev]
pull_request:

jobs:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target/
/.vscode/
/.vscode/
best-agent.json
fitness-plot.svg
6 changes: 0 additions & 6 deletions CONTRIBUTING

This file was deleted.

7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Thanks for contributing to this project.

To get started, check out the [issues page](https://github.com/hypercodec/neat). You can either find a feature/fix from there or start a new issue, then begin implementing it in your own fork of this repo.

Once you are done making the changes you'd like the make, start a pull request to the [dev](https://github.com/hypercodec/neat/tree/dev) branch. State your changes and request a review. After all branch rules have been satisfied and the pull request has a valid reason, someone with management permissions on this repository will merge it.

You could also make a draft PR while implementing your features if you want feedback or discussion before finalizing your changes.
78 changes: 41 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 12 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name = "neat"
description = "Crate for working with NEAT in rust"
version = "0.5.1"
edition = "2021"
authors = ["Inflectrix"]
repository = "https://github.com/inflectrix/neat"
homepage = "https://github.com/inflectrix/neat"
authors = ["HyperCodec"]
repository = "https://github.com/HyperCodec/neat"
homepage = "https://github.com/HyperCodec/neat"
readme = "README.md"
keywords = ["genetic", "machine-learning", "ai", "algorithm", "evolution"]
categories = ["algorithms", "science", "simulation"]
Expand All @@ -18,22 +18,19 @@ rustdoc-args = ["--cfg", "docsrs"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["max-index"]
crossover = ["genetic-rs/crossover"]
rayon = ["genetic-rs/rayon", "dep:rayon"]
max-index = []
default = []
serde = ["dep:serde", "dep:serde-big-array"]


[dependencies]
bitflags = "2.5.0"
genetic-rs = { version = "0.5.1", features = ["derive"] }
lazy_static = "1.4.0"
rand = "0.8.5"
rayon = { version = "1.8.1", optional = true }
serde = { version = "1.0.197", features = ["derive"], optional = true }
atomic_float = "1.1.0"
bitflags = "2.8.0"
genetic-rs = { version = "0.5.4", features = ["rayon", "derive"] }
lazy_static = "1.5.0"
rayon = "1.10.0"
replace_with = "0.1.7"
serde = { version = "1.0.217", features = ["derive"], optional = true }
serde-big-array = { version = "0.5.1", optional = true }

[dev-dependencies]
bincode = "1.3.3"
serde_json = "1.0.114"
serde_json = "1.0.138"
95 changes: 5 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,17 @@
# neat
[<img alt="github" src="https://img.shields.io/github/last-commit/inflectrix/neat" height="20">](https://github.com/inflectrix/neat)
[<img alt="github" src="https://img.shields.io/github/last-commit/hypercodec/neat" height="20">](https://github.com/hypercodec/neat)
[<img alt="crates.io" src="https://img.shields.io/crates/d/neat" height="20">](https://crates.io/crates/neat)
[<img alt="docs.rs" src="https://img.shields.io/docsrs/neat" height="20">](https://docs.rs/neat)

Implementation of the NEAT algorithm using `genetic-rs`.

### Features
- rayon - Uses parallelization on the `NeuralNetwork` struct and adds the `rayon` feature to the `genetic-rs` re-export.
- serde - Adds the NNTSerde struct and allows for serialization of `NeuralNetworkTopology`
- crossover - Implements the `CrossoverReproduction` trait on `NeuralNetworkTopology` and adds the `crossover` feature to the `genetic-rs` re-export.
- serde - Implements `Serialize` and `Deserialize` on most of the types in this crate.

*Do you like this repo and want to support it? If so, leave a ⭐*
*Do you like this crate and want to support it? If so, leave a ⭐*

### How To Use
When working with this crate, you'll want to use the `NeuralNetworkTopology` struct in your agent's DNA and
the use `NeuralNetwork::from` when you finally want to test its performance. The `genetic-rs` crate is also re-exported with the rest of this crate.

Here's an example of how one might use this crate:
```rust
use neat::*;

#[derive(Clone, RandomlyMutable, DivisionReproduction)]
struct MyAgentDNA {
network: NeuralNetworkTopology<1, 2>,
}

impl GenerateRandom for MyAgentDNA {
fn gen_random(rng: &mut impl rand::Rng) -> Self {
Self {
network: NeuralNetworkTopology::new(0.01, 3, rng),
}
}
}

struct MyAgent {
network: NeuralNetwork<1, 2>,
// ... other state
}

impl From<&MyAgentDNA> for MyAgent {
fn from(value: &MyAgentDNA) -> Self {
Self {
network: NeuralNetwork::from(&value.network),
}
}
}

fn fitness(dna: &MyAgentDNA) -> f32 {
// agent will simply try to predict whether a number is greater than 0.5
let mut agent = MyAgent::from(dna);
let mut rng = rand::thread_rng();
let mut fitness = 0;

// use repeated tests to avoid situational bias and some local maximums, overall providing more accurate score
for _ in 0..10 {
let n = rng.gen::<f32>();
let above = n > 0.5;

let res = agent.network.predict([n]);
let resi = res.iter().max_index();

if resi == 0 ^ above {
// agent did not guess correctly, punish slightly (too much will hinder exploration)
fitness -= 0.5;

continue;
}

// agent guessed correctly, they become more fit.
fitness += 3.;
}

fitness
}

fn main() {
let mut rng = rand::thread_rng();

let mut sim = GeneticSim::new(
Vec::gen_random(&mut rng, 100),
fitness,
division_pruning_nextgen,
);

// simulate 100 generations
for _ in 0..100 {
sim.next_generation();
}

// display fitness results
let fits: Vec<_> = sim.entities
.iter()
.map(fitness)
.collect();

dbg!(&fits, fits.iter().max());
}
```
# How To Use
TODO

### License
This crate falls under the `MIT` license
Loading