Example #1
0
 def getRouteDistances(self, location, routes):
     distances = []
     if len(routes) < 1:
         return distances
     distances.append(getDistanceBetween(self.location, routes[0]))
     for i, loc1 in enumerate(routes[:-1]):
         distances.append(getDistanceBetween(loc1, routes[i + 1]))
     return distances
Example #2
0
def calc_all_distances(distance, c_x, c_y):
   distances = []
   for x in c_x:
      for y in c_y:
         dist = None
         if (x,y) in pre_computed:
            dist = pre_computed[(x,y)]
         else:
            dist = distance(x,y)
            pre_computed[(x,y)] = dist
         distances.append(dist)
   return distances
Example #3
0
 def calc_stats(self, centroid, cluster):
     distances = []
     for x in cluster:
         distances.append(self.distance(x, centroid))
     try:
         return (
             max(distances),
             min(distances),
             sum(distances) / len(distances),
             squared_error(centroid, cluster, self.distance),
         )
     except ValueError as e:
         print("FUCCCCCCCCCCCCKKKKKKKKKK")
         print(distances)
         print(cluster)
         print(centroid)
         raise e
Example #4
0
 def calc_stats(self, centroid, cluster):
    distances = []
    for x in cluster:
       distances.append(self.distance(x, centroid))
    return max(distances), min(distances), sum(distances)/len(distances),\
          squared_error(centroid, cluster, self.distance)