def test_function(self): from math import cos from Goulib.math2 import vecmul, norm_2 class function(object): def __init__(self): self.x = None self.n = 9 self.domain = [(-100, 100)] * self.n self.optimizer = DifferentialEvolution(self, population_size=100, n_cross=5, show_progress=True) def target(self, vector): result = (sum(map(cos, vecmul(vector, 10))) + self.n + 1) * norm_2(vector) return result def print_status(self, mins, means, vector, txt): logging.info('%s %s %s %s' % (txt, mins, means, vector)) v = function() logging.info('%s' % v.x) assert_true(norm_2(v.x) < 1e-5)
def test_function(self): from math import cos from Goulib.math2 import vecmul, norm_2 class function(object): def __init__(self): self.x = None self.n = 9 self.domain = [ (-100,100) ]*self.n self.optimizer = DifferentialEvolution( self,population_size=100,n_cross=5, show_progress=True ) def target(self, vector): result = (sum(map(cos,vecmul(vector,10)))+self.n+1)*norm_2(vector) return result def print_status(self, mins,means,vector,txt): logging.info('%s %s %s %s'%(txt,mins, means, vector)) v=function() logging.info('%s'%v.x) assert_true(norm_2(v.x)<1e-5)
def target(self, vector): result = (sum(map(cos,vecmul(vector,10)))+self.n+1)*norm_2(vector) return result
def target(self, vector): result = (sum(map(cos, vecmul(vector, 10))) + self.n + 1) * norm_2(vector) return result