本文整理汇总了Python中classifier.Classifier.conditions[0][value]方法的典型用法代码示例。如果您正苦于以下问题:Python Classifier.conditions[0][value]方法的具体用法?Python Classifier.conditions[0][value]怎么用?Python Classifier.conditions[0][value]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classifier.Classifier
的用法示例。
在下文中一共展示了Classifier.conditions[0][value]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_classifier
# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import conditions[0][value] [as 别名]
def _create_classifier(self, message = None):
"""Create a new classifier that optionally matches a message"""
c = Classifier()
min_specifity = 10
total_str = 0
if self.classifiers:
for classify in self.classifiers:
total_str += classify.strength
average_str = total_str / len(self.classifiers)
c.strength = average_str
else:
c.strength = 100
# Set condition(s)
elements = range(len(Message.game_msg_index))
random.shuffle(elements)
elements_specifity = [ random.randint(1,5) for x in xrange(len(Message.game_msg_index))]
c.specifity = 0
# Create the condition
for i,value in enumerate(elements):
c.specifity += 6 - elements_specifity[i]
c.conditions[0][value] = \
random.sample(xrange(0,5),elements_specifity[i] )
# Ensure message's value is in the condition
if ( message != None ):
if ( message.status[value] not in c.conditions[0][value] ):
c.conditions[0][value][0] = message.status[value]
c.conditions[0][value].sort()
# Stop adding to the condition sometime after you have > min_specifity
if ( c.specifity > min_specifity ):
if ( random.random() < float(i) / float(len(Message.game_msg_index) ) ):
break
if ( random.random() < 0.01 and c.specifity < min_specifity * 0.3 ):
c.conditions.append( [ None ] * len( Message.game_msg_index) )
break
if ( len(c.conditions) == 2 ):
elements = range(len(Message.game_msg_index))
random.shuffle(elements)
elements_specifity = [ random.randint(1,5) for x in xrange(len(Message.game_msg_index))]
# Create the condition
for i,value in enumerate(elements):
c.specifity += 6 - elements_specifity[i]
c.conditions[1][value] = \
random.sample(xrange(0,5),elements_specifity[i] )
# Ensure message's value is in the condition
if ( message != None ):
if ( message.status[value] not in c.conditions[1][value] ):
c.conditions[1][value][0] = message.status[value]
c.conditions[1][value].sort()
# Stop adding to the condition sometime after you have > min_specifity
if ( c.specifity > min_specifity ):
if ( random.random() < float(i) / float(len(Message.game_msg_index) ) ):
break
if ( random.random() < 0.01 and c.specifity < min_specifity * 0.3 ):
c.conditions.append( [ None ] * len( Message.game_msg_index) )
break
# Set output
output_message = Message()
output_message.classifier_message()
output_message.emitter = c
c.output = output_message, random.choice(['Heal','Mine','Attack','Wait'])
return c