[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 <srowen@gmail.com>
This commit is contained in:
parent
ad187227f1
commit
1cf18a2277
|
@ -87,11 +87,10 @@ object GraphGenerators extends Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Randomly samples from a log normal distribution whose corresponding normal distribution has
|
* Randomly samples from the given mean and standard deviation of the normal distribution.
|
||||||
* the given mean and standard deviation. It uses the formula `X = exp(m+s*Z)` where `m`,
|
* It uses the formula `X = exp(mu+sigma*Z)` where `mu`,
|
||||||
* `s` are the mean, standard deviation of the lognormal distribution and
|
* `sigma` are the mean, standard deviation of the normal distribution and
|
||||||
* `Z ~ N(0, 1)`. In this function,
|
* `Z ~ N(0, 1)`.
|
||||||
* `m = e^(mu+sigma^2/2)` and `s = sqrt[(e^(sigma^2) - 1)(e^(2*mu+sigma^2))]`.
|
|
||||||
*
|
*
|
||||||
* @param mu the mean of the normal distribution
|
* @param mu the mean of the normal distribution
|
||||||
* @param sigma the standard deviation 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 = {
|
mu: Double, sigma: Double, maxVal: Int, seed: Long = -1): Int = {
|
||||||
val rand = if (seed == -1) new Random() else new Random(seed)
|
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)
|
// Z ~ N(0, 1)
|
||||||
var X: Double = maxVal
|
var X: Double = maxVal
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue