Skip to content

Dual

dstz.math.matrix.dual

conjunctive_rule(ev1, ev2, curItem=Element)

Performs conjunctive combination using the matrix method.

This function uses the Commonality Function Relation Matrix (QFRM) to perform the conjunctive rule of combination.

Parameters:

Name Type Description Default
ev1 Evidence

The first evidence object.

required
ev2 Evidence

The second evidence object.

required
curItem callable

Factory function for new elements. Defaults to Element.

Element

Returns:

Name Type Description
Evidence

The combined evidence.

Source code in dstz/math/matrix/dual.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def conjunctive_rule(ev1, ev2, curItem=Element):
    """Performs conjunctive combination using the matrix method.

    This function uses the Commonality Function Relation Matrix (QFRM) to
    perform the conjunctive rule of combination.

    Args:
        ev1 (Evidence): The first evidence object.
        ev2 (Evidence): The second evidence object.
        curItem (callable, optional): Factory function for new elements.
                                   Defaults to `Element`.

    Returns:
        Evidence: The combined evidence.
    """
    fod = list(get_fod(ev1).union(get_fod(ev2)))
    return matrix_rule(ev1, ev2, get_qfrm(len(fod)), fod)

de_conjunctive_rule(ev1, ev2, curItem=Element)

Performs the inverse conjunctive combination using the matrix method.

This can be used to "un-combine" evidence, effectively performing a division in the commonality space.

Parameters:

Name Type Description Default
ev1 Evidence

The evidence to be divided.

required
ev2 Evidence

The evidence to divide by.

required
curItem callable

Factory function for new elements. Defaults to Element.

Element

Returns:

Name Type Description
Evidence

The resulting evidence.

Source code in dstz/math/matrix/dual.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def de_conjunctive_rule(ev1, ev2, curItem=Element):
    """Performs the inverse conjunctive combination using the matrix method.

    This can be used to "un-combine" evidence, effectively performing a
    division in the commonality space.

    Args:
        ev1 (Evidence): The evidence to be divided.
        ev2 (Evidence): The evidence to divide by.
        curItem (callable, optional): Factory function for new elements.
                                   Defaults to `Element`.

    Returns:
        Evidence: The resulting evidence.
    """
    fod = list(get_fod(ev1).union(get_fod(ev2)))
    return matrix_rule(ev1, ev2, get_qfrm(len(fod)), fod, False)

de_disjunctive_rule(ev1, ev2, curItem=Element)

Performs the inverse disjunctive combination using the matrix method.

This can be used to "un-combine" evidence, effectively performing a division in the belief space.

Parameters:

Name Type Description Default
ev1 Evidence

The evidence to be divided.

required
ev2 Evidence

The evidence to divide by.

required
curItem callable

Factory function for new elements. Defaults to Element.

Element

Returns:

Name Type Description
Evidence

The resulting evidence.

Source code in dstz/math/matrix/dual.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def de_disjunctive_rule(ev1, ev2, curItem=Element):
    """Performs the inverse disjunctive combination using the matrix method.

    This can be used to "un-combine" evidence, effectively performing a
    division in the belief space.

    Args:
        ev1 (Evidence): The evidence to be divided.
        ev2 (Evidence): The evidence to divide by.
        curItem (callable, optional): Factory function for new elements.
                                   Defaults to `Element`.

    Returns:
        Evidence: The resulting evidence.
    """
    fod = list(get_fod(ev1).union(get_fod(ev2)))
    return matrix_rule(ev1, ev2, get_bfrm(len(fod)), fod, False)

disjunctive_rule(ev1, ev2, curItem=Element)

Performs disjunctive combination using the matrix method.

This function uses the Belief Function Relation Matrix (BFRM) to perform the disjunctive rule of combination.

Parameters:

Name Type Description Default
ev1 Evidence

The first evidence object.

required
ev2 Evidence

The second evidence object.

required
curItem callable

Factory function for new elements. Defaults to Element.

Element

Returns:

Name Type Description
Evidence

The combined evidence.

Source code in dstz/math/matrix/dual.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def disjunctive_rule(ev1, ev2, curItem=Element):
    """Performs disjunctive combination using the matrix method.

    This function uses the Belief Function Relation Matrix (BFRM) to
    perform the disjunctive rule of combination.

    Args:
        ev1 (Evidence): The first evidence object.
        ev2 (Evidence): The second evidence object.
        curItem (callable, optional): Factory function for new elements.
                                   Defaults to `Element`.

    Returns:
        Evidence: The combined evidence.
    """
    fod = list(get_fod(ev1).union(get_fod(ev2)))
    return matrix_rule(ev1, ev2, get_bfrm(len(fod)), fod)

matrix_rule(ev1, ev2, matrix, fod, mul=True, curItem=Element)

Combines two evidence objects using a generic matrix-based rule.

This function provides a framework for evidence combination using linear algebra. It transforms evidence mass functions into another domain (e.g., belief or commonality space) using a transformation matrix, combines them in that domain, and then transforms the result back into a mass function.

Parameters:

Name Type Description Default
ev1 Evidence

The first evidence object.

required
ev2 Evidence

The second evidence object.

required
matrix ndarray

The transformation matrix (e.g., BFRM or QFRM).

required
fod list

An ordered list of the singleton elements forming the Frame of Discernment.

required
mul bool

If True, the transformed vectors are combined by element-wise multiplication. If False, they are combined by division. Defaults to True.

True
curItem callable

A factory function to create new item instances. Defaults to Element.

Element

Returns:

Name Type Description
Evidence

A new Evidence object representing the combined evidence.

Source code in dstz/math/matrix/dual.py
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
def matrix_rule(ev1, ev2, matrix, fod, mul=True, curItem=Element):
    """Combines two evidence objects using a generic matrix-based rule.

    This function provides a framework for evidence combination using linear
    algebra. It transforms evidence mass functions into another domain (e.g.,
    belief or commonality space) using a transformation matrix, combines them
    in that domain, and then transforms the result back into a mass function.

    Args:
        ev1 (Evidence): The first evidence object.
        ev2 (Evidence): The second evidence object.
        matrix (np.ndarray): The transformation matrix (e.g., BFRM or QFRM).
        fod (list): An ordered list of the singleton elements forming the
                    Frame of Discernment.
        mul (bool, optional): If `True`, the transformed vectors are combined
                              by element-wise multiplication. If `False`, they
                              are combined by division. Defaults to `True`.
        curItem (callable, optional): A factory function to create new item
            instances. Defaults to `Element`.

    Returns:
        Evidence: A new `Evidence` object representing the combined evidence.
    """
    ev = Evidence()
    events = []
    # Create vector representations of the mass functions
    ev1_m = np.zeros(2 ** len(fod))
    ev2_m = np.zeros(2 ** len(fod))
    for i in range(2 ** len(fod)):
        event = set()
        event_index = get_ones_indices(i)
        if event_index:
            for j in get_ones_indices(i):
                event.add(fod[j])
        element = Element(event)
        events.append(element)
        if element in ev1:
            ev1_m[i] = ev1[element]
        if element in ev2:
            ev2_m[i] = ev2[element]

    # Transform, combine, and inverse-transform
    ev1_q = np.dot(matrix, ev1_m)
    ev2_q = np.dot(matrix, ev2_m)
    if mul:
        ev_q = ev1_q * ev2_q
    else:
        ev_q = ev1_q / ev2_q
    matrix_inv = np.linalg.inv(matrix)
    ev_m = np.dot(matrix_inv, ev_q)

    # Convert the resulting vector back to an Evidence object
    for i in range(len(events)):
        if ev_m[i] > 0:
            ev[events[i]] = ev_m[i]
    return ev