Skip to content

Commit

Permalink
optimized sub-optimal code and added the ant environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Jark5455 committed Apr 6, 2024
1 parent 09df3ce commit bcc6c1e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/optimizer/cmaes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl CMAES {
let mut weights = vec![0f64; mu as usize];

for i in 0..weights.len() {
weights[i] = (mu as f64 + 0.5f64).log2() - (i as f64 + 1f64).log2();
weights[i] = ((lambda as f64 / 2f64) + 0.5f64).log2() - (i as f64).log2();
}

let weights = tch::Tensor::from_slice(weights.as_slice());
Expand All @@ -70,7 +70,7 @@ impl CMAES {
2f64 * (mueff - 2f64 + 1f64 / mueff) / ((N as f64 + 2f64).powi(2) + mueff),
);

let damps = f64::min(0f64, ((mu as f64 - 1f64) / (N as f64 + 1f64)).sqrt() - 1f64) + cs;
let damps = 1f64 + 2f64 * f64::max(0f64, ((mueff - 1f64) / (N as f64 + 1f64)).sqrt() - 1f64) + cs;

let chiN = (N as f64).sqrt()
* (1f64 - 1f64 / (4f64 * N as f64) + 1f64 / (21f64 * (N as f64).sqrt()));
Expand Down Expand Up @@ -262,6 +262,11 @@ impl MilkshakeOptimizer for CMAES {

self.sigma = self.sigma * ((self.cs / self.damps) * (psNorm / self.chiN - 1f64)).exp();

println!("P1: {}", self.cs / self.damps);
println!("P2: {}", psNorm / self.chiN - 1f64);
println!("P3: {}", ((self.cs / self.damps) * (psNorm / self.chiN - 1f64)).exp());
println!("SIGMA: {}", self.sigma);

if (self.counteval - self.eigeneval) as f64
> self.lambda as f64 / (self.c1 + self.cmu) / self.N as f64 / 10f64
{
Expand Down

0 comments on commit bcc6c1e

Please sign in to comment.