HierMat package¶
Submodules¶
HierMat.block_cluster_tree module¶
block_cluster_tree.py: BlockClusterTree
,
build_block_cluster_tree()
,
recursion_build_block_cluster_tree()
-
class
HierMat.block_cluster_tree.
BlockClusterTree
(left_clustertree, right_clustertree, sons=None, level=0, is_admissible=False, plot_info=None)[source]¶ Bases:
object
Compares two cluster trees level wise with respect to an admissibility condition and builds a tree
-
depth
(root_level=None)[source]¶ Get depth of the tree
Parameters: root_level (int) – internal use. Returns: depth Return type: int Hint
recursive function
-
draw
(axes, admissible_color='#1e26bc', inadmissible_color='#bc1d38')[source]¶ Draw a patch into given axes
Parameters: - axes (matplotlib.pyplot.axes) – axes instance to draw in
- admissible_color (str) – color for admissible patch (see matplotlib for color specs)
- inadmissible_color (str) – color for inadmissible patch
-
export
(form='xml', out_file='bct_out')[source]¶ Export obj in specified format.
Parameters: Raises: NotImplementedError – if form is not supported
Note
implemented so far:
- xml
- dot
- bin
-
plot
(filename=None, ticks=False, face_color='#133f52', admissible_color='#76f7a8', inadmissible_color='#ff234b')[source]¶ Plot the block cluster tree
Parameters: Note
depends on
matplotlib.pyplot
-
-
HierMat.block_cluster_tree.
build_block_cluster_tree
(left_cluster_tree, right_cluster_tree=None, start_level=0, admissible_function=<function admissible>)[source]¶ Factory for building a block cluster tree
Parameters: - left_cluster_tree (ClusterTree) – “left side” cluster tree
- right_cluster_tree (ClusterTree) – “right side” cluster tree
- start_level (int) – counter that keeps track of the level
- admissible_function (function that returns a bool) – function that determines whether two cluster trees are admissible or not. This is
crucial for the structure of the block cluster tree. (See
utils.admissible
for an example)
Returns: block cluster tree
Return type:
-
HierMat.block_cluster_tree.
recursion_build_block_cluster_tree
(current_tree, admissible_function)[source]¶ Recursion to
build_block_cluster_tree()
HierMat.cluster module¶
cluster.py: Cluster
object and iterator
-
class
HierMat.cluster.
Cluster
(grid, indices=None)[source]¶ Bases:
object
Handles operations on a
Grid
object by manipulating an index list-
diameter
()[source]¶ Compute diameter
Return the maximal Euclidean distance between two points For big Clusters this is costly
Returns: diameter Return type: float
-
distance
(other)[source]¶ Compute distance to other cluster
Return minimal Euclidean distance between points of self and other
Parameters: other – another instance of Cluster Returns: distance Return type: float
-
HierMat.cluster_tree module¶
cluster_tree.py: ClusterTree
, build_cluster_tree()
, recursion_build_cluster_tree()
-
class
HierMat.cluster_tree.
ClusterTree
(content, sons=None, max_leaf_size=1, level=0)[source]¶ Bases:
object
Tree structure built according to the
Splitable
in useSplits are done until max_leaf_size is reached
-
depth
(root_level=None)[source]¶ Get depth of the tree
Parameters: root_level (int) – internal use. Returns: depth Return type: int Hint
recursive function
-
distance
(other)[source]¶ Return distance to other
Parameters: other (ClusterTree) – other cluster tree Returns: distance Return type: float
-
export
(form='xml', out_file='out')[source]¶ Export obj in specified format.
Parameters: Raises: NotImplementedError – if form is not supported
Note
implemented so far:
- xml
- dot
- bin
-
get_grid_item
(item)[source]¶ Get grid item from content
Parameters: item (int) – index of item to get
-
get_index
(item)[source]¶ Get index from content
Parameters: item (int) – index to get Returns: index Return type: int
-
-
HierMat.cluster_tree.
build_cluster_tree
(splitable, max_leaf_size=1, start_level=0)[source]¶ Factory for building a cluster tree
Parameters: Returns: cluster tree
Return type:
-
HierMat.cluster_tree.
recursion_build_cluster_tree
(current_tree)[source]¶ Recursion to
build_cluster_tree()
HierMat.cuboid module¶
cuboid.py: Cuboid
and minimal_cuboid()
-
class
HierMat.cuboid.
Cuboid
(low_corner, high_corner)[source]¶ Bases:
object
Cuboid that is parallel to the axis in Cartesian coordinates.
Characterized by two diagonal corners.
Attributes:
low_corner: numpy.array with minimal values in each dimension
high_corner: numpy.array with maximal values in each dimension
-
diameter
()[source]¶ Return the diameter of the cuboid.
Diameter is the Euclidean distance between low_corner and high_corner.
Returns: diameter Return type: float
HierMat.grid module¶
grid.py: Grid
object and iterator
HierMat.hmat module¶
hmat.py: HMat
-
class
HierMat.hmat.
HMat
(blocks=(), content=None, shape=(), root_index=())[source]¶ Bases:
object
Implement a hierarchical Matrix
-
to_matrix
()[source]¶ Full matrix representation
Returns: full matrix Return type: numpy.matrix
-
-
HierMat.hmat.
build_hmatrix
(block_cluster_tree=None, generate_rmat_function=None, generate_full_matrix_function=None)[source]¶ Factory to build an HMat instance
Parameters: - block_cluster_tree (BlockClusterTree) – block cluster tree giving the structure
- generate_rmat_function – function taking an admissible block cluster tree and returning a rank-k matrix
- generate_full_matrix_function – function taking an inadmissible block cluster tree and returning a numpy.matrix
Returns: hmatrix
Return type: Raises: ValueError if root of BlockClusterTree is admissible
-
HierMat.hmat.
recursion_build_hmatrix
(current_hmat, block_cluster_tree, generate_rmat, generate_full_mat)[source]¶ Recursion to
build_hmatrix()
HierMat.rmat module¶
rmat.py: RMat
-
class
HierMat.rmat.
RMat
(left_mat, right_mat=None, max_rank=None)[source]¶ Bases:
object
Rank-k matrix
Implementation of the low rank matrix as described in [HB2015]
-
form_add
(other, rank=None)[source]¶ Formatted addition of self and other, i.e. addition and reduction to rank:
(self + other).reduce(rank)
If rank is omitted, reduction to min(rank(self), rank(other))
Parameters: Returns: reduced result
Return type:
-
from_matrix
(matrix, max_rank)[source]¶ Convert a full matrix to the rank k format
Parameters: - matrix (numpy.matrix) – Matrix to convert to RMat
- max_rank (int) – maximum rank
Returns: Best approximation of matrix in RMat format
Return type:
-
norm
(order=None)[source]¶ Norm of the matrix
Parameters: order – order of the norm (see in numpy.linalg.norm()
)Returns: norm Return type: float
-
reduce
(new_k)[source]¶ Perform a reduced QR decomposition to rank new_k
Parameters: new_k (int) – rank to reduce to Returns: reduced matrix Return type: RMat
-
to_matrix
()[source]¶ Full matrix representation:
left_mat * right_mat.T
Returns: full matrix Return type: numpy.matrix
-
HierMat.splitable module¶
splitable.py: Splitable
(Interface) and iterator and different strategies
-
Starting from a minimal cuboid that get’s split in half on every level, points are distributed according to their geometric location
-
Same as RegularCuboid, but after every split, the cuboids are reduced to minimal size
-
Distributes the points evenly on every level, depends solely on the order of the initial list
-
class
HierMat.splitable.
Balanced
(cluster)[source]¶ Bases:
HierMat.splitable.Splitable
Balanced strategy, where a cluster is always split in half only according to its size, without regarding the geometry
Gives a binary tree
-
diameter
()[source]¶ Return the diameter
Diameter of the contained cluster
Returns: diameter Return type: float
-
distance
(other)[source]¶ Distance to other balanced
Parameters: other (Balanced) – other balanced Returns: distance Return type: float
-
get_grid_item
(item)[source]¶ Get grid item from cluster
Parameters: item (int) – index of item to get
-
get_index
(item)[source]¶ Get index from cluster
Parameters: item (int) – index to get Returns: index Return type: int
-
-
class
HierMat.splitable.
MinimalCuboid
(cluster)[source]¶ Bases:
HierMat.splitable.RegularCuboid
Method of minimal cuboids
Split is implemented by splitting the surrounding cuboid in half along longest axis and distributing indices according to the cuboid they belong to. Afterwards all resulting cuboids are shrunk to minimal.
Gives a binary tree
-
split
()[source]¶ Split the cuboid and distribute items in cluster according to the cuboid they belong to. Reduce every split to minimal size
Returns: list of minimal cuboids of smaller size Return type: list(MinimalCuboid)
-
-
class
HierMat.splitable.
RegularCuboid
(cluster, cuboid=None)[source]¶ Bases:
HierMat.splitable.Splitable
Method of regular cuboids
If no cuboid is given, a minimal cuboid is built around initial list of indices. Split is then implemented by splitting the surrounding cuboid in half along longest axis and distributing indices according to the cuboid they belong to.
Gives a binary tree
-
diameter
()[source]¶ Return the diameter of the cuboid
Diameter of the surrounding cuboid
Returns: diameter Return type: float
-
distance
(other)[source]¶ Return the distance between own cuboid and other cuboid
Parameters: other (RegularCuboid) – other regular cuboid Returns: distance Return type: float
-
get_grid_item
(item)[source]¶ Get grid item from cluster
Parameters: item (int) – index of item to get
-
get_index
(item)[source]¶ Get index from cluster
Parameters: item (int) – index to get Returns: index Return type: int
-
get_patch_coordinates
()[source]¶ Return min and max out of indices
Returns: min and max Return type: tuple(int, int)
-
split
()[source]¶ Split the cuboid and distribute items in cluster according to the cuboid they belong to
Returns: list of smaller regular cuboids Return type: list(RegularCuboid)
-
-
class
HierMat.splitable.
Splitable
[source]¶ Bases:
object
Interface to the different strategies that can be used to split a cluster in two or more.
Note
Methods that need to be implemented by subclasses:
- __len__: return the length of the cluster
- __iter__: return SplitableIterator(self)
- __repr__: give a meaningful string representation
- __getitem__: return item from inner cluster
- __eq__: check for equality against other Splitable
- get_index: return index from inner cluster
- get_grid_item: return grid item from inner cluster
- get_patch_coordinates: return min and max of index list of cluster
- split: split the object in two or more, return new instances
- diameter: return the diameter of the object
- distance: return the distance to other object
HierMat.utils module¶
utils.py: Utilities for the HMatrix
module
-
HierMat.utils.
admissible
(left_clustertree, right_clustertree)[source]¶ Default admissible condition for BlockClusterTree
True if the smaller diameter of the input is smaller or equal to the distance between the two ClusterTrees
Parameters: - left_clustertree (ClusterTree) – “Left-side” ClusterTree
- right_clustertree (ClusterTree) – “Right-side” ClusterTree
Returns: admissible
Return type:
-
HierMat.utils.
divisor_generator
(n)[source]¶ Return divisors of n
Parameters: n (int) – integer to find divisors of Returns: divisors Return type: list[int] Warning
This is a generator! To get a list with all divisors call:
list(divisor_generator(n))
Note
found at StackOverflow on 2017.03.08
-
HierMat.utils.
load
(filename)[source]¶ Load a
ClusterTree
orBlockClusterTree
from fileParameters: filename (String) – file to import Returns: object Return type: BlockClusterTree or ClusterTree Note
Depends on
pickle