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

    https://github.com/apache/spark/pull/12016#discussion_r57726326
  
    --- 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 --
    
    Unfortunately without the final branch confFactor resolves to Any type.
    That last branch is necessary to keep it as double - either by returning a
    dummy value or throwing an exception. I think an exception is safer because
    it's more easily detected that it is no longer impossible.
    
    I'll work on the tests tomorrow.
    
    On Tuesday, March 29, 2016, Sean Owen <[email protected]> wrote:
    
    > In core/src/main/scala/org/apache/spark/partial/SumEvaluator.scala
    > <https://github.com/apache/spark/pull/12016#discussion_r57723805>:
    >
    > >            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")
    >
    > This is unnecessary, as you say. Just remove this branch right?
    >
    > —
    > 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#r57723805>
    >
    
    -- 
    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 [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