Factorisation matricielle booleenne : structures bit-packees et solveurs exacts
Project description
FPMsBMF
Factorisation matricielle booléenne : structures bit-packées et solveurs exacts.
Étant donné une matrice binaire X de taille m × n et un rang r, on cherche
W (m × r) et H (r × n) binaires minimisant
||X - W ∘ H||² où (W ∘ H)[i,j] = OR_k (W[i,k] ET H[k,j])
Le problème est NP-difficile et inapproximable à tout facteur multiplicatif. Cette bibliothèque fournit des solveurs exacts pour le sous-problème à un facteur fixé, ce qui permet une optimisation alternée dont chaque demi-itération est un minimum global sur son bloc.
Installation
pip install FPMsBMF
Utilisation
import numpy as np
import FPMsBMF as bmf
X_np = np.random.rand(500, 300) < 0.3
X = bmf.BitMatrix.from_numpy(X_np) # packing : une seule fois
res = bmf.ao_bmf(X, r=8, method="zeta", seed=0)
print(res.error, res.iterations)
print(res.w.shape, res.h.shape)
# res.w @ res.h est le produit booléen
assert res.error == X.hamming(res.w @ res.h)
L'optimisation alternée converge vers un point stationnaire par blocs, pas vers l'optimum global. Des graines différentes explorent des bassins différents :
best = min(bmf.ao_bmf(X, r=8, seed=s) for s in range(20), key=lambda r: r.error)
Le type BitMatrix
Un booléen occupe un bit et non un octet : huit fois moins de mémoire qu'un tableau numpy, et les opérations logiques traitent 64 entrées par instruction.
L'intérêt principal face à numpy n'est pas la vitesse brute des opérations
élémentaires, numpy est déjà vectorisé, mais la persistance de la
représentation packée. La conversion coûte O(m·n) ; garder l'objet entre
deux appels évite de repayer ce coût à chaque expérience.
A = bmf.BitMatrix.from_numpy(a)
B = bmf.BitMatrix.from_numpy(b)
A | B # ou logique (nouvelle matrice)
A |= B # en place, sans allocation
A & B # et logique
A ^ B # ou exclusif
A - B # retrait ensembliste A & ~B
~A # complément
A @ B # produit BOOLÉEN, pas arithmétique
A.count_ones() # nombre d'entrées à 1
A.hamming(B) # ||A - B||², soit le nombre d'entrées différentes
A.count_andnot(B) # |A & ~B|
A.transpose()
A[i, j] # lecture / écriture d'une entrée
Le sous-problème BoolLS
À W fixé, le problème se décompose en n sous-problèmes indépendants, un par
colonne. Résoudre min_h ||x - W ∘ h||² est le cœur de l'algorithme.
solver = bmf.BoolLs(W) # prétraitement, amorti sur les appels suivants
h, cost = solver.solve(x_np, method="zeta")
H, total = solver.solve_all(X, method="zeta")
Quatre méthodes sont disponibles :
method |
Nature | Coût par colonne |
|---|---|---|
"naive" |
exact | O(2^r · m) |
"zeta" |
exact | O(nnz(x) + 2^r · r) |
"greedy" |
heuristique | O(r² · m/64) |
"greedy-ls" |
heuristique | O(r³ log r · m/64) |
"zeta" regroupe les lignes par motif, il n'y en a que min(m, 2^r) distincts,
puis évalue tous les candidats en une transformée zêta sur le treillis des
sous-ensembles. Après le prétraitement, m a disparu du coût par colonne.
Les deux méthodes exactes donnent toujours le même résultat ; "zeta" est plus
rapide dès que m > r · 64.
Limites
- Le rang est plafonné à 26 : le tableau interne de la transformée zêta compte
2^rentrées. - La conversion depuis numpy est une copie obligatoire : un booléen numpy occupe un octet, un bit ici.
- L'optimisation alternée n'offre aucune garantie d'optimalité globale.
Licence
MIT
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 Distributions
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 fpmsbmf-0.1.1.tar.gz.
File metadata
- Download URL: fpmsbmf-0.1.1.tar.gz
- Upload date:
- Size: 41.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7451311cc5ab4e1fa2dff21a4b32dea35d50a2e378f14821b284b6854134ce6
|
|
| MD5 |
a1dbd9b9ffd262737ad21cb06857a571
|
|
| BLAKE2b-256 |
cebfed9a935b03c696cfa18b0de2f610706d8628c9ca55db81a135e5cbb746ac
|
Provenance
The following attestation bundles were made for fpmsbmf-0.1.1.tar.gz:
Publisher:
publish.yml on 16Flavio/FPMsBMF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fpmsbmf-0.1.1.tar.gz -
Subject digest:
a7451311cc5ab4e1fa2dff21a4b32dea35d50a2e378f14821b284b6854134ce6 - Sigstore transparency entry: 2321642610
- Sigstore integration time:
-
Permalink:
16Flavio/FPMsBMF@38677f5cd195791f0577f3c434b9667c74a5810c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/16Flavio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38677f5cd195791f0577f3c434b9667c74a5810c -
Trigger Event:
push
-
Statement type:
File details
Details for the file fpmsbmf-0.1.1-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: fpmsbmf-0.1.1-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 210.7 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47fca5a12e2cc6f9be77ed0f1254a726b7f31c4d4def79e01cf9bfa9710a6d55
|
|
| MD5 |
5e97c63e091f60b78c01fd0908e4d65a
|
|
| BLAKE2b-256 |
cef3a687ec58893557d085889fcca4208a538403a06f36b0bb7b8b51b4b67c1e
|
File details
Details for the file fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 333.4 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7244d4c280dc1d668cdc79fd0633ace5e84b40f9ca716e2d39c193ba25b71149
|
|
| MD5 |
55664bf461f0963b320a1ac778614e4a
|
|
| BLAKE2b-256 |
64b17e57085d9b8885a77ba19efb7a213c7986a300a4c51e8b8cd9b23d88a1e8
|
Provenance
The following attestation bundles were made for fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on 16Flavio/FPMsBMF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
7244d4c280dc1d668cdc79fd0633ace5e84b40f9ca716e2d39c193ba25b71149 - Sigstore transparency entry: 2321521577
- Sigstore integration time:
-
Permalink:
16Flavio/FPMsBMF@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/16Flavio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Trigger Event:
push
-
Statement type:
File details
Details for the file fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 326.9 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b27d3553fefd4aac31ef71757196715bcc56039d0363def1328cedace635b58
|
|
| MD5 |
739a685c826e3bb1ef40e7e7c674e45a
|
|
| BLAKE2b-256 |
01265676000e73c177d59588cb93a1a93524e357bfa4f921415efccb18bd2624
|
Provenance
The following attestation bundles were made for fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
publish.yml on 16Flavio/FPMsBMF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fpmsbmf-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
0b27d3553fefd4aac31ef71757196715bcc56039d0363def1328cedace635b58 - Sigstore transparency entry: 2321521986
- Sigstore integration time:
-
Permalink:
16Flavio/FPMsBMF@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/16Flavio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Trigger Event:
push
-
Statement type:
File details
Details for the file fpmsbmf-0.1.1-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: fpmsbmf-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 301.6 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ff51556dee8c37cb0a4cbd9407565b2a3159973207576b25660d1b72857c6d3
|
|
| MD5 |
8a994ef30cc376c1e37dcac7985a071b
|
|
| BLAKE2b-256 |
9d516b9d9b890437b9527cc1d88e3f12f0048636845e98acd471bf8986a4e185
|
Provenance
The following attestation bundles were made for fpmsbmf-0.1.1-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on 16Flavio/FPMsBMF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fpmsbmf-0.1.1-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
1ff51556dee8c37cb0a4cbd9407565b2a3159973207576b25660d1b72857c6d3 - Sigstore transparency entry: 2321520758
- Sigstore integration time:
-
Permalink:
16Flavio/FPMsBMF@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/16Flavio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Trigger Event:
push
-
Statement type:
File details
Details for the file fpmsbmf-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: fpmsbmf-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 303.8 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d0cc42a1fc6685fe95bee25aff8f5f5df9384d7a41d83d03bab454794ac3935
|
|
| MD5 |
1c75b9b75907b4b88dbe9524da0326d7
|
|
| BLAKE2b-256 |
fec0a26311690c0117f47c96e74953fae62608b6611bd11b7798d0d57b0e3bd8
|
Provenance
The following attestation bundles were made for fpmsbmf-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl:
Publisher:
publish.yml on 16Flavio/FPMsBMF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fpmsbmf-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl -
Subject digest:
5d0cc42a1fc6685fe95bee25aff8f5f5df9384d7a41d83d03bab454794ac3935 - Sigstore transparency entry: 2321521242
- Sigstore integration time:
-
Permalink:
16Flavio/FPMsBMF@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/16Flavio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b66b19140f8b8a05fba139fcff4619f12b15fb2c -
Trigger Event:
push
-
Statement type: