PNMF: Probabilistic Non-negative Matrix Factorization
A PyTorch-based implementation of Probabilistic NMF with projected gradient optimization, compatible with scikit-learn's API.
Installation
pip install pnmf
For development installation:
git clone https://github.com/luisdiaz1997/Probabilistic-NMF.git
cd Probabilistic-NMF
pip install -e .
Quick Start
from PNMF import PNMF
import numpy as np
# Create some sample data
X = np.random.rand(100, 50)
# Initialize and fit the model
model = PNMF(n_components=5, init='random', random_state=42)
W = model.fit_transform(X) # Transformed data: (100, 5)
H = model.components_ # Components: (5, 50)
# Reconstruct the data
X_reconstructed = model.inverse_transform(W)
Model
PNMF uses a Poisson likelihood for the observed data:
- yij ~ Poisson(λij)
- λij = Σl Wjl exp(Fil)
- Fil ~ N(0, σ²)
where W ≥ 0 are the loadings and F are the latent factors (variational inference with Gaussian prior).
Features
- Probabilistic NMF: Uses Poisson factorization for count data
- Projected Gradients: Three modes for enforcing non-negativity:
softplus: Uses softplus transformationexp: Uses exponential transformationprojected: Uses projected gradient descent (default)
- sklearn-compatible API: Works seamlessly with scikit-learn workflows
- GPU Support: Automatic CUDA detection and utilization
API Reference
PNMF(n_components=2, init='random', init_mode='projected', max_iter=200, tol=1e-4, learning_rate=0.01, random_state=None, verbose=False, device='auto')
Parameters:
n_components: Number of latent components (default: 2)init: Initialization method - 'random' or 'custom' (default: 'random')init_mode: Non-negativity enforcement - 'softplus', 'exp', or 'projected' (default: 'projected')max_iter: Maximum number of iterations (default: 200)tol: Tolerance for convergence (default: 1e-4)learning_rate: Learning rate for gradient descent (default: 0.01)random_state: Random seed for reproducibility (default: None)verbose: Whether to print progress messages (default: False)device: Device to use - 'cpu', 'cuda', or 'auto' (default: 'auto')
Methods:
fit(X, y=None, W=None, H=None): Fit the model to data Xtransform(X): Transform X using the fitted modelfit_transform(X, **kwargs): Fit the model and transform Xinverse_transform(H): Transform data back to original space
License
GNU General Public License v2.0
Author
Luis Chumpitaz Diaz
Acknowledgments
This implementation borrows code from GPzoo.
Metadata
Release files for pnmf 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pnmf-0.1.0.tar.gz | 18.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pnmf-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.4 kB
Release files / pnmf-0.1.0.tar.gz
| Download URL | pnmf-0.1.0.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03ab523d26475353a2ec588fc4ba83490397f4ab67498753384e2e5c2afc1084
|
|
BLAKE2b-256 checksum How to use checksums |
c10961f46b381058b4f6f70bd607c829bf79c70cb16a687d79029abd05cc4d99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / pnmf-0.1.0-py3-none-any.whl
| Download URL | pnmf-0.1.0-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
255e49d596058f0ebd16ca1783825d2f5f87c4183e86becf62caf25dbb032e2b
|
|
BLAKE2b-256 checksum How to use checksums |
5e67e9d9a069a88e91ac9a89be6dd9f00dc3e07f41f2531e1d5dcbb0f36b3234
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|