示例#1
0
 def _distance_to_group(self, point, group):
     min_distance = sys.float_info.max
     for pt in group:
         dist = ms_utils.euclidean_dist(point, pt)
         if dist < min_distance:
             min_distance = dist
     return min_distance
示例#2
0
    def cluster(self, points, kernel_bandwidth, iteration_callback=None):
        if (iteration_callback):
            iteration_callback(points, 0)
        shift_points = np.array(points)
        max_min_dist = 1
        iteration_number = 0

        still_shifting = [True] * points.shape[0]
        while max_min_dist > MIN_DISTANCE:
            # print max_min_dist
            max_min_dist = 0
            iteration_number += 1
            for i in range(0, len(shift_points)):
                if not still_shifting[i]:
                    continue
                p_new = shift_points[i]
                p_new_start = p_new
                p_new = self._shift_point(p_new, points, kernel_bandwidth)
                dist = ms_utils.euclidean_dist(p_new, p_new_start)
                if dist > max_min_dist:
                    max_min_dist = dist
                if dist < MIN_DISTANCE:
                    still_shifting[i] = False
                shift_points[i] = p_new
            if iteration_callback:
                iteration_callback(shift_points, iteration_number)
        point_grouper = pg.PointGrouper()
        group_assignments = point_grouper.group_points(shift_points.tolist())
        return MeanShiftResult(points, shift_points, group_assignments)
示例#3
0
    def cluster(self, points, kernel_bandwidth, iteration_callback=None):
        if(iteration_callback):
            iteration_callback(points, 0)
        shift_points = np.array(points)
        max_min_dist = 1
        iteration_number = 0

        still_shifting = [True] * points.shape[0]
        while max_min_dist > MIN_DISTANCE:
            # print max_min_dist
            max_min_dist = 0
            iteration_number += 1
            for i in range(0, len(shift_points)):
                if not still_shifting[i]:
                    continue
                p_new = shift_points[i]
                p_new_start = p_new
                p_new = self._shift_point(p_new, points, kernel_bandwidth)
                dist = ms_utils.euclidean_dist(p_new, p_new_start)
                if dist > max_min_dist:
                    max_min_dist = dist
                if dist < MIN_DISTANCE:
                    still_shifting[i] = False
                shift_points[i] = p_new
            if iteration_callback:
                iteration_callback(shift_points, iteration_number)
        point_grouper = pg.PointGrouper()
        group_assignments = point_grouper.group_points(shift_points.tolist())
        return MeanShiftResult(points, shift_points, group_assignments)
示例#4
0
    def cluster(self,
                points,
                kernel_bandwidth,
                pressureWeights,
                iteration_callback=None):
        if (iteration_callback):
            iteration_callback(points, 0)
        shift_points = np.array(points)
        max_min_dist = 1
        iteration_number = 0

        still_shifting = [True] * points.shape[0]
        old_max_min_dist = max_min_dist + 1
        while max_min_dist > MIN_DISTANCE and np.linalg.norm(
                old_max_min_dist -
                max_min_dist) > 0.0001 and iteration_number < 50:
            print('old_max_min_dis is ' + str(old_max_min_dist))
            print('max_min_dis is ' + str(max_min_dist))
            print('diff is ' +
                  str(np.linalg.norm(old_max_min_dist - max_min_dist)))
            # print max_min_dist
            old_max_min_dist = max_min_dist
            max_min_dist = 0
            iteration_number += 1
            for i in range(0, len(shift_points)):
                if not still_shifting[i]:
                    continue
                p_new = shift_points[i]
                p_new_start = p_new
                p_new = self._shift_point(p_new, points, kernel_bandwidth,
                                          pressureWeights)
                dist = ms_utils.euclidean_dist(p_new, p_new_start)
                if dist > max_min_dist:
                    max_min_dist = dist
                if dist < MIN_DISTANCE:
                    still_shifting[i] = False
                shift_points[i] = p_new
            if iteration_callback:
                iteration_callback(shift_points, iteration_number)
        point_grouper = pg.PointGrouper()
        group_assignments = point_grouper.group_points(shift_points.tolist())
        return MeanShiftResult(points, shift_points, group_assignments)
示例#5
0
    def cluster_cell(self, points, kernel_bandwidth, iteration_callback=None):
        if (iteration_callback):
            iteration_callback(points, 0)
        #将这些点的集合变成np的数组
        shift_points = np.array(points)
        #最大最小距离?
        max_min_dist = 1
        iteration_number = 0

        #shape[0] 代表行数,[true........]  多少个点就多少个,这就是个标志位
        still_shifting = [True] * points.shape[0]

        #应该是这个最小的欧氏距离小到一定的程度,我就停止移位我的点
        while max_min_dist > MIN_DISTANCE:
            # print max_min_dist
            max_min_dist = 0
            iteration_number += 1

            #这个小循环遍历每一个点集合X
            for i in range(0, len(shift_points)):
                if not still_shifting[i]:  #标志位,如果没有漂移过
                    continue
                p_new = shift_points[i]
                p_new_start = p_new
                #这个点已经漂移完了
                p_new = self._shift_point(p_new, points, kernel_bandwidth)
                #计算漂移的欧氏距离
                dist = ms_utils.euclidean_dist(p_new, p_new_start)
                #一轮轮得到最小的欧氏距离
                if dist > max_min_dist:
                    max_min_dist = dist
                if dist < MIN_DISTANCE:
                    still_shifting[i] = False
                shift_points[i] = p_new
            if iteration_callback:
                iteration_callback(shift_points, iteration_number)
        #此处一个基站只有一个密度中心,所以求shift_points 的均值
        print "iter:"
        print iteration_number
        return self.getcenterpoint_from_array(shift_points)
示例#6
0
    def cluster(self, points, kernel_bandwidth, iteration_callback=None):
        if (iteration_callback):
            iteration_callback(points, 0)
        #将这些点的集合变成np的数组
        shift_points = np.array(points)
        #最大最小距离?
        max_min_dist = 1
        iteration_number = 0

        #shape[0] 代表行数,[true........]  多少个点就多少个,这就是个标志位
        still_shifting = [True] * points.shape[0]

        #应该是这个最小的欧氏距离小到一定的程度,我就停止移位我的点
        while max_min_dist > MIN_DISTANCE:
            # print max_min_dist
            max_min_dist = 0
            iteration_number += 1

            #这个小循环遍历每一个点集合X
            for i in range(0, len(shift_points)):
                if not still_shifting[i]:  #标志位,如果没有漂移过
                    continue
                p_new = shift_points[i]
                p_new_start = p_new
                #这个点已经漂移完了
                p_new = self._shift_point(p_new, points, kernel_bandwidth)
                #计算漂移的欧氏距离
                dist = ms_utils.euclidean_dist(p_new, p_new_start)
                #一轮轮得到最小的欧氏距离
                if dist > max_min_dist:
                    max_min_dist = dist
                if dist < MIN_DISTANCE:
                    still_shifting[i] = False
                shift_points[i] = p_new
            if iteration_callback:
                iteration_callback(shift_points, iteration_number)
        point_grouper = pg.PointGrouper()
        group_assignments = point_grouper.group_points(shift_points.tolist())
        return MeanShiftResult(points, shift_points, group_assignments)