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

    https://github.com/apache/spark/pull/7412#discussion_r35504114
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/fpm/PrefixSpan.scala 
---
    @@ -82,20 +86,106 @@ class PrefixSpan private (
           logWarning("Input data is not cached.")
         }
         val minCount = getMinCount(sequences)
    -    val lengthOnePatternsAndCounts =
    -      getFreqItemAndCounts(minCount, sequences).collect()
    -    val prefixAndProjectedDatabase = getPrefixAndProjectedDatabase(
    -      lengthOnePatternsAndCounts.map(_._1), sequences)
    -    val groupedProjectedDatabase = prefixAndProjectedDatabase
    -      .map(x => (x._1.toSeq, x._2))
    +    val lengthOnePatternsAndCounts = getFreqItemAndCounts(minCount, 
sequences)
    +    val prefixSuffixPairs = getPrefixSuffixPairs(
    +      lengthOnePatternsAndCounts.map(_._1).collect(), sequences)
    +    var patternsCount: Long = lengthOnePatternsAndCounts.count()
    +    var allPatternAndCounts = lengthOnePatternsAndCounts.map(x => 
(ArrayBuffer(x._1), x._2))
    +    var (smallPrefixSuffixPairs, largePrefixSuffixPairs) =
    +      splitPrefixSuffixPairs(prefixSuffixPairs)
    +    largePrefixSuffixPairs.persist(StorageLevel.MEMORY_AND_DISK)
    +    var patternLength: Int = 1
    +    while (patternLength < maxPatternLength &&
    +      largePrefixSuffixPairs.count() != 0) {
    +      val (nextPatternAndCounts, nextPrefixSuffixPairs) =
    +        getPatternCountsAndPrefixSuffixPairs(minCount, 
largePrefixSuffixPairs)
    +      patternsCount = nextPatternAndCounts.count()
    +      largePrefixSuffixPairs.unpersist()
    +      val splitedPrefixSuffixPairs = 
splitPrefixSuffixPairs(nextPrefixSuffixPairs)
    +      largePrefixSuffixPairs = splitedPrefixSuffixPairs._2
    +      largePrefixSuffixPairs.persist(StorageLevel.MEMORY_AND_DISK)
    +      smallPrefixSuffixPairs = smallPrefixSuffixPairs ++ 
splitedPrefixSuffixPairs._1
    +      allPatternAndCounts = allPatternAndCounts ++ nextPatternAndCounts
    +      patternLength = patternLength + 1
    +    }
    +    if (smallPrefixSuffixPairs.count() > 0) {
    +      val projectedDatabase = smallPrefixSuffixPairs
    +        .map(x => (x._1.toSeq, x._2))
    +        .groupByKey()
    +        .map(x => (x._1.toArray, x._2.toArray))
    +      val nextPatternAndCounts = getPatternsInLocal(minCount, 
projectedDatabase)
    +      allPatternAndCounts = allPatternAndCounts ++ nextPatternAndCounts
    +    }
    +    allPatternAndCounts.map { case (pattern, count) => (pattern.toArray, 
count) }
    +  }
    +
    +
    +  /**
    +   * Split prefix suffix pairs to two parts:
    +   * suffixes' size less than maxSuffixesBeforeLocalProcessing and
    +   * suffixes' size more than maxSuffixesBeforeLocalProcessing
    +   * @param prefixSuffixPairs prefix (length n) and suffix pairs,
    +   * @return small size prefix suffix pairs and big size prefix suffix 
pairs
    +   *         (RDD[prefix, suffix], RDD[prefix, suffix ])
    +   */
    +  private def splitPrefixSuffixPairs(
    +      prefixSuffixPairs: RDD[(ArrayBuffer[Int], Array[Int])]):
    +  (RDD[(ArrayBuffer[Int], Array[Int])], RDD[(ArrayBuffer[Int], 
Array[Int])]) = {
    +    val suffixSizeMap = prefixSuffixPairs
    +      .map(x => (x._1, x._2.length))
    +      .reduceByKey(_ + _)
    --- End diff --
    
    @feynmanliang  I compared these two methods. I find your method's running 
time more  than mine. And the result is not correct. I don't know why it was 
so, please check it, thank you.


---
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