def objfunc(test_median, data_points):
"""This function calculates the sum of linear distances from the current candidate median to all points
in the data set, as such it is the objective function that we are minimising.
"""
temp = 0.0
for i in range(0, len(data_points)):
try:
temp += vincenty(test_median, data_points[i]).kilometers
except ValueError:
# Vincenty doesn't always converge so fall back on great circle distance which is less accurate but always converges
temp += great_circle(test_median, data_points[i]).kilometers
return temp
评论列表
文章目录