Module nmtf.modules.nmtf_core
Non-negative matrix and tensor factorization core functions
Functions
def NMFApplyKernel(M, NMFKernel, Mt, Mw)
-
Calculate kernel (used with convex NMF)
Input
M: Input matrix NMFKernel: Type of kernel =-1: linear = 2: quadratic = 3: radiant Mt: Left factoring matrix Mw: Right factoring matrix
Output
Kernel
def NMFProjGrad(V, Vmis, W, Hinit, NMFAlgo, lambdax, tol, MaxIterations, NMFPriors)
-
Projected gradient Code and notations adapted from Matlab code, Chih-Jen Lin
Input
V: Input matrix Vmis: Define missing values (0 = missing cell, 1 = real cell) W: Left factoring vectors (fixed) Hinit: Right factoring vectors (initial values) NMFAlgo: =1,3: Divergence; =2,4: Least squares; lambdax: Sparseness parameter =-1: no penalty < 0: Target percent zeroed rows in H > 0: Current penalty tol: Tolerance MaxIterations: max number of iterations to achieve norm(projected gradient) < tol NMFPriors: Elements in H that should be updated (others remain 0)
Output
H: Estimated right factoring vectors tol: Current level of the tolerance lambdax: Current level of the penalty
Reference
C.J. Lin (2007) Projected Gradient Methods for Non-negative Matrix Factorization Neural Comput. 2007 Oct;19(10):2756-79.
def NMFProjGradKernel(Kernel, V, Vmis, W, Hinit, NMFAlgo, tol, MaxIterations, NMFPriors)
-
Projected gradient, kernel version Code and notations adapted from Matlab code, Chih-Jen Lin
Input
Kernel: Kernel used V: Input matrix Vmis: Define missing values (0 = missing cell, 1 = real cell) W: Left factoring vectors (fixed) Hinit: Right factoring vectors (initial values) NMFAlgo: =1,3: Divergence; =2,4: Least squares; tol: Tolerance MaxIterations: max number of iterations to achieve norm(projected gradient) < tol NMFPriors: Elements in H that should be updated (others remain 0)
Output
H: Estimated right factoring vectors tol: Current level of the tolerance
Reference
C.J. Lin (2007) Projected Gradient Methods for Non-negative Matrix Factorization Neural Comput. 2007 Oct;19(10):2756-79.
def NMFReweigh(M, Mt, NMFPriors, AddMessage)
-
Overload skewed variables (used with deconvolution only)
Input
M: Input matrix Mt: Left hand matrix NMFPriors: priors on right hand matrix
Output
NMFPriors: updated priors
Note: This code is still experimental
def NMFSolve(M, Mmis, Mt0, Mw0, nc, tolerance, precision, LogIter, Status0, MaxIterations, NMFAlgo, NMFFixUserLHE, NMFFixUserRHE, NMFMaxInterm, NMFMaxIterProj, NMFSparseLevel, NMFFindParts, NMFFindCentroids, NMFKernel, NMFReweighColumns, NMFPriors, flagNonconvex, AddMessage, myStatusBox)
-
Estimate left and right hand matrices
Input
M: Input matrix Mmis: Define missing values (0 = missing cell, 1 = real cell) Mt0: Initial left hand matrix Mw0: Initial right hand matrix nc: NMF rank tolerance: Convergence threshold precision: Replace 0-value in multiplication rules LogIter: Log results through iterations Status0: Initial displayed status to be updated during iterations MaxIterations: Max iterations NMFAlgo: =1,3: Divergence; =2,4: Least squares; NMFFixUserLHE: = 1 => fixed left hand matrix columns NMFFixUserRHE: = 1 => fixed right hand matrix columns NMFMaxInterm: Max iterations for warmup multiplication rules NMFMaxIterProj: Max iterations for projected gradient NMFSparseLevel: Requested sparsity in terms of relative number of rows with 0 values in right hand matrix NMFFindParts: Enforce convexity on left hand matrix NMFFindCentroids: Enforce convexity on right hand matrix NMFKernel: Type of kernel used; 1: linear; 2: quadratic; 3: radial NMFReweighColumns: Reweigh columns in 2nd step of parts-based NMF NMFPriors: Priors on right hand matrix flagNonconvex: Non-convexity flag on left hand matrix
Output
Mt: Left hand matrix Mw: Right hand matrix diff: objective cost Mh: Convexity matrix NMFPriors: Updated priors on right hand matrix flagNonconvex: Updated non-convexity flag on left hand matrix
Reference
C. H.Q. Ding et al (2010) Convex and Semi-Nonnegative Matrix Factorizations IEEE Transactions on Pattern Analysis and Machine Intelligence Vol: 32 Issue: 1
def NTFSolve(M, Mmis, Mt0, Mw0, Mb0, nc, tolerance, LogIter, Status0, MaxIterations, NMFFixUserLHE, NMFFixUserRHE, NMFFixUserBHE, NMFSparseLevel, NTFUnimodal, NTFSmooth, NTFLeftComponents, NTFRightComponents, NTFBlockComponents, NBlocks, NTFNConv, NMFPriors, myStatusBox)
-
Interface to: - NTFSolve_simple - NTFSolve_conv
def NTFSolveFast(M, Mmis, Mt0, Mw0, Mb0, nc, tolerance, precision, LogIter, Status0, MaxIterations, NMFFixUserLHE, NMFFixUserRHE, NMFFixUserBHE, NTFUnimodal, NTFSmooth, NTFLeftComponents, NTFRightComponents, NTFBlockComponents, NBlocks, myStatusBox)
-
Estimate NTF matrices (fast HALS)
Input
M: Input matrix Mmis: Define missing values (0 = missing cell, 1 = real cell) Mt0: Initial left hand matrix Mw0: Initial right hand matrix Mb0: Initial block hand matrix nc: NTF rank tolerance: Convergence threshold precision: Replace 0-values in multiplication rules LogIter: Log results through iterations Status0: Initial displayed status to be updated during iterations MaxIterations: Max iterations NMFFixUserLHE: fix left hand matrix columns: = 1, else = 0 NMFFixUserRHE: fix right hand matrix columns: = 1, else = 0 NMFFixUserBHE: fix block hand matrix columns: = 1, else = 0 NTFUnimodal: Apply Unimodal constraint on factoring vectors NTFSmooth: Apply Smooth constraint on factoring vectors NTFLeftComponents: Apply Unimodal/Smooth constraint on left hand matrix NTFRightComponents: Apply Unimodal/Smooth constraint on right hand matrix NTFBlockComponents: Apply Unimodal/Smooth constraint on block hand matrix NBlocks: Number of NTF blocks
Output
Mt: Left hand matrix Mw: Right hand matrix Mb: Block hand matrix diff: objective cost
Note: This code does not support missing values, nor sparsity constraint
def NTFSolve_conv(M, Mmis, Mt0, Mw0, Mb0, nc, tolerance, LogIter, Status0, MaxIterations, NMFFixUserLHE, NMFFixUserRHE, NMFFixUserBHE, NMFSparseLevel, NTFUnimodal, NTFSmooth, NTFLeftComponents, NTFRightComponents, NTFBlockComponents, NBlocks, NTFNConv, NMFPriors, myStatusBox)
-
Estimate NTF matrices (HALS)
Input
M: Input matrix Mmis: Define missing values (0 = missing cell, 1 = real cell) Mt0: Initial left hand matrix Mw0: Initial right hand matrix Mb0: Initial block hand matrix nc: NTF rank tolerance: Convergence threshold LogIter: Log results through iterations Status0: Initial displayed status to be updated during iterations MaxIterations: Max iterations NMFFixUserLHE: = 1 => fixed left hand matrix columns NMFFixUserRHE: = 1 => fixed right hand matrix columns NMFFixUserBHE: = 1 => fixed block hand matrix columns NMFSparseLevel : sparsity level (as defined by Hoyer); +/- = make RHE/LHe sparse NTFUnimodal: Apply Unimodal constraint on factoring vectors NTFSmooth: Apply Smooth constraint on factoring vectors NTFLeftComponents: Apply Unimodal/Smooth constraint on left hand matrix NTFRightComponents: Apply Unimodal/Smooth constraint on right hand matrix NTFBlockComponents: Apply Unimodal/Smooth constraint on block hand matrix NBlocks: Number of NTF blocks NTFNConv: Half-Size of the convolution window on 3rd-dimension of the tensor NMFPriors: Elements in Mw that should be updated (others remain 0)
Output
Mt : if NTFNConv > 0 only otherwise empty. Contains sub-components for each phase in convolution window Mt_simple: Left hand matrix (sum of columns Mt_conv for each k) Mw_simple: Right hand matrix Mb_simple: Block hand matrix diff: objective cost
Note: This code extends HALS to allow for shifting on the 3rd dimension of the tensor. Suffix '_simple' is added to the non-convolutional components. Convolutional components are named the usual way.
def NTFSolve_simple(M, Mmis, Mt0, Mw0, Mb0, nc, tolerance, LogIter, Status0, MaxIterations, NMFFixUserLHE, NMFFixUserRHE, NMFFixUserBHE, NMFSparseLevel, NTFUnimodal, NTFSmooth, NTFLeftComponents, NTFRightComponents, NTFBlockComponents, NBlocks, NMFPriors, myStatusBox)
-
Estimate NTF matrices (HALS)
Input
M: Input matrix Mmis: Define missing values (0 = missing cell, 1 = real cell) Mt0: Initial left hand matrix Mw0: Initial right hand matrix Mb0: Initial block hand matrix nc: NTF rank tolerance: Convergence threshold LogIter: Log results through iterations Status0: Initial displayed status to be updated during iterations MaxIterations: Max iterations NMFFixUserLHE: = 1 => fixed left hand matrix columns NMFFixUserRHE: = 1 => fixed right hand matrix columns NMFFixUserBHE: = 1 => fixed block hand matrix columns NMFSparseLevel : sparsity level (as defined by Hoyer); +/- = make RHE/LHe sparse NTFUnimodal: Apply Unimodal constraint on factoring vectors NTFSmooth: Apply Smooth constraint on factoring vectors NTFLeftComponents: Apply Unimodal/Smooth constraint on left hand matrix NTFRightComponents: Apply Unimodal/Smooth constraint on right hand matrix NTFBlockComponents: Apply Unimodal/Smooth constraint on block hand matrix NBlocks: Number of NTF blocks NMFPriors: Elements in Mw that should be updated (others remain 0)
Output
Mt: Left hand matrix Mw: Right hand matrix Mb: Block hand matrix diff: objective cost
Reference
A. Cichocki, P.H.A.N. Anh-Huym, Fast local algorithms for large scale nonnegative matrix and tensor factorizations, IEICE Trans. Fundam. Electron. Commun. Comput. Sci. 92 (3) (2009) 708–721.
def NTFStack(M, Mmis, NBlocks)
-
Unfold tensor M for future use with NMF
def NTFUpdate(NBlocks, Mpart, IDBlockp, p, Mb, k, Mt, n, Mw, n_Mmis, Mmis, Mres, NMFFixUserLHE, denomt, Mw2, denomCutoff, alpha, NTFUnimodal, NTFLeftComponents, NTFSmooth, A, NMFFixUserRHE, denomw, Mt2, NTFRightComponents, B, NMFFixUserBHE, MtMw, nxp, denomBlock, NTFBlockComponents, C, Mfit, NMFPriors)
-
Core updating code called by NTFSolve_simple & NTF Solve_conv
Input
All variables in the calling function used in the function
Output
Same as Input