From 1cf18a22775fecfae70f97ac345008dc70a8ba5f Mon Sep 17 00:00:00 2001 From: zengruios <578395184@qq.com> Date: Wed, 23 Jun 2021 18:20:33 -0500 Subject: [PATCH] [SPARK-35851][GRAPHX] Modify the wrong variable used in GraphGenerators.sampleLogNormal ### What changes were proposed in this pull request? modify the wrong variable used in GraphGenerators.sampleLogNormal ### Why are the changes needed? wrong variable used ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? UT Closes #33010 from zengruios/SPARK-35851. Authored-by: zengruios <578395184@qq.com> Signed-off-by: Sean Owen --- .../apache/spark/graphx/util/GraphGenerators.scala | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala b/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala index 419731146d..ea531b6cf0 100644 --- a/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala +++ b/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala @@ -87,11 +87,10 @@ object GraphGenerators extends Logging { } /** - * Randomly samples from a log normal distribution whose corresponding normal distribution has - * the given mean and standard deviation. It uses the formula `X = exp(m+s*Z)` where `m`, - * `s` are the mean, standard deviation of the lognormal distribution and - * `Z ~ N(0, 1)`. In this function, - * `m = e^(mu+sigma^2/2)` and `s = sqrt[(e^(sigma^2) - 1)(e^(2*mu+sigma^2))]`. + * Randomly samples from the given mean and standard deviation of the normal distribution. + * It uses the formula `X = exp(mu+sigma*Z)` where `mu`, + * `sigma` are the mean, standard deviation of the normal distribution and + * `Z ~ N(0, 1)`. * * @param mu the mean of the normal distribution * @param sigma the standard deviation of the normal distribution @@ -102,10 +101,6 @@ object GraphGenerators extends Logging { mu: Double, sigma: Double, maxVal: Int, seed: Long = -1): Int = { val rand = if (seed == -1) new Random() else new Random(seed) - val sigmaSq = sigma * sigma - val m = math.exp(mu + sigmaSq / 2.0) - // expm1 is exp(m)-1 with better accuracy for tiny m - val s = math.sqrt(math.expm1(sigmaSq) * math.exp(2*mu + sigmaSq)) // Z ~ N(0, 1) var X: Double = maxVal