subjective-logic 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- subjective_logic-0.0.1/LICENSE +21 -0
- subjective_logic-0.0.1/PKG-INFO +75 -0
- subjective_logic-0.0.1/README.md +24 -0
- subjective_logic-0.0.1/pyproject.toml +63 -0
- subjective_logic-0.0.1/setup.cfg +4 -0
- subjective_logic-0.0.1/src/subjective_logic/__init__.py +1 -0
- subjective_logic-0.0.1/src/subjective_logic/__main__.py +20 -0
- subjective_logic-0.0.1/src/subjective_logic/binomial_opinion.py +72 -0
- subjective_logic-0.0.1/src/subjective_logic.egg-info/PKG-INFO +75 -0
- subjective_logic-0.0.1/src/subjective_logic.egg-info/SOURCES.txt +12 -0
- subjective_logic-0.0.1/src/subjective_logic.egg-info/dependency_links.txt +1 -0
- subjective_logic-0.0.1/src/subjective_logic.egg-info/requires.txt +13 -0
- subjective_logic-0.0.1/src/subjective_logic.egg-info/top_level.txt +1 -0
- subjective_logic-0.0.1/tests/test_binomial_opinion.py +10 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Waleed Khan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: subjective_logic
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python implementation of subjective logic.
|
|
5
|
+
Author-email: Waleed Khan <waleedqk@gmail.com>
|
|
6
|
+
Maintainer-email: Waleed Khan <waleedqk@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2024 Waleed Khan
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/waleedqk/subjective-logic
|
|
30
|
+
Project-URL: Documentation, https://github.com/waleedqk/subjective-logic/blob/main/README.md
|
|
31
|
+
Project-URL: Repository, https://github.com/waleedqk/subjective-logic
|
|
32
|
+
Project-URL: Issues, https://github.com/waleedqk/subjective-logic/issues
|
|
33
|
+
Project-URL: Changelog, https://github.com/waleedqk/subjective-logic/CHANGELOG.md
|
|
34
|
+
Keywords: subjective logic,opinion,python
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: numpy>=1.24.0
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: tox; extra == "dev"
|
|
44
|
+
Requires-Dist: black; extra == "dev"
|
|
45
|
+
Provides-Extra: doc
|
|
46
|
+
Requires-Dist: sphinx; extra == "doc"
|
|
47
|
+
Requires-Dist: sphinx-rtd-theme; extra == "doc"
|
|
48
|
+
Provides-Extra: test
|
|
49
|
+
Requires-Dist: pytest>=6.0; extra == "test"
|
|
50
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
51
|
+
|
|
52
|
+
# subjective-logic
|
|
53
|
+
A subjective logic implementaion in python
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
python -m pip install subjective-logic
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Tests
|
|
62
|
+
|
|
63
|
+
To test the code base, simply run tox from the root directory of your project:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install -e .[dev]
|
|
67
|
+
tox
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## References
|
|
72
|
+
|
|
73
|
+
Audun Jøsang. “Categories of Belief Fusion”. In: _Journal of Advances in Information Fusion_ 13.2 (2018), pp. 235–254.
|
|
74
|
+
|
|
75
|
+
Audun Jøsang. _Subjective Logic - A Formalism for Reasoning Under Uncertainty_. Artificial Intelligence: Foundations, Theory, and Algorithms. Springer, 2016
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# subjective-logic
|
|
2
|
+
A subjective logic implementaion in python
|
|
3
|
+
|
|
4
|
+
## Install
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
python -m pip install subjective-logic
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Tests
|
|
11
|
+
|
|
12
|
+
To test the code base, simply run tox from the root directory of your project:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install -e .[dev]
|
|
16
|
+
tox
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## References
|
|
21
|
+
|
|
22
|
+
Audun Jøsang. “Categories of Belief Fusion”. In: _Journal of Advances in Information Fusion_ 13.2 (2018), pp. 235–254.
|
|
23
|
+
|
|
24
|
+
Audun Jøsang. _Subjective Logic - A Formalism for Reasoning Under Uncertainty_. Artificial Intelligence: Foundations, Theory, and Algorithms. Springer, 2016
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69.5.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "subjective_logic"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
dynamic = []
|
|
9
|
+
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "Waleed Khan", email = "waleedqk@gmail.com"},
|
|
12
|
+
]
|
|
13
|
+
maintainers = [
|
|
14
|
+
{name = "Waleed Khan", email = "waleedqk@gmail.com"}
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
description = "A Python implementation of subjective logic."
|
|
18
|
+
keywords = ["subjective logic", "opinion", "python"]
|
|
19
|
+
|
|
20
|
+
readme = {file = "README.md", content-type = "text/markdown"}
|
|
21
|
+
license = {file = "LICENSE"}
|
|
22
|
+
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"License :: OSI Approved :: MIT License",
|
|
26
|
+
"Operating System :: OS Independent",
|
|
27
|
+
]
|
|
28
|
+
requires-python = ">=3.10"
|
|
29
|
+
dependencies = [
|
|
30
|
+
"numpy>=1.24.0"
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"tox",
|
|
37
|
+
"black"
|
|
38
|
+
]
|
|
39
|
+
doc = [
|
|
40
|
+
"sphinx",
|
|
41
|
+
"sphinx-rtd-theme"
|
|
42
|
+
]
|
|
43
|
+
test = [
|
|
44
|
+
"pytest>=6.0",
|
|
45
|
+
"pytest-cov"
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/waleedqk/subjective-logic"
|
|
50
|
+
Documentation = "https://github.com/waleedqk/subjective-logic/blob/main/README.md"
|
|
51
|
+
Repository = "https://github.com/waleedqk/subjective-logic"
|
|
52
|
+
Issues = "https://github.com/waleedqk/subjective-logic/issues"
|
|
53
|
+
Changelog = "https://github.com/waleedqk/subjective-logic/CHANGELOG.md"
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
minversion = "6.0"
|
|
57
|
+
addopts = "-ra -q"
|
|
58
|
+
testpaths = [
|
|
59
|
+
"tests", "src"
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
# [project.scripts]
|
|
63
|
+
# realpython = "reader.__main__:main"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .binomial_opinion import BinomialOpinion
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# __main__.py
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from .binomial_opinion import BinomialOpinion
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
if len(sys.argv) != 5:
|
|
8
|
+
print("Usage: python -m subjective_logic <belief> <disbelief> <uncertainty> <base_rate>")
|
|
9
|
+
sys.exit(1)
|
|
10
|
+
|
|
11
|
+
belief = float(sys.argv[1])
|
|
12
|
+
disbelief = float(sys.argv[2])
|
|
13
|
+
uncertainty = float(sys.argv[3])
|
|
14
|
+
base_rate = float(sys.argv[4])
|
|
15
|
+
|
|
16
|
+
opinion = BinomialOpinion(belief, disbelief, uncertainty, base_rate)
|
|
17
|
+
print(f"Created Binomial Opinion: {opinion}")
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
main()
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from typing import Annotated
|
|
3
|
+
|
|
4
|
+
class BinomialOpinion:
|
|
5
|
+
"""
|
|
6
|
+
Represents a binomial opinion in subjective logic.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
belief: Annotated[int | float, "The belief value."]
|
|
10
|
+
disbelief: Annotated[int | float, "The disbelief value."]
|
|
11
|
+
uncertainty: Annotated[int | float, "The uncertainty value."]
|
|
12
|
+
base_rate: Annotated[int | float, " The base rate (a priori probability)."]
|
|
13
|
+
|
|
14
|
+
def __init__(self, belief, disbelief, uncertainty, base_rate=0.5):
|
|
15
|
+
"""
|
|
16
|
+
Initializes a BinomialOpinion instance.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
belief (float): The belief component of the opinion.
|
|
20
|
+
disbelief (float): The disbelief component of the opinion.
|
|
21
|
+
uncertainty (float): The uncertainty component of the opinion.
|
|
22
|
+
base_rate (float): The base rate (default 0.5).
|
|
23
|
+
"""
|
|
24
|
+
self.set_param('belief', belief)
|
|
25
|
+
self.set_param('disbelief', disbelief)
|
|
26
|
+
self.set_param('uncertainty', uncertainty)
|
|
27
|
+
self.set_param('base_rate', base_rate)
|
|
28
|
+
self.validate_opinion()
|
|
29
|
+
|
|
30
|
+
def set_param(self, attribute, value):
|
|
31
|
+
"""
|
|
32
|
+
Set the value of a parameter of the opinion object.
|
|
33
|
+
"""
|
|
34
|
+
setattr(self, attribute, self._validate_value(self._set_to_zero_if_close(value)))
|
|
35
|
+
|
|
36
|
+
def _set_to_zero_if_close(self, value, n_decimal_places = 6):
|
|
37
|
+
# Threshold for closeness to zero
|
|
38
|
+
threshold = 10 ** (-n_decimal_places)
|
|
39
|
+
|
|
40
|
+
if abs(value) < threshold:
|
|
41
|
+
return 0
|
|
42
|
+
else:
|
|
43
|
+
return value
|
|
44
|
+
|
|
45
|
+
def _validate_value(self, value):
|
|
46
|
+
|
|
47
|
+
# Validate that the input is a float between 0 and 1
|
|
48
|
+
if not isinstance(value, (float, int)):
|
|
49
|
+
raise ValueError("Value must be a float or an integer.")
|
|
50
|
+
if not 0 <= value <= 1:
|
|
51
|
+
raise ValueError("Value must be between 0 and 1.")
|
|
52
|
+
return float(value)
|
|
53
|
+
|
|
54
|
+
def validate_opinion(self):
|
|
55
|
+
"""
|
|
56
|
+
Validates the opinion to ensure the sum of belief, disbelief, and uncertainty equals 1.
|
|
57
|
+
Raises an exception if the validation fails.
|
|
58
|
+
"""
|
|
59
|
+
total = self.belief + self.disbelief + self.uncertainty
|
|
60
|
+
if not (0.999 <= total <= 1.001): # Allows a small margin for floating-point errors
|
|
61
|
+
raise ValueError("The sum of belief, disbelief, and uncertainty must equal 1.")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def __str__(self):
|
|
65
|
+
"""
|
|
66
|
+
Returns a string representation of the binomial opinion.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
str: A string describing the binomial opinion.
|
|
70
|
+
"""
|
|
71
|
+
return (f"BinomialOpinion(belief={self.belief:.3f}, disbelief={self.disbelief:.3f}, "
|
|
72
|
+
f"uncertainty={self.uncertainty:.3f}, base_rate={self.base_rate:.3f})")
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: subjective_logic
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python implementation of subjective logic.
|
|
5
|
+
Author-email: Waleed Khan <waleedqk@gmail.com>
|
|
6
|
+
Maintainer-email: Waleed Khan <waleedqk@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2024 Waleed Khan
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/waleedqk/subjective-logic
|
|
30
|
+
Project-URL: Documentation, https://github.com/waleedqk/subjective-logic/blob/main/README.md
|
|
31
|
+
Project-URL: Repository, https://github.com/waleedqk/subjective-logic
|
|
32
|
+
Project-URL: Issues, https://github.com/waleedqk/subjective-logic/issues
|
|
33
|
+
Project-URL: Changelog, https://github.com/waleedqk/subjective-logic/CHANGELOG.md
|
|
34
|
+
Keywords: subjective logic,opinion,python
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: numpy>=1.24.0
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: tox; extra == "dev"
|
|
44
|
+
Requires-Dist: black; extra == "dev"
|
|
45
|
+
Provides-Extra: doc
|
|
46
|
+
Requires-Dist: sphinx; extra == "doc"
|
|
47
|
+
Requires-Dist: sphinx-rtd-theme; extra == "doc"
|
|
48
|
+
Provides-Extra: test
|
|
49
|
+
Requires-Dist: pytest>=6.0; extra == "test"
|
|
50
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
51
|
+
|
|
52
|
+
# subjective-logic
|
|
53
|
+
A subjective logic implementaion in python
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
python -m pip install subjective-logic
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Tests
|
|
62
|
+
|
|
63
|
+
To test the code base, simply run tox from the root directory of your project:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install -e .[dev]
|
|
67
|
+
tox
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## References
|
|
72
|
+
|
|
73
|
+
Audun Jøsang. “Categories of Belief Fusion”. In: _Journal of Advances in Information Fusion_ 13.2 (2018), pp. 235–254.
|
|
74
|
+
|
|
75
|
+
Audun Jøsang. _Subjective Logic - A Formalism for Reasoning Under Uncertainty_. Artificial Intelligence: Foundations, Theory, and Algorithms. Springer, 2016
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/subjective_logic/__init__.py
|
|
5
|
+
src/subjective_logic/__main__.py
|
|
6
|
+
src/subjective_logic/binomial_opinion.py
|
|
7
|
+
src/subjective_logic.egg-info/PKG-INFO
|
|
8
|
+
src/subjective_logic.egg-info/SOURCES.txt
|
|
9
|
+
src/subjective_logic.egg-info/dependency_links.txt
|
|
10
|
+
src/subjective_logic.egg-info/requires.txt
|
|
11
|
+
src/subjective_logic.egg-info/top_level.txt
|
|
12
|
+
tests/test_binomial_opinion.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
subjective_logic
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from subjective_logic import BinomialOpinion
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
def test_binomial_opinion_initialization():
|
|
5
|
+
opinion = BinomialOpinion(belief=0.5, disbelief=0.3, uncertainty=0.2, base_rate=0.5)
|
|
6
|
+
assert opinion.belief == 0.5
|
|
7
|
+
assert opinion.disbelief == 0.3
|
|
8
|
+
assert opinion.uncertainty == 0.2
|
|
9
|
+
assert opinion.base_rate == 0.5
|
|
10
|
+
|