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 == _PERCEPTRON: new_leaf = SSTInactiveLearningNode( to_deactivate.get_observed_class_distribution(), to_deactivate.perceptron_weight) elif self.leaf_prediction == _ADAPTIVE: new_leaf = SSTInactiveLearningNodeAdaptive( to_deactivate.get_observed_class_distribution(), to_deactivate.perceptron_weight) new_leaf.fMAE_M = to_deactivate.fMAE_M new_leaf.fMAE_P = to_deactivate.fMAE_P new_leaf.fMAE_SP = to_deactivate.fMAE_SP 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
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._PERCEPTRON: return SSTActiveLearningNode(initial_class_observations, parent_node, random_state=self.random_state) elif self.leaf_prediction == self._ADAPTIVE: new_node = SSTActiveLearningNodeAdaptive( 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) new_node.fMAE_SP = np.zeros(self._n_targets, dtype=np.float64) return new_node else: if self.leaf_prediction == self._PERCEPTRON: return SSTInactiveLearningNode( initial_class_observations, parent_node, random_state=parent_node.random_state) elif self.leaf_prediction == self._ADAPTIVE: new_node = SSTInactiveLearningNodeAdaptive( 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 new_node.fMAE_SP = parent_node.fMAE_SP return new_node