Desc: 根据设定矩形大小的聚类算法, 每个类的MBR <= width * width 采用层次聚类, 层次聚类选择合并的依据是 min (delta_x + delta_y) cluster A 的宽度为(xa, ya), cluster B 的宽度为(xb, yb) A, B合并后的类cluster C 的宽度为(xc, yc), xc < width, yc < width if xa + ya > xb + yb: delta_x = xc - x
(points, width=40)
| 18 | |
| 19 | |
| 20 | def rect_cluster(points, width=40): |
| 21 | """ |
| 22 | Desc: 根据设定矩形大小的聚类算法, 每个类的MBR <= width * width |
| 23 | 采用层次聚类, 层次聚类选择合并的依据是 min (delta_x + delta_y) |
| 24 | cluster A 的宽度为(xa, ya), cluster B 的宽度为(xb, yb) |
| 25 | A, B合并后的类cluster C 的宽度为(xc, yc), xc < width, yc < width |
| 26 | if xa + ya > xb + yb: |
| 27 | delta_x = xc - xa |
| 28 | delta_y = yc - ya |
| 29 | else |
| 30 | delta_x = xc - xb |
| 31 | delta_y = yc - yb |
| 32 | Args: |
| 33 | points : 需要聚类的点的集合, Point集合 |
| 34 | width : 类的宽度阈值 |
| 35 | Return: |
| 36 | list of cluster.Cluster |
| 37 | Raises: |
| 38 | None |
| 39 | """ |
| 40 | alg = cluster.HCAlgorithm(width) |
| 41 | return alg.run(points) |
| 42 | |
| 43 | |
| 44 | def rect_classify(points, clusters, width=40): |