Github user mtustin-handy commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12016#discussion_r57733543
  
    --- Diff: core/src/main/scala/org/apache/spark/partial/SumEvaluator.scala 
---
    @@ -40,30 +41,39 @@ private[spark] class SumEvaluator(totalOutputs: Int, 
confidence: Double)
       override def currentResult(): BoundedDouble = {
         if (outputsMerged == totalOutputs) {
           new BoundedDouble(counter.sum, 1.0, counter.sum, counter.sum)
    -    } else if (outputsMerged == 0) {
    +    } else if (outputsMerged == 0 || counter.count == 0) {
           new BoundedDouble(0, 0.0, Double.NegativeInfinity, 
Double.PositiveInfinity)
         } else {
           val p = outputsMerged.toDouble / totalOutputs
           val meanEstimate = counter.mean
    -      val meanVar = counter.sampleVariance / counter.count
           val countEstimate = (counter.count + 1 - p) / p
    -      val countVar = (counter.count + 1) * (1 - p) / (p * p)
           val sumEstimate = meanEstimate * countEstimate
    -      val sumVar = (meanEstimate * meanEstimate * countVar) +
    -                   (countEstimate * countEstimate * meanVar) +
    -                   (meanVar * countVar)
    -      val sumStdev = math.sqrt(sumVar)
    -      val confFactor = {
    -        if (counter.count > 100) {
    +
    +      val meanVar = counter.sampleVariance / counter.count
    +
    +      // branch at this point because counter.count == 1 implies 
counter.sampleVariance == Nan
    +      // and we don't want to ever return a bound of NaN
    +      if (meanVar == Double.NaN || counter.count == 1) {
    +        new BoundedDouble(sumEstimate, confidence, 
Double.NegativeInfinity, Double.PositiveInfinity)
    +      } else {
    +        val countVar = (counter.count + 1) * (1 - p) / (p * p)
    +        val sumVar = (meanEstimate * meanEstimate * countVar) +
    +          (countEstimate * countEstimate * meanVar) +
    +          (meanVar * countVar)
    +        val sumStdev = math.sqrt(sumVar)
    +        val confFactor = if (counter.count > 100) {
               new NormalDistribution().inverseCumulativeProbability(1 - (1 - 
confidence) / 2)
    -        } else {
    +        } else if (counter.count > 1) {
               val degreesOfFreedom = (counter.count - 1).toInt
               new 
TDistribution(degreesOfFreedom).inverseCumulativeProbability(1 - (1 - 
confidence) / 2)
    +        } else {
    +          throw new Exception("Counter.count <= 1; this should be 
impossible at this point")
    --- End diff --
    
    I understand that the check does nothing for the computer but it makes it
    easier to read. It's slightly better than a comment because it won't lie
    around being incorrect and stale.
    
    Nevertheless I can fix it up to your preference together the tests.
    
    On Tuesday, March 29, 2016, Sean Owen <notificati...@github.com> wrote:
    
    > In core/src/main/scala/org/apache/spark/partial/SumEvaluator.scala
    > <https://github.com/apache/spark/pull/12016#discussion_r57732511>:
    >
    > >            val degreesOfFreedom = (counter.count - 1).toInt
    > >            new 
TDistribution(degreesOfFreedom).inverseCumulativeProbability(1 - (1 - 
confidence) / 2)
    > > +        } else {
    > > +          throw new Exception("Counter.count <= 1; this should be 
impossible at this point")
    >
    > You've already handled the count=0 and count=1 cases earlier. Checking
    > count > 1 doesn't do anything since it can't happen so having a branch for
    > it is odd. Tests are how we catch regressions.
    >
    > —
    > You are receiving this because you authored the thread.
    > Reply to this email directly or view it on GitHub
    > 
<https://github.com/apache/spark/pull/12016/files/3faecc4f18094686c843060a1e53b81b9e04e75d#r57732511>
    >
    
    -- 
    Want to work at Handy? Check out our culture deck and open roles 
    <http://www.handy.com/careers>
    Latest news <http://www.handy.com/press> at Handy
    Handy just raised $50m 
    
<http://venturebeat.com/2015/11/02/on-demand-home-service-handy-raises-50m-in-round-led-by-fidelity/>
 led 
    by Fidelity
    



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to