-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdelphi.py
More file actions
140 lines (93 loc) · 4.06 KB
/
delphi.py
File metadata and controls
140 lines (93 loc) · 4.06 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import collections
import numpy
import operator
import random
criteria = [
'data analysis',
'highload development',
'network stack',
'databases',
'programming language profficiency',
'microbiology',
'virilory',
'immunology',
'bacteriology',
'protein structures',
'leadership',
'scientific reputation',
'time management',
'management skills',
'estimate salary',
]
alternatives = [
'Tony',
'Rudolf',
'Kate',
'Lee Ann',
'Mustafa',
]
experts = [
'Bill',
'Bob',
'Mary',
'Jack',
'Dave',
]
def generate_criteria_weights(criteria):
criteria_weights = collections.defaultdict(dict)
criteria_weights_mean = {}
for criterion in criteria:
for expert in experts:
criteria_weights[criterion][expert] = random.randint(1, 100)
criteria_weights_mean[criterion] = numpy.mean(criteria_weights[criterion].values())
return criteria_weights_mean
def generate_expert_scores():
expert_scores = collections.defaultdict(lambda : collections.defaultdict(dict))
for criterion in criteria:
for alternative in alternatives:
for expert in experts:
expert_scores[criterion][alternative][expert] = random.randint(0, 10)
return expert_scores
def get_average_scores(expert_scores):
average_scores = collections.defaultdict(dict)
for criterion in criteria:
for alternative in alternatives:
scores = expert_scores[criterion][alternative].values()
average_scores[criterion][alternative] = numpy.mean(scores)
return average_scores
def normalize_expert_scores(expert_scores, average_scores):
total_distance_before = 0
total_distance_after = 0
for criterion in criteria:
for alternative in alternatives:
for expert in experts:
expert_score = expert_scores[criterion][alternative][expert]
average_scrore = average_scores[criterion][alternative]
distance_from_mean = average_scrore - expert_score
total_distance_before += abs(distance_from_mean)
smooth_coefficient = distance_from_mean / random.randint(1, 10)
expert_scores[criterion][alternative][expert] += smooth_coefficient
total_distance_after += abs(distance_from_mean) - abs(smooth_coefficient)
return expert_scores
def get_result_rating(average_expert_scores, criteria_weights):
result_rating = collections.defaultdict(float)
for alternative in alternatives:
for criterion in criteria:
expert_score = average_expert_scores[criterion][alternative]
criteria_weight = criteria_weights[criterion]
result_rating[alternative] += expert_score * criteria_weight
return sorted(result_rating.iteritems(), key=operator.itemgetter(1), reverse=True)
if __name__ == '__main__':
criteria_weights = generate_criteria_weights(criteria)
expert_scores = generate_expert_scores()
average_scores = get_average_scores(expert_scores)
#First round of normalization/smoothing
normalized_expert_scores_1 = normalize_expert_scores(expert_scores, average_scores)
average_scores = get_average_scores(normalized_expert_scores_1)
#Second round of normalization/smoothing
normalized_expert_scores_2 = normalize_expert_scores(normalized_expert_scores_1, average_scores)
average_scores = get_average_scores(normalized_expert_scores_2)
result_rating = get_result_rating(average_scores, criteria_weights)
print('Best choice is {0}.\nRating:'.format(result_rating[0][0]))
for alternative, rating in result_rating:
print(' {0} {1}'.format(alternative, int(rating)))