本文整理汇总了Python中Statistics.Statistics.__repr__方法的典型用法代码示例。如果您正苦于以下问题:Python Statistics.__repr__方法的具体用法?Python Statistics.__repr__怎么用?Python Statistics.__repr__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statistics.Statistics
的用法示例。
在下文中一共展示了Statistics.__repr__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xrange
# 需要导入模块: from Statistics import Statistics [as 别名]
# 或者: from Statistics.Statistics import __repr__ [as 别名]
#.........这里部分代码省略.........
"""Initialize the multiprocessing interface. Create the process pool."""
#Close the pool if it exists (we'll be creating a new one)
self.cleanupMultiProcessing()
if self.multiProcessing[0]:
t1 = time.time()
#Create the process pool with the # of processes
num_proc = self.multiProcessing[2]
if num_proc is None:
self.proc_pool = Pool()
elif num_proc > 0:
self.proc_pool = Pool(processes=num_proc)
else:
self.proc_pool = Pool()
print "Multiprocessing initialized in %03.3f sec; will use %d processors." % ( (time.time()-t1), num_proc )
#---------------------------------------------------------------------------------
def cleanupMultiProcessing(self):
"""Clean up process pools."""
if not self.proc_pool is None:
self.proc_pool.close()
def setMinimax(self, minimax):
""" Sets the population minimax
Example:
>>> pop.setMinimax(Consts.minimaxType["maximize"])
:param minimax: the minimax type
"""
self.minimax = minimax
def __repr__(self):
""" Returns the string representation of the population """
ret = "- GPopulation\n"
ret += "\tPopulation Size:\t %d\n" % (self.popSize,)
ret += "\tSort Type:\t\t %s\n" % (Consts.sortType.keys()[Consts.sortType.values().index(self.sortType)].capitalize(),)
ret += "\tMinimax Type:\t\t %s\n" % (Consts.minimaxType.keys()[Consts.minimaxType.values().index(self.minimax)].capitalize(),)
for slot in self.allSlots:
ret+= "\t" + slot.__repr__()
ret+="\n"
ret+= self.stats.__repr__()
return ret
def __len__(self):
""" Return the length of population """
return len(self.internalPop)
def __getitem__(self, key):
""" Returns the specified individual from population """
return self.internalPop[key]
def __iter__(self):
""" Returns the iterator of the population """
return iter(self.internalPop)
def __setitem__(self, key, value):
""" Set an individual of population """
self.internalPop[key] = value
self.clearFlags()
def clearFlags(self):
""" Clear the sorted and statted internal flags """
self.sorted = False
self.statted = False
示例2: xrange
# 需要导入模块: from Statistics import Statistics [as 别名]
# 或者: from Statistics.Statistics import __repr__ [as 别名]
class GPopulation:
""" GPopulation Class - The container for the population
**Examples**
Get the population from the :class:`GSimpleGA.GSimpleGA` (GA Engine) instance
>>> pop = ga_engine.getPopulation()
Get the best fitness individual
>>> bestIndividual = pop.bestFitness()
Get the best raw individual
>>> bestIndividual = pop.bestRaw()
Get the statistics from the :class:`Statistics.Statistics` instance
>>> stats = pop.getStatistics()
>>> print stats["rawMax"]
10.4
Iterate, get/set individuals
>>> for ind in pop:
>>> print ind
(...)
>>> for i in xrange(len(pop)):
>>> print pop[i]
(...)
>>> pop[10] = newGenome
>>> pop[10].fitness
12.5
:param genome: the :term:`Sample genome`
"""
def __init__(self, genome):
""" The GPopulation Class creator """
logging.debug("New population instance, %s class genomes.", genome.__class__.__name__)
self.oneSelfGenome = genome
self.internalPop = []
self.popSize = 0
self.sortType = Consts.CDefPopSortType
self.sorted = False
self.minimax = Consts.CDefPopMinimax
self.scaleMethod = FunctionSlot("Scale Method")
self.scaleMethod.set(Consts.CDefPopScale)
self.allSlots = [self.scaleMethod]
# Statistics
self.statted = False
self.stats = Statistics()
def setMinimax(minimax):
""" Sets the population minimax
Example:
>>> pop.setMinimax(Consts.minimaxType["maximize"])
:param minimax: the minimax type
"""
self.minimax = minimax
def __repr__(self):
""" Returns the string representation of the population """
ret = "- GPopulation\n"
ret += "\tPopulation Size:\t %d\n" % (self.popSize,)
ret += "\tSort Type:\t\t %s\n" % (Consts.sortType.keys()[Consts.sortType.values().index(self.sortType)].capitalize(),)
ret += "\tMinimax Type:\t\t %s\n" % (Consts.minimaxType.keys()[Consts.minimaxType.values().index(self.minimax)].capitalize(),)
for slot in self.allSlots:
ret+= "\t" + slot.__repr__()
ret+="\n"
ret+= self.stats.__repr__()
return ret
def __len__(self):
""" Return the length of population """
return len(self.internalPop)
def __getitem__(self, key):
""" Returns the specified individual from population """
return self.internalPop[key]
def __iter__(self):
""" Returns the iterator of the population """
return iter(self.internalPop)
def __setitem__(self, key, value):
""" Set an individual of population """
self.internalPop[key] = value
self.__clear_flags()
def __clear_flags(self):
self.sorted = False
self.statted = False
def getStatistics(self):
""" Return a Statistics class for statistics
#.........这里部分代码省略.........