-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcma_es.py
23 lines (17 loc) · 834 Bytes
/
cma_es.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import cma
import numpy as np
class CMAEvolutionStrategy:
def __init__(self, population_size, init_sigma, init_params):
self.__module = cma.CMAEvolutionStrategy(x0=init_params,
sigma0=init_sigma,
inopts={'popsize': population_size,
'randn': np.random.randn,
}, )
def get_population(self):
return self.__module.ask()
def get_current_parameters(self):
return self.__module.result.xfavorite
def get_best_result(self):
return self.__module.result.xbest, self.__module.result.fbest
def evolve(self, fitness):
self.__module.tell(self.get_population(), -fitness)