pyfdm 1.0.1__zip
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.
- Program Files/Lib/site-packages/pyfdm/__init__.py +4 -0
- Program Files/Lib/site-packages/pyfdm/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/__pycache__/correlations.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/__pycache__/helpers.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/__pycache__/weights.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/correlations.py +92 -0
- Program Files/Lib/site-packages/pyfdm/helpers.py +62 -0
- Program Files/Lib/site-packages/pyfdm/methods/__init__.py +11 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_aras.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_codas.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_copras.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_edas.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_mabac.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_mairca.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_moora.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_ocra.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_topsis.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/f_vikor.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/__pycache__/validator.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/aras/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/aras/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/aras/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/aras/fuzzy.py +50 -0
- Program Files/Lib/site-packages/pyfdm/methods/codas/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/codas/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/codas/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/codas/fuzzy.py +92 -0
- Program Files/Lib/site-packages/pyfdm/methods/copras/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/copras/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/copras/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/copras/fuzzy.py +54 -0
- Program Files/Lib/site-packages/pyfdm/methods/edas/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/edas/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/edas/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/edas/fuzzy.py +80 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_aras.py +47 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_codas.py +59 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_copras.py +47 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_edas.py +47 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_mabac.py +52 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_mairca.py +52 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_moora.py +47 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_ocra.py +47 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_topsis.py +52 -0
- Program Files/Lib/site-packages/pyfdm/methods/f_vikor.py +51 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/__init__.py +3 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/__pycache__/defuzzifications.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/__pycache__/distances.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/__pycache__/normalizations.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/defuzzifications.py +86 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/distances.py +173 -0
- Program Files/Lib/site-packages/pyfdm/methods/fuzzy_sets/tfn/normalizations.py +188 -0
- Program Files/Lib/site-packages/pyfdm/methods/mabac/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/mabac/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/mabac/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/mabac/fuzzy.py +51 -0
- Program Files/Lib/site-packages/pyfdm/methods/mairca/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/mairca/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/mairca/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/mairca/fuzzy.py +57 -0
- Program Files/Lib/site-packages/pyfdm/methods/moora/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/moora/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/moora/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/moora/fuzzy.py +47 -0
- Program Files/Lib/site-packages/pyfdm/methods/ocra/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/ocra/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/ocra/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/ocra/fuzzy.py +52 -0
- Program Files/Lib/site-packages/pyfdm/methods/topsis/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/topsis/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/topsis/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/topsis/fuzzy.py +56 -0
- Program Files/Lib/site-packages/pyfdm/methods/validator.py +133 -0
- Program Files/Lib/site-packages/pyfdm/methods/vikor/__init__.py +1 -0
- Program Files/Lib/site-packages/pyfdm/methods/vikor/__pycache__/__init__.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/vikor/__pycache__/fuzzy.cpython-310.pyc +0 -0
- Program Files/Lib/site-packages/pyfdm/methods/vikor/fuzzy.py +77 -0
- Program Files/Lib/site-packages/pyfdm/weights.py +100 -0
- Program Files/Lib/site-packages/pyfdm-1.0.1-py3.10.egg-info/PKG-INFO +196 -0
- Program Files/Lib/site-packages/pyfdm-1.0.1-py3.10.egg-info/SOURCES.txt +49 -0
- Program Files/Lib/site-packages/pyfdm-1.0.1-py3.10.egg-info/dependency_links.txt +1 -0
- Program Files/Lib/site-packages/pyfdm-1.0.1-py3.10.egg-info/requires.txt +2 -0
- Program Files/Lib/site-packages/pyfdm-1.0.1-py3.10.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
'sum_normalization',
|
|
7
|
+
'max_normalization',
|
|
8
|
+
'linear_normalization',
|
|
9
|
+
'minmax_normalization',
|
|
10
|
+
'vector_normalization',
|
|
11
|
+
'saw_normalization'
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def sum_normalization(matrix, types):
|
|
16
|
+
"""
|
|
17
|
+
Calculates the normalized value of Triangular Fuzzy matrix using sum normalization
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
matrix : ndarray
|
|
22
|
+
Matrix with Triangular Fuzzy Numbers
|
|
23
|
+
|
|
24
|
+
types : ndarray
|
|
25
|
+
Types of criteria, 1 profit, -1 cost
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
ndarray
|
|
30
|
+
Normalized Triangular Fuzzy matrix
|
|
31
|
+
"""
|
|
32
|
+
nmatrix = np.zeros(matrix.shape, dtype=object)
|
|
33
|
+
|
|
34
|
+
# profit criteria
|
|
35
|
+
if 1 in types:
|
|
36
|
+
nmatrix[:, types == 1] = matrix[:, types == 1] / \
|
|
37
|
+
np.flip(np.sum(matrix[:, types == 1], axis=0))
|
|
38
|
+
|
|
39
|
+
# cost criteria
|
|
40
|
+
if -1 in types:
|
|
41
|
+
nmatrix[:, types == -1] = (1/matrix[:, types == -1]) / \
|
|
42
|
+
np.flip(np.sum(1/matrix[:, types == -1], axis=0))
|
|
43
|
+
|
|
44
|
+
return nmatrix.astype(float)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def max_normalization(matrix, types):
|
|
48
|
+
"""
|
|
49
|
+
Calculates the normalized value of Triangular Fuzzy matrix using max normalization
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
matrix : ndarray
|
|
54
|
+
Matrix with Triangular Fuzzy Numbers
|
|
55
|
+
|
|
56
|
+
types : ndarray
|
|
57
|
+
Types of criteria, 1 profit, -1 cost
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
ndarray
|
|
62
|
+
Normalized Triangular Fuzzy matrix
|
|
63
|
+
"""
|
|
64
|
+
nmatrix = np.zeros(matrix.shape, dtype=object)
|
|
65
|
+
|
|
66
|
+
# profit criteria
|
|
67
|
+
if 1 in types:
|
|
68
|
+
nmatrix[:, types == 1] = matrix[:, types == 1] / \
|
|
69
|
+
np.max(matrix[:, types == 1], axis=0)
|
|
70
|
+
|
|
71
|
+
# cost criteria
|
|
72
|
+
if -1 in types:
|
|
73
|
+
nmatrix[:, types == -1] = 1 - \
|
|
74
|
+
(matrix[:, types == -1] / np.max(matrix[:, types == -1], axis=0))
|
|
75
|
+
|
|
76
|
+
return nmatrix.astype(float)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def linear_normalization(matrix, types):
|
|
80
|
+
"""
|
|
81
|
+
Calculates the normalized value of Triangular Fuzzy matrix using linear normalization
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
matrix : ndarray
|
|
86
|
+
Matrix with Triangular Fuzzy Numbers
|
|
87
|
+
|
|
88
|
+
types : ndarray
|
|
89
|
+
Types of criteria, 1 profit, -1 cost
|
|
90
|
+
|
|
91
|
+
Returns
|
|
92
|
+
-------
|
|
93
|
+
ndarray
|
|
94
|
+
Normalized Triangular Fuzzy matrix
|
|
95
|
+
"""
|
|
96
|
+
nmatrix = np.zeros(matrix.shape, dtype=object)
|
|
97
|
+
|
|
98
|
+
# profit criteria
|
|
99
|
+
if 1 in types:
|
|
100
|
+
nmatrix[:, types == 1] = matrix[:, types == 1] / \
|
|
101
|
+
np.max(np.max(matrix[:, types == 1], axis=0), axis=1)[...,None]
|
|
102
|
+
|
|
103
|
+
# cost criteria
|
|
104
|
+
if -1 in types:
|
|
105
|
+
nmatrix[:, types == -1] = np.min(np.min(matrix[:, types == -1], axis=0), axis=1)[...,None] / \
|
|
106
|
+
matrix[:, types == -1][..., ::-1]
|
|
107
|
+
|
|
108
|
+
return nmatrix.astype(float)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def minmax_normalization(matrix, types):
|
|
112
|
+
"""
|
|
113
|
+
Calculates the normalized value of Triangular Fuzzy matrix using Min-Max normalization
|
|
114
|
+
|
|
115
|
+
Parameters
|
|
116
|
+
----------
|
|
117
|
+
matrix : ndarray
|
|
118
|
+
Matrix with Triangular Fuzzy Numbers
|
|
119
|
+
|
|
120
|
+
types : ndarray
|
|
121
|
+
Types of criteria, 1 profit, -1 cost
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
-------
|
|
125
|
+
ndarray
|
|
126
|
+
Normalized Triangular Fuzzy matrix
|
|
127
|
+
"""
|
|
128
|
+
nmatrix = np.zeros(matrix.shape, dtype=object)
|
|
129
|
+
|
|
130
|
+
# profit criteria
|
|
131
|
+
if 1 in types:
|
|
132
|
+
nmatrix[:, types == 1] = (matrix[:, types == 1] - np.min(matrix[:, types == 1, 0], axis=0)[..., None]) / \
|
|
133
|
+
(np.max(matrix[:, types == 1, 2], axis=0) -
|
|
134
|
+
np.min(matrix[:, types == 1, 0], axis=0))[...,None]
|
|
135
|
+
|
|
136
|
+
# cost criteria
|
|
137
|
+
if -1 in types:
|
|
138
|
+
nmatrix[:, types == -1] = ((matrix[:, types == -1] - np.max(matrix[:, types == -1, 2], axis=0)[...,None]) / (
|
|
139
|
+
np.min(matrix[:, types == -1, 0], axis=0) - np.max(matrix[:, types == -1, 2], axis=0))[...,None])[..., ::-1]
|
|
140
|
+
|
|
141
|
+
return nmatrix.astype(float)
|
|
142
|
+
|
|
143
|
+
def vector_normalization(matrix, *args):
|
|
144
|
+
"""
|
|
145
|
+
Calculates the normalized value of Triangular Fuzzy matrix using vector normalization
|
|
146
|
+
|
|
147
|
+
Parameters
|
|
148
|
+
----------
|
|
149
|
+
matrix : ndarray
|
|
150
|
+
Matrix with Triangular Fuzzy Numbers
|
|
151
|
+
|
|
152
|
+
*args is necessary for methods which reqiure some additional data
|
|
153
|
+
Returns
|
|
154
|
+
-------
|
|
155
|
+
ndarray
|
|
156
|
+
Normalized Triangular Fuzzy matrix
|
|
157
|
+
"""
|
|
158
|
+
nmatrix = np.zeros(matrix.shape, dtype=object)
|
|
159
|
+
|
|
160
|
+
# for each column
|
|
161
|
+
for j in range(nmatrix.shape[1]):
|
|
162
|
+
nmatrix[:, j] = matrix[:, j] / np.sqrt(np.sum(matrix[:, j]**2))
|
|
163
|
+
|
|
164
|
+
return nmatrix.astype(float)
|
|
165
|
+
|
|
166
|
+
def saw_normalization(matrix, *args):
|
|
167
|
+
"""
|
|
168
|
+
Calculates the normalized value of Triangular Fuzzy matrix using simple addictive weight normalization
|
|
169
|
+
|
|
170
|
+
Parameters
|
|
171
|
+
----------
|
|
172
|
+
matrix : ndarray
|
|
173
|
+
Matrix with Triangular Fuzzy Numbers
|
|
174
|
+
|
|
175
|
+
*args is necessary for methods which reqiure some additional data
|
|
176
|
+
Returns
|
|
177
|
+
-------
|
|
178
|
+
ndarray
|
|
179
|
+
Normalized Triangular Fuzzy matrix
|
|
180
|
+
"""
|
|
181
|
+
nmatrix = np.zeros(matrix.shape, dtype=object)
|
|
182
|
+
|
|
183
|
+
# for each column
|
|
184
|
+
for j in range(nmatrix.shape[1]):
|
|
185
|
+
nmatrix[:, j] = matrix[:, j] / np.max(matrix[:, j])
|
|
186
|
+
|
|
187
|
+
return nmatrix.astype(float)
|
|
188
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def fuzzy(matrix, weights, types, normalization, defuzzify):
|
|
6
|
+
"""
|
|
7
|
+
Calculates the alternatives preferences based on Triangular Fuzzy Number extension
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
matrix : ndarray
|
|
12
|
+
Decision matrix / alternatives data.
|
|
13
|
+
Alternatives are in rows and Criteria are in columns.
|
|
14
|
+
|
|
15
|
+
weights : ndarray
|
|
16
|
+
Vector of criteria weights in a crisp form
|
|
17
|
+
|
|
18
|
+
types : ndarray
|
|
19
|
+
Types of criteria, 1 profit, -1 cost
|
|
20
|
+
|
|
21
|
+
normalization: callable
|
|
22
|
+
Function used to normalize the decision matrix
|
|
23
|
+
|
|
24
|
+
defuzzify: callable
|
|
25
|
+
Function used to defuzzify the TFN into crisp value
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
ndarray:
|
|
30
|
+
Crisp preferences of alternatives
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# normalized decision matrix
|
|
35
|
+
nmatrix = normalization(matrix, types)
|
|
36
|
+
|
|
37
|
+
if weights.ndim == 1:
|
|
38
|
+
weights = np.repeat(weights, 3).reshape((len(weights), 3))
|
|
39
|
+
|
|
40
|
+
# weighted normalized decision matrix
|
|
41
|
+
wmatrix = nmatrix * weights + weights
|
|
42
|
+
|
|
43
|
+
# approximate border area matrix
|
|
44
|
+
G = np.product(wmatrix, axis=0) ** (1/wmatrix.shape[0])
|
|
45
|
+
|
|
46
|
+
# distance
|
|
47
|
+
Q = wmatrix - G[..., ::-1]
|
|
48
|
+
|
|
49
|
+
# preference value
|
|
50
|
+
S = np.array([np.sum(q, axis=0) for q in Q])
|
|
51
|
+
return np.array([defuzzify(s) for s in S])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def fuzzy(matrix, weights, types, normalization, distance):
|
|
6
|
+
"""
|
|
7
|
+
Calculates the alternatives preferences based on Triangular Fuzzy Number extension
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
matrix : ndarray
|
|
12
|
+
Decision matrix / alternatives data.
|
|
13
|
+
Alternatives are in rows and Criteria are in columns.
|
|
14
|
+
|
|
15
|
+
weights : ndarray
|
|
16
|
+
Vector of criteria weights in a crisp form
|
|
17
|
+
|
|
18
|
+
types : ndarray
|
|
19
|
+
Types of criteria, 1 profit, -1 cost
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
normalization: callable
|
|
23
|
+
Function used to normalize the decision matrix
|
|
24
|
+
|
|
25
|
+
distance: callable
|
|
26
|
+
Function used to calculate distance between two Triangular Fuzzy Numbers
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
ndarray:
|
|
31
|
+
Crisp preferences of alternatives
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# alternative selection propability
|
|
36
|
+
P = 1 / matrix.shape[0]
|
|
37
|
+
|
|
38
|
+
# Fuzzy theoretical evaluation matrix
|
|
39
|
+
tpa = np.ones((matrix.shape), dtype=object)
|
|
40
|
+
for j in range(matrix.shape[1]):
|
|
41
|
+
tpa[:, j] = P * weights[j]
|
|
42
|
+
|
|
43
|
+
# normalized fuzzy decision matrix
|
|
44
|
+
nmatrix = normalization(matrix, types)
|
|
45
|
+
|
|
46
|
+
# fuzzy elements of the actual ponder matrix
|
|
47
|
+
tra = nmatrix * tpa
|
|
48
|
+
|
|
49
|
+
# distance between Fuzzy Numbers
|
|
50
|
+
d = np.zeros((matrix.shape[0], matrix.shape[1], 1))
|
|
51
|
+
for i in range(matrix.shape[0]):
|
|
52
|
+
for j in range(matrix.shape[1]):
|
|
53
|
+
d[i, j] = distance(tpa[i, j], tra[i, j])
|
|
54
|
+
|
|
55
|
+
# preference value
|
|
56
|
+
Q = np.sum(d, axis=1).flatten()
|
|
57
|
+
return Q
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def fuzzy(matrix, weights, types, normalization):
|
|
6
|
+
"""
|
|
7
|
+
Calculates the alternatives preferences based on Triangular Fuzzy Number extension
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
matrix : ndarray
|
|
12
|
+
Decision matrix / alternatives data.
|
|
13
|
+
Alternatives are in rows and Criteria are in columns.
|
|
14
|
+
|
|
15
|
+
weights : ndarray
|
|
16
|
+
Vector of criteria weights in a crisp form
|
|
17
|
+
|
|
18
|
+
types : ndarray
|
|
19
|
+
Types of criteria, 1 profit, -1 cost
|
|
20
|
+
|
|
21
|
+
normalization: callable
|
|
22
|
+
Function used to normalize the decision matrix
|
|
23
|
+
|
|
24
|
+
Returns
|
|
25
|
+
-------
|
|
26
|
+
ndarray:
|
|
27
|
+
Crisp preferences of alternatives
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
# normalized decision matrix
|
|
32
|
+
nmatrix = normalization(matrix, types)
|
|
33
|
+
|
|
34
|
+
if weights.ndim == 1:
|
|
35
|
+
weights = np.repeat(weights, 3).reshape((len(weights), 3))
|
|
36
|
+
|
|
37
|
+
# weighted normalized decision matrix
|
|
38
|
+
wmatrix = nmatrix * weights
|
|
39
|
+
|
|
40
|
+
# profit and cost overall ratings
|
|
41
|
+
Sp = np.sum(wmatrix[:, types == 1], axis=1)
|
|
42
|
+
Sm = np.sum(wmatrix[:, types == -1], axis=1)
|
|
43
|
+
|
|
44
|
+
# preference value
|
|
45
|
+
S = np.array([np.sqrt(1/3 * ((sp[0]-sm[0])**2 + (sp[1]-sm[1])
|
|
46
|
+
** 2 + (sp[2]-sm[2])**2)) for sp, sm in zip(Sp, Sm)])
|
|
47
|
+
return S
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def fuzzy(matrix, weights, types, defuzzify):
|
|
6
|
+
"""
|
|
7
|
+
Calculates the alternatives preferences based on Triangular Fuzzy Number extension
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
matrix : ndarray
|
|
12
|
+
Decision matrix / alternatives data.
|
|
13
|
+
Alternatives are in rows and Criteria are in columns.
|
|
14
|
+
|
|
15
|
+
weights : ndarray
|
|
16
|
+
Vector of criteria weights in a crisp form
|
|
17
|
+
|
|
18
|
+
types : ndarray
|
|
19
|
+
Types of criteria, 1 profit, -1 cost
|
|
20
|
+
|
|
21
|
+
defuzzify: callable
|
|
22
|
+
Function used to defuzzify the TFN into crisp value
|
|
23
|
+
|
|
24
|
+
Returns
|
|
25
|
+
-------
|
|
26
|
+
ndarray:
|
|
27
|
+
Crisp preferences of alternatives
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
# cost fuzzy performance rating
|
|
32
|
+
Is = np.zeros((matrix.shape[0], matrix.shape[2]))
|
|
33
|
+
for i in range(matrix.shape[0]):
|
|
34
|
+
Is[i] = np.sum([weights[j] * ((np.max(matrix[:, j], axis=0) - matrix[i, j][..., ::-1]) /
|
|
35
|
+
(np.min(matrix[:, j], axis=0))) for j in range(matrix.shape[1]) if types[j] == -1], axis=0)
|
|
36
|
+
|
|
37
|
+
# cost fuzzy linear performance rating
|
|
38
|
+
Iss = Is - np.min(Is, axis=0)[..., ::-1]
|
|
39
|
+
|
|
40
|
+
# profit fuzzy performance rating
|
|
41
|
+
Os = np.zeros((matrix.shape[0], matrix.shape[2]))
|
|
42
|
+
for i in range(matrix.shape[0]):
|
|
43
|
+
Os[i] = np.sum([weights[j] * ((matrix[i, j] - np.min(matrix[:, j][..., ::-1], axis=0)) /
|
|
44
|
+
(np.min(matrix[:, j], axis=0))) for j in range(matrix.shape[1]) if types[j] == 1], axis=0)
|
|
45
|
+
|
|
46
|
+
# profit fuzzy linear performance rating
|
|
47
|
+
Oss = Os - np.min(Os, axis=0)[..., ::-1]
|
|
48
|
+
|
|
49
|
+
# aggregate fuzzy performance rating
|
|
50
|
+
P = Iss + Oss - np.min(Iss + Oss, axis=0)[..., ::-1]
|
|
51
|
+
|
|
52
|
+
return np.array([defuzzify(p) for p in P])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def fuzzy(matrix, weights, types, normalization, distance):
|
|
6
|
+
"""
|
|
7
|
+
Calculates the alternatives preferences based on Triangular Fuzzy Number extension
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
matrix : ndarray
|
|
12
|
+
Decision matrix / alternatives data.
|
|
13
|
+
Alternatives are in rows and Criteria are in columns.
|
|
14
|
+
|
|
15
|
+
weights : ndarray
|
|
16
|
+
Vector of criteria weights in a crisp form
|
|
17
|
+
|
|
18
|
+
types : ndarray
|
|
19
|
+
Types of criteria, 1 profit, -1 cost
|
|
20
|
+
|
|
21
|
+
normalization: callable
|
|
22
|
+
Function used to normalize the decision matrix
|
|
23
|
+
|
|
24
|
+
distance: callable
|
|
25
|
+
Function used to calculate distance from fuzzy negative solution
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
ndarray:
|
|
30
|
+
Crisp preferences of alternatives
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# Normalized fuzzy decision matrix
|
|
35
|
+
nmatrix = normalization(matrix, types)
|
|
36
|
+
|
|
37
|
+
if weights.ndim == 1:
|
|
38
|
+
weights = np.repeat(weights, 3).reshape((len(weights), 3))
|
|
39
|
+
|
|
40
|
+
# Weighted normalized fuzzy decision matrix
|
|
41
|
+
wmatrix = nmatrix * weights
|
|
42
|
+
|
|
43
|
+
# Fuzzy positive ideal solution and fuzzy negative ideal solution
|
|
44
|
+
ideal = np.ones((matrix.shape[1], matrix.shape[2]))
|
|
45
|
+
nideal = np.zeros((matrix.shape[1], matrix.shape[2]))
|
|
46
|
+
|
|
47
|
+
# Distance to FPIS and FNIS
|
|
48
|
+
fpis, fnis = np.zeros((matrix.shape[0], ), dtype=object), np.zeros(
|
|
49
|
+
(matrix.shape[0], ), dtype=object)
|
|
50
|
+
for i in range(matrix.shape[0]):
|
|
51
|
+
fpis[i] = np.sum([distance(wmatrix[i, j], ideal[j])
|
|
52
|
+
for j in range(matrix.shape[1])])
|
|
53
|
+
fnis[i] = np.sum([distance(wmatrix[i, j], nideal[j])
|
|
54
|
+
for j in range(matrix.shape[1])])
|
|
55
|
+
|
|
56
|
+
return fnis / (fpis + fnis)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Validator():
|
|
7
|
+
|
|
8
|
+
@staticmethod
|
|
9
|
+
def validate_input(matrix, weights, types):
|
|
10
|
+
"""
|
|
11
|
+
Checks if number of criteria, number of weights, and number of types are the same
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
matrix : ndarray
|
|
16
|
+
Decision matrix / alternatives data.
|
|
17
|
+
Alternatives are in rows and Criteria are in columns.
|
|
18
|
+
|
|
19
|
+
weights : ndarray
|
|
20
|
+
Vector of weights in a crisp form
|
|
21
|
+
|
|
22
|
+
types : ndarray
|
|
23
|
+
Types of criteria, 1 profit, -1 cost
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
raises:
|
|
28
|
+
ValueError if shapes of matrix, weights and types are not the same
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
if types is not None:
|
|
32
|
+
if len(np.unique([matrix.shape[1], weights.shape[0], types.shape[0]])) != 1:
|
|
33
|
+
raise ValueError(
|
|
34
|
+
f'Number of criteria should equals number of weights and types, not {matrix.shape[1]}, {weights.shape[0]}, {types.shape[0]}')
|
|
35
|
+
else:
|
|
36
|
+
if len(np.unique([matrix.shape[1], weights.shape[0]])) != 1:
|
|
37
|
+
raise ValueError(
|
|
38
|
+
f'Number of criteria should equals number of weights, not {matrix.shape[1]}, {weights.shape[0]}')
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def validate_tfn_matrix(matrix):
|
|
42
|
+
"""
|
|
43
|
+
Checks if TFN matrix is defined properly, all elements should have length of 3
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
matrix : ndarray
|
|
48
|
+
Decision matrix / alternatives data.
|
|
49
|
+
Alternatives are in rows and Criteria are in columns.
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
raises:
|
|
54
|
+
ValueError if matrix elements has different length than 3
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
if matrix.ndim != 3 or matrix.shape[2] != 3:
|
|
58
|
+
raise ValueError(
|
|
59
|
+
'TFN matrix elements should all have length of 3')
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def validate_weights(weights):
|
|
63
|
+
"""
|
|
64
|
+
For crisp weights checks if sum of weights equals 1
|
|
65
|
+
For fuzzy weights checks if given as Triangular Fuzzy Numbers
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
weights : ndarray
|
|
70
|
+
Vector of weights in a crisp form or as a TFNs
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
raises:
|
|
75
|
+
ValueError if sum of weights is different than 1 or not in TFN form
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
if weights.ndim == 1:
|
|
79
|
+
if np.round(np.sum(weights), 4) != 1:
|
|
80
|
+
raise ValueError(
|
|
81
|
+
f'Sum of crisp weights should equal 1, not {np.sum(weights)}')
|
|
82
|
+
else:
|
|
83
|
+
if weights.ndim != 2 or weights.shape[1] != 3:
|
|
84
|
+
raise ValueError(
|
|
85
|
+
'Fuzzy weights should be given as Triangular Fuzzy Numbers')
|
|
86
|
+
|
|
87
|
+
@staticmethod
|
|
88
|
+
def validate_types(types):
|
|
89
|
+
"""
|
|
90
|
+
Checks if all criteria types are same type
|
|
91
|
+
|
|
92
|
+
Parameters
|
|
93
|
+
----------
|
|
94
|
+
types : ndarray
|
|
95
|
+
Types of criteria, 1 profit, -1 cost
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
raises:
|
|
100
|
+
ValueError if criteria types are the same
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
if types is not None:
|
|
104
|
+
if len(np.unique(types)) == 1:
|
|
105
|
+
raise ValueError('Criteria types should not be the same')
|
|
106
|
+
|
|
107
|
+
@staticmethod
|
|
108
|
+
def fuzzy_validation(matrix, weights, types=None):
|
|
109
|
+
"""
|
|
110
|
+
Runs all validations for the fuzzy TFN extension
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
matrix : ndarray
|
|
115
|
+
Decision matrix / alternatives data.
|
|
116
|
+
Alternatives are in rows and Criteria are in columns.
|
|
117
|
+
|
|
118
|
+
weights : ndarray
|
|
119
|
+
Vector of weights in a crisp form
|
|
120
|
+
|
|
121
|
+
types : ndarray, default=None
|
|
122
|
+
Types of criteria, 1 profit, -1 cost
|
|
123
|
+
|
|
124
|
+
Returns
|
|
125
|
+
-------
|
|
126
|
+
raises:
|
|
127
|
+
ValueError if one of validations do not pass
|
|
128
|
+
|
|
129
|
+
"""
|
|
130
|
+
Validator.validate_input(matrix, weights, types)
|
|
131
|
+
Validator.validate_tfn_matrix(matrix)
|
|
132
|
+
Validator.validate_weights(weights)
|
|
133
|
+
Validator.validate_types(types)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|