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,92 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
'spearman_coef',
|
|
7
|
+
'pearson_coef',
|
|
8
|
+
'weighted_spearman_coef',
|
|
9
|
+
'ws_rank_similarity_coef'
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def spearman_coef(x, y):
|
|
14
|
+
"""
|
|
15
|
+
Calculate Spearman correlation between two vectors
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
x : ndarray
|
|
20
|
+
Array with values
|
|
21
|
+
|
|
22
|
+
y : ndarray
|
|
23
|
+
Array with values
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
float
|
|
28
|
+
Correlation between two vectors
|
|
29
|
+
"""
|
|
30
|
+
return (np.cov(x, y, bias=True)[0][1]) / (np.std(x) * np.std(y))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def pearson_coef(x, y):
|
|
34
|
+
"""
|
|
35
|
+
Calculate Pearson correlation between two vectors
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
x : ndarray
|
|
40
|
+
Array with values
|
|
41
|
+
|
|
42
|
+
y : ndarray
|
|
43
|
+
Array with values
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
float
|
|
48
|
+
Correlation between two vectors
|
|
49
|
+
"""
|
|
50
|
+
return (np.cov(x, y, bias=True)[0][1]) / (np.std(x) * np.std(y))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def weighted_spearman_coef(x, y):
|
|
54
|
+
"""
|
|
55
|
+
Calculate Weighted Spearman correlation between two rankings
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
x : ndarray
|
|
60
|
+
Array with ranking
|
|
61
|
+
|
|
62
|
+
y : ndarray
|
|
63
|
+
Array with ranking
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
float
|
|
68
|
+
Correlation between two vectors
|
|
69
|
+
"""
|
|
70
|
+
N = x.shape[0]
|
|
71
|
+
return 1 - ((6 * np.sum((x-y)**2 * ((N - x + 1) + (N - y + 1)))) / (N**4 + N**3 - N**2 - N))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def ws_rank_similarity_coef(x, y):
|
|
75
|
+
"""
|
|
76
|
+
Calculate WS Rank Similarity Coefficient between two rankings
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
x : ndarray
|
|
81
|
+
Array with ranking
|
|
82
|
+
|
|
83
|
+
y : ndarray
|
|
84
|
+
Array with ranking
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
float
|
|
89
|
+
Correlation between two rankings
|
|
90
|
+
"""
|
|
91
|
+
N = x.shape[0]
|
|
92
|
+
return 1 - np.sum(2.0**(-1.0 * x) * (np.fabs(x - y)) / (np.max((np.fabs(1 - x), np.fabs(N - x)), axis=0)))
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
'rank',
|
|
7
|
+
'generate_fuzzy_matrix'
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def rank(x, descending=True):
|
|
12
|
+
"""
|
|
13
|
+
Calculates ranking of given values with the given direction, default descending order
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
x: ndarray
|
|
18
|
+
Array with values
|
|
19
|
+
|
|
20
|
+
descending: boolean, default=True
|
|
21
|
+
Switch to change ranking order
|
|
22
|
+
|
|
23
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
ndarray
|
|
26
|
+
Ranking with given order
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
s = [sorted(x, reverse=descending).index(r)+1 for r in x]
|
|
30
|
+
return np.array([(ss * s.count(ss) + s.count(ss) - 1) / s.count(ss) if s.count(ss) <= 2 else np.sum(list(range(ss, ss+s.count(ss)))) / s.count(ss) for ss in s])
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def generate_fuzzy_matrix(m, n, lower=0.0, upper=1.0):
|
|
34
|
+
"""
|
|
35
|
+
Generates random Triangular Fuzzy Numbers with m alternatives and n criteria, each TFN is places between lower and upper bound
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
m: int
|
|
40
|
+
Number of alternatives
|
|
41
|
+
|
|
42
|
+
n: int
|
|
43
|
+
Number of criteria
|
|
44
|
+
|
|
45
|
+
lower: float, default=0.0
|
|
46
|
+
Minimum value of left bound
|
|
47
|
+
|
|
48
|
+
upper: float, default=1.0
|
|
49
|
+
Maximum value of right bound
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
ndarray
|
|
54
|
+
Matrix with random TFN within given bounds
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
if lower > upper:
|
|
59
|
+
raise ValueError("Lower bound of TFN must be greater than upper")
|
|
60
|
+
|
|
61
|
+
matrix = np.random.uniform(low=lower, high=upper, size=(m, n, 3))
|
|
62
|
+
return np.array([np.sort(m, axis=1) for m in matrix])
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .f_aras import fARAS
|
|
2
|
+
from .f_codas import fCODAS
|
|
3
|
+
from .f_copras import fCOPRAS
|
|
4
|
+
from .f_edas import fEDAS
|
|
5
|
+
from .f_mabac import fMABAC
|
|
6
|
+
from .f_mairca import fMAIRCA
|
|
7
|
+
from .f_moora import fMOORA
|
|
8
|
+
from .f_ocra import fOCRA
|
|
9
|
+
from .f_topsis import fTOPSIS
|
|
10
|
+
from .f_vikor import fVIKOR
|
|
11
|
+
from .fuzzy_sets import *
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
# extended decision matrix
|
|
32
|
+
exmatrix = np.zeros(
|
|
33
|
+
(matrix.shape[0]+1, matrix.shape[1], matrix.shape[2]), dtype=object)
|
|
34
|
+
exmatrix[1:] = matrix
|
|
35
|
+
|
|
36
|
+
exmatrix[0, :] = np.repeat(np.max(np.max(matrix, axis=0), axis=1), 3).reshape(
|
|
37
|
+
matrix.shape[1], matrix.shape[2])
|
|
38
|
+
|
|
39
|
+
# normalized decision matrix
|
|
40
|
+
nmatrix = normalization(exmatrix, types)
|
|
41
|
+
|
|
42
|
+
if weights.ndim == 1:
|
|
43
|
+
weights = np.repeat(weights, 3).reshape((len(weights), 3))
|
|
44
|
+
|
|
45
|
+
# weighted normalized decision matrix
|
|
46
|
+
wmatrix = nmatrix * weights
|
|
47
|
+
|
|
48
|
+
# overall preference
|
|
49
|
+
S = 1/3 * np.sum(np.sum(wmatrix, axis=1), axis=1)
|
|
50
|
+
return S[1:] / S[0]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def fuzzy(matrix, weights, types, normalization, distance_1, distance_2, tau):
|
|
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_1: callable
|
|
25
|
+
Function used to calculate distance from fuzzy negative solution
|
|
26
|
+
|
|
27
|
+
distance_2: callable
|
|
28
|
+
Function used to calculate distance form fuzzy negative solution
|
|
29
|
+
|
|
30
|
+
tau: float
|
|
31
|
+
Threshold parameter
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
ndarray:
|
|
36
|
+
Crisp preferences of alternatives
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def _psi(x, tau=0.02):
|
|
41
|
+
"""
|
|
42
|
+
Threshold function
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
x: float
|
|
47
|
+
Value to assess
|
|
48
|
+
|
|
49
|
+
tau: float, default=0.02
|
|
50
|
+
Threshold parameter
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
int
|
|
55
|
+
0 if absolute value of x below threshold, otherwise 1
|
|
56
|
+
"""
|
|
57
|
+
# tau from 0.01 to 0.05
|
|
58
|
+
if np.abs(x) >= tau:
|
|
59
|
+
return 1
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
# normalized decision matrix
|
|
63
|
+
nmatrix = normalization(matrix, types)
|
|
64
|
+
|
|
65
|
+
if weights.ndim == 1:
|
|
66
|
+
weights = np.repeat(weights, 3).reshape((len(weights), 3))
|
|
67
|
+
|
|
68
|
+
# weighted decision matrix
|
|
69
|
+
wmatrix = nmatrix * weights
|
|
70
|
+
|
|
71
|
+
# fuzzy negative solution
|
|
72
|
+
NS = np.min(wmatrix, axis=0)
|
|
73
|
+
|
|
74
|
+
# distances from fuzzy negative solution
|
|
75
|
+
D1, D2 = np.zeros((matrix.shape[0], ), dtype=object), np.zeros(
|
|
76
|
+
(matrix.shape[0], ), dtype=object)
|
|
77
|
+
for i in range(matrix.shape[0]):
|
|
78
|
+
D1[i] = np.sum([distance_1(wmatrix[i, j], NS[j])
|
|
79
|
+
for j in range(matrix.shape[1])])
|
|
80
|
+
D2[i] = np.sum([distance_2(wmatrix[i, j], NS[j])
|
|
81
|
+
for j in range(matrix.shape[1])])
|
|
82
|
+
|
|
83
|
+
# relative assessment matrix
|
|
84
|
+
RA = np.zeros((matrix.shape[0], matrix.shape[0]), dtype=object)
|
|
85
|
+
for i in range(RA.shape[0]):
|
|
86
|
+
for j in range(RA.shape[1]):
|
|
87
|
+
RA[i, j] = (D1[i] - D1[j]) + \
|
|
88
|
+
(_psi(D1[i] - D1[j], tau) * (D2[i] - D2[j]))
|
|
89
|
+
|
|
90
|
+
# assessment score
|
|
91
|
+
AS = np.sum(RA, axis=1)
|
|
92
|
+
return AS
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
a : float
|
|
25
|
+
Threshold parameter
|
|
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
|
|
42
|
+
|
|
43
|
+
# aggregated profit and cost values
|
|
44
|
+
Tp = np.sum(wmatrix[:, types == 1], axis=1)
|
|
45
|
+
Tm = np.sum(wmatrix[:, types == -1], axis=1)
|
|
46
|
+
|
|
47
|
+
# distance
|
|
48
|
+
Q = Tp + (np.sum(Tm)) / (Tm * np.sum(np.divide(1,Tm.astype(float))))
|
|
49
|
+
if np.isnan(np.max(Q.astype(float).ravel())):
|
|
50
|
+
Q = np.nan_to_num(Q.ravel().astype(float)).reshape(Tp.shape)
|
|
51
|
+
|
|
52
|
+
# defuzzified values
|
|
53
|
+
Q = Q[:, 0] + ((Q[:, 2] - Q[:, 0]) - (Q[:, 1] - Q[:, 2])) / 3
|
|
54
|
+
return Q / np.max(Q)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import fuzzy
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
ndarray:
|
|
26
|
+
Crisp preferences of alternatives
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def psi(a):
|
|
31
|
+
"""
|
|
32
|
+
Threshold function
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
a: ndarray
|
|
37
|
+
Triangular Fuzzy Number
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
ndarray
|
|
42
|
+
0 if defuzzified TFN lower than 0, otherwise TFN
|
|
43
|
+
"""
|
|
44
|
+
if defuzzify(a) > 0:
|
|
45
|
+
return a
|
|
46
|
+
return [0, 0, 0]
|
|
47
|
+
|
|
48
|
+
# fuzzy average decision matrix
|
|
49
|
+
av_matrix = np.mean(matrix, axis=0)
|
|
50
|
+
k = np.array([defuzzify(a) for a in av_matrix])
|
|
51
|
+
|
|
52
|
+
# positive and negative distances from average
|
|
53
|
+
pda, nda = np.zeros((matrix.shape)), np.zeros((matrix.shape))
|
|
54
|
+
for i in range(matrix.shape[0]):
|
|
55
|
+
for j in range(matrix.shape[1]):
|
|
56
|
+
if types[j] == 1:
|
|
57
|
+
pda[i, j] = psi(
|
|
58
|
+
matrix[i, j] - av_matrix[j][..., ::-1]) / k[j]
|
|
59
|
+
nda[i, j] = psi(
|
|
60
|
+
av_matrix[j] - matrix[i, j][..., ::-1]) / k[j]
|
|
61
|
+
else:
|
|
62
|
+
pda[i, j] = psi(
|
|
63
|
+
av_matrix[j] - matrix[i, j][..., ::-1]) / k[j]
|
|
64
|
+
nda[i, j] = psi(
|
|
65
|
+
matrix[i, j] - av_matrix[j][..., ::-1]) / k[j]
|
|
66
|
+
|
|
67
|
+
if weights.ndim == 1:
|
|
68
|
+
weights = np.repeat(weights, 3).reshape((len(weights), 3))
|
|
69
|
+
|
|
70
|
+
# fuzzy weighted positive and negative distances
|
|
71
|
+
sp = np.sum(pda * weights, axis=1)
|
|
72
|
+
sn = np.sum(nda * weights, axis=1)
|
|
73
|
+
|
|
74
|
+
# fuzzy normalized weighted positive and negative distances
|
|
75
|
+
nsp = sp / np.max([defuzzify(p) for p in sp])
|
|
76
|
+
nsn = 1 - (sn / np.max([defuzzify(n) for n in sn]))
|
|
77
|
+
|
|
78
|
+
# fuzzy appraisal score
|
|
79
|
+
a = (nsp + nsn) / 2
|
|
80
|
+
return np.array([defuzzify(alt) for alt in a])
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
from .aras.fuzzy import fuzzy
|
|
4
|
+
from .fuzzy_sets.tfn.normalizations import sum_normalization
|
|
5
|
+
|
|
6
|
+
from .validator import Validator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class fARAS():
|
|
10
|
+
def __init__(self, normalization=sum_normalization):
|
|
11
|
+
"""
|
|
12
|
+
Create fuzzy ARAS method object with sum normalization function
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
normalization: callable
|
|
17
|
+
Function used to calculate normalized decision matrix
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
self.normalization = normalization
|
|
21
|
+
|
|
22
|
+
def __call__(self, matrix, weights, types):
|
|
23
|
+
"""
|
|
24
|
+
Calculates the alternatives preferences
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
matrix : ndarray
|
|
29
|
+
Decision matrix / alternatives data.
|
|
30
|
+
Alternatives are in rows and Criteria are in columns.
|
|
31
|
+
|
|
32
|
+
weights : ndarray
|
|
33
|
+
Vector of criteria weights in a crisp form
|
|
34
|
+
|
|
35
|
+
types : ndarray
|
|
36
|
+
Types of criteria, 1 profit, -1 cost
|
|
37
|
+
|
|
38
|
+
Returns
|
|
39
|
+
----------
|
|
40
|
+
ndarray:
|
|
41
|
+
Preference calculated for alternatives. Greater values are placed higher in ranking
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
# validate data
|
|
45
|
+
Validator.fuzzy_validation(matrix, weights)
|
|
46
|
+
|
|
47
|
+
return fuzzy(matrix, weights, types, self.normalization).astype(float)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
from .codas.fuzzy import fuzzy
|
|
4
|
+
from .fuzzy_sets.tfn.normalizations import max_normalization
|
|
5
|
+
from .fuzzy_sets.tfn.distances import euclidean_distance, hamming_distance
|
|
6
|
+
|
|
7
|
+
from .validator import Validator
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class fCODAS():
|
|
11
|
+
def __init__(self, normalization=max_normalization, distance_1=euclidean_distance, distance_2=hamming_distance):
|
|
12
|
+
"""
|
|
13
|
+
Create fuzzy CODAS method object with max normalization function and Euclidean and Hamming distances metrics
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
normalization: callable
|
|
18
|
+
Function used to calculate normalized decision matrix
|
|
19
|
+
|
|
20
|
+
distance_1: callable
|
|
21
|
+
Function used to calculate distance from fuzzy negative solution
|
|
22
|
+
|
|
23
|
+
distance_2: callable
|
|
24
|
+
Function used to calculate distance form fuzzy negative solution
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
self.normalization = normalization
|
|
29
|
+
self.distance_1 = distance_1
|
|
30
|
+
self.distance_2 = distance_2
|
|
31
|
+
|
|
32
|
+
def __call__(self, matrix, weights, types, tau=0.02):
|
|
33
|
+
"""
|
|
34
|
+
Calculates the alternatives preferences
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
matrix : ndarray
|
|
39
|
+
Decision matrix / alternatives data.
|
|
40
|
+
Alternatives are in rows and Criteria are in columns.
|
|
41
|
+
|
|
42
|
+
weights : ndarray
|
|
43
|
+
Vector of criteria weights in a crisp form
|
|
44
|
+
|
|
45
|
+
types : ndarray
|
|
46
|
+
Types of criteria, 1 profit, -1 cost
|
|
47
|
+
|
|
48
|
+
tau: float, default = 0.02
|
|
49
|
+
Threshold parameter
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
----------
|
|
53
|
+
ndarray:
|
|
54
|
+
Preference calculated for alternatives. Greater values are placed higher in ranking
|
|
55
|
+
"""
|
|
56
|
+
# validate data
|
|
57
|
+
Validator.fuzzy_validation(matrix, weights)
|
|
58
|
+
|
|
59
|
+
return fuzzy(matrix, weights, types, self.normalization, self.distance_1, self.distance_2, tau).astype(float)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright (c) 2022 Jakub Więckowski
|
|
2
|
+
|
|
3
|
+
from .copras.fuzzy import fuzzy
|
|
4
|
+
from .fuzzy_sets.tfn.normalizations import saw_normalization
|
|
5
|
+
|
|
6
|
+
from .validator import Validator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class fCOPRAS():
|
|
10
|
+
def __init__(self, normalization=saw_normalization):
|
|
11
|
+
"""
|
|
12
|
+
Create fuzzy COPRAS method object with saw normalization function
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
normalization: callable
|
|
17
|
+
Function used to calculate normalized decision matrix
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
self.normalization = normalization
|
|
22
|
+
|
|
23
|
+
def __call__(self, matrix, weights, types):
|
|
24
|
+
"""
|
|
25
|
+
Calculates the alternatives preferences
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
matrix : ndarray
|
|
30
|
+
Decision matrix / alternatives data.
|
|
31
|
+
Alternatives are in rows and Criteria are in columns.
|
|
32
|
+
|
|
33
|
+
weights : ndarray
|
|
34
|
+
Vector of criteria weights in a crisp form
|
|
35
|
+
|
|
36
|
+
types : ndarray
|
|
37
|
+
Types of criteria, 1 profit, -1 cost
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
----------
|
|
41
|
+
ndarray:
|
|
42
|
+
Preference calculated for alternatives. Greater values are placed higher in ranking
|
|
43
|
+
"""
|
|
44
|
+
# validate data
|
|
45
|
+
Validator.fuzzy_validation(matrix, weights, types)
|
|
46
|
+
|
|
47
|
+
return fuzzy(matrix, weights, types, self.normalization).astype(float)
|