Distribution
dstz.core.distribution
Evidence
Bases: dict
A dictionary subclass for storing evidence data.
Evidence enforces type constraints, requiring that all keys be instances
of the Item class and all values be floats. This structure is fundamental
for representing belief masses in evidence theory.
It behaves like a standard dictionary but adds validation during initialization and item assignment.
Source code in dstz/core/distribution.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__getitem__(item)
Retrieves an item from the dictionary.
This method ensures that the key used for retrieval is an instance of
Item before accessing the value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Item
|
The key whose associated value is to be returned. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
The value associated with the given key. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the key is not an |
Source code in dstz/core/distribution.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__init__(*args, **kwargs)
Initializes the Evidence dictionary.
This constructor accepts the same arguments as a standard dict.
After initializing, it validates that all keys are instances of Item
and all values are floats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list, passed to the |
()
|
|
**kwargs
|
Arbitrary keyword arguments, passed to the |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If any key is not an |
Source code in dstz/core/distribution.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
__setitem__(key, value)
Sets a key-value pair in the dictionary with type validation.
Before adding or updating a key-value pair, this method ensures the
key is an Item instance and the value is a float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Item
|
The key to set, which must be an instance of |
required |
value
|
float
|
The value to associate with the key. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the key is not an |
Source code in dstz/core/distribution.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |