-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLower_bound_a_star_utils.py
60 lines (56 loc) · 2.55 KB
/
Lower_bound_a_star_utils.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
import math
import numpy as np
def scoring_with_avg(feature_dict):
"""
Calculating the average distance between specific landmark to all other nodes, then passing through sigmoid
function to resize scale. The lower the average distance, the higher the output value
:param feature_dict: This dictionary is of the following format: {(source_node,target_node):
{landmark1:estimated_distance, landmark2:estimated_distance2....}}
:return: A dict, {landmark1:score1.....}
"""
landmark_score = {}
# print(feature_dict)
for key, value in feature_dict.items():
for landmark, distance in value.items():
if landmark not in landmark_score:
landmark_score[landmark] = distance
else:
landmark_score[landmark] += distance
#landmark_score = sorted(landmark_score.items(), key=lambda x: x[1], reverse=True)
#print(landmark_score)
#print('k', k)
#for key, value in landmark_score.items():
# landmark_score[key] = - math.tanh(value) + 1
#print(landmark_score)
return landmark_score
def scoring_with_ordering(feature_dict):
"""
For every node pairs, we could get the order of the landmark estimated distance, every landmark will get a value
indicates their order in specific pair, we then add them up and reorder the landmark. From nearest
(the lowest order) to furthest (the highest order), the final value will start from 1 to n
:param feature_dict: This dictionary is of the following format: {(source_node,target_node):
{landmark1:estimated_distance, landmark2:estimated_distance2....}}
:param feature_dict:
:return: A dict, {landmark1:score1.....} n >= score_n >= 1
"""
landmark_score = {}
# print("=============================")
# print(feature_dict)
# print(":+++++++++++++++++++++++++++++++")
for key, value_dict in feature_dict.items():
# print(value_dict)
distance_list = sorted(value_dict.items(), key=lambda x: x[1], reverse=True)
score_default = 0
for pairs in distance_list:
if pairs[0] not in landmark_score:
landmark_score[pairs[0]] = score_default
score_default += 1
else:
landmark_score[pairs[0]] += score_default
score_default += 1
#print(landmark_score)
#for key, value in landmark_score.items():
# landmark_score[key] = - math.tanh(value) + 1
#print(landmark_score)
#landmark_score = sorted(landmark_score.items(), key=lambda x: x[1], reverse=True)
return landmark_score