evtools-dst 0.1.0__py3-none-any.whl

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.
evtools/__init__.py ADDED
@@ -0,0 +1,29 @@
1
+ """
2
+ evtools — Evidence Theory Tools
3
+ ================================
4
+
5
+ A growing collection of utilities for working with belief functions
6
+ in the Dempster-Shafer theory of evidence.
7
+
8
+ Submodules
9
+ ----------
10
+ evtools.conversions
11
+ Conversion functions between all standard belief function
12
+ representations (m, bel, pl, b, q, v, w).
13
+
14
+ Usage
15
+ -----
16
+ Import the submodule::
17
+
18
+ from evtools import conversions
19
+ conversions.mtob(m)
20
+
21
+ Or import functions directly::
22
+
23
+ from evtools.conversions import mtob, mtopl
24
+ """
25
+
26
+ from . import conversions
27
+
28
+ __version__ = "0.1.0"
29
+ __all__ = ["conversions"]
evtools/conversions.py ADDED
@@ -0,0 +1,329 @@
1
+ """
2
+ Conversion functions between the different representations of belief functions
3
+ in the Dempster-Shafer theory of evidence.
4
+
5
+ Supported representations:
6
+ - b : commonality function
7
+ - bel : belief function
8
+ - m : basic belief assignment (mass function)
9
+ - pl : plausibility function
10
+ - q : implicability function
11
+ - v : conjunctive weight function
12
+ - w : disjunctive weight function
13
+
14
+ Each function is named ``<source>to<target>``, e.g. ``mtob`` converts a mass
15
+ function to a commonality function.
16
+
17
+ References:
18
+ Smets, P. (2002). The application of the transferable belief model to
19
+ diagnostic problems. International Journal of Intelligent Systems.
20
+
21
+ Denoeux, T. (2008). Conjunctive and disjunctive combination of belief
22
+ functions induced by non-distinct bodies of evidence. Artificial
23
+ Intelligence.
24
+ """
25
+
26
+ import numpy as np
27
+
28
+
29
+ # ---------------------------------------------------------------------------
30
+ # bto* — from commonality function
31
+ # ---------------------------------------------------------------------------
32
+
33
+ def btobel(b: np.ndarray) -> np.ndarray:
34
+ """Convert commonality *b* to belief function *bel*.
35
+
36
+ bel(A) = b(A) - m(∅)
37
+ """
38
+ return b - b[0]
39
+
40
+
41
+ def btom(b: np.ndarray) -> np.ndarray:
42
+ """Convert commonality *b* to mass function *m* using the FMT (Smets)."""
43
+ b = np.copy(b)
44
+ lb = len(b)
45
+ natoms = int(np.round(np.log2(lb)))
46
+ for step in range(1, natoms + 1):
47
+ i124 = 2 ** (step - 1)
48
+ i842 = 2 ** (natoms + 1 - step)
49
+ i421 = 2 ** (natoms - step)
50
+ b = b.reshape(i124, i842, order="F")
51
+ b[:, np.arange(1, i421 + 1) * 2 - 1] -= b[:, np.arange(1, i421 + 1) * 2 - 2]
52
+ return b.reshape(1, lb, order="F").ravel()
53
+
54
+
55
+ def btopl(b: np.ndarray) -> np.ndarray:
56
+ """Convert commonality *b* to plausibility function *pl*.
57
+
58
+ pl(A) = 1 - b(Ā)
59
+ """
60
+ b = np.copy(b)
61
+ lb = len(b)
62
+ b = b.reshape(1, lb, order="F")
63
+ b = b[0][-1] - np.fliplr(b).ravel()
64
+ b[0] = 0
65
+ return b
66
+
67
+
68
+ def btoq(b: np.ndarray) -> np.ndarray:
69
+ """Convert commonality *b* to implicability function *q*."""
70
+ return pltoq(btopl(b))
71
+
72
+
73
+ def btov(b: np.ndarray) -> np.ndarray:
74
+ """Convert commonality *b* to conjunctive weight function *v* (Denoeux 2008)."""
75
+ v = np.exp(-btom(np.log(b)))
76
+ v[0] = 1
77
+ return v
78
+
79
+
80
+ def btow(b: np.ndarray) -> np.ndarray:
81
+ """Convert commonality *b* to disjunctive weight function *w*."""
82
+ return qtow(btoq(b))
83
+
84
+
85
+ # ---------------------------------------------------------------------------
86
+ # belto* — from belief function
87
+ # ---------------------------------------------------------------------------
88
+
89
+ def beltob(bel: np.ndarray) -> np.ndarray:
90
+ """Convert belief function *bel* to commonality *b*.
91
+
92
+ b(A) = bel(A) + m(∅)
93
+ """
94
+ m_emptyset = 1 - bel[-1]
95
+ return bel + m_emptyset
96
+
97
+
98
+ def beltom(bel: np.ndarray) -> np.ndarray:
99
+ """Convert belief function *bel* to mass function *m*."""
100
+ return btom(beltob(bel))
101
+
102
+
103
+ def beltopl(bel: np.ndarray) -> np.ndarray:
104
+ """Convert belief function *bel* to plausibility function *pl*."""
105
+ return btopl(bel)
106
+
107
+
108
+ def beltoq(bel: np.ndarray) -> np.ndarray:
109
+ """Convert belief function *bel* to implicability function *q*."""
110
+ return btoq(bel)
111
+
112
+
113
+ def beltov(bel: np.ndarray) -> np.ndarray:
114
+ """Convert belief function *bel* to conjunctive weight function *v*."""
115
+ return btov(beltob(bel))
116
+
117
+
118
+ def beltow(bel: np.ndarray) -> np.ndarray:
119
+ """Convert belief function *bel* to disjunctive weight function *w*."""
120
+ return qtow(beltoq(bel))
121
+
122
+
123
+ # ---------------------------------------------------------------------------
124
+ # mto* — from mass function
125
+ # ---------------------------------------------------------------------------
126
+
127
+ def mtob(m: np.ndarray) -> np.ndarray:
128
+ """Convert mass function *m* to commonality *b* using the FMT (Smets)."""
129
+ m = np.copy(m)
130
+ lm = len(m)
131
+ natoms = int(np.round(np.log2(lm)))
132
+ for step in range(1, natoms + 1):
133
+ i124 = 2 ** (step - 1)
134
+ i842 = 2 ** (natoms + 1 - step)
135
+ i421 = 2 ** (natoms - step)
136
+ m = m.reshape(i124, i842, order="F")
137
+ m[:, np.arange(1, i421 + 1) * 2 - 1] += m[:, np.arange(1, i421 + 1) * 2 - 2]
138
+ return m.reshape(1, lm, order="F").ravel()
139
+
140
+
141
+ def mtobel(m: np.ndarray) -> np.ndarray:
142
+ """Convert mass function *m* to belief function *bel*."""
143
+ return btobel(mtob(m))
144
+
145
+
146
+ def mtopl(m: np.ndarray) -> np.ndarray:
147
+ """Convert mass function *m* to plausibility function *pl*."""
148
+ return btopl(mtob(m))
149
+
150
+
151
+ def mtoq(m: np.ndarray) -> np.ndarray:
152
+ """Convert mass function *m* to implicability function *q* using the FMT (Smets)."""
153
+ m = np.copy(m)
154
+ lm = len(m)
155
+ natoms = int(np.round(np.log2(lm)))
156
+ for step in range(1, natoms + 1):
157
+ i124 = 2 ** (step - 1)
158
+ i842 = 2 ** (natoms + 1 - step)
159
+ i421 = 2 ** (natoms - step)
160
+ m = m.reshape(i124, i842, order="F")
161
+ m[:, np.arange(1, i421 + 1) * 2 - 2] += m[:, np.arange(1, i421 + 1) * 2 - 1]
162
+ return m.reshape(1, lm, order="F").ravel()
163
+
164
+
165
+ def mtov(m: np.ndarray) -> np.ndarray:
166
+ """Convert mass function *m* to conjunctive weight function *v*."""
167
+ return btov(mtob(m))
168
+
169
+
170
+ def mtow(m: np.ndarray) -> np.ndarray:
171
+ """Convert mass function *m* to disjunctive weight function *w*."""
172
+ return qtow(mtoq(m))
173
+
174
+
175
+ # ---------------------------------------------------------------------------
176
+ # plto* — from plausibility function
177
+ # ---------------------------------------------------------------------------
178
+
179
+ def pltob(pl: np.ndarray) -> np.ndarray:
180
+ """Convert plausibility function *pl* to commonality *b*.
181
+
182
+ b(A) = 1 - pl(Ā)
183
+ """
184
+ pl = np.copy(pl)
185
+ lpl = len(pl)
186
+ pl = pl.reshape(1, lpl, order="F")
187
+ return 1 - np.fliplr(pl).ravel()
188
+
189
+
190
+ def pltobel(pl: np.ndarray) -> np.ndarray:
191
+ """Convert plausibility function *pl* to belief function *bel*."""
192
+ return btobel(pltob(pl))
193
+
194
+
195
+ def pltom(pl: np.ndarray) -> np.ndarray:
196
+ """Convert plausibility function *pl* to mass function *m*."""
197
+ return btom(pltob(pl))
198
+
199
+
200
+ def pltoq(pl: np.ndarray) -> np.ndarray:
201
+ """Convert plausibility function *pl* to implicability function *q* (Smets 2002)."""
202
+ q = np.abs(btom(pl))
203
+ q[0] = 1
204
+ return q
205
+
206
+
207
+ def pltov(pl: np.ndarray) -> np.ndarray:
208
+ """Convert plausibility function *pl* to conjunctive weight function *v*."""
209
+ return btov(pltob(pl))
210
+
211
+
212
+ def pltow(pl: np.ndarray) -> np.ndarray:
213
+ """Convert plausibility function *pl* to disjunctive weight function *w*."""
214
+ return qtow(pltoq(pl))
215
+
216
+
217
+ # ---------------------------------------------------------------------------
218
+ # qto* — from implicability function
219
+ # ---------------------------------------------------------------------------
220
+
221
+ def qtob(q: np.ndarray) -> np.ndarray:
222
+ """Convert implicability function *q* to commonality *b*."""
223
+ return pltob(qtopl(q))
224
+
225
+
226
+ def qtobel(q: np.ndarray) -> np.ndarray:
227
+ """Convert implicability function *q* to belief function *bel*."""
228
+ return btobel(qtob(q))
229
+
230
+
231
+ def qtom(q: np.ndarray) -> np.ndarray:
232
+ """Convert implicability function *q* to mass function *m* using the FMT (Smets)."""
233
+ q = np.copy(q)
234
+ lq = len(q)
235
+ natoms = int(np.round(np.log2(lq)))
236
+ for step in range(1, natoms + 1):
237
+ i124 = 2 ** (step - 1)
238
+ i842 = 2 ** (natoms + 1 - step)
239
+ i421 = 2 ** (natoms - step)
240
+ q = q.reshape(i124, i842, order="F")
241
+ q[:, np.arange(1, i421 + 1) * 2 - 2] -= q[:, np.arange(1, i421 + 1) * 2 - 1]
242
+ return q.reshape(1, lq, order="F").ravel()
243
+
244
+
245
+ def qtopl(q: np.ndarray) -> np.ndarray:
246
+ """Convert implicability function *q* to plausibility function *pl* (Smets 2002)."""
247
+ q = np.copy(q)
248
+ q[0] = 0
249
+ return np.abs(btom(q))
250
+
251
+
252
+ def qtov(q: np.ndarray) -> np.ndarray:
253
+ """Convert implicability function *q* to conjunctive weight function *v*."""
254
+ return btov(qtob(q))
255
+
256
+
257
+ def qtow(q: np.ndarray) -> np.ndarray:
258
+ """Convert implicability function *q* to disjunctive weight function *w* (Denoeux 2008)."""
259
+ w = np.exp(-qtom(np.log(q)))
260
+ w[-1] = 1
261
+ return w
262
+
263
+
264
+ # ---------------------------------------------------------------------------
265
+ # vto* — from conjunctive weight function
266
+ # ---------------------------------------------------------------------------
267
+
268
+ def vtob(v: np.ndarray) -> np.ndarray:
269
+ """Convert conjunctive weight function *v* to commonality *b* (Denoeux 2008)."""
270
+ return np.prod(v) / np.exp(mtob(np.log(v)))
271
+
272
+
273
+ def vtobel(v: np.ndarray) -> np.ndarray:
274
+ """Convert conjunctive weight function *v* to belief function *bel*."""
275
+ return btobel(vtob(v))
276
+
277
+
278
+ def vtom(v: np.ndarray) -> np.ndarray:
279
+ """Convert conjunctive weight function *v* to mass function *m*."""
280
+ return btom(vtob(v))
281
+
282
+
283
+ def vtopl(v: np.ndarray) -> np.ndarray:
284
+ """Convert conjunctive weight function *v* to plausibility function *pl*."""
285
+ return btopl(vtob(v))
286
+
287
+
288
+ def vtoq(v: np.ndarray) -> np.ndarray:
289
+ """Convert conjunctive weight function *v* to implicability function *q*."""
290
+ return btoq(vtob(v))
291
+
292
+
293
+ def vtow(v: np.ndarray) -> np.ndarray:
294
+ """Convert conjunctive weight function *v* to disjunctive weight function *w*."""
295
+ return btow(vtob(v))
296
+
297
+
298
+ # ---------------------------------------------------------------------------
299
+ # wto* — from disjunctive weight function
300
+ # ---------------------------------------------------------------------------
301
+
302
+ def wtob(w: np.ndarray) -> np.ndarray:
303
+ """Convert disjunctive weight function *w* to commonality *b*."""
304
+ return qtob(wtoq(w))
305
+
306
+
307
+ def wtobel(w: np.ndarray) -> np.ndarray:
308
+ """Convert disjunctive weight function *w* to belief function *bel*."""
309
+ return qtobel(wtoq(w))
310
+
311
+
312
+ def wtom(w: np.ndarray) -> np.ndarray:
313
+ """Convert disjunctive weight function *w* to mass function *m*."""
314
+ return qtom(wtoq(w))
315
+
316
+
317
+ def wtopl(w: np.ndarray) -> np.ndarray:
318
+ """Convert disjunctive weight function *w* to plausibility function *pl*."""
319
+ return qtopl(wtoq(w))
320
+
321
+
322
+ def wtoq(w: np.ndarray) -> np.ndarray:
323
+ """Convert disjunctive weight function *w* to implicability function *q* (Denoeux 2008)."""
324
+ return np.prod(w) / np.exp(mtoq(np.log(w)))
325
+
326
+
327
+ def wtov(w: np.ndarray) -> np.ndarray:
328
+ """Convert disjunctive weight function *w* to conjunctive weight function *v*."""
329
+ return qtov(wtoq(w))
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.4
2
+ Name: evtools-dst
3
+ Version: 0.1.0
4
+ Summary: Evidence Theory Tools — utilities for Dempster-Shafer theory of belief functions
5
+ Project-URL: Homepage, https://github.com/ton-username/evtools
6
+ Project-URL: Repository, https://github.com/ton-username/evtools
7
+ Project-URL: Issues, https://github.com/ton-username/evtools/issues
8
+ Keywords: belief functions,Dempster-Shafer,evidence theory,mass function,plausibility,transferable belief model
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: numpy>=1.24
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7; extra == "dev"
24
+ Requires-Dist: pytest-cov; extra == "dev"
25
+
26
+ # evtools
27
+
28
+ **Evidence Theory Tools** — a growing Python library of utilities for working
29
+ with belief functions in the Dempster-Shafer theory of evidence.
30
+
31
+ ## Modules
32
+
33
+ | Module | Description |
34
+ |--------|-------------|
35
+ | `evtools.conversions` | Conversions between all standard belief function representations |
36
+
37
+ ---
38
+
39
+ ## `evtools.conversions`
40
+
41
+ Converts between all standard representations of belief functions using the
42
+ **Fast Möbius Transform** (FMT) from Smets (2002) and Denoeux (2008).
43
+
44
+ ### Supported representations
45
+
46
+ | Symbol | Name |
47
+ |--------|------|
48
+ | `m` | Basic Belief Assignment (mass function) |
49
+ | `bel` | Belief function |
50
+ | `pl` | Plausibility function |
51
+ | `b` | Commonality function |
52
+ | `q` | Implicability function |
53
+ | `v` | Conjunctive weight function |
54
+ | `w` | Disjunctive weight function |
55
+
56
+ Every conversion is available as a `<source>to<target>` function.
57
+ For example `mtob`, `pltom`, `qtow`, `beltov`, etc.
58
+
59
+ ---
60
+
61
+ ## Installation
62
+
63
+ ```bash
64
+ pip install evtools
65
+ ```
66
+
67
+ Or from source:
68
+
69
+ ```bash
70
+ git clone https://github.com/<your-username>/evtools.git
71
+ cd evtools
72
+ pip install -e .
73
+ ```
74
+
75
+ ## Quick start
76
+
77
+ ```python
78
+ import numpy as np
79
+ from evtools.conversions import mtob, mtopl, mtobel, mtow
80
+
81
+ # Mass function over a 2-atom frame {a, b}
82
+ # Index order: ∅, {a}, {b}, {a,b}
83
+ m = np.array([0.0, 0.3, 0.5, 0.2])
84
+
85
+ print(mtob(m)) # commonality function
86
+ print(mtopl(m)) # plausibility function
87
+ print(mtobel(m)) # belief function
88
+ print(mtow(m)) # disjunctive weight function
89
+ ```
90
+
91
+ ## Running tests
92
+
93
+ ```bash
94
+ pip install -e ".[dev]"
95
+ pytest tests/
96
+ ```
97
+
98
+ ## References
99
+
100
+ - Smets, P. (2002). *The application of the transferable belief model to diagnostic problems.* International Journal of Intelligent Systems.
101
+ - Denoeux, T. (2008). *Conjunctive and disjunctive combination of belief functions induced by non-distinct bodies of evidence.* Artificial Intelligence.
102
+
103
+ ## License
104
+
105
+ MIT
@@ -0,0 +1,6 @@
1
+ evtools/__init__.py,sha256=dT51vadV8RJuDLuQv66ubEC_vYFurr5SEe4AzO4zLkc,592
2
+ evtools/conversions.py,sha256=14qtcgyTYqsjfsTMkCea7rjh27nnvjx6DkSFQ1wesbA,10296
3
+ evtools_dst-0.1.0.dist-info/METADATA,sha256=ScZ38a7Gb1O0lvRDprIj6XWf7LL5k17PCdF4wqpxtms,3072
4
+ evtools_dst-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ evtools_dst-0.1.0.dist-info/top_level.txt,sha256=2yDR1wgq5Z6XeHVKOu4LSDzFAvetUUEVrmUF2nkARUg,8
6
+ evtools_dst-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ evtools