2323import numpy
2424import pickle
2525import random
26- from functools import partial
26+ import functools
2727
28- from deap import tools
28+ import deap . tools
2929
3030from .CMA_SO import CMA_SO
3131from .CMA_MO import CMA_MO
32- from .utils import _update_history_and_hof , _record_stats , _reduce_method , \
33- _uniform
32+ from . import utils
33+
34+ import bluepyopt .optimisations
3435
3536logger = logging .getLogger ('__main__' )
3637
@@ -166,9 +167,9 @@ def __init__(self,
166167 self .to_space = []
167168 for r , m in zip (bounds_radius , bounds_mean ):
168169 self .to_norm .append (
169- partial (lambda param , bm , br : (param - bm ) / br , bm = m , br = r ))
170+ functools . partial (lambda param , bm , br : (param - bm ) / br , bm = m , br = r ))
170171 self .to_space .append (
171- partial (lambda param , bm , br : (param * br ) + bm , bm = m , br = r ))
172+ functools . partial (lambda param , bm , br : (param * br ) + bm , bm = m , br = r ))
172173
173174 # Overwrite the bounds with -1. and 1.
174175 self .lbounds = numpy .full (self .problem_size , - 1. )
@@ -191,7 +192,9 @@ def setup_deap(self):
191192 numpy .random .seed (self .seed )
192193
193194 # Register the 'uniform' function
194- self .toolbox .register ("uniformparams" , _uniform , self .lbounds ,
195+ self .toolbox .register ("uniformparams" ,
196+ utils .uniform ,
197+ self .lbounds ,
195198 self .ubounds ,
196199 self .ind_size )
197200
@@ -222,8 +225,10 @@ def setup_deap(self):
222225
223226 # Register the evaluation function for the individuals
224227 self .toolbox .register ("evaluate" , self .evaluator .evaluate_with_lists )
225-
226- copyreg .pickle (types .MethodType , _reduce_method )
228+
229+ import copyreg
230+ import types
231+ copyreg .pickle (types .MethodType , utils .reduce_method )
227232
228233 if self .use_scoop :
229234 if self .map_function :
@@ -266,8 +271,8 @@ def run(self,
266271 CMA_es .map_function = self .map_function
267272
268273 else :
269- history = tools .History ()
270- logbook = tools .Logbook ()
274+ history = deap . tools .History ()
275+ logbook = deap . tools .Logbook ()
271276 logbook .header = ["gen" , "nevals" ] + stats .fields
272277
273278 # Instantiate the CMA strategies centered on the centroids
@@ -309,8 +314,8 @@ def run(self,
309314
310315 # Update the hall of fame, history and logbook
311316 pop = CMA_es .get_population (self .to_space )
312- _update_history_and_hof (self .hof , history , pop )
313- record = _record_stats (stats , logbook , gen , pop , nevals )
317+ utils . update_history_and_hof (self .hof , history , pop )
318+ record = utils . record_stats (stats , logbook , gen , pop , nevals )
314319 logger .info (logbook .stream )
315320
316321 # Update the CMA strategy using the new fitness and check if
@@ -345,4 +350,4 @@ def get_stats(self):
345350 stats .register ("std" , numpy .std )
346351 stats .register ("min" , numpy .min )
347352 stats .register ("max" , numpy .max )
348- return stats
353+ return stats
0 commit comments