RobertTLange / evosax

Evolution Strategies in JAX 🦎

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does the samples (population) for the first iteration not uniform?

smao-astro opened this issue · comments

Dear @RobertTLange ,

Thank you for creating and sharing this valuable repository. I am new to evolutionary algorithms and have a question regarding the initial population distribution.

Following the tutorial at https://github.com/RobertTLange/evosax/blob/af5c32271583672a42adef08f19cd535a9fa0d93/README.md?plain=1#LL10C1-L10C1 or https://colab.research.google.com/github/RobertTLange/evosax/blob/main/examples/01_classic_benchmark.ipynb, I notice that the population at the first iteration, before evaluating the objective functions, is non-uniform.

For your reference, please see the test code and its outputs below:

import jax
import jax.numpy as jnp
import numpy as np
from evosax import PSO

key=jax.random.PRNGKey(0)
strategy=PSO(128, 1)

es_params=strategy.default_params
state=strategy.initialize(key, es_params)
print(np.mean(state.archive))
print(state.mean)
global_best = state.best_archive[jnp.argmin(state.best_archive_fitness)]
print(f"Biased global_best in `single_member_velocity`:", global_best)
_, key = jax.random.split(key, 2)
x, state = strategy.ask(key, state, es_params)
print("Biased samples:")
print(np.mean(state.velocity))
print(np.mean(x))

Outputs

-0.0031656926
[-0.00316569]
Biased global_best in `single_member_velocity`: [-0.08077727]
Biased samples:
-0.08185574
-0.085021436

The questions are,

  1. Why does the x from the code above bias towards the lower boundary?
  2. To achieve a uniformly distributed population in the first iteration, should I use state.archive? Is this the recommended approach?

Thanks,
Shunyuan