首页 > 解决方案 > set S = N \ {P} 在伪代码中意味着什么?

问题描述

从Wikipedia了解 DBscan 。文章有如下伪代码:

DBSCAN(DB, distFunc, eps, minPts) {
   C = 0                                                  /* Cluster counter */
   for each point P in database DB {
      if label(P) ≠ undefined then continue               /* Previously processed in inner loop */
      Neighbors N = RangeQuery(DB, distFunc, P, eps)      /* Find neighbors */
      if |N| < minPts then {                              /* Density check */
         label(P) = Noise                                 /* Label as Noise */
         continue
      }
      C = C + 1                                           /* next cluster label */
      label(P) = C                                        /* Label initial point */
      Seed set S = N \ {P}                                /* Neighbors to expand */
      for each point Q in S {                             /* Process every seed point */
         if label(Q) = Noise then label(Q) = C            /* Change Noise to border point */
         if label(Q) ≠ undefined then continue            /* Previously processed */
         label(Q) = C                                     /* Label neighbor */
         Neighbors N = RangeQuery(DB, distFunc, Q, eps)   /* Find neighbors */
         if |N| ≥ minPts then {                           /* Density check */
            S = S ∪ N                                     /* Add new neighbors to seed set */
         }
      }
   }
}

我很确定|N| 将意味着 N 的计数。

这条线会是什么:

      Seed set S = N \ {P}                                /* Neighbors to expand */

意思是?我认为S 是一个种子集,就像一个对象列表。N \ {P} 是什么意思?

标签: pseudocode

解决方案


\是补运算,因此是没有点N \ {P}的邻居集合。表示围绕一定距离的所有点,由(查询结果包括)返回。NPPRangeQuery(DB, distFunc, P, eps)P

https://en.wikipedia.org/wiki/Complement_(set_theory)


推荐阅读