def __recurse_ct(self, ct, n, d):
     """given a cached category tree, a current node, and a dictionary of
     category->preference mappings"""
     current_pref = d[n.id]
     for child in ct.children(n):
         d[child.id] = ml.sample_category_distribution(self.transition_matrix[current_pref])[0]
         self.__recurse_ct(ct, child, d)
Exemple #2
0
 def __recurse_ct(self, ct, n, d):
     """given a cached category tree, a current node, and a dictionary of
     category->preference mappings"""
     current_pref = d[n.id]
     for child in ct.children(n):
         d[child.id] = ml.sample_category_distribution(
             self.transition_matrix[current_pref])[0]
         self.__recurse_ct(ct, child, d)
 def get_preference_dictionary(self, ct):
     """passed a CachedCategoryTree, return category->preference dict"""
     # pass around a dictionary to add
     ret = {}
     
     # start at the concrete node's children
     top_level = ct.children(ct.concrete_node)
     
     for n in top_level:
         # assign randomly
         ret[n.id] = ml.sample_category_distribution(self.original_distribution)[0]
         self.__recurse_ct(ct, n, ret)
     
     return ret
Exemple #4
0
    def get_preference_dictionary(self, ct):
        """passed a CachedCategoryTree, return category->preference dict"""
        # pass around a dictionary to add
        ret = {}

        # start at the concrete node's children
        top_level = ct.children(ct.concrete_node)

        for n in top_level:
            # assign randomly
            ret[n.id] = ml.sample_category_distribution(
                self.original_distribution)[0]
            self.__recurse_ct(ct, n, ret)

        return ret
 def run_round(self, num_recommendations=settings.N):
     """
     run a single round with the given number of recommendations, adding 
     to the behavior database and returning the Round object
     """
     cats = ml.recommend_categories(self.user, ctree=self.ctree,
                                     db=self.db).items()
     categories = [c.id for c in
                   ml.sample_category_distribution(cats, settings.N)]
     actions = map(self.get_action, categories)
     
     r = Round(categories, actions)
     
     # add behavior and to rounds
     self.db.update_from_round(self.user, r)
     return r
Exemple #6
0
    def run_round(self, num_recommendations=settings.N):
        """
        run a single round with the given number of recommendations, adding 
        to the behavior database and returning the Round object
        """
        cats = ml.recommend_categories(self.user, ctree=self.ctree,
                                       db=self.db).items()
        categories = [
            c.id for c in ml.sample_category_distribution(cats, settings.N)
        ]
        actions = map(self.get_action, categories)

        r = Round(categories, actions)

        # add behavior and to rounds
        self.db.update_from_round(self.user, r)
        return r
 def sample_action(self):
     """get one random from this preference distribution"""
     return ml.sample_category_distribution(self.distribution)[0]
Exemple #8
0
 def sample_action(self):
     """get one random from this preference distribution"""
     return ml.sample_category_distribution(self.distribution)[0]