简体   繁体   English

如何在python中对极坐标系数据进行分组或聚类

[英]How to group or cluster polar coordinate system data in python

I have an RPLidar and my task is to detect an obstacle.我有一个 RPLidar,我的任务是检测障碍物。 From the sensor, I am getting a set of truples which contains the quality of signal, angle and distance in mm.从传感器中,我得到一组元组,其中包含信号质量、角度和距离(以毫米为单位)。

Here are the example:以下是示例:

[(15, 1.375, 2569.0), (15, 3.0, 2491.5), (15, 4.578125, 2528.75), (15, 6.203125, 2419.75), (15, 7.796875, 2299.75), (15, 9.40625, 2200.5), (15, 11.078125, 2104.25), (15, 12.703125, 2047.25), (15, 14.3125, 2091.75), (15, 15.84375, 2132.25), (15, 17.46875, 2183.75), (15, 19.015625, 2232.5), (15, 20.609375, 2288.75), (15, 22.15625, 2341.0), (15, 23.765625, 2411.0), (15, 25.34375, 2481.0), (15, 26.875, 2554.25), (15, 28.453125, 2641.0), (15, 30.046875, 2731.5), (15, 31.609375, 2824.0), (15, 33.1875, 2854.75), (11, 39.8125, 2178.0), (15, 41.390625, 2278.0), (15, 42.984375, 2199.5), (13, 44.546875, 2269.0), (15, 46.171875, 2265.5), (15, 47.71875, 2300.75), (15, 49.3125, 2454.25), (15, 50.890625, 2442.0), (15, 52.484375, 2415.0), (15, 54.109375, 2404.0), (15, 55.703125, 2390.0), (15, 57.28125, 2371.0), (15, 58.796875, 2357.5), (15, 60.421875, 2348.5), (15, 61.984375, 2344.0), (15, 63.5625, 2340.5), (15, 65.171875, 2332.75), (15, 66.75, 2328.25), (15, 68.34375, 2330.75), (15, 69.984375, 2324.5), (15, 71.515625, 2328.25), (15, 73.125, 2332.75), (15, 74.71875, 2335.75), (15, 76.28125, 2341.5)]

I have plot those data in a matplotlib and that is how they look like:我在 matplotlib 中绘制了这些数据,这就是它们的样子:

![在此处输入图片说明

As you can see i am getting the surroundings information as point and each point has quality,angle,distance from the center.如您所见,我将周围环境信息作为点获取,并且每个点都有质量、角度、与中心的距离。 Now i want to group them and need to find the length of the each group.现在我想将它们分组并需要找到每个组的长度。 how can i achive this?我怎样才能做到这一点? is there any library available in python by which i can do the clustering like as bellow? python中是否有任何可用的库,我可以通过它进行如下聚类? 在此处输入图片说明

Obvious solution #1: 明显的解决方案1:

Project your data from polar coordinates to carthesian coordinates. 将数据从极坐标投影到笛卡尔坐标。 Then you can use any coordinate-based algorithm such as k-means, and anything that works with Euclidean distance (eg, HAC, DBSCAN) 然后,您可以使用任何基于坐标的算法(例如k均值)以及任何适用于欧几里德距离的算法(例如HAC,DBSCAN)

Obvious solution #2: 明显的解决方案2:

Compute the pairwise distances in polar coordinates. 计算极坐标中的成对距离。 That will likely be more complicated and thus slower for large data than above approach, but a bit more obvious. 对于大数据而言,这可能比上述方法更为复杂,因此速度较慢,但​​更为明显。 When you have the distance matrix, use any distance-based algorithm such as HAC, DBSCAN, affinity propagation, spectral clustering. 当您具有距离矩阵时,请使用任何基于距离的算法,例如HAC,DBSCAN,亲和力传播,光谱聚类。

Based on your plots, I'd project and use DBSCAN. 根据您的绘图,我将设计并使用DBSCAN。

This feels like a K-mean clustering problem to me. 在我看来,这就像一个K均值聚类问题。 You can leverage lots of existing solutions to achieve this. 您可以利用许多现有解决方案来实现这一目标。 Here is blog post about how to achieve this in Panda. 这是有关如何在Panda中实现此目标的博客文章

If the volume is potentially large, I did a project to do k-means clustering in Pyspark a while backe. 如果容量可能很大,我会做一个项目在backside Pyspark中进行k均值聚类。 You can find more info here 您可以在这里找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM