Skip to content

implementation of nonnegative matrix factorization in Java for GC-MS spectral deconvolution

License

Notifications You must be signed in to change notification settings

du-lab/nonnegative_matrix_factorization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaNMF: A Java library for Non-negative Matrix Factorization

Java library for performing non-negative matrix factorization. A non-negative matrix X is factorized into the product of two matrices W and H, such that the distance between X and WH is minimal. The distance can be evaluated using the euclidean distance or the generalized Kullback-Leibler divergence with optional regularization terms. Two types of gradient-descent update rules are supported.

Implemented distance org.dulab.javanmf.measures
  • Euclidean distance || XWH ||2.
Implemented update rules
Implemented org.dulab.javanmf.algorithms

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Installation

To install the package, clone this project and use maven to build it:

git clone https://github.com/du-lab/nonnegative_matrix_factorization.git
cd nonnegative_matrix_factorization/
mvn clean install

Documentation

Example: Given matrixX and num_components, perform non-negative matrix factorization using the euclidean distance with regularization, multiplicative update rule, and NNDSVD-initialization.

final int num_points = matrixX.rows;
final int num_vectors = matrixX.columns;

// Create matrices W and H
DMatrixRMaj matrixW = new DMatrixRMaj(num_points, num_components);
DMatrixRMaj matrixH = new DMatrixRMaj(num_components, num_vectors);

// Initialize matrices W and H by the NNDSVD-method
new SingularValueDecomposition(matrixX).decompose(matrixW, matrixH);

// Choose update rules for matrices W and H:
// Multiplicative update rule for the euclidean distance with l1-regularization
UpdateRule updateRuleW = new MUpdateRule(1.0, 0.0);
// Multiplicative update rule for the euclidean distance with l2-regularization
UpdateRule updateRuleH = new MUpdateRule(0.0, 1.0);

// Perform factorization
new MatrixFactorization(updateRuleW, updateRuleH, 1e-4, 10000).execute(matrixX, matrixW, matrixH);

Or, perform non-negative matrix factorization using the alternating least squares method.

final int num_points = matrixX.rows;
final int num_vectors = matrixX.columns;

// Randomly initialize matrices W and H
Random random = new Random(0);
DMatrixRMaj matrixW = rectangle(num_points, num_components, 0.0, 1.0, random);
DMatrixRMaj matrixH = rectangle(num_components, num_vectors, 0.0, 1.0, random);

// Perform factorization
new AlternatingLeastSquaresMatrixFactorization(1e-4, 10000).solve(matrixX, matrixW, matrixH);

Detailed API documentation can be found here.

Contributing

Code contributions are welcome. Please, contact us if you have any questions.

Authors

Licence

This project is licenced under the GNU GPL v2 licence - see the LICENSE file for details.

Versions

Version 0.2.3

  • Set a limit on the number of iterations in NonNegativeLeastSquares algorithm

Version 0.2.2

  • Fix the error when the passive set is empty and vector S is calculated

Version 0.2.1

  • Adds the active set method for solving Non-Negative Least Squares problem
  • Adds the alternating least squares method for solving Non-Negative Least Squares problem

Version 0.2.0

  • Replaces matrix library jBlas with EJML (Efficient Java Matrix Library)

About

implementation of nonnegative matrix factorization in Java for GC-MS spectral deconvolution

Resources

License

Stars

Watchers

Forks

Packages

No packages published