def update_stats(self): """Gather statistics from the various populations to the mga's population. """ sum_fields = [ 'selections', 'crossovers', 'mutations', 'replacements', 'ind_evals' ] s = [] for ga in self.GAs: for field in sum_fields: self.pop.stats[field] = self.pop.stats[field] + ga.stats[field] s = s + ga.pop.scores().tolist() self.pop.stats['current']['max'] = self.pop.best().score() self.pop.stats['current']['avg'] = my_mean(s) self.pop.stats['current']['min'] = min(s) if len(s) > 1: self.pop.stats['current']['dev'] = my_std(s) else: self.pop.stats['current']['dev'] = 0 try: self.pop.stats['overall']['max'] = max( self.pop.stats['overall']['max'], self.pop.stats['current']['max']) except KeyError: self.pop.stats['overall']['max'] = self.pop.stats['current']['max'] try: self.pop.stats['overall']['min'] = min( self.pop.stats['overall']['min'], self.pop.stats['current']['min']) except KeyError: self.pop.stats['overall']['min'] = self.pop.stats['current']['min'] self.pop.stats # XXX: Is this a no-op? self.pop.stats['pop_evals'] = self.GAs[0].stats['pop_evals'] self.stats.update(self.pop.stats)
def pop_deviation(self): """calculate the std deviation across all populations""" all_scores = [] for ga in self.GAs: all_scores = all_scores + ga.pop.scores().tolist() if len(all_scores) > 1: denom = my_mean(all_scores) if denom == 0.: denom = .0001 # what should I do here? return abs(my_std(all_scores)/denom) return 0
def pop_deviation(self): """calculate the std deviation across all populations""" all_scores = [] for ga in self.GAs: all_scores = all_scores + ga.pop.scores().tolist() if len(all_scores) > 1: denom = my_mean(all_scores) if denom == 0.: denom = .0001 # what should I do here? return abs(my_std(all_scores) / denom) return 0
def scale(self, pop): sc = pop.scores() avg = my_mean(sc) if len(sc) > 1: dev = my_std(sc) else: dev = 0 f = clip(sc - avg + self.scaling * dev, 0, inf) for i in range(len(pop)): pop[i].fitness(f[i]) return pop
def update_stats(self): """Update the statistics for the population.""" s = self.scores() self.stats['current']['max'] = max(s) self.stats['current']['avg'] = my_mean(s) self.stats['current']['min'] = min(s) if len(s) > 1: self.stats['current']['dev'] = my_std(s) else: self.stats['current']['dev'] = 0 try: self.stats['overall']['max'] = max(self.stats['overall']['max'], self.stats['current']['max']) except KeyError: self.stats['overall']['max'] = self.stats['current']['max'] try: self.stats['overall']['min'] = min(self.stats['overall']['min'], self.stats['current']['min']) except KeyError: self.stats['overall']['min'] = self.stats['current']['min']
def scale(self, pop): sc = pop.scores() pmin = min(sc) if pmin < 0: raise GAError("linear scaling does not work with objective scores < 0") pmax = max(sc) pavg = my_mean(sc) if pavg == pmax: a = 1.0 b = 0.0 elif pmin > (self.mult * pavg - pmax) / (self.mult - 1.0): delta = pmax - pavg a = (self.mult - 1.0) * pavg / delta b = pavg * (pmax - self.mult * pavg) / delta else: delta = pavg - pmin a = pavg / delta b = -pmin * pavg / delta f = clip(sc * a + b, 0, inf) for i in range(len(pop)): pop[i].fitness(f[i])
def update_stats(self): """Gather statistics from the various populations to the mga's population. """ sum_fields = ['selections','crossovers','mutations','replacements','ind_evals'] s = [] for ga in self.GAs: for field in sum_fields: self.pop.stats[field] = self.pop.stats[field] + ga.stats[field] s = s + ga.pop.scores().tolist() self.pop.stats['current']['max'] = self.pop.best().score() self.pop.stats['current']['avg'] = my_mean(s) self.pop.stats['current']['min'] = min(s) if len(s) > 1: self.pop.stats['current']['dev'] = my_std(s) else: self.pop.stats['current']['dev'] = 0 try: self.pop.stats['overall']['max'] = max(self.pop.stats['overall']['max'], self.pop.stats['current']['max']) except KeyError: self.pop.stats['overall']['max'] = self.pop.stats['current']['max'] try: self.pop.stats['overall']['min'] = min(self.pop.stats['overall']['min'], self.pop.stats['current']['min']) except KeyError: self.pop.stats['overall']['min'] = self.pop.stats['current']['min'] self.pop.stats # XXX: Is this a no-op? self.pop.stats['pop_evals'] = self.GAs[0].stats['pop_evals'] self.stats.update(self.pop.stats)
def pop_deviation(self): #calculate the std deviation across all populations as a percent of mean scores = self.pop.scores() denom = my_mean(scores) if denom == 0.: denom = .0001 # what should I do here? return abs(my_std(scores)/denom)
def pop_deviation(self): #calculate the std deviation across all populations as a percent of mean scores = self.pop.scores() denom = my_mean(scores) if denom == 0.: denom = .0001 # what should I do here? return abs(my_std(scores) / denom)