Skip to content

Commit 228f7af

Browse files
authored
Merge pull request #46 from inflectrix/dev
hotfix
2 parents fd65396 + b96ad33 commit 228f7af

File tree

4 files changed

+24
-72
lines changed

4 files changed

+24
-72
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "neat"
33
description = "Crate for working with NEAT in rust"
4-
version = "0.5.0"
4+
version = "0.5.1"
55
edition = "2021"
66
authors = ["Inflectrix"]
77
repository = "https://github.com/inflectrix/neat"

examples/basic.rs

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -87,92 +87,44 @@ fn fitness(dna: &AgentDNA) -> f32 {
8787
fitness
8888
}
8989

90-
#[cfg(all(not(feature = "crossover"), not(feature = "rayon")))]
9190
fn main() {
91+
#[cfg(not(feature = "rayon"))]
9292
let mut rng = rand::thread_rng();
9393

9494
let mut sim = GeneticSim::new(
95+
#[cfg(not(feature = "rayon"))]
9596
Vec::gen_random(&mut rng, 100),
97+
#[cfg(feature = "rayon")]
98+
Vec::gen_random(100),
9699
fitness,
100+
#[cfg(not(feature = "crossover"))]
97101
division_pruning_nextgen,
98-
);
99-
100-
for _ in 0..100 {
101-
sim.next_generation();
102-
}
103-
104-
let fits: Vec<_> = sim.genomes.iter().map(fitness).collect();
105-
106-
let maxfit = fits
107-
.iter()
108-
.max_by(|a, b| a.partial_cmp(b).unwrap())
109-
.unwrap();
110-
111-
dbg!(&fits, maxfit);
112-
}
113-
114-
#[cfg(all(not(feature = "crossover"), feature = "rayon"))]
115-
fn main() {
116-
let mut sim = GeneticSim::new(Vec::gen_random(100), fitness, division_pruning_nextgen);
117-
118-
for _ in 0..100 {
119-
sim.next_generation();
120-
}
121-
122-
let fits: Vec<_> = sim.genomes.iter().map(fitness).collect();
123-
124-
let maxfit = fits
125-
.iter()
126-
.max_by(|a, b| a.partial_cmp(b).unwrap())
127-
.unwrap();
128-
129-
dbg!(&fits, maxfit);
130-
}
131-
132-
#[cfg(all(feature = "crossover", not(feature = "rayon")))]
133-
fn main() {
134-
let mut rng = rand::thread_rng();
135-
136-
let mut sim = GeneticSim::new(
137-
Vec::gen_random(&mut rng, 100),
138-
fitness,
102+
#[cfg(feature = "crossover")]
139103
crossover_pruning_nextgen,
140104
);
141105

142106
for _ in 0..100 {
143107
sim.next_generation();
144108
}
145109

146-
let mut fits: Vec<_> = sim.genomes.iter().map(|e| (e, fitness(e))).collect();
147-
148-
fits.sort_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap());
149-
150-
dbg!(&fits);
151-
152-
if cfg!(feature = "serde") {
153-
let intermediate = NNTSerde::from(&fits[0].0.network);
154-
let serialized = serde_json::to_string(&intermediate).unwrap();
155-
println!("{}", serialized);
156-
}
157-
}
158-
159-
#[cfg(all(feature = "crossover", feature = "rayon"))]
160-
fn main() {
161-
let mut sim = GeneticSim::new(Vec::gen_random(100), fitness, crossover_pruning_nextgen);
162-
163-
for _ in 0..100 {
164-
sim.next_generation();
165-
}
110+
#[cfg(not(feature = "serde"))]
111+
let mut fits: Vec<_> = sim.genomes.iter().map(fitness).collect();
166112

113+
#[cfg(feature = "serde")]
167114
let mut fits: Vec<_> = sim.genomes.iter().map(|e| (e, fitness(e))).collect();
168115

169-
fits.sort_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap());
116+
#[cfg(not(feature = "serde"))]
117+
fits.sort_by(|a, b| a.partial_cmp(&b).unwrap());
118+
119+
#[cfg(feature = "serde")]
120+
fits.sort_by(|(_, a), (_, b)| a.partial_cmp(&b).unwrap());
170121

171122
dbg!(&fits);
172123

173-
if cfg!(feature = "serde") {
124+
#[cfg(feature = "serde")]
125+
{
174126
let intermediate = NNTSerde::from(&fits[0].0.network);
175127
let serialized = serde_json::to_string(&intermediate).unwrap();
176-
println!("serialized: {}", serialized);
128+
println!("{}", serialized);
177129
}
178130
}

src/topology/activation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ActivationRegistry {
6767
}
6868
}
6969

70-
/// Gets a Vec of all the
70+
/// Gets a Vec of all the activation functions registered. Unless you need an owned value, use [fns][ActivationRegistry::fns].values() instead.
7171
pub fn activations(&self) -> Vec<ActivationFn> {
7272
self.fns.values().cloned().collect()
7373
}
@@ -77,7 +77,7 @@ impl ActivationRegistry {
7777
let acts = self.activations();
7878

7979
acts.into_iter()
80-
.filter(|a| !scope.contains(ActivationScope::NONE) && scope.contains(a.scope))
80+
.filter(|a| a.scope != ActivationScope::NONE && a.scope.contains(scope))
8181
.collect()
8282
}
8383
}
@@ -101,7 +101,7 @@ impl Default for ActivationRegistry {
101101

102102
bitflags! {
103103
/// Specifies where an activation function can occur
104-
#[derive(Copy, Clone)]
104+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
105105
pub struct ActivationScope: u8 {
106106
/// Whether the activation can be applied to the input layer.
107107
const INPUT = 0b001;
@@ -112,8 +112,8 @@ bitflags! {
112112
/// Whether the activation can be applied to the output layer.
113113
const OUTPUT = 0b100;
114114

115-
/// If this flag is true, it ignores all the rest and does not make the function naturally occur.
116-
const NONE = 0b1000;
115+
/// The activation function will not be randomly placed anywhere
116+
const NONE = 0b000;
117117
}
118118
}
119119

0 commit comments

Comments
 (0)