本文整理汇总了Python中jmoo_individual函数的典型用法代码示例。如果您正苦于以下问题:Python jmoo_individual函数的具体用法?Python jmoo_individual怎么用?Python jmoo_individual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jmoo_individual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gale_nm_Mutate
def gale_nm_Mutate(problem, NDLeafs, configuration):
#################
# Mutation Phase
#################
number_of_evaluation = 0
# After mutation; Convert back to JMOO Data Structures
population = []
for leaf in NDLeafs:
for row in leaf.table.rows:
if row.evaluated:
population.append(jmoo_individual(problem, [x for x in row.cells[:len(problem.decisions)]],
[x for x in row.cells[len(problem.decisions):]]))
number_of_evaluation += 1
else:
population.append(jmoo_individual(problem, [x for x in row.cells[:len(problem.decisions)]], None))
if number_of_evaluation < 2:
while True:
from random import randint
index = randint(0, len(population) - 1)
if population[index].valid is not True:
population[index].evaluate()
number_of_evaluation +=1
break
if number_of_evaluation == 0:
return population, 0
else:
return population, number_of_evaluation
示例2: gale0WHERE
def gale0WHERE(problem, population, configuration, values_to_be_passed):
"The Core method behind GALE"
# for pop in population:
# assert(pop.generation_number == 0), "Generation has to be 0"
# Compile population into table form used by WHERE
t = slurp([[x for x in row.decisionValues] + ["?" for y in problem.objectives] for row in population],
problem.buildHeader().split(","))
# Initialize some parameters for WHERE
The.allowDomination = True
The.alpha = 1
for i, row in enumerate(t.rows):
row.evaluated = False
# Run WHERE
m = Moo(problem, t, len(t.rows), N=1).divide(minnie=rstop(t))
print "Where done"
# Organizing
NDLeafs = m.nonPrunedLeaves() # The surviving non-dominated leafs
allLeafs = m.nonPrunedLeaves() + m.prunedLeaves() # All of the leafs
# After mutation: Check how many rows were actually evaluated
numEval = 0
for leaf in allLeafs:
for row in leaf.table.rows:
if row.evaluated:
numEval += 1
# After mutation; Convert back to JMOO Data Structures
population = []
for leaf in NDLeafs:
for row in leaf.table.rows:
if row.evaluated:
population.append(jmoo_individual(problem, [x for x in row.cells[:len(problem.decisions)]], 0,
[x for x in row.cells[len(problem.decisions):]]))
else:
indi = jmoo_individual(problem, [x for x in row.cells[:len(problem.decisions)]], 0, None)
indi.fitness.fitness = problem.evaluate(indi.decisionValues)
# print "> ", indi.fitness.fitness
population.append(indi)
numEval += 1
# median_values = []
# for i in xrange(len(problem.objectives)):
# temp_values = []
# for pop in population:
# temp_values.append(pop.fitness.fitness[i])
# median_values.append(median(temp_values))
#
# print median_values
print "number of evals: ", numEval
return population, numEval
示例3: loadInitialPopulation
def loadInitialPopulation(problem, MU):
"a way to load *the* initial problem as used in jmoo_jmoea.py"
"this will load a csv as generated by the dataGen method of"
"jmoo_problems.py"
filename = "data/" + problem.name + "-p" + str(MU) + "-d" + str(len(problem.decisions)) + "-o" + str(len(problem.objectives)) + "-dataset.txt"
input = open(filename, 'rb')
reader = csv.reader(input, delimiter=',')
population = []
#Use the csv file to build the initial population
for k,p in enumerate(reader):
if k > MU:
problem.objectives[k-MU-1].med = float(p[1])
lownotfound = False
upnotfound = False
if problem.objectives[k-MU-1].low == None:
problem.objectives[k-MU-1].low = float(p[0])
lownotfound = True
if problem.objectives[k-MU-1].up == None:
problem.objectives[k-MU-1].up = float(p[2])
upnotfound = True
rangeX5 = (problem.objectives[k-MU-1].up - problem.objectives[k-MU-1].low)*5
if lownotfound:
problem.objectives[k-MU-1].low -= rangeX5
if upnotfound:
problem.objectives[k-MU-1].up += rangeX5
elif k > 0:
population.append(jmoo_individual(problem,[float(p[n]) for n,dec in enumerate(problem.decisions)],None))
#population[-1].fitness = jmoo_fitness(problem, [float(p[n+len(problem.decisions)]) for n,obj in enumerate(problem.objectives)])
return population
示例4: polynomial_mutation
def polynomial_mutation(problem, individual, configuration):
from numpy.random import random
eta_m_ = configuration["NSGAIII"]["ETA_M_DEFAULT_"]
distributionIndex_ = eta_m_
output = jmoo_individual(problem, individual.decisionValues)
probability = 1/len(problem.decisions)
for var in xrange(len(problem.decisions)):
if random() <= probability:
y = individual.decisionValues[var]
yU = problem.decisions[var].up
yL = problem.decisions[var].low
delta1 = (y - yL)/(yU - yL)
delta2 = (yU - y)/(yU - yL)
rnd = random()
mut_pow = 1.0/(eta_m_ + 1.0)
if rnd < 0.5:
xy = 1.0 - delta1
val = 2.0 * rnd + (1 - 2 * rnd) * (xy ** (distributionIndex_ + 1.0))
deltaq = val ** mut_pow - 1
else:
xy = 1.0 - delta2
val = 2.0 * (1.0-rnd) + 2.0 * (rnd-0.5) * (xy ** (distributionIndex_+1.0))
deltaq = 1.0 - (val ** mut_pow)
y += deltaq * (yU - yL)
if y < yL: y = yL
if y > yU: y = yU
output.decisionValues[var] = y
return output
示例5: extrapolate
def extrapolate(problem, individuals, one, f, cf):
from random import randint
two, three, four = three_others(individuals, one)
solution = []
# from Binary Differential Evolution Algorithm with New Mutation Operator
if problem.is_binary is True:
for d, decision in enumerate(problem.decisions):
assert isinstance(two, jmoo_individual)
x, y, z = two.decisionValues[d], three.decisionValues[d], four.decisionValues[d]
if random.random() < cf:
if x == 0 or x == 1:
solution.append(1 - x)
else:
solution.append(1 - x)
else:
solution.append(one.decisionValues[d])
else:
for d, decision in enumerate(problem.decisions):
assert isinstance(two, jmoo_individual)
x, y, z = two.decisionValues[d], three.decisionValues[d], four.decisionValues[d]
if random.random() < cf or randint(0, len(problem.decisions)) == d:
solution.append(trim(x + f * (y - z), decision.low, decision.up))
else:
solution.append(one.decisionValues[d])
return jmoo_individual(problem, [float(d) for d in solution], None)
示例6: update_neighbor
def update_neighbor(problem, individual, mutant, population, dist_function, configuration, values_to_be_passed):
from copy import deepcopy
new_population = population[:] #deepcopy(population)
for i in xrange(configuration["MOEAD"]["niche"]):
k = individual.neighbor[i]
neighbor = [pop for pop in new_population if pop.id == k][-1]
f1 = dist_function(problem, neighbor.fitness.fitness, neighbor.weight, values_to_be_passed, configuration)
f2 = dist_function(problem, mutant.fitness.fitness, neighbor.weight, values_to_be_passed, configuration)
if f2 < f1:
backup_copy = None
for pop in new_population:
if pop.id == k:
backup_copy = deepcopy(pop)
new_population.remove(pop)
break
assert(backup_copy.id == k), "Assumption of value of pop exists is wrong!"
new_solution = jmoo_individual(problem, mutant.decisionValues, mutant.fitness.fitness)
new_solution.id = k
new_solution.neighbor = deepcopy(backup_copy.neighbor)
new_solution.weight = deepcopy(backup_copy.weight)
new_population.append(new_solution)
assert(new_solution.id == backup_copy.id), "Something is wrong"
assert(len(new_population) == configuration["Universal"]["Population_Size"]), "Something is wrong with updation"
return new_population
示例7: over_sampling
def over_sampling(problem, population, more_count, f=0.75):
def trim(mutated, low, up):
"""Constraint checking of decision"""
return max(low, min(mutated, up))
def interpolate(a, b, random_number):
return a + random_number * (b - a)
new_population = []
for i in xrange(more_count):
from random import choice, randint, random
one_count = i%len(population)
one = population[one_count]
while True:
two_count = randint(0, len(population)-1)
if one_count != two_count: break
two = population[two_count]
solution = []
for d, decision in enumerate(problem.decisions):
assert isinstance(one, jmoo_individual)
assert isinstance(two, jmoo_individual)
solution.append(trim(interpolate(one.decisionValues[d], two.decisionValues[d], random()), decision.low, decision.up))
new_population.append(jmoo_individual(problem, solution, None))
return new_population
示例8: gale_nm_Regen
def gale_nm_Regen(problem, unusedslot, mutants, configuration, generation_number):
howMany = configuration["Universal"]["Population_Size"]
# Generate random individuals
population = []
for i in range(howMany):
population.append(jmoo_individual(problem, problem.generateInput(), [generation_number], None))
return population, 0
示例9: gale_nm_Mutate
def gale_nm_Mutate(problem, NDLeafs, configuration, gen, actual_population):
#################
# Mutation Phase
#################
# After mutation; Convert back to JMOO Data Structures
population = []
for leaf in NDLeafs:
for row in leaf.table.rows:
if row.evaluated:
population.append(jmoo_individual(problem, [x for x in row.cells[:len(problem.decisions)]], 0,
[x for x in row.cells[len(problem.decisions):]]))
else:
population.append(jmoo_individual(problem, [x for x in row.cells[:len(problem.decisions)]], 0, None))
# Return selectees and number of evaluations
return population, 0
示例10: gale_64_Regen
def gale_64_Regen(problem, unusedslot, mutants, configuration):
howMany = configuration["Universal"]["Population_Size"] - len(mutants)
# Generate random individuals
population = []
for i in range(howMany):
population.append(jmoo_individual(problem, problem.generateInput(), None))
return mutants+population, 0
示例11: galeRegen
def galeRegen(problem, unusedSlot, mutants, MU):
howMany = MU - len(mutants)
# Generate random individuals
population = []
for i in range(howMany):
population.append(jmoo_individual(problem, problem.generateInput(), None))
return mutants+population, 0
示例12: gale_8_Mutate
def gale_8_Mutate(problem, leaves, configuration):
def mutate(candidate, SouthPole, NorthPole):
mutant = [None for _ in xrange(len(candidate.decisionValues))]
g = abs(SouthPole.x - NorthPole.x)
for attr in range(0, len(problem.decisions)):
# just some naming shortcuts
me = candidate.decisionValues[attr]
good = SouthPole.decisionValues[attr]
bad = NorthPole.decisionValues[attr]
dec = problem.decisions[attr]
# Find direction to mutate (Want to mutate towards good pole)
if me > good: d = -1
if me < good: d = +1
if me == good: d = 0
mutant[attr] = min(dec.up, max(dec.low, (me + me * g * d) * 1.1))
return jmoo_individual(problem, mutant, None)
#################
# Mutation Phase
#################
new_population = []
# Keep track of evals
number_of_evaluations = 0
for leaf in leaves:
initial_length = len(leaf)
sorted_population = fastmap(problem, leaf)
# print "sorted_population: ", len(sorted_population), len([g for g in sorted_population if g.fitness.valid])
number_of_evaluations += 2
good_ones = sorted_population[:initial_length/2]
# print "good_ones: ", len(good_ones), len([g for g in good_ones if g.fitness.valid])
mutants = [mutate(good_one, sorted_population[0], sorted_population[-1]) for good_one in good_ones]
# print "mutants: ", len(mutants)
excess = initial_length - (len(good_ones) + len(mutants))
random_points = [jmoo_individual(problem, problem.generateInput(), None) for _ in xrange(excess)]
# print "excess: ", excess
new_population += good_ones
new_population += mutants
new_population += random_points
# print "new_population: ", len(new_population)
assert(initial_length == len(good_ones) + len(mutants) + len(random_points)), "Something is wrong"
# print len(new_population), configuration["Universal"]["Population_Size"]
assert(len(new_population) == configuration["Universal"]["Population_Size"]), "Something is wrong"
return new_population, number_of_evaluations
示例13: extrapolate
def extrapolate(problem, individuals, one, f, cf):
from random import randint
two, three, four = three_others(individuals, one)
solution = []
for d, decision in enumerate(problem.decisions):
assert isinstance(two, jmoo_individual)
x, y, z = two.decisionValues[d], three.decisionValues[d], four.decisionValues[d]
if random.random() < cf or randint(0, len(problem.decisions)) == d:
solution.append(trim(x + f * (y - z), decision.low, decision.up))
else: solution.append(one.decisionValues[d])
return jmoo_individual(problem, [float(d) for d in solution], None)
示例14: gale_8_WHERE
def gale_8_WHERE(problem, population, configuration, values_to_be_passed):
"The Core method behind GALE"
from Utilities.where import where
import numpy as np
decisions = np.array([pop.decisionValues for pop in population])
leaves = where(decisions)
filled_leaves = []
for leaf in leaves:
temp_list = [jmoo_individual(problem, list(member), None) for member in leaf]
filled_leaves.append(temp_list)
return filled_leaves, 0
示例15: convert_to_jmoo
def convert_to_jmoo(problem, pareto_fronts):
tpopulation = []
for front_no, front in enumerate(pareto_fronts[:-1]):
for i, dIndividual in enumerate(front):
cells = []
for j in xrange(len(dIndividual)):
cells.append(dIndividual[j])
tpopulation.append(jmoo_individual(problem, cells, list(dIndividual.fitness.values)))
for pop in tpopulation: pop.front_no = 0 # all the front except the last front
lpopulation = []
for front_no, front in enumerate(pareto_fronts[-1:]):
for i, dIndividual in enumerate(front):
cells = []
for j in xrange(len(dIndividual)):
cells.append(dIndividual[j])
lpopulation.append(jmoo_individual(problem, cells, list(dIndividual.fitness.values)))
for pop in lpopulation: pop.front_no = -1 # last front
from itertools import chain
assert(len(list(chain(*pareto_fronts))) <= len(lpopulation) + len(tpopulation)), "Non Dominated Sorting is wrong!"
return lpopulation + tpopulation