Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9ed73ce
fix mutation to include negative numbers
HyperCodec Feb 12, 2024
75eb9ef
save on gh actions calls
HyperCodec Feb 12, 2024
479a361
update dep in Cargo.toml
HyperCodec Feb 13, 2024
f314ace
change function names
HyperCodec Feb 13, 2024
0325fb8
fix error with example
HyperCodec Feb 13, 2024
171736a
Merge pull request #11 from inflectrix/genetic-rs-update
HyperCodec Feb 13, 2024
4f74e87
fix addneuron and add removeneuron
HyperCodec Feb 14, 2024
e255eaf
add bias mutation
HyperCodec Feb 14, 2024
c9efe0e
implement activation function mutation
HyperCodec Feb 14, 2024
174313d
fix making ActivationFn sync
HyperCodec Feb 14, 2024
582edc0
cargo fmt
HyperCodec Feb 14, 2024
1f0bf3b
fix topology index error (runnable still an issue)
HyperCodec Feb 14, 2024
5fcfffb
restructure neuron deletion (and potentially fix)
HyperCodec Feb 16, 2024
8ea5fd7
fix index error
HyperCodec Feb 16, 2024
e821cfb
fix remaining subtraction/index errors
HyperCodec Feb 16, 2024
8dd5b68
fix is_connection_cyclic
HyperCodec Feb 20, 2024
7a8396a
cargo fmt
HyperCodec Feb 20, 2024
cf1dd51
Merge pull request #13 from inflectrix/8-more-mutations
HyperCodec Feb 20, 2024
23c7081
implement serde (untested)
HyperCodec Feb 22, 2024
bb4fe37
add docstrings
HyperCodec Feb 22, 2024
a4eba64
fix deser
HyperCodec Feb 22, 2024
34bf32d
fix clippy warnings
HyperCodec Feb 22, 2024
674ad6e
cargo fmt
HyperCodec Feb 22, 2024
0e07c57
Merge pull request #14 from inflectrix/serde
HyperCodec Feb 22, 2024
62e8876
add feature docs
HyperCodec Feb 22, 2024
c6eb622
Merge pull request #15 from inflectrix/12-feature-docs
HyperCodec Feb 22, 2024
e7f3eca
update version number
HyperCodec Feb 22, 2024
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
5 changes: 4 additions & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: CI-CD

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

jobs:
test:
Expand Down
82 changes: 79 additions & 3 deletions Cargo.lock

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

16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "neat"
description = "Crate for working with NEAT in rust"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
authors = ["Inflectrix"]
repository = "https://github.com/inflectrix/neat"
Expand All @@ -11,16 +11,26 @@ keywords = ["genetic", "machine-learning", "ai", "algorithm", "evolution"]
categories = ["algorithms", "science", "simulation"]
license = "MIT"

[package.metadata.docs.rs]
features = ["serde"]
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 = []
serde = ["dep:serde", "dep:serde-big-array"]


[dependencies]
genetic-rs = "0.2.1"
genetic-rs = "0.3"
rand = "0.8.5"
rayon = { version = "1.8.1", optional = true }
rayon = { version = "1.8.1", optional = true }
serde = { version = "1.0.197", features = ["derive"], optional = true }
serde-big-array = { version = "0.5.1", optional = true }

[dev-dependencies]
bincode = "1.3.3"
6 changes: 3 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl RandomlyMutable for AgentDNA {
impl Prunable for AgentDNA {}

impl DivisionReproduction for AgentDNA {
fn spawn_child(&self, rng: &mut impl Rng) -> Self {
fn divide(&self, rng: &mut impl Rng) -> Self {
let mut child = self.clone();
child.mutate(self.network.mutation_rate, rng);
child
Expand Down Expand Up @@ -112,7 +112,7 @@ fn main() {
sim.next_generation();
}

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

let maxfit = fits
.iter()
Expand All @@ -130,7 +130,7 @@ fn main() {
sim.next_generation();
}

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

let maxfit = fits
.iter()
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
//! ### Feature Roadmap:
//! - [x] base (single-core) crate
//! - [x] rayon
//! - [x] serde
//! - [ ] crossover
//!
//! You can get started by looking at [genetic-rs docs](https://docs.rs/genetic-rs) and checking the examples for this crate.

#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]

/// A module containing the [`NeuralNetworkTopology`] struct. This is what you want to use in the DNA of your agent, as it is the thing that goes through nextgens and suppors mutation.
pub mod topology;
Expand All @@ -18,3 +20,6 @@ pub mod runnable;
pub use genetic_rs::prelude::*;
pub use runnable::*;
pub use topology::*;

#[cfg(feature = "serde")]
pub use nnt_serde::*;
16 changes: 10 additions & 6 deletions src/runnable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rayon::prelude::*;
#[cfg(feature = "rayon")]
use std::sync::{Arc, RwLock};

/// A runnable, stated Neural Network generated from a [NeuralNetworkToplogy]. Use [`NeuralNetwork::from`] to go from stateles to runnable.
/// A runnable, stated Neural Network generated from a [NeuralNetworkTopology]. Use [`NeuralNetwork::from`] to go from stateles to runnable.
/// Because this has state, you need to run [`NeuralNetwork::flush_state`] between [`NeuralNetwork::predict`] calls.
#[derive(Debug)]
#[cfg(not(feature = "rayon"))]
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
n.state.value += self.process_neuron(l) * w;
}

n.sigmoid();
n.activate();

n.state.value
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {

let mut nw = n.write().unwrap();
nw.state.value += val;
nw.sigmoid();
nw.activate();

nw.state.value
}
Expand Down Expand Up @@ -240,6 +240,9 @@ pub struct Neuron {

/// The current state of the neuron.
pub state: NeuronState,

/// The neuron's activation function
pub activation: ActivationFn,
}

impl Neuron {
Expand All @@ -248,9 +251,9 @@ impl Neuron {
self.state.value = self.bias;
}

/// Applies the sigoid activation function to the state's current value.
pub fn sigmoid(&mut self) {
self.state.value = 1. / (1. + std::f32::consts::E.powf(-self.state.value))
/// Applies the activation function to the neuron
pub fn activate(&mut self) {
self.state.value = (self.activation.func)(self.state.value);
}
}

Expand All @@ -263,6 +266,7 @@ impl From<&NeuronTopology> for Neuron {
value: value.bias,
..Default::default()
},
activation: value.activation.clone(),
}
}
}
Expand Down
Loading