【问题标题】:What algorithm is used to filter out from higher dimensional data points?使用什么算法从高维数据点中过滤掉?
【发布时间】:2020-04-04 20:15:13
【问题描述】:

我在服务器的MySQL 数据库中存储了 4 维数据点。具有三个空间 GPS 数据(lat、lon、alt)的一维数据。 GPS 数据按 1 分钟的时间范围对数千名用户进行采样,并将 24x7 全天候添加到我的服务器中。

示例 REST/post json 看起来像,

{
   "id": "1005",
    "location": {
        "lat":-87.8788,
        "lon":37.909090,
        "alt":0.0,
    },
    "datetime": 11882784
}

现在,我需要过滤掉在给定时间段内位置与给定userID 距离在公里范围内的所有候选人 (userID)。

用于过滤的示例 REST/get 查询参数看起来像,

{
    "id": "1001",      // user for whose we need to filter out candidates IDs
    "maxDistance":3,   // max distance in meter to consider (euclidian distance from users location to candidates location)
    "maxDuration":14   // duration offset (in days) from current datetime to consider
}

正如我们所见,每分钟在我的数据库中插入数以千计的条目,从而导致总条目数巨大。因此,要对所有过滤条目进行迭代,恐怕对于我目前的要求来说,简单的幼稚方法是不可行的。那么,我应该在服务器中实现什么算法呢?我试图实现简单的算法,例如,

params ($uid, $mDis, $mDay)

1.     Init $candidates = []
2.     For all the locations $Li of user with $uid
3.         For all locations $Di in database within $mDay
4.             $dif = EuclidianDis($Li, $Di)
5.             If $dif < $mDis
6.                 $candidates += userId for $Di
7.     Return $candidates

但是,这种方法在实践中非常缓慢。并且预先计算可能不可行,因为它为所有userIDs 花费了巨大的空间。 还有什么算法可以提高效率?

【问题讨论】:

  • k 是固定的还是每个查询都不同?
  • 距离可以在(2~5)米范围内,持续时间可以在(1~14)天范围内。

标签: mysql algorithm multidimensional-array data-structures filter


【解决方案1】:

您可以实施spatial hashing 算法来有效地查询您的数据库以查找给定区域/时间内的候选人。

将 3D 空间划分为宽度为 k 的 3D 立方体网格,在将数据点插入数据库时​​,计算该点所在的立方体并根据立方体坐标计算哈希值。

当查询另一个数据点 d 的 k 内的所有数据点时,计算 d 所在的立方体,并找到 8 个相邻的立方体(每个维度中 +/- 1)。计算 9 个多维数据集的哈希值,并在数据库中查询给定时间段内具有这些哈希值的所有条目。您将有一个小的候选集,然后您可以从中迭代以查找 d 的 k 内的所有数据点。

如果您的 k 值介于 2-5 米之间,请将立方体的宽度设为 5。

时间戳可以存储为单独的字段,或者您可以将多维数据集设为 4 维并在哈希中包含时间戳,然后搜索 27 个多维数据集而不是 9 个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 2023-01-09
    相关资源
    最近更新 更多