Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7360#discussion_r34485420
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/fpm/LocalPrefixSpan.scala ---
    @@ -86,28 +86,30 @@ private[fpm] object LocalPrefixSpan extends Logging 
with Serializable {
           minCount: Long,
           sequences: Array[Array[Int]]): Array[(Int, Long)] = {
         sequences.flatMap(_.distinct)
    -      .groupBy(x => x)
    -      .mapValues(_.length.toLong)
    +      .foldRight(Map[Int, Long]().withDefaultValue(0L)) { case (item, ctr) 
=>
    +        ctr + (item -> (ctr(item) + 1))
    +      }
           .filter(_._2 >= minCount)
           .toArray
       }
     
       /**
        * Get the frequent prefixes' projected database.
    -   * @param prePrefix the frequent prefixes' prefix
    -   * @param frequentPrefixes frequent prefixes
    -   * @param sequences sequences data
    -   * @return prefixes and projected database
    +   * @param prefix the frequent prefixes' prefix
    +   * @param frequentPrefixes frequent next prefixes
    +   * @param projDB projected database for given prefix
    +   * @return extensions of prefix by one item and corresponding projected 
databases
        */
       private def getPatternAndProjectedDatabase(
    -      prePrefix: Array[Int],
    +      prefix: ArrayBuffer[Int],
           frequentPrefixes: Array[Int],
    -      sequences: Array[Array[Int]]): Array[(Array[Int], 
Array[Array[Int]])] = {
    -    val filteredProjectedDatabase = sequences
    -      .map(x => x.filter(frequentPrefixes.contains(_)))
    -    frequentPrefixes.map { x =>
    -      val sub = filteredProjectedDatabase.map(y => getSuffix(x, 
y)).filter(_.nonEmpty)
    -      (prePrefix ++ Array(x), sub)
    +      projDB: Array[Array[Int]]): Array[(ArrayBuffer[Int], 
Array[Array[Int]])] = {
    --- End diff --
    
    We should do projection one by one.
    
    ~~~scala
    frequentItems.flatMap { p =>
      val projected = project(database, p) // returns Array[Array[Int]]
      getFrequentPatterns(database) // returns Iterator[(List[Int], Long)]
        .map { case (pattern, count) =>
          (p :: pattern, count)
        }
    }
    ~~~


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to