-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweighting_methods.py
76 lines (60 loc) · 2.1 KB
/
weighting_methods.py
1
2
3
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
75
76
import numpy as np
from correlations import *
from normalizations import *
# equal weighting
def equal_weighting(X):
N = np.shape(X)[1]
return np.ones(N) / N
# entropy weighting
def entropy_weighting(X):
# normalization for profit criteria
criteria_type = np.ones(np.shape(X)[1])
pij = sum_normalization(X, criteria_type)
m, n = np.shape(pij)
H = np.zeros((m, n))
for j in range(n):
for i in range(m):
if pij[i, j] != 0:
H[i, j] = pij[i, j] * np.log(pij[i, j])
h = np.sum(H, axis = 0) * (-1 * ((np.log(m)) ** (-1)))
d = 1 - h
w = d / (np.sum(d))
return w
# standard deviation weighting
def std_weighting(X):
stdv = np.std(X, axis = 0)
return stdv / np.sum(stdv)
# CRITIC weighting
def critic_weighting(X):
# normalization for profit criteria
criteria_type = np.ones(np.shape(X)[1])
x_norm = minmax_normalization(X, criteria_type)
std = np.std(x_norm, axis = 0)
n = np.shape(x_norm)[1]
correlations = np.zeros((n, n))
for i in range(0, n):
for j in range(0, n):
correlations[i, j] = pearson_coeff(x_norm[:, i], x_norm[:, j])
difference = 1 - correlations
suma = np.sum(difference, axis = 0)
C = std * suma
w = C / (np.sum(C, axis = 0))
return w
# Equal distribution of main weights on the hierarchical structure of the model criteria
def structured_equal_weights(modules, main_weights):
flag_begin = True
crit_list = []
num_of_modules = len(modules)
for g, module in enumerate(modules):
num_of_submodules = len(module)
for submodule in module:
num_of_elements = len(submodule)
subweights = np.ones(num_of_elements) * ((main_weights[g] / num_of_submodules) / num_of_elements)
if flag_begin:
old_subweights = copy.deepcopy(subweights)
flag_begin = False
else:
old_subweights = np.hstack((old_subweights, subweights))
for sub in submodule:
crit_list.append(sub)
return old_subweights, crit_list