本文整理汇总了Python中population.Population.population方法的典型用法代码示例。如果您正苦于以下问题:Python Population.population方法的具体用法?Python Population.population怎么用?Python Population.population使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类population.Population
的用法示例。
在下文中一共展示了Population.population方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import population [as 别名]
def run(pop,
surveyList,
nostdout=False,
allsurveyfile=False,
scint=False):
""" Run the surveys and detect the pulsars."""
# print the population
if not nostdout:
print "Running doSurvey on population..."
print pop
# loop over the surveys we want to run on the pop file
surveyPops = []
for surv in surveyList:
s = Survey(surv)
s.discoveries = 0
if not nostdout:
print "\nRunning survey {0}".format(surv)
# create a new population object to store discovered pulsars in
survpop = Population()
# HERE SHOULD INCLUDE THE PROPERTIES OF THE ORIGINAL POPULATION
# counters
nsmear = 0
nout = 0
ntf = 0
ndet = 0
# loop over the pulsars in the population list
for psr in pop.population:
# pulsar could be dead (evolve!) - continue if so
if psr.dead:
continue
# is the pulsar over the detection threshold?
snr = s.SNRcalc(psr, pop)
# add scintillation, if required
# modifying S/N rather than flux is sensible because then
# a pulsar can have same flux but change S/N in repeated surveys
if scint:
snr = s.scint(psr, snr)
if snr > s.SNRlimit:
ndet += 1
psr.snr = snr
survpop.population.append(psr)
# check if the pulsar has been detected in other
# surveys
if not psr.detected:
# if not, set to detected and increment
# number of discoveries by the survey
psr.detected = True
s.discoveries += 1
elif snr == -1.0:
nsmear += 1
elif snr == -2.0:
nout += 1
else:
ntf += 1
# report the results
if not nostdout:
print "Number detected by survey {0} = {1}".format(surv,ndet)
print "Of which are discoveries = {0}".format(s.discoveries)
print "Number too faint = {0}".format(ntf)
print "Number smeared = {0}".format(nsmear)
print "Number out = {0}".format(nout)
print "\n"
d = Detections(ndet=ndet,
ntf=ntf,
nsmear=nsmear,
nout=nout,
ndisc=s.discoveries)
surveyPops.append([surv,survpop,d])
if allsurveyfile:
allsurvpop = Population()
allsurvpop.population = [psr for psr in pop.population if psr.detected]
surveyPops.append([None, allsurvpop, None])
return surveyPops
示例2: print
# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import population [as 别名]
print("Gen: {}\tPopulation: {}\tFitnesses: {}\tAverage Fitness: {}"
.format(current_generation, ga.population, ga.fitnesses, avg))
# Selection at random for mating
lowest_fitness_index = ga.fitnesses.index(min(ga.fitnesses))
del ga.population[lowest_fitness_index]
del ga.fitnesses[lowest_fitness_index]
# Crossover/Repr
parents = ga.random_mate_select(ga.population)
children = ga.reproduce(parents[0], parents[1])
parents2 = ga.random_mate_select(ga.population)
children = children + ga.reproduce(parents2[0], parents2[1])
# Mutation with small independent probability
for child in children:
if random.random() < ga.p_mutation:
children[children.index(child)] = ga.mutate(child)
ga.population = children
ga.fitnesses.clear()
current_generation += 1
if current_generation == ga.max_generations:
print("\nGlobal Optimum: ")
print("Individual: {}\tFitness: {}\tGeneration: {}\n"
.format(ga.global_optimum[0], ga.global_optimum[1], ga.global_optimum[2]))
num_gens = input("How many more generations would you like to run? (0 to stop)\n")
ga.max_generations += int(num_gens)