The evolution strategy of Salimans et al. (2017): a search for the parameters that maximise a fitness, which needs only the fitness, not its gradient.
More...
|
| | EvolutionStrategy (const ESConfig &config, std::vector< real_t > initial_parameters) |
| GenerationResult | step (const fitness_type &fitness, bitsim::utils::concurrency::ThreadPool &pool=bitsim::utils::concurrency::default_thread_pool()) |
| | One generation, evaluated on the threads of pool.
|
| GenerationResult | step (const fitness_type &fitness, rl::distributed::Communicator &communicator, bitsim::utils::concurrency::ThreadPool &pool=bitsim::utils::concurrency::default_thread_pool()) |
| | One generation, the pairs shared out among the ranks of communicator: rank r evaluates the pairs k with k % world_size == r, on the threads of pool, and sends their fitnesses to the others. Every rank must call it, with an EvolutionStrategy made alike; afterwards every rank has the same parameters as a run on one rank.
|
| const std::vector< real_t > & | parameters () const noexcept |
| | The parameters: the mean of the search distribution.
|
| std::vector< real_t > | noise (uint_t generation, uint_t pair) const |
| | The noise of pair k in generation generation.
|
| uint_t | generation () const noexcept |
| | The generations taken so far.
|
| const std::vector< real_t > & | last_fitnesses () const noexcept |
| | The fitnesses of the last generation: entry 2k is pair k plus, 2k + 1 pair k minus.
|
| const ESConfig & | config () const noexcept |
| std::uint64_t | checksum () const noexcept |
| | A checksum of the parameters, to tell that two runs, or two ranks, agree.
|
The evolution strategy of Salimans et al. (2017): a search for the parameters that maximise a fitness, which needs only the fitness, not its gradient.
Every generation draws n_pairs directions eps_k of standard normal noise, and evaluates the fitness at theta + sigma eps_k and at theta - sigma eps_k: an antithetic pair. The fitnesses are replaced by their centred ranks, in [-0.5, 0.5], which ignores how far apart they are and so copes with outliers; then
g = sum_k (F(theta + sigma eps_k) - F(theta - sigma eps_k)) eps_k / (2 n_pairs sigma)
estimates the gradient of the fitness smoothed by the noise, and Adam takes a step up it, with weight decay.
The fitness can be anything: the return of an episode, a cost a controller should keep low negated, something that is not differentiable. The evaluations of a generation do not depend on each other, so step() runs them on the threads of a pool, or shares them out among the ranks of a distributed run. The noise of pair k in generation g is drawn with the seed task_seed(task_seed(seed, g), k), so every rank can make every direction itself, and only the fitnesses travel: 2 * n_pairs numbers per generation, however many parameters there are. The result does not depend on the number of threads or ranks, to the last bit.
A fitness is called as fitness(parameters, generation, pair), and must be safe to call from several threads at once. Both members of a pair get the same pair index, so that they can play the same episode, with the same seed: that cancels the luck of the episode out of their difference.