-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve analyzer plot functions
- Loading branch information
1 parent
528468a
commit 8247751
Showing
7 changed files
with
88 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,52 @@ | ||
#![recursion_limit = "512"] | ||
mod helper; | ||
|
||
use petgraph::dot::{Config, Dot}; | ||
|
||
use neat::network::Network; | ||
use neat::{innovation_record::InnovationRecord, network::feedforward::Feedforward, pool::Pool}; | ||
|
||
pub fn main() { | ||
let args = helper::cli::get_arguments(); | ||
let params = helper::read_parameters_file("./params/sin.toml"); | ||
|
||
let mut innov_record = InnovationRecord::new(params.input_number, params.output_number); | ||
let mut pool = Pool::<Feedforward>::new(params, args.verbosity, &mut innov_record); | ||
|
||
loop { | ||
let best_genome = pool.evaluate(|_, network| { | ||
let n = 50; | ||
let mut error_sum = 0.0; | ||
|
||
for i in -n..=n { | ||
let x = i as f64 / n as f64; | ||
|
||
let output = network.activate(&[x]).unwrap()[0]; | ||
let expected = (x * std::f64::consts::PI).sin(); | ||
let err = output - expected; | ||
|
||
error_sum += err * err; | ||
for _ in 0..10 { | ||
println!("<Case Start>"); | ||
|
||
let params = helper::read_parameters_file("./params/sin.toml"); | ||
let mut innov_record = InnovationRecord::new(params.input_number, params.output_number); | ||
let mut pool = Pool::<Feedforward>::new(params, args.verbosity, &mut innov_record); | ||
|
||
for _ in 0..500 { | ||
pool.evaluate(|_, network| { | ||
let n = 50; | ||
let mut error_sum = 0.0; | ||
|
||
for i in -n..=n { | ||
let x = i as f64 / n as f64; | ||
|
||
let output = network.activate(&[x]).unwrap()[0]; | ||
let expected = (x * std::f64::consts::PI).sin(); | ||
let err = output - expected; | ||
|
||
error_sum += err * err; | ||
} | ||
|
||
let error_mean = error_sum / (n * 2 + 1) as f64; | ||
network.evaluate(4.0 - error_mean); | ||
}); | ||
|
||
/* | ||
if best_genome.fitness().unwrap() > 3.999 { | ||
let dot = Dot::with_attr_getters( | ||
best_genome.graph().inner_data(), | ||
&[Config::NodeNoLabel, Config::EdgeNoLabel], | ||
&|_, data| format!("label = \"{:.2}\"", data.weight().get_weight()), | ||
&|_, (index, _)| format!("label = \"{}\"", index.index()), | ||
); | ||
println!("{:?}", dot); | ||
break; | ||
} | ||
*/ | ||
|
||
let error_mean = error_sum / (n * 2 + 1) as f64; | ||
network.evaluate(4.0 - error_mean); | ||
}); | ||
|
||
if best_genome.fitness().unwrap() > 3.999 { | ||
let dot = Dot::with_attr_getters( | ||
best_genome.graph().inner_data(), | ||
&[Config::NodeNoLabel, Config::EdgeNoLabel], | ||
&|_, data| format!("label = \"{:.2}\"", data.weight().get_weight()), | ||
&|_, (index, _)| format!("label = \"{}\"", index.index()), | ||
); | ||
println!("{:?}", dot); | ||
break; | ||
pool.evolve(&mut innov_record); | ||
} | ||
|
||
pool.evolve(&mut innov_record); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters