PyBMF.generators package¶
Submodules¶
PyBMF.generators.BaseGenerator module¶
- class PyBMF.generators.BaseGenerator.BaseGenerator[source]¶
Bases:
objectBase class of Boolean matrix generator.
Note
Attributes of
BaseGenerator.- Xndarray, spmatrix
A
m-by-ndata matrix. \(X = U * V\)- Undarray, spmatrix
A
m-by-kfactor matrix.- Vndarray, spmatrix
A
n-by-kfactor matrix.- factor_info: list
[
U_info,V_info]
- add_noise(noise=[0.0, 0.0], seed=None)[source]¶
Add noise to a matrix.
- Parameters:
noise (list of 2 float in [0, 1]) – Probabilities for false negative (p_pos) and false positive (p_neg).
seed (optional) – Random seed.
- check_params(**kwargs)[source]¶
Check parameters.
- Parameters:
overlap_flag (bool) – Whether overlap is allowed or not.
size_range (list of 2 or 4 floats) –
The lower and upper bounds of factor rectangle size (height_low, height_high, width_low, width_high), or just upper bounds (height_high, width_high).
The real size limit is the bounds times size m, n divided by k.
E.g., if k = 5 and the image height m = 1000, the lower and upper bounds are [0.2, 2.0] * 1000 / 5.
seed (int) – Random seed.
- measure()[source]¶
Measure a matrix.
- Returns:
measured_density – Percentage on the number of 1’s.
measured_overlap – Percentage on the number of overlapped 1’s.
- show_matrix(scaling=1.0, pixels=5, colorbar=True, discrete=True, center=True, clim=[0, 1], keep_nan=True, **kwargs)[source]¶
The show_matrix wrapper for Boolean matrix generators.
PyBMF.generators.BlockDiagonalMatrixGenerator module¶
- class PyBMF.generators.BlockDiagonalMatrixGenerator.BlockDiagonalMatrixGenerator(m, n, k, overlap=[0.0, 0.0])[source]¶
Bases:
BaseGeneratorThe block diagonal Boolean matrix generator.
This generation procedure produces factor matrices U and V with C1P (contiguous-1 property). The factors form a block diagonal matrix with overlap configuration (when overlap < 0, there’s no overlap). The matrix is sorted by nature upon generation.
- Parameters:
m (int) – The number of rows in X.
n (int, optional) – The number of columns in X.
k (int, optional) – The rank.
overlap (list of 2 floats in (-inf, 1.0)) – Overlap ratio for factor U (overlap among columns) and factor V (overlap among rows).
PyBMF.generators.BlockMatrixGenerator module¶
- class PyBMF.generators.BlockMatrixGenerator.BlockMatrixGenerator(m, n, k, overlap_flag=None, size_range=None)[source]¶
Bases:
BaseGeneratorThe block Boolean matrix generator.
This generation procedure produces factor matrices U and V with C1P (contiguous-1 property). The factors form a arbitrarily placed block matrix with or without overlapping. The matrix is sorted by nature upon generation.
- Parameters:
m (int) – The number of rows in X.
n (int, optional) – The number of columns in X.
k (int, optional) – The rank.
overlap_flag (bool) – Whether overlap is allowed or not.
size_range (list of 2 or 4 floats) –
The lower and upper bounds of factor rectangle size (height_low, height_high, width_low, width_high), or just upper bounds (height_high, width_high).
The real size limit is the bounds times size m, n divided by k.
E.g., if k = 5 and the image height m = 1000, the lower and upper bounds are [0.2, 2.0] * 1000 / 5.
- check_overlap(k, points_start_u, points_end_u, points_start_v, points_end_v)[source]¶
Check overlap.
- Parameters:
k (int) – The rank.
points_start_u (list of ints) – The start points of U.
points_end_u (list of ints) – The end points of U.
points_start_v (list of ints) – The start points of V.
points_end_v (list of ints) – The end points of V.
- Returns:
is_overlapped
- Return type:
bool
- generate_factor(n, k, points_start, points_end)[source]¶
Generate a factor.
- Parameters:
n (int) – The number of rows in X.
k (int) – The rank.
points_start (list of ints) – The start points of X.
points_end (list of ints) – The end points of X.
- generate_factor_points(n, k, low, high)[source]¶
Generate a factor point sequence.
- Parameters:
n (int) – The number of points.
k (int) – The rank.
low (float) – The lower bound of the interval.
high (float) – The upper bound of the interval.
- Returns:
points_start (list of ints) – The start points.
points_end (list of ints) – The end points.
PyBMF.generators.SyntheticMatrixGenerator module¶
- class PyBMF.generators.SyntheticMatrixGenerator.SyntheticMatrixGenerator(m, n, k, density=[0.2, 0.2])[source]¶
Bases:
BaseGeneratorThe synthetic Boolean matrix generator.
- Parameters:
m (int) – The number of rows in X.
n (int, optional) – The number of columns in X.
k (int, optional) – The rank.
density (float, list of floats) – Accept a value between [0, 1] or a 2-element list. When it’s a list, it represents densities for factor U (density of columns of X) and factor V (density of rows of X). Typically, density lies between [0.1, 0.3].
Module contents¶
- class PyBMF.generators.BlockDiagonalMatrixGenerator(m, n, k, overlap=[0.0, 0.0])[source]¶
Bases:
BaseGeneratorThe block diagonal Boolean matrix generator.
This generation procedure produces factor matrices U and V with C1P (contiguous-1 property). The factors form a block diagonal matrix with overlap configuration (when overlap < 0, there’s no overlap). The matrix is sorted by nature upon generation.
- Parameters:
m (int) – The number of rows in X.
n (int, optional) – The number of columns in X.
k (int, optional) – The rank.
overlap (list of 2 floats in (-inf, 1.0)) – Overlap ratio for factor U (overlap among columns) and factor V (overlap among rows).