Exemple #1
0
 def check_variables(self):
     if not all([
             Manager.is_digit(i)
             for i in [self.ratio, self.capacity, self.indices]
     ]):
         return ManagerError(
             "split_ratio, capacity, indices must be all digits")
     if any([
             point for point in self.points
             if not isinstance(point, np.ndarray)
     ]):
         return ManagerError(
             "every point in node must be in the form of Numpy array")
     else:
         if self.cell_count() > 0:
             vec_dim = [
                 vec.ndim for vec in self.points
             ]  # Identifying whether or not passed data is a vector space
             if vec_dim.count(vec_dim[0]) != len(vec_dim):
                 return ManagerError(
                     "every basis of vector space must be equal")
     if not isinstance(self.parent, InternalNode) or isinstance(
             self.parent, RootNode):
         return TreeError(
             "parent node must be either InternalNode or RootNode instance")
Exemple #2
0
 def remove_node(
     self, tree_node
 ):  # Negligible for current version, but might be helpful in the future
     if tree_node in self.node_array.values():
         self.node_array.__delitem__(
             self.node_array.values().index(tree_node))
     else:
         raise TreeError("input must be present in node_array")
Exemple #3
0
 def node_exists(tree, position):
     if isinstance(tree, PartitionTree):
         for node in tree.node_array:
             if node.node_position == position:
                 return node
         return []
     else:
         return TreeError("tree must be passed as first argument")
Exemple #4
0
 def add_node(
     self, tree_node
 ):  # Negligible for current version, but might be helpful in the future
     if isinstance(tree_node, RootNode):
         if not self.root_node:  # Root node must obviously be the first node
             self.root_node = tree_node
             self.node_array.__setitem__(0, self.root_node)
         else:
             self.node_array.__delitem__(0)
             self.root_node = tree_node
             self.node_array.__setitem__(0, self.root_node)
     elif isinstance(tree_node, InternalNode):
         if not self.root_node:
             raise TreeError("RootNode instance must be added first")
         else:
             self.node_array.__setitem__(
                 len(self.node_array) - 1, tree_node)
     else:
         raise TreeError("input must be InternalNode or RootNode instance")
Exemple #5
0
 def set_node_array(self, node_array):
     if isinstance(node_array, dict):
         if all([
                 isinstance(node[0], InternalNode)
                 or isinstance(node[0], RootNode)
                 for node in node_array.values()
         ]):
             if not isinstance(
                     node_array.get(0, [InternalNode])[0], RootNode):
                 raise TreeError(
                     "node_array must contain RootNode as its first element"
                 )
             else:
                 self.root_node = node_array[0]
                 self.node_array = node_array
         else:
             raise TreeError(
                 "node_array dictionary objects shall only contain InternalNode and RootNode values"
             )
     else:
         raise TreeError("node_array must be a dict object")
Exemple #6
0
 def check_variables(self):
     if not isinstance(self.space, np.ndarray):
         raise TreeError("vector space must be in the form of Numpy array")
Exemple #7
0
 def show_root(self):
     if not self.root_node:
         raise TreeError("root node not present in tree")
     else:
         return self.root_node