예제 #1
0
    def _distance_iter_random(self, other, ntimes):
        self._logger.debug(
            f"APTED: Heuristic search. {len(self.trees)} {len(other.trees)}")
        config = AptedConfig(randomize=False)
        yield Apted(self.first_tree, other.first_tree,
                    config).compute_edit_distance()

        config = AptedConfig(randomize=True)
        for _ in range(ntimes):
            yield Apted(self.first_tree, other.first_tree,
                        config).compute_edit_distance()
예제 #2
0
    def _distance_iter_random(self, other: "ReactionTreeWrapper",
                              ntimes: int) -> _FloatIterator:
        self._logger.debug(
            f"APTED: Heuristic search. {len(self.trees)} {len(other.trees)}")
        config = AptedConfig(randomize=False)
        yield Apted(self.first_tree, other.first_tree,
                    config).compute_edit_distance()

        config = AptedConfig(randomize=True)
        for _ in range(ntimes):
            yield Apted(self.first_tree, other.first_tree,
                        config).compute_edit_distance()
예제 #3
0
 def _distance_iter_exhaustive(
         self, other: "ReactionTreeWrapper") -> _FloatIterator:
     self._logger.debug(
         f"APTED: Exhaustive search. {len(self.trees)} {len(other.trees)}")
     config = AptedConfig(randomize=False)
     for tree1, tree2 in itertools.product(self.trees, other.trees):
         yield Apted(tree1, tree2, config).compute_edit_distance()
예제 #4
0
    def distance_to_with_sorting(self, other: "ReactionTreeWrapper") -> float:
        """
        Compute the distance to another tree, by simpling sorting the children
        of both trees. This is not guaranteed to return the minimum distance.

        :param other: another tree to calculate distance to
        :return: the distance
        """
        config = AptedConfig(sort_children=True, dist_func=self._dist_func)
        return Apted(self.first_tree, other.first_tree, config).compute_edit_distance()
예제 #5
0
    def _distance_iter_semi_exhaustive(self, other):
        self._logger.debug(
            f"APTED: Semi-exhaustive search. {len(self.trees)} {len(other.trees)}"
        )
        if len(self.trees) < len(other.trees):
            first_wrapper = self
            second_wrapper = other
        else:
            first_wrapper = other
            second_wrapper = self

        config = AptedConfig(randomize=False)
        for tree1 in first_wrapper.trees:
            yield Apted(tree1, second_wrapper.first_tree,
                        config).compute_edit_distance()