EM_BMF
Robust Boolean matrix factorization via EM_BMF The code is completely process-oriented. Sorry for contaminating your name space.
Dependency: (I think it will work as long as Annaconda on Python3 is installed)
numpy -- 1.11.3
scipy -- 1.1.0
numba -- 0.40.0
Example usage:
import numpy as np
from boolem import boolem
def synthesis(shape, latent_size, P, noise_p=0.0):
'''
In this synthesis, the probability of X was sampled from the joint probability of the latent factors.
P is the parameter as Beta(1/(1-p),2) for generating the probability in latent factors.
'''
a = np.zeros((shape[0], latent_size))
b = np.zeros((latent_size, shape[1]))
X = np.zeros(shape)
for l in range(latent_size):
a[:,l] = np.random.binomial(1, P[l], shape[0])
b[l,:] = np.random.binomial(1, P[l], shape[1])
X += np.outer(a[:,l],b[l,:])
X[X>1] = 1
flip = np.random.binomial(1, noise_p, X.shape)
X_noisy = np.abs(X-flip)
return X_noisy, X, a, b
# Generate a Boolean matrice with heterogeneous Boolean factors and uniform noise.
X_noisy, X, a, b = synthesis((1000, 1000), 4, np.random.uniform(0.2,0.5,4), noise_p=0.2)
# Feed the model with noisy matrix.
# Latent_size: the dimension of latent Boolean factors.
# alpha: the alpha for the beta prior. Default is recommended.
# beta: the beta for the beta prior. Default is recommended.
# mask: the matrix with the same shape as X. 0 means the correponding element in X is missing.
# max_iter: the maximum iteration for gradient-based optimization
model = boolem(np.int8(X_noisy), latent_size=5, alpha=0.95, beta=0.95, mask=np.ones(X.shape, dtype=np.int8), max_iter=200)
model.run()
# After running factorization, the model will contain several new attributes as the output:
# model.U: the latent factor with the shape (X.shape[0], latent_size)
# model.Z: the latent facotr with the shape (latent_size, X.shape[1])
# model.X_hat: reconstructed Boolean matrix from U and Z. Note that values in X_hat is continuous within [0,1]
print('Reconstruction error:', np.abs((model.X_hat>0.5)-X).mean())
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
boolem-0.0.5.tar.gz
(4.0 kB
view details)
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 boolem-0.0.5.tar.gz.
File metadata
- Download URL: boolem-0.0.5.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3daebffa83d2f9a8ba30b3703d8add5196b6e8138ff9ac4b2c156077dc3ec6a7
|
|
| MD5 |
74043adf0feda10a68ca668d7a88f6c8
|
|
| BLAKE2b-256 |
7ae1bb7f87997e6efdc73654487eef5e311d9be77e1a84bcf9471c83dc07264b
|
File details
Details for the file boolem-0.0.5-py3-none-any.whl.
File metadata
- Download URL: boolem-0.0.5-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c754583c93b5abbdc1cf488c4e0435c49161431e242ddfb9485d00acd34237b0
|
|
| MD5 |
69e1860cc05df2cb0cedef851523c5d5
|
|
| BLAKE2b-256 |
3320275eb8b75414bacf143cc91decd0c7d43e60b603a407b04f05033732fe58
|