Esempio n. 1
0
    def filter_instance_to_leaf(self, X, parent, parent_branch):
        """ Traverse down the tree to locate the corresponding leaf for an instance.

        Parameters
        ----------
        X: numpy.ndarray of shape (n_samples, n_features)
           Data instances.
        parent: skmultiflow.trees.nodes.Node
            Parent node.
        parent_branch: int
            Parent branch index.

        Returns
        -------
        FoundNode
            Leaf node for the instance.

        """
        child_index = self.instance_child_index(X)
        if child_index >= 0:
            child = self.get_child(child_index)
            if child is not None:
                return child.filter_instance_to_leaf(X, self, child_index)
            else:
                return FoundNode(None, self, child_index)
        else:
            return FoundNode(self, parent, parent_branch)
Esempio n. 2
0
 def filter_instance_to_leaves(self,
                               X,
                               y,
                               weight,
                               parent,
                               parent_branch,
                               update_splitter_counts=False,
                               found_nodes=None):
     if found_nodes is None:
         found_nodes = []
     if update_splitter_counts:
         try:
             self._observed_class_distribution[
                 y] += weight  # Dictionary (class_value, weight)
         except KeyError:
             self._observed_class_distribution[y] = weight
     child_index = self.instance_child_index(X)
     if child_index >= 0:
         child = self.get_child(child_index)
         if child is not None:
             child.filter_instance_to_leaves(X, y, weight, parent,
                                             parent_branch,
                                             update_splitter_counts,
                                             found_nodes)
         else:
             found_nodes.append(FoundNode(None, self, child_index))
     if self._alternate_tree is not None:
         self._alternate_tree.filter_instance_to_leaves(
             X, y, weight, self, -999, update_splitter_counts, found_nodes)
    def __find_learning_nodes(self, node, parent, parent_branch, found):
        """ Find learning nodes in the tree from a given node.

        Parameters
        ----------
        node: skmultiflow.trees.nodes.Node
            The node to start the search.
        parent: LearningNode or SplitNode
            The node's parent.
        parent_branch: int
            Parent node's branch.

        Returns
        -------
        list
            List of learning nodes.
        """
        if node is not None:
            if isinstance(node, LearningNode):
                found.append(FoundNode(node, parent, parent_branch))
            if isinstance(node, SplitNode):
                split_node = node
                for i in range(split_node.num_children()):
                    self.__find_learning_nodes(split_node.get_child(i),
                                               split_node, i, found)
 def filter_instance_to_leaves(self,
                               X,
                               y,
                               weight,
                               parent,
                               parent_branch,
                               update_splitter_counts,
                               found_nodes=None):
     if found_nodes is None:
         found_nodes = []
     found_nodes.append(FoundNode(self, parent, parent_branch))
Esempio n. 5
0
    def filter_instance_to_leaf(self, X, parent, parent_branch):
        """ Traverse down the tree to locate the corresponding leaf for an instance.

        Parameters
        ----------
        X: numpy.ndarray of shape (n_samples, n_features)
           Data instances.
        parent: skmultiflow.trees.nodes.Node or None
            Parent node.
        parent_branch: Int
            Parent branch index

        Returns
        -------
        FoundNode
            The corresponding leaf.

        """
        return FoundNode(self, parent, parent_branch)