本文整理汇总了Python中lib.util.Util.hubeny_distance方法的典型用法代码示例。如果您正苦于以下问题:Python Util.hubeny_distance方法的具体用法?Python Util.hubeny_distance怎么用?Python Util.hubeny_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.util.Util
的用法示例。
在下文中一共展示了Util.hubeny_distance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: predict
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import hubeny_distance [as 别名]
def predict(self, user_id):
min_d = 100000000
min_p = None
p = self.user_locations[user_id]
for follower_id in self.graph.get_followers(user_id):
follower = self.users.get(follower_id)
if follower != None:
follower_p = follower['location_point']
if follower_p != None:
d = Util.hubeny_distance(follower_p, p)
if min_d > d:
min_d = d
min_p = follower_p
for friend_id in self.graph.get_friends(user_id):
friend = self.users.get(friend_id)
if friend != None:
friend_p = friend['location_point']
if friend_p != None:
d = Util.hubeny_distance(friend_p, p)
if min_d > d:
min_d = d
min_p = friend_p
for venue_name in self.venues.get_venues(user_id):
venue_p = self.venues.get_point(venue_name)
d = Util.hubeny_distance(venue_p, p)
if min_d > d:
min_d = d
min_p = venue_p
return min_p
示例2: calc_error_distances
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import hubeny_distance [as 别名]
def calc_error_distances(self, inferred_users):
error_distances = []
for test_user in self.test_users.iter():
true_point = test_user['location_point']
inferred_user = inferred_users.get(test_user['id'])
if inferred_user != None:
inferred_point = inferred_user['location_point']
if inferred_point != None:
error_distance = Util.hubeny_distance(inferred_point, true_point)
error_distances.append(error_distance)
return error_distances
示例3: compute_gamma
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import hubeny_distance [as 别名]
def compute_gamma(self):
""" returns log gammma values """
gamma = {}
locations = set([])
for user in self.users.iter():
if user['location_point'] != None:
locations.add(tuple(user['location_point']))
for l in locations:
gamma[l] = 0
for user in self.users.iter():
d = Util.hubeny_distance(l, user['location_point'])
gamma[l] += math.log(1 - self.edge_prob(d))
return gamma
示例4: compute_gamma_u
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import hubeny_distance [as 别名]
def compute_gamma_u(self, user):
gamma_u = {}
friends = self.graph.get_friends(user['id'])
followers = self.graph.get_followers(user['id'])
neighbors = set(friends) | set(followers)
for vid in neighbors:
v = self.users.get(vid)
if v != None and v['location_point'] != None:
if not tuple(v['location_point']) in gamma_u:
gamma_u[tuple(v['location_point'])] = 0
for wid in neighbors:
w = self.users.get(wid)
if w != None and w['location_point'] != None:
d = Util.hubeny_distance(w['location_point'], v['location_point'])
p = self.edge_prob(d)
gamma_u[tuple(v['location_point'])] += math.log(p) - math.log(1-p)
return gamma_u
示例5: evaluate
# 需要导入模块: from lib.util import Util [as 别名]
# 或者: from lib.util.Util import hubeny_distance [as 别名]
def evaluate(inferred, answer):
for u in answer.iter():
v = inferred.get(u['id'])
if v['location'] != None:
print Util.hubeny_distance(v['location'], u['location'])