Skip to content

Commit

Permalink
unit bug and style violation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dorx committed Jun 19, 2014
1 parent 1fe1cff commit bd9dc6e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
fractionByKey: Map[K, Double],
seed: Long = Utils.random.nextLong,
exact: Boolean = true): RDD[(K, V)]= {
require(fractionByKey.forall({case(k, v) => v >= 0.0}), "Invalid sampling rates.")
if (withReplacement) {
require(fractionByKey.forall({case(k, v) => v >= 0.0}), "Invalid sampling rates.")
val counts = if (exact) Some(this.countByKey()) else None
val samplingFunc =
StratifiedSampler.getPoissonSamplingFunction(self, fractionByKey, exact, counts, seed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ private[spark] object SamplingUtils {
} else {
val delta = 1e-4
val gamma = - math.log(delta) / total
math.min(1, math.max(1e-10, fraction + gamma + math.sqrt(gamma * gamma + 2 * gamma * fraction)))
math.min(1,
math.max(1e-10, fraction + gamma + math.sqrt(gamma * gamma + 2 * gamma * fraction)))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class PairRDDFunctionsSuite extends FunSuite with SharedSparkContext {
n: Long) = {
val expectedSampleSize = stratifiedData.countByKey().mapValues(count =>
math.ceil(count * samplingRate).toInt)
val fractionByKey = (_:String) => samplingRate
val fractionByKey = Map("1" -> samplingRate, "0" -> samplingRate)
val sample = stratifiedData.sampleByKey(false, fractionByKey, seed, exact)
val sampleCounts = sample.countByKey()
val takeSample = sample.collect()
Expand All @@ -124,7 +124,7 @@ class PairRDDFunctionsSuite extends FunSuite with SharedSparkContext {
n: Long) = {
val expectedSampleSize = stratifiedData.countByKey().mapValues(count =>
math.ceil(count * samplingRate).toInt)
val fractionByKey = (_:String) => samplingRate
val fractionByKey = Map("1" -> samplingRate, "0" -> samplingRate)
val sample = stratifiedData.sampleByKey(true, fractionByKey, seed, exact)
val sampleCounts = sample.countByKey()
val takeSample = sample.collect()
Expand Down

0 comments on commit bd9dc6e

Please sign in to comment.