flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chiwanpark <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-1745] Add exact k-nearest-neighbours al...
Date Mon, 02 Nov 2015 17:42:08 GMT
Github user chiwanpark commented on the pull request:

    https://github.com/apache/flink/pull/1220#issuecomment-153096308
  
    I would suggest logic like following:
    
    ```scala
    val useQuadTree = ~~~
    
    if (useQuadTree) {
      knnQueryWithQuadTree(training, testing, out)
    } else {
      knnQueryBasic(training, testing, out)
    }
    ```
    
    Or to reduce duplicated code in L257-L266, we can use following:
    
    ```scala
    val useQuadTree = ~~~
    val quadTree: Option[QuadTree] = if (useQuadTree) {
      Some(buildQuadTree(training, testing))
    } else {
      None
    }
    
    for (a <- testing.values) {
      val trainingFiltered: Seq[Vector] = quadTree match {
        case Some(tree) => getSibilingsFromQuadTree(a, tree)
        case None => training.values
      }
    
      for (b <- trainingFiltered) {
        // (training vector, input vector, input key, distance)
        queue.enqueue((b, a._2, a._1, metric.distance(b, a._2)))
        if (queue.size > k) {
          queue.dequeue()
        }
      }
      for (v <- queue) {
        out.collect(v)
      }
    }
    ```
    
    In this case, we create methods about quadtree operation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message