kmapper.Cover¶

class
kmapper.
Cover
(n_cubes=10, perc_overlap=0.5, limits=None, verbose=0)[source]¶ Bases:
object
Helper class that defines the default covering scheme
It calculates the cover based on the following formula for overlap. (https://arxiv.org/pdf/1706.00204.pdf)
cube[i] intersection cube[i+1] overlap =  cube[i]
 Parameters
n_cubes (int) – Number of hypercubes along each dimension. Sometimes referred to as resolution.
perc_overlap (float) – Amount of overlap between adjacent cubes calculated only along 1 dimension.
limits (Numpy Array (n_dim,2)) – (lower bound, upper bound) for every dimension If a value is set to np.float(‘inf’), the bound will be assumed to be the min/max value of the dimension Also, if limits == None, the limits are defined by the maximum and minimum value of the lens for all dimensions. i.e. [[min_1, max_1], [min_2, max_2], [min_3, max_3]]
Example
>>> import numpy as np >>> from kmapper.cover import Cover >>> data = np.random.random((100,2)) >>> cov = Cover(n_cubes=15, perc_overlap=0.75) >>> cube_centers = cov.fit(data) >>> cov.transform_single(data, cube_centers[0]) array([[0.3594448 , 0.07428465], [0.14490332, 0.01395559], [0.94988668, 0.03983579], [0.73517978, 0.09420806], [0.16903735, 0.06901085], [0.81578595, 0.10708731], [0.26923572, 0.12216203], [0.89203167, 0.0711279 ], [0.80442115, 0.10220901], [0.33210782, 0.04365007], [0.52207707, 0.05892861], [0.26589744, 0.08502856], [0.02360067, 0.1263653 ], [0.29855631, 0.01209373]]) >>> hyper_cubes = cov.transform(data, cube_centers)

__init__
(n_cubes=10, perc_overlap=0.5, limits=None, verbose=0)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([n_cubes, perc_overlap, limits, …])Initialize self.
find
(data_point)Finds the hypercubes that contain the given data point.
fit
(data)Fit a cover on the data.
fit_transform
(data)transform
(data[, centers])Find entries of all hypercubes.
transform_single
(data, center[, i])Compute entries of data in hypercube centered at center

find
(data_point)[source]¶ Finds the hypercubes that contain the given data point.
 Parameters
data_point (arraylike) – The data point to locate.
 Returns
cube_ids (list of int) – list of hypercube indices, empty if the data point is outside the cover.

fit
(data)[source]¶ Fit a cover on the data. This method constructs centers and radii in each dimension given the perc_overlap and n_cube.
 Parameters
data (arraylike) – Data to apply the cover to. Warning: First column must be an index column.
 Returns
centers (list of arrays) – A list of centers for each cube

transform
(data, centers=None)[source]¶ Find entries of all hypercubes. If centers=None, then use self.centers_ as computed in self.fit.
Empty hypercubes are removed from the result
 Parameters
data (arraylike) – Data to find in entries in cube. Warning: first column must be index column.
centers (list of arraylike) – Center points for all cubes as returned by self.fit. Default is to use self.centers_.
 Returns
hypercubes (list of arraylike) – list of entries in each hypercube in data.

transform_single
(data, center, i=0)[source]¶ Compute entries of data in hypercube centered at center
 Parameters
data (arraylike) – Data to find in entries in cube. Warning: first column must be index column.
center (arraylike) – Center points for the cube. Cube is found as all data in [centerself.radius_, center+self.radius_]
i (int, default 0) – Optional counter to aid in verbose debugging.