Package org.dulab.javanmf.algorithms
Class MatrixFactorization
java.lang.Object
org.dulab.javanmf.algorithms.MatrixFactorization
public class MatrixFactorization
extends java.lang.Object
This class performs non-negative matrix factorization: for given matrix X, find matrices W and H that minimize the
objective function
D(X, WH) + λw||W||1 + λh||H||1 + 0.5 μw||W||2 + 0.5 μh||H||2
where D(X, WH) is either the euclidean distance or the Kullback-Leibler divergence, ||·|| is the Frobenius norm, and ||·||1 is the l1-norm.
Example for given matrix matrixX
, matrices matrixW
and matrixH
are modified
to minimize the euclidean distance with regularization.
UpdateRule updateRuleW = new MUpdateRule(1.0, 0.0);
UpdateRule updateRuleH = new MUpdateRule(0.0, 1.0);
MatrixFactorization factorization = new MatrixFactorization(
updateRuleW, updateRuleH, 1e-6, 10000);
factorization.execute(matrixX, matrixW, matrixH);
- Author:
- Du-Lab Team dulab.binf@gmail.com
-
Constructor Summary
Constructors Constructor Description MatrixFactorization(UpdateRule updateRuleW, UpdateRule updateRuleH, double tolerance, int maxIteration)
Creates an instance ofMatrixFactorization
-
Method Summary
Modifier and Type Method Description void
execute(org.ejml.data.DMatrixRMaj data, org.ejml.data.DMatrixRMaj w, org.ejml.data.DMatrixRMaj h)
Performs the non-negative matrix factorization with given initial matrices W and H.void
execute(org.ejml.data.DMatrixRMaj data, org.ejml.data.DMatrixRMaj w, org.ejml.data.DMatrixRMaj h, boolean verbose)
Performs the non-negative matrix factorization with given initial matrices W and H.
-
Constructor Details
-
MatrixFactorization
public MatrixFactorization(@Nonnull UpdateRule updateRuleW, @Nonnull UpdateRule updateRuleH, double tolerance, int maxIteration)Creates an instance ofMatrixFactorization
- Parameters:
updateRuleW
- instance ofUpdateRule
for matrix WupdateRuleH
- instance ofUpdateRule
for matrix Htolerance
- the fitting error tolerancemaxIteration
- maximum number of iterations to use
-
-
Method Details
-
execute
public void execute(@Nonnull org.ejml.data.DMatrixRMaj data, @Nonnull org.ejml.data.DMatrixRMaj w, @Nonnull org.ejml.data.DMatrixRMaj h, boolean verbose)Performs the non-negative matrix factorization with given initial matrices W and H.Parameters
w
andh
contain the result of the factorization.- Parameters:
data
- matrix of shape [Npoints, Nvectors], a collection of vectors in Npoints-dimensional spacew
- matrix of shape [Npoints, Ncomponents], a collection of initial componentsh
- matrix of shape [Ncomponents, Nvectors], a collection of initial coefficientsverbose
- flag to output verbose information
-
execute
public void execute(@Nonnull org.ejml.data.DMatrixRMaj data, @Nonnull org.ejml.data.DMatrixRMaj w, @Nonnull org.ejml.data.DMatrixRMaj h)Performs the non-negative matrix factorization with given initial matrices W and H.Parameters
w
andh
contain the result of the factorization.- Parameters:
data
- matrix of shape [Npoints, Nvectors], a collection of vectors in Npoints-dimensional spacew
- matrix of shape [Npoints, Ncomponents], a collection of initial componentsh
- matrix of shape [Ncomponents, Nvectors], a collection of initial coefficients
-