def test_get_children_random(): config = AptedConfig(randomize=True) children = config.children(node1) assert len(children) == 3 for expected_child in ["A", "B", "C"]: assert expected_child in children
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, dist_func=self._dist_func) yield Apted(self.first_tree, other.first_tree, config).compute_edit_distance() config = AptedConfig(randomize=True, dist_func=self._dist_func) for _ in range(ntimes): yield Apted( self.first_tree, other.first_tree, config ).compute_edit_distance()
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, dist_func=self._dist_func) for tree1, tree2 in itertools.product(self.trees, other.trees): yield Apted(tree1, tree2, config).compute_edit_distance()
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()
def _distance_iter_semi_exhaustive( self, other: "ReactionTreeWrapper" ) -> _FloatIterator: 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, dist_func=self._dist_func) for tree1 in first_wrapper.trees: yield Apted( tree1, second_wrapper.first_tree, config ).compute_edit_distance()
def test_get_children_fixed(): config = AptedConfig() assert config.children(node1) == ["A", "B", "C"]
def test_rename_cost_same_types(): config = AptedConfig() cost = config.rename(node1, node2) assert cost == 0.5
def test_rename_cost_different_types(): config = AptedConfig() cost = config.rename({"type": "type1"}, {"type": "type2"}) assert cost == 1