PyBMF.generators package

Submodules

PyBMF.generators.BaseGenerator module

class PyBMF.generators.BaseGenerator.BaseGenerator[source]

Bases: object

Base class of Boolean matrix generator.

Note

Attributes of BaseGenerator.

Xndarray, spmatrix

A m-by-n data matrix. \(X = U * V\)

Undarray, spmatrix

A m-by-k factor matrix.

Vndarray, spmatrix

A n-by-k factor 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.

boolean_matmul()[source]

Boolean matrix multiplication.

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.

generate()[source]

Generate a matrix.

generate_factor()[source]

Generate a factor.

generate_factors()[source]

Generate factors.

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.

measure_density()[source]

Measure the density of a matrix.

measure_overlap()[source]

Measure the overlap of a matrix.

set_config(**kwargs)[source]
set_factor_info()[source]

Set factor_info.

set_params(**kwargs)[source]
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.

shuffle(seed=None)[source]

Shuffle a matrix together with its factors.

Parameters:

seed (int) – Random seed.

shuffle_factors(seed=None)[source]

Shuffle the factors of a matrix to re-arrange the bi-clusters.

sorted_index()[source]

Make index sorted for a sorted matrix.

sortout(method=None)[source]

Sort out a matrix.

to_dense()[source]

Convert U, V, X to dense matrices.

to_sparse(type='csr')[source]

Convert U, V, X to sparse matrices.

PyBMF.generators.BlockDiagonalMatrixGenerator module

class PyBMF.generators.BlockDiagonalMatrixGenerator.BlockDiagonalMatrixGenerator(m, n, k, overlap=[0.0, 0.0])[source]

Bases: BaseGenerator

The 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).

generate(seed=None)[source]

Generate a matrix.

generate_factor(n, k, overlap)[source]

Generate a factor.

generate_factors()[source]

Generate factors.

PyBMF.generators.BlockMatrixGenerator module

class PyBMF.generators.BlockMatrixGenerator.BlockMatrixGenerator(m, n, k, overlap_flag=None, size_range=None)[source]

Bases: BaseGenerator

The 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(seed=None)[source]

Generate a matrix.

Parameters:

seed (int) – Random seed.

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.

generate_factors()[source]

Generate factors.

is_overlapped(A, B)[source]

Check if two rectangles are overlapped.

Parameters:
  • A (list of 4 ints) – The first rectangle.

  • B (list of 4 ints) – The second rectangle.

Returns:

is_overlapped

Return type:

int

PyBMF.generators.SyntheticMatrixGenerator module

class PyBMF.generators.SyntheticMatrixGenerator.SyntheticMatrixGenerator(m, n, k, density=[0.2, 0.2])[source]

Bases: BaseGenerator

The 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].

generate(seed=None)[source]

Generate a matrix.

generate_factor(n, k, density)[source]

Generate a factor matrix.

Parameters:
  • n (int) – Number of rows.

  • k (int) – Number of columns.

  • density (float) – Density of 1’s on the tail of each column.

Returns:

The n-by-k factor matrix.

Return type:

array

generate_factors()[source]

Generate factors.

Module contents

class PyBMF.generators.BlockDiagonalMatrixGenerator(m, n, k, overlap=[0.0, 0.0])[source]

Bases: BaseGenerator

The 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).

generate(seed=None)[source]

Generate a matrix.

generate_factor(n, k, overlap)[source]

Generate a factor.

generate_factors()[source]

Generate factors.