-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added optimize method and half benchmark for bna
- Loading branch information
Showing
7 changed files
with
82 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
use std::f64::consts::PI; | ||
use neuroevolution::vneuron::*; | ||
use neuroevolution::bna::*; | ||
|
||
fn main() { | ||
let input = vec![1., PI / 8.]; | ||
let dim = 2; | ||
let bend = PI / 4.; | ||
let angles = vec![PI / 4.]; | ||
let bias = 0.; | ||
let vneuron = VNeuron::from_params(dim, bias, angles, bend); | ||
println!("{:?}", vneuron.evaluate(&input)); | ||
let mut vneuron = VNeuron::new(2); | ||
|
||
vneuron.optimize(half, 1000); | ||
println!("half fitness: {}", half(&vneuron)); | ||
println!("Half: {}", vneuron); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::f64::consts::PI; | ||
use crate::vneuron::*; | ||
|
||
const UNIT_CIRCLE_STEPS: u32 = 1000; | ||
|
||
pub fn half(vneuron: &VNeuron) -> f64 { | ||
let mut sum = 0; | ||
for i in 0..UNIT_CIRCLE_STEPS { | ||
let angle = 2. * PI * i as f64 / UNIT_CIRCLE_STEPS as f64; | ||
let output = vneuron.evaluate(&vec![1., angle]); | ||
if output && angle < PI || !output && angle > PI { | ||
sum += 1; | ||
} | ||
} | ||
sum as f64 / UNIT_CIRCLE_STEPS as f64 | ||
} |
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,5 +1,6 @@ | ||
pub mod one_plus_one_na; | ||
pub mod oneplusone_na; | ||
pub mod cma_es; | ||
pub mod network; | ||
pub mod vneuron; | ||
pub mod utils; | ||
pub mod bna; |
File renamed without changes.
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