Skip to main content

PyPI Python License

A PyTorch implementation on Non-negative Matrix Factorization.

Installation

This package is published on PyPI:

pip install nmf-torch

Usage

NMF

Given a non-negative numeric matrix X of shape M-by-N (M is number of samples, N number of features) in either numpy array or torch tensor structure, run the following code:

from nmf import run_nmf
H, W, err = run_nmf(X, n_components=20)

will decompose X into two new non-negative matrices:

  • H of shape (M, 20), representing the transformed coordinates of samples regarding the 20 components;

  • W of shape (20, N), representing the composition of each component in terms of features;

along with the loss between X and its approximation H*W.

Advanced Settings

By default, run_nmf function uses the batch HALS solver for NMF decomposition. In total, there are other solvers available in NMF-torch:

  • HALS: Hierarchical Alternative Least Squares ([Kimura et al., 2015]). The default.

  • MU: Multiplicative Update. Set algo='mu' in run_nmf function.

  • BPP: Alternative non-negative least squares with Block Principal Pivoting method ([Kim & Park, 2011]). Set algo='bpp' in run_nmf function.

Besides, each solver has two modes: batch and online. The online mode is a modified version which is scalable for input matrix of a large number of samples. You can set mode='online' in run_nmf function to switch to use the online mode.

The default beta loss is Frobenius (L2) distance, which is the most commonly used. By changing beta_loss parameter in run_nmf function, users can specify other beta loss metrics:

  • KL divergence: beta_loss='kullback-leibler' or beta_loss=1.0;

  • Itakura-Saito divergence: beta_loss='itakura-saito' or beta_loss=0;

  • Or any non-negative float number.

Notice that since online mode only works for L2 loss, if you specify other beta loss, run_nmf will automatically switch back to batch mode.

For the other parameters in run_nmf function, please type help(run_nmf) in your Python interpreter to view.


Data Integration using Integrative NMF (iNMF)

In this case, we have a list of k batches, with their corresponding non-negative numeric matrices to be integrated. Let X be such a list, and all matrices in X have the same number of features, i.e. each Xi in X has shape (Mi, N), where Mi is number of samples in batch i, and N is number of features.

The following code:

from nmf import integrative_nmf
H, W, V, err = integrative_nmf(X, n_components=20)

will perform iNMF, which results in the following non-negative matrices:

  • H: List of matrices of shape (Mi, 20), each of which represents the transformed coordinates of samples regarding components of the corresponding batch;

  • W of shape (20, N), representing the common composition (shared information) across the given batches in terms of features;

  • V: List of matrices of the same shape (20, N), each of which represents the batch-specific composition in terms of features of the corresponding batch,

along with the overall L2 loss between Xi and its approximation Hi * (W + Vi) for each batch i.

Advanced Settings

Similarly as in run_nmf function above, integrative_nmf provides 2 modes (batch and online) and 3 solvers: HALS, MU, and BPP. By default, batch HALS is used. You can switch to other solvers and modes by specifying algo and mode parameters.

There is another important parameter lam for the coefficient for regularization terms, with default value 5.0. If set to 0, then no regularization will be applied.

Notice that only L2 loss is accepted in iNMF.

For the other parameters in integrative_nmf function, please type help(integrative_nmf) in your Python interpreter to view.

Metadata

Release files for nmf-torch 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nmf-torch 0.1.1
File Size Uploaded
nmf-torch-0.1.1.tar.gz 158.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for nmf-torch 0.1.1
File
nmf_torch-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
nmf_torch-0.1.1-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
nmf_torch-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
nmf_torch-0.1.1-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
nmf_torch-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
nmf_torch-0.1.1-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details

Total release size: 2.7 MB

Release files / nmf-torch-0.1.1.tar.gz

Download URL nmf-torch-0.1.1.tar.gz
Size 158.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5d2c967e5caa6f9cd4bb662290a4f34942a1dc51778be28e283ce57233ef3ce6
BLAKE2b-256 checksum
How to use checksums
8592b3b0ace261e2da347ccd35fc7afa080d68c1f992827190a4991d14280516
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

Release files / nmf_torch-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nmf_torch-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 705.4 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
69de5ea83adbb0ad79415b5b6f7d525b5c511ff5c9e1f97acdc563ea86c6d6ab
BLAKE2b-256 checksum
How to use checksums
47c4efed0bf014017ce18baec317fbef6b81c2be68e5dea5703ee6f9a4ccff27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

Release files / nmf_torch-0.1.1-cp39-cp39-macosx_10_9_x86_64.whl

Download URL nmf_torch-0.1.1-cp39-cp39-macosx_10_9_x86_64.whl
Size 142.9 kB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
dd159cbcff0c6cb2792aa062dc6dff04cbe8254627c5b7cb69bbedba3728b9f0
BLAKE2b-256 checksum
How to use checksums
e0a1eab01c63164819733031fca67c1be371bc88b9e0d1789a45dce2beab0d65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

Release files / nmf_torch-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nmf_torch-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 757.7 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5386cc43584db5e4ffbb03c1a29e43277e4d726d508b0f1340054ae5eb14deec
BLAKE2b-256 checksum
How to use checksums
0aab40eff3daef53f5893f106a410a03045e718a35547b1f37d0131593a876ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

Release files / nmf_torch-0.1.1-cp38-cp38-macosx_10_9_x86_64.whl

Download URL nmf_torch-0.1.1-cp38-cp38-macosx_10_9_x86_64.whl
Size 151.8 kB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
3b2d036a2fd95956fa83f87e15b3609692da5b2af9006125ef248f423f157a6f
BLAKE2b-256 checksum
How to use checksums
9c613be73d3e560fcbf1bcc29a0126964dc1ef9865ec6a0c116cdf8eaa7bac7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

Release files / nmf_torch-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nmf_torch-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 659.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
05449f76e09eb5d0a465dd9a848e6134cac8450cc1dd82421121ac23eb8fce58
BLAKE2b-256 checksum
How to use checksums
6199a04150e6a0f61bad9244fe927b214a59cdf4fdb71c1e8f6327c984b869a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

Release files / nmf_torch-0.1.1-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL nmf_torch-0.1.1-cp37-cp37m-macosx_10_9_x86_64.whl
Size 156.3 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
1cd6d8790886aca4119e5914ee0b36f6d4b7b89c7fcb03f1da97202acfc01801
BLAKE2b-256 checksum
How to use checksums
cb0d26bd1110d591071d1c003dff497dce20181c50b35a7c28d4a1093aabfa35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

Release history Release notifications | RSS feed

This release

0.1.1 This release

7 release files

0.1.0

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page