当前位置: 首页>>代码示例>>Python>>正文


Python GeneralMethods.weightedChoice方法代码示例

本文整理汇总了Python中library.classes.GeneralMethods.weightedChoice方法的典型用法代码示例。如果您正苦于以下问题:Python GeneralMethods.weightedChoice方法的具体用法?Python GeneralMethods.weightedChoice怎么用?Python GeneralMethods.weightedChoice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在library.classes.GeneralMethods的用法示例。


在下文中一共展示了GeneralMethods.weightedChoice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: messageSelectionMethod

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import weightedChoice [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
开发者ID:kykamath,项目名称:spam_model,代码行数:35,代码来源:models.py

示例2: hedging_get_best_model

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import weightedChoice [as 别名]
 def hedging_get_best_model(mf_model_id_to_cumulative_losses):
     if not mf_model_id_to_cumulative_losses: return random.sample(LIST_OF_MODELS, 1)[0]
     else:
         total_weight = float(sum(mf_model_id_to_cumulative_losses.values()))
         for model in mf_model_id_to_cumulative_losses.keys(): mf_model_id_to_cumulative_losses[model]/=total_weight 
         id_and_model_id_and_cumulative_losses = [(id, model_id, cumulative_loss)
                                                     for id, (model_id, cumulative_loss) in 
                                                         enumerate(mf_model_id_to_cumulative_losses.iteritems())
                                                 ]
         selected_id = GeneralMethods.weightedChoice(zip(*id_and_model_id_and_cumulative_losses)[2])
         return filter(lambda (id, model, _): id==selected_id, id_and_model_id_and_cumulative_losses)[0][1]
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:13,代码来源:mr_predict_hashtags_for_locations.py


注:本文中的library.classes.GeneralMethods.weightedChoice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。