Probabilistic Non-negative Matrix Factorization with Projected Gradients
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pnmf-0.1.0.tar.gz.
File metadata
- Download URL: pnmf-0.1.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03ab523d26475353a2ec588fc4ba83490397f4ab67498753384e2e5c2afc1084
|
|
| MD5 |
9387300a4dfa3e394fc9149354851b2c
|
|
| BLAKE2b-256 |
c10961f46b381058b4f6f70bd607c829bf79c70cb16a687d79029abd05cc4d99
|
File details
Details for the file pnmf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pnmf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
255e49d596058f0ebd16ca1783825d2f5f87c4183e86becf62caf25dbb032e2b
|
|
| MD5 |
2e0468851612023689bcfb8abd84e949
|
|
| BLAKE2b-256 |
5e67e9d9a069a88e91ac9a89be6dd9f00dc3e07f41f2531e1d5dcbb0f36b3234
|