Module nmtf.modules.nmtf_utils

Non-negative matrix and tensor factorization utility functions

Functions

def BuildClusters(Mt, Mw, Mb, MtPct, MwPct, NBlocks, BlkSize, NMFCalculateLeverage, NMFUseRobustLeverage, NMFAlgo, NMFRobustClusterByStability, CellPlotOrderedClusters, AddMessage, myStatusBox)

Builder clusters from leverages

def ClusterPvalues(ClusterSize, nbGroups, Mt, RCt, NCt, RowGroups, ListGroups, Ngroup)

Calculate Pvalue of each group versus cluster

def GlobalSign(Nrun, nbGroups, Mt, RCt, NCt, RowGroups, ListGroups, Ngroup, myStatusBox)

Calculate global significance of association with a covariate following multiple factorization trials

def Leverage(V, NMFUseRobustLeverage, AddMessage, myStatusBox)

Calculate leverages

Input

V: Input column vectors NMFUseRobustLeverage: Estimate robust through columns of V

Output

Vn: Leveraged column vectors

Reference

P. Fogel et al (2016) Applications of a Novel Clustering Approach Using Non-Negative Matrix Factorization to Environmental Research in Public Health Int. J. Environ. Res. Public Health 2016, 13, 509; doi:10.3390/ijerph13050509

def NMFDet(Mt, Mw, NMFExactDet)

Volume occupied by Left and Right factoring vectors

Input

Mt: Left hand matrix Mw: Right hand matrix NMFExactDet if = 0 compute an approximate determinant in reduced space n x n or p x p through random sampling in the largest dimension

Output

detXcells: determinant

Reference

P. Fogel et al (2016) Applications of a Novel Clustering Approach Using Non-Negative Matrix Factorization to Environmental Research in Public Health Int. J. Environ. Res. Public Health 2016, 13, 509; doi:10.3390/ijerph13050509

def NMFGetConvexScores(Mt, Mw, Mh, flag, AddMessage)

Rescale scores to sum up to 1 (used with deconvolution)

Input

Mt: Left factoring matrix Mw: Right factoring matrix flag: Current value

Output

Mt: Left factoring matrix Mw: Right factoring matrix flag: += 1: Negative weights found

def RobustMax(V0, AddMessage, myStatusBox)

Robust max of column vectors

For each column: = weighted mean of column elements larger than 95% percentile for each row, weight = specificity of the column value wrt other columns

Input

V0: column vectors Output: Robust max by column

Reference

P. Fogel et al (2016) Applications of a Novel Clustering Approach Using Non-Negative Matrix Factorization to Environmental Research in Public Health Int. J. Environ. Res. Public Health 2016, 13, 509; doi:10.3390/ijerph13050509

def percentile_exc(a, q)

Percentile, exclusive

Input

a: Matrix q: Percentile

Output

Percentile

def shift(arr, num, fill_value=1.1920929e-07)

Shift a vector

Parameters

arr: Input column vector
num: number of indexes to shift ( < 0: To the left )

Returns

result: shifted column vector

Examples

>>> import pytest
>>> import numpy as np
>>> from nmtf.modules.nmtf_utils import shift
>>> arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> b = arr
>>> num = -2
>>> fill_value = 0
>>> shift(b, num, fill_value)
array([ 3,  4,  5,  6,  7,  8,  9, 10,  0,  0])
>>> num = 2
array([0, 0, 1, 2, 3, 4, 5, 6, 7, 8])
def sparse_opt(b, alpha, two_sided)

Return the L2-closest vector with sparsity alpha

Input

b: original vector

Output

x: sparse vector

Reference

V. K. Potluru & all (2013) Block Coordinate Descent for Sparse NMF arXiv:1301.3527v2 [cs.LG]

Examples

>>> from nmtf.modules.nmtf_utils import sparse_opt
>>> b_ = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> alpha_ = 1
>>> two_sided_ = True
>>> sparse_opt(b_, alpha_, two_sided_)
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., nan])
>>> two_sided_ = False
>>> sparse_opt(b_, alpha_, two_sided_)
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., nan])

Classes

class StatusBox

Methods

def close(self)
def close_dialog(self)
def init_bar(self, delay=1)
def myPrint(self, status='')
def update_bar(self, delay=1, step=1)
def update_status(self, delay=1, status='')
class StatusBoxTqdm (verbose=0)

Methods

def close(self)
def init_bar(self, delay=0)
def myPrint(self, status='')
def update_bar(self, delay=0, step=1)
def update_status(self, delay=0, status='')