Finite-frame Dempster-Shafer belief functions with sparse bitmask storage
Project description
pybelief
Finite-frame Dempster-Shafer belief functions with sparse bitmask storage.
Installation
pip install pybelief
Quick start
from pybelief import MassFunction
frame = ["a", "b", "c"]
# Create mass functions using label sets
m1 = MassFunction(frame, named_focal_elements={
frozenset({"a"}): 0.3,
frozenset({"a", "b"}): 0.2,
frozenset({"a", "b", "c"}): 0.5,
})
m2 = MassFunction(frame, named_focal_elements={
frozenset({"b"}): 0.5,
frozenset({"a", "b"}): 0.2,
frozenset({"a", "b", "c"}): 0.3,
})
# Query belief, plausibility, commonality
m1.belief({"a"}) # 0.3
m1.plausibility({"b"}) # 0.7
m1.commonality({"a"}) # 1.0
# Combine sources
m12 = m1 & m2 # Dempster's rule
m12 = m1 | m2 # Conjunctive (TBM)
m12 = m1.combine_yager(m2) # Yager's rule
# Decision making
m1.pignistic() # {'a': 0.567, 'b': 0.267, 'c': 0.167}
Bitmask convention
Element i of the frame maps to bit i. For frame = ["a", "b", "c"]:
| Set | Binary | Int |
|---|---|---|
| {a} | 001 |
1 |
| {b} | 010 |
2 |
| {a, b} | 011 |
3 |
| {c} | 100 |
4 |
| {a, c} | 101 |
5 |
| {b, c} | 110 |
6 |
| {a, b, c} | 111 |
7 |
You can use either bitmasks or label sets in all API calls:
m.belief(0b011) # bitmask
m.belief({"a", "b"}) # label set — same result
API overview
Construction
| Method | Description |
|---|---|
MassFunction(frame, focal_elements={mask: mass}) |
From bitmask dict |
MassFunction(frame, named_focal_elements={labels: mass}) |
From label-set dict |
MassFunction.vacuous(frame) |
Total ignorance |
MassFunction.certain(frame, element) |
All mass on one element |
MassFunction.from_bayesian(frame, {label: prob}) |
Probability distribution |
Transforms
| Method | Description |
|---|---|
m.belief(A) |
Bel(A) — sum of masses of subsets of A |
m.plausibility(A) |
Pl(A) — sum of masses intersecting A |
m.commonality(A) |
Q(A) — sum of masses of supersets of A |
m.belief_function() |
Bel for all 2^n subsets (fast zeta) |
m.plausibility_function() |
Pl for all 2^n subsets |
m.commonality_function() |
Q for all 2^n subsets |
m.pignistic() |
BetP probability transform |
m.plausibility_transform() |
Normalized singleton plausibilities |
Operations
| Method | Description |
|---|---|
m1 & m2 / m1.combine_dempster(m2) |
Dempster's rule (normalized) |
m1 | m2 / m1.combine_conjunctive(m2) |
Conjunctive / TBM (unnormalized) |
m1.combine_yager(m2) |
Yager's rule |
m.discount(alpha) |
Shafer's discounting |
m.condition(event) |
Dempster conditioning |
m1.conflict(m2) |
Conflict mass K |
Measures
| Method | Description |
|---|---|
m.specificity() |
Non-specificity N(m) |
m.entropy_deng() |
Deng entropy |
Performance
Focal elements are stored sparsely. Combination runs in O(|F1| x |F2|) — fast when mass functions are sparse. Full transforms use the fast zeta transform in O(n * 2^n). Practical for frames up to ~20 elements.
Citation
If you use pybelief in your research, please cite:
@software{afifi2025pybelief,
author = {Afifi, Sohaib},
title = {pybelief: Finite-Frame Dempster--Shafer Belief Functions in Python},
year = {2025},
url = {https://github.com/sohaibafifi/pybelief},
}
License
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 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 pybelief-0.1.0.tar.gz.
File metadata
- Download URL: pybelief-0.1.0.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8556c836bc36fbc11bcacbdc806d4fab7811346a43e6b4910d3fedaed0f76cd2
|
|
| MD5 |
e7a7b64f8a05c518207f724eff7cc2de
|
|
| BLAKE2b-256 |
5faad06c6d1a266cd867b951deaee7e92de28f3eea2dedcb23cdb1974bf420f3
|
Provenance
The following attestation bundles were made for pybelief-0.1.0.tar.gz:
Publisher:
publish.yml on sohaibafifi/pybelief
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybelief-0.1.0.tar.gz -
Subject digest:
8556c836bc36fbc11bcacbdc806d4fab7811346a43e6b4910d3fedaed0f76cd2 - Sigstore transparency entry: 1186309654
- Sigstore integration time:
-
Permalink:
sohaibafifi/pybelief@0b05db087ce338413c8dfa3ebeef718b6cc7f722 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sohaibafifi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0b05db087ce338413c8dfa3ebeef718b6cc7f722 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pybelief-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pybelief-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b7c6b2f36ee67df445d970348e9ef4c77b2559670a08d13c7b81a380760e876
|
|
| MD5 |
e0487eff2beeeef888dbe6395a72270a
|
|
| BLAKE2b-256 |
6eb8fec8361a5b8551b09b3a4d9d5928851e92ea36a71a55d71e24c0de1fa12e
|
Provenance
The following attestation bundles were made for pybelief-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on sohaibafifi/pybelief
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybelief-0.1.0-py3-none-any.whl -
Subject digest:
2b7c6b2f36ee67df445d970348e9ef4c77b2559670a08d13c7b81a380760e876 - Sigstore transparency entry: 1186309670
- Sigstore integration time:
-
Permalink:
sohaibafifi/pybelief@0b05db087ce338413c8dfa3ebeef718b6cc7f722 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sohaibafifi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0b05db087ce338413c8dfa3ebeef718b6cc7f722 -
Trigger Event:
push
-
Statement type: