Exemplo n.º 1
0
    def _deactivate_learning_node(self, to_deactivate: ActiveLearningNode,
                                  parent: SplitNode, parent_branch: int):
        """Deactivate a learning node.

        Parameters
        ----------
        to_deactivate: ActiveLearningNode
            The node to deactivate.
        parent: SplitNode
            The node's parent.
        parent_branch: int
            Parent node's branch index.
        """
        if self.leaf_prediction == _TARGET_MEAN:
            new_leaf = InactiveLearningNodeForRegression(
                to_deactivate.get_observed_class_distribution())
        elif self.leaf_prediction == _PERCEPTRON:
            new_leaf = InactiveLearningNodePerceptronMultiTarget(
                to_deactivate.get_observed_class_distribution(),
                to_deactivate.perceptron_weight, to_deactivate.random_state)
        elif self.leaf_prediction == _ADAPTIVE:
            new_leaf = InactiveLearningNodeAdaptiveMultiTarget(
                to_deactivate.get_observed_class_distribution(),
                to_deactivate.perceptron_weight, to_deactivate.random_state)
            new_leaf.fMAE_M = to_deactivate.fMAE_M
            new_leaf.fMAE_P = to_deactivate.fMAE_P
        if parent is None:
            self._tree_root = new_leaf
        else:
            parent.set_child(parent_branch, new_leaf)
        self._active_leaf_node_cnt -= 1
        self._inactive_leaf_node_cnt += 1
Exemplo n.º 2
0
    def _new_learning_node(self, initial_class_observations=None, parent_node=None,
                           is_active_node=True):
        """Create a new learning node. The type of learning node depends on
        the tree configuration.
        """
        if initial_class_observations is None:
            initial_class_observations = {}

        if is_active_node:
            if self.leaf_prediction == self._TARGET_MEAN:
                return ActiveLearningNodeForRegressionMultiTarget(
                    initial_class_observations
                )
            elif self.leaf_prediction == self._PERCEPTRON:
                return ActiveLearningNodePerceptronMultiTarget(
                    initial_class_observations,
                    parent_node,
                    random_state=self.random_state
                )
            elif self.leaf_prediction == self._ADAPTIVE:
                new_node = ActiveLearningNodeAdaptiveMultiTarget(
                    initial_class_observations,
                    parent_node,
                    random_state=self.random_state
                )
                # Resets faded errors
                new_node.fMAE_M = np.zeros(self._n_targets, dtype=np.float64)
                new_node.fMAE_P = np.zeros(self._n_targets, dtype=np.float64)
                return new_node
        else:
            if self.leaf_prediction == self._TARGET_MEAN:
                return InactiveLearningNodeForRegression(
                    initial_class_observations
                )
            elif self.leaf_prediction == self._PERCEPTRON:
                return InactiveLearningNodePerceptronMultiTarget(
                    initial_class_observations,
                    parent_node,
                    random_state=parent_node.random_state
                )
            elif self.leaf_prediction == self._ADAPTIVE:
                new_node = InactiveLearningNodeAdaptiveMultiTarget(
                    initial_class_observations,
                    parent_node,
                    random_state=parent_node.random_state
                )
                new_node.fMAE_M = parent_node.fMAE_M
                new_node.fMAE_P = parent_node.fMAE_P
                return new_node