GitHub user ankurdave opened a pull request:

    https://github.com/apache/spark/pull/2439

    [SPARK-3578] Fix upper bound in GraphGenerators.sampleLogNormal

    GraphGenerators.sampleLogNormal is supposed to return an integer strictly 
less than maxVal. However, it violates this guarantee. It generates its return 
value as follows:
    
    ```scala
    var X: Double = maxVal
    
    while (X >= maxVal) {
      val Z = rand.nextGaussian()
      X = math.exp(mu + sigma*Z)
    }
    math.round(X.toFloat)
    ```
    
    When X is sampled to be close to (but less than) maxVal, then it will pass 
the while loop condition, but the rounded result will be equal to maxVal, which 
will fail the test. For example, if maxVal is 5 and X is 4.9, then X < maxVal, 
but `math.round(X.toFloat)` is 5.
    
    Instead of rounding X to the nearest integer, this PR rounds X down using 
`math.floor(X).toInt`. This is necessary to enable negative bounds.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ankurdave/spark SPARK-3578

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/2439.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2439
    
----
commit 16385984ae25e23309d3c5de7cf106a520a4a88d
Author: Ankur Dave <[email protected]>
Date:   2014-09-17T23:14:35Z

    Round down in sampleLogNormal to guarantee upper bound

----


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