Пример #1
0
    def parent_sets(self, child_index):
        # a parent set is a subset of all nodes preceding the child in the order
        before_child = self.order[:child_index]
        child = self.order[child_index]
        use_best_families, families = self._family_cache.best_families(child, before_child)
        if use_best_families:
            return families

        parents = frozenset(before_child) & self._family_cache.potential_parents(child)
        return powersetn(parents, self._family_cache._max_parents_family)
Пример #2
0
    def _update_best_families(self, child):
        # calculate the best families for a child.
        # the best families are those that score highest; keep the top max_parents_family
        # families.
        family_score = {}
        for parents in powersetn(self._potential_parents[child], self._max_parents_family):
            family_score[frozenset(parents)] = self.family_score(child, parents)

        family_order = sorted(family_score.keys(), cmp=lambda x,y: cmp(family_score[y], family_score[x]))
        family_order = family_order[:self._max_best_families]
        self._best_families[child] = tuple([(parents,family_score[parents]) for parents in family_order])
Пример #3
0
    def parent_sets(self, child_index):
        # a parent set is a subset of all nodes preceding the child in the order
        before_child = self.order[:child_index]
        child = self.order[child_index]
        use_best_families, families = self._family_cache.best_families(
            child, before_child)
        if use_best_families:
            return families

        parents = frozenset(
            before_child) & self._family_cache.potential_parents(child)
        return powersetn(parents, self._family_cache._max_parents_family)
Пример #4
0
    def _update_best_families(self, child):
        # calculate the best families for a child.
        # the best families are those that score highest; keep the top max_parents_family
        # families.
        family_score = {}
        for parents in powersetn(self._potential_parents[child],
                                 self._max_parents_family):
            family_score[frozenset(parents)] = self.family_score(
                child, parents)

        family_order = sorted(
            family_score.keys(),
            cmp=lambda x, y: cmp(family_score[y], family_score[x]))
        family_order = family_order[:self._max_best_families]
        self._best_families[child] = tuple([(parents, family_score[parents])
                                            for parents in family_order])