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

    https://github.com/apache/spark/pull/7075#discussion_r36148400
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/stat/test/KolmogorovSmirnovTest.scala
 ---
    @@ -190,5 +191,104 @@ private[stat] object KolmogorovSmirnovTest extends 
Logging {
         val pval = 1 - new CommonMathKolmogorovSmirnovTest().cdf(ksStat, 
n.toInt)
         new KolmogorovSmirnovTestResult(pval, ksStat, 
NullHypothesis.OneSampleTwoSided.toString)
       }
    +
    +  /**
    +   * Implements a two-sample, two-sided Kolmogorov-Smirnov test, which 
tests if the 2 samples
    +   * come from the same distribution
    +   * @param data1 `RDD[Double]` first sample of data
    +   * @param data2 `RDD[Double]` second sample of data
    +   * @return 
[[org.apache.spark.mllib.stat.test.KolmogorovSmirnovTestResult]] with the test
    +   *        statistic, p-value, and appropriate null hypothesis
    +   */
    +  def testTwoSamples(data1: RDD[Double], data2: RDD[Double]): 
KolmogorovSmirnovTestResult = {
    +    val n1 = data1.count().toDouble
    +    val n2 = data2.count().toDouble
    +    // identifier for sample 1, needed after co-sort
    +    val isSample1 = true
    +    // combine identified samples
    +    val unionedData = data1.map((_, isSample1)).union(data2.map((_, 
!isSample1)))
    +    // co-sort and operate on each partition, returning local extrema to 
the driver
    +    val localData = unionedData.sortByKey().mapPartitions(
    +      searchTwoSampleCandidates(_, n1, n2)
    +    ).collect()
    +    // result: global extreme
    +    val ksStat = searchTwoSampleStatistic(localData, n1 * n2)
    +    evalTwoSampleP(ksStat, n1.toInt, n2.toInt)
    +  }
    +
    +  /**
    +   * Calculates maximum distance candidates and counts of elements from 
each sample within one
    +   * partition for the two-sample, two-sided Kolmogorov-Smirnov test 
implementation
    +   * @param partData `Iterator[(Double, Boolean)]` the data in 1 partition 
of the co-sorted RDDs,
    +   *                each element is additionally tagged with a boolean 
flag for sample 1 membership
    +   * @param n1 `Double` sample 1 size
    +   * @param n2 `Double` sample 2 size
    +   * @return `Iterator[(Double, Double, Double)]` where the first element 
is an unadjusted minimum
    +   *        distance, the second is an unadjusted maximum distance (both 
of which will later
    +   *        be adjusted by a constant to account for elements in prior 
partitions), and the third is
    +   *        a count corresponding to the numerator of the adjustment 
constant coming from this
    --- End diff --
    
    done, thanks for feedback


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