def _get_leaf_nodes(self, node, i_tree, class_label, box): from copy import deepcopy from art.metrics.verification_decisions_trees import LeafNode, Box, Interval leaf_nodes = list() if 'split_index' in node: node_left = node['left_child'] node_right = node['right_child'] box_left = deepcopy(box) box_right = deepcopy(box) feature = node['split_feature'] box_split_left = Box(intervals={feature: Interval(-np.inf, node['threshold'])}) box_split_right = Box(intervals={feature: Interval(node['threshold'], np.inf)}) if box.intervals: box_left.intersect_with_box(box_split_left) box_right.intersect_with_box(box_split_right) else: box_left = box_split_left box_right = box_split_right leaf_nodes += self._get_leaf_nodes(node_left, i_tree, class_label, box_left) leaf_nodes += self._get_leaf_nodes(node_right, i_tree, class_label, box_right) if 'leaf_index' in node: leaf_nodes.append(LeafNode(tree_id=i_tree, class_label=class_label, node_id=node['leaf_index'], box=box, value=node['leaf_value'])) return leaf_nodes
def _get_leaf_nodes(self, node_id, i_tree, class_label, box): from copy import deepcopy from art.metrics.verification_decisions_trees import LeafNode, Box, Interval leaf_nodes = list() if self.get_left_child(node_id) != self.get_right_child(node_id): node_left = self.get_left_child(node_id) node_right = self.get_right_child(node_id) box_left = deepcopy(box) box_right = deepcopy(box) feature = self.get_feature_at_node(node_id) box_split_left = Box(intervals={feature: Interval(-np.inf, self.get_threshold_at_node(node_id))}) box_split_right = Box(intervals={feature: Interval(self.get_threshold_at_node(node_id), np.inf)}) if box.intervals: box_left.intersect_with_box(box_split_left) box_right.intersect_with_box(box_split_right) else: box_left = box_split_left box_right = box_split_right leaf_nodes += self._get_leaf_nodes(node_left, i_tree, class_label, box_left) leaf_nodes += self._get_leaf_nodes(node_right, i_tree, class_label, box_right) else: leaf_nodes.append(LeafNode(tree_id=i_tree, class_label=class_label, node_id=node_id, box=box, value=self.get_values_at_node(node_id)[0, 0])) return leaf_nodes
def _get_leaf_nodes(self, node, i_tree, class_label, box) -> List["LeafNode"]: from art.metrics.verification_decisions_trees import LeafNode, Box, Interval leaf_nodes: List[LeafNode] = [] if "children" in node: if node["children"][0]["nodeid"] == node["yes"] and node[ "children"][1]["nodeid"] == node["no"]: node_left = node["children"][0] node_right = node["children"][1] elif node["children"][1]["nodeid"] == node["yes"] and node[ "children"][0]["nodeid"] == node["no"]: node_left = node["children"][1] node_right = node["children"][0] else: raise ValueError box_left = deepcopy(box) box_right = deepcopy(box) feature = int(node["split"][1:]) box_split_left = Box( intervals={ feature: Interval(-np.inf, node["split_condition"]) }) box_split_right = Box( intervals={feature: Interval(node["split_condition"], np.inf)}) if box.intervals: box_left.intersect_with_box(box_split_left) box_right.intersect_with_box(box_split_right) else: box_left = box_split_left box_right = box_split_right leaf_nodes += self._get_leaf_nodes(node_left, i_tree, class_label, box_left) leaf_nodes += self._get_leaf_nodes(node_right, i_tree, class_label, box_right) if "leaf" in node: leaf_nodes.append( LeafNode( tree_id=i_tree, class_label=class_label, node_id=node["nodeid"], box=box, value=node["leaf"], )) return leaf_nodes
def _get_leaf_nodes(self, node, i_tree, class_label, box): from copy import deepcopy from art.metrics.verification_decisions_trees import LeafNode, Box, Interval leaf_nodes = list() if 'children' in node: if node['children'][0]['nodeid'] == node['yes'] and node[ 'children'][1]['nodeid'] == node['no']: node_left = node['children'][0] node_right = node['children'][1] elif node['children'][1]['nodeid'] == node['yes'] and node[ 'children'][0]['nodeid'] == node['no']: node_left = node['children'][1] node_right = node['children'][0] else: raise ValueError box_left = deepcopy(box) box_right = deepcopy(box) feature = int(node['split'][1:]) box_split_left = Box( intervals={ feature: Interval(-np.inf, node['split_condition']) }) box_split_right = Box( intervals={feature: Interval(node['split_condition'], np.inf)}) if box.intervals: box_left.intersect_with_box(box_split_left) box_right.intersect_with_box(box_split_right) else: box_left = box_split_left box_right = box_split_right leaf_nodes += self._get_leaf_nodes(node_left, i_tree, class_label, box_left) leaf_nodes += self._get_leaf_nodes(node_right, i_tree, class_label, box_right) if 'leaf' in node: leaf_nodes.append( LeafNode(tree_id=i_tree, class_label=class_label, node_id=node['nodeid'], box=box, value=node['leaf'])) return leaf_nodes
def _get_leaf_nodes(self, node, i_tree, class_label, box) -> List["LeafNode"]: from art.metrics.verification_decisions_trees import Box, Interval, LeafNode leaf_nodes: List[LeafNode] = list() if "split_index" in node: node_left = node["left_child"] node_right = node["right_child"] box_left = deepcopy(box) box_right = deepcopy(box) feature = node["split_feature"] box_split_left = Box( intervals={feature: Interval(-np.inf, node["threshold"])}) box_split_right = Box( intervals={feature: Interval(node["threshold"], np.inf)}) if box.intervals: box_left.intersect_with_box(box_split_left) box_right.intersect_with_box(box_split_right) else: box_left = box_split_left box_right = box_split_right leaf_nodes += self._get_leaf_nodes(node_left, i_tree, class_label, box_left) leaf_nodes += self._get_leaf_nodes(node_right, i_tree, class_label, box_right) if "leaf_index" in node: leaf_nodes.append( LeafNode( tree_id=i_tree, class_label=class_label, node_id=node["leaf_index"], box=box, value=node["leaf_value"], )) return leaf_nodes