本文整理汇总了Python中library.classes.GeneralMethods.trueWith方法的典型用法代码示例。如果您正苦于以下问题:Python GeneralMethods.trueWith方法的具体用法?Python GeneralMethods.trueWith怎么用?Python GeneralMethods.trueWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类library.classes.GeneralMethods
的用法示例。
在下文中一共展示了GeneralMethods.trueWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: messageSelectionMethod
# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import trueWith [as 别名]
def messageSelectionMethod(self, currentTimeStep, user, currentTopics, **conf):
if self.lastObservedTimeStep != currentTimeStep:
self._updateTopicProbabilities(currentTimeStep, currentTopics, **conf)
message = None
if GeneralMethods.trueWith(user.messagingProbability):
if GeneralMethods.trueWith(user.newTopicProbability):
topic = Topic(len(currentTopics))
currentTopics.append(topic)
message = user.generateMessage(currentTimeStep, topic)
else:
if GeneralMethods.trueWith(user.probabilityOfPickingPopularTopic):
if user.topicClass != None:
topicIndex = GeneralMethods.weightedChoice(
[i[1] for i in self.topicProbabilities[user.topicClass]]
)
topic = self.topicProbabilities[user.topicClass][topicIndex][0]
message = user.generateMessage(currentTimeStep, topic)
if not GeneralMethods.trueWith(topic.stickiness):
message = None
else:
topicIndex = GeneralMethods.weightedChoice([i[1] for i in self.topTopics])
topic = self.topTopics[topicIndex][0]
message = user.generateMessage(currentTimeStep, topic)
else:
if user.topicClass != None:
message = user.generateMessage(
currentTimeStep, random.choice(self.topicProbabilities[user.topicClass])[0]
)
else:
topicIndex = GeneralMethods.weightedChoice([i[1] for i in self.allTopics])
topic = self.allTopics[topicIndex][0]
message = user.generateMessage(currentTimeStep, topic)
return message
示例2: __init__
# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import trueWith [as 别名]
def __init__(self, id):
self.id = id
self.totalCount = 0
self.countDistribution = defaultdict(int)
self.age = 0
self.topicClass = random.choice(topicClasses)
self.decayCoefficient = -3
if GeneralMethods.trueWith(0.05): self.stickiness = random.uniform(stickinessLowerThreshold, 1.0)
else: self.stickiness = random.uniform(0.0, 0.1)
self.payloads = PayLoad.generatePayloads(self.id, noOfPayloadsPerTopic)
#Non-modeling attributes.
self.color = GeneralMethods.getRandomColor()