本文整理汇总了Python中State.State.getRandomState方法的典型用法代码示例。如果您正苦于以下问题:Python State.getRandomState方法的具体用法?Python State.getRandomState怎么用?Python State.getRandomState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State.State
的用法示例。
在下文中一共展示了State.getRandomState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reproduce
# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import getRandomState [as 别名]
def reproduce(self, other, numChildren=2, percentMutation=5):
"""return numChildren Organisms that are offspring of this organism, and the
'other' organism"""
children = []
for i in range(numChildren):
#do "DNA crossover"
child = self.crossOver(other, percentMutation)
#average values for memory between the two
for j in range(child.memorySize):
child.memory[j] = (self.memory[j] + other.memory[j]) / 2
#do this to adjust for always rounding down
if (self.memory[j] + other.memory[j]) % 2 is not 0 and random.randint(0,1) is 1:
child.memory[j] = (child.memory[j] + 1) % child.numValues
#and introduce some random mutation
pMutation = random.randint(max(percentMutation/2,0),
min(percentMutation*3/2,100))
numMutations = (child.numStates*child.numValues +
child.memorySize)*pMutation/100
for j in range(numMutations):
mutationLocation = random.randint(0,child.numStates*child.numValues + child.memorySize - 1)
if mutationLocation < child.numStates*child.numValues:
state = mutationLocation / child.numValues
value = mutationLocation % child.numValues
child.states[state][value] = \
State.getRandomState((0,child.numValues-1),
(0,child.numStates-1),
(0,child.memorySize-1))
else:
mem = mutationLocation-child.numStates*child.numValues
child.memory[mem] = random.randint(0,child.numValues-1)
children.append(child)
return children
示例2: __init__
# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import getRandomState [as 别名]
def __init__(self, numStates, memorySize, numValues, initStates=None,
initMemory=None):
"""Initialize this Organism. If teh initStates or initMemory parameters
are not provided, the states and/or memory will be generated randomly"""
if initStates is not None:
self.states = initStates
else:
self.states = [[State.getRandomState((0,numValues-1),
(0,numStates-1),
(0,memorySize-1)) for j in
range(numValues)] for i in range(numStates)]
if initMemory is not None:
self.memory = initMemory
else:
self.memory = [random.randint(0,numValues-1) for i in
range(0,memorySize)]
self.numStates = numStates
self.memorySize = memorySize
self.numValues = numValues