def fitness(self, ind, user_feedback): ''' Compute fitness. user_feedback is a list of the user's input, the list contents are ordered the same as the feedback variable in the config yaml file. [best] ''' # needs to be rewritten best = user_feedback[0] subj = 0 for attr_name, chrom in ind.genome.iteritems(): if chrom: subj += ham(best.genome[attr_name], chrom) ind.scalefit = ind.fitness = subj
def fitness(self, ind, user_feedback): ''' Compute fitness. user_feedback is [best,worst] ''' best = user_feedback[0] subj = 0 widgetNum = self.widgetNum for attr_name, chrom in ind.genome.iteritems(): if chrom: subj += ham(best.genome[attr_name], chrom) #-------------------------------------------------------------# # BEGIN OBJECTIVE EVALUATION #-------------------------------------------------------------# grid, myValues = self.decode(ind) red = green = blue = 0 # and the background color # A high value is good # window color is stored at pos 0 red = myValues[1][0] - myValues[0][0] green = myValues[1][1] - myValues[0][1] blue = myValues[1][2] - myValues[0][2] distance = (red*red + green*green + blue*blue)**0.5 obj = distance / self.maxDist * 100. #-------------------------------------------------------------# # END OBJECTIVE EVALUATION #-------------------------------------------------------------# subj = float(subj) # Scale objective and subjective fitness components objFitness = (obj-self.objMin)/(self.objMax-self.objMin) * self.objScaleMax + self.objScaleMin subjFitness = (subj-self.subjMin)/(self.subjMax-self.subjMin) * self.subjScaleMax + self.subjScaleMin ind.objFitness = objFitness ind.subjFitness = subjFitness ind.fitness = [self.objScaleMax-objFitness, self.subjScaleMax-subjFitness]