Skip to main content

About

wNMFx implements a simple version of Non-Negative Matrix Factorization (NMF) that utilizes a weight matrix to weight the importance of each feature in each sample of the data matrix to be factorized.

wNMFx is easy to use, because it behaves like an sklearn.decomposition model, but also allows for multiple fitting attempts.

More information about the modified multiplicative update algorithim utilized can be found here: Blondel, Vincent & Ho, Ngoc-Diep & Van Dooren, Paul. (2007). Weighted Nonnegative Matrix Factorization and Face Feature Extraction

wNMFx specifically implements solutions for determining the decomposed matrices U and V when minimizing the Frobenius Norm or the Kullback-Leibler Divergence:

wNMF was developed by SN: https://github.com/asn32/weighted-nmf. wNMFx is a fork which speeds up the computation with jax. wNMFx follows the scikit-learn conventions. Additional features include transform().

Installation

This package is available on PyPI and can be installed with pip:

$ pip install wNMFx

Alternatively, download the source from github and install:

$ git clone https://github.com/JohannesBuchner/weighted-nmf-jax
$ cd weighted-nmf-jax
$ python3 setup.py install --user

Usage

wNMFx is a python library that can be imported:

from wNMFx import wNMF

And it can be used like an sklearn.decomposition model.

First create an instance of the wNMF model by setting the number of components.

Other parameters can be set too, such as the loss function, maximum number of iterations, and whether or not to track the decreasing error over every single run:

## Mock data, a 100x100 data matrix, reduce to 25 dimensions
n = 100
features = 100
components = 25
X = 100 * np.random.uniform(size=(features, n))
W = np.ones_like(X)

## Define the model / fit
model = wNMF(n_components=25,
            beta_loss='kullback-leibler',
            max_iter=1000,
            track_error=True)

Then, fit the model to the data using the instance methods wNMF().fit or wNMF().fit_transform:

fit = model.fit(X=X,W=W,n_run=5)

After the fit is complete, explore the fit quality by examining the decomposed matrices and / or overall error:

## Get the best solutions
lowest_error = fit.err
best_V = fit.V
best_U = fit.U

## Or look at all the solutions from the 5 runs in this example
all_Vs = fit.V_all

License

wNMFx is MIT-licensed

Disclaimer

wNMFx is provided with no guarantees.

Metadata

Release files for wNMFx 1.0.3

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

Source distribution (sdist)

Source distribution for wNMFx 1.0.3
File Size Uploaded
wnmfx-1.0.3.tar.gz 20.2 kB Details

Release files / wnmfx-1.0.3.tar.gz

Download URL wnmfx-1.0.3.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4ad4670ccfa3ced016024fae824fed8fa1d5dfef3a071b4235adb08f35189cb4
BLAKE2b-256 checksum
How to use checksums
cc11a17923267ad6d97b17174e40695a11d3a4ea7c6f83e2eb0d6a2e35711a72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.1

1 release file

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