Skip to content

Commit ffde810

Browse files
committed
address comments
1 parent aef6d07 commit ffde810

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

mllib/src/main/scala/org/apache/spark/mllib/random/RandomRDDs.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ import org.apache.spark.util.Utils
3535
object RandomRDDs {
3636

3737
/**
38-
* Generates an RDD comprised of i.i.d. samples from the uniform distribution on [0.0, 1.0].
38+
* Generates an RDD comprised of i.i.d. samples from the uniform distribution `U(0.0, 1.0)`.
3939
*
40-
* To transform the distribution in the generated RDD from U[0.0, 1.0] to U[a, b], use
41-
* `RandomRDDGenerators.uniformRDD(sc, n, p, seed).map(v => a + (b - a) * v)`.
40+
* To transform the distribution in the generated RDD from `U(0.0, 1.0)` to `U(a, b)`, use
41+
* `RandomRDDs.uniformRDD(sc, n, p, seed).map(v => a + (b - a) * v)`.
4242
*
4343
* @param sc SparkContext used to create the RDD.
4444
* @param size Size of the RDD.
4545
* @param numPartitions Number of partitions in the RDD (default: `sc.defaultParallelism`).
4646
* @param seed Random seed (default: a random long integer).
47-
* @return RDD[Double] comprised of i.i.d. samples ~ U[0.0, 1.0].
47+
* @return RDD[Double] comprised of i.i.d. samples ~ `U(0.0, 1.0)`.
4848
*/
4949
def uniformRDD(
5050
sc: SparkContext,
@@ -84,7 +84,7 @@ object RandomRDDs {
8484
* Generates an RDD comprised of i.i.d. samples from the standard normal distribution.
8585
*
8686
* To transform the distribution in the generated RDD from standard normal to some other normal
87-
* N(mean, sigma), use `RandomRDDGenerators.normalRDD(sc, n, p, seed).map(v => mean + sigma * v)`.
87+
* `N(mean, sigma^2^)`, use `RandomRDDs.normalRDD(sc, n, p, seed).map(v => mean + sigma * v)`.
8888
*
8989
* @param sc SparkContext used to create the RDD.
9090
* @param size Size of the RDD.
@@ -97,9 +97,8 @@ object RandomRDDs {
9797
size: Long,
9898
numPartitions: Int = 0,
9999
seed: Long = Utils.random.nextLong()): RDD[Double] = {
100-
val p = if (numPartitions > 0) numPartitions else sc.defaultParallelism
101100
val normal = new StandardNormalGenerator()
102-
randomRDD(sc, normal, size, p, seed)
101+
randomRDD(sc, normal, size, numPartitionsOrDefault(sc, numPartitions), seed)
103102
}
104103

105104
/**
@@ -202,14 +201,14 @@ object RandomRDDs {
202201

203202
/**
204203
* Generates an RDD[Vector] with vectors containing i.i.d. samples drawn from the
205-
* uniform distribution on [0.0 1.0].
204+
* uniform distribution on `U(0.0 1.0)`.
206205
*
207206
* @param sc SparkContext used to create the RDD.
208207
* @param numRows Number of Vectors in the RDD.
209208
* @param numCols Number of elements in each Vector.
210209
* @param numPartitions Number of partitions in the RDD.
211210
* @param seed Seed for the RNG that generates the seed for the generator in each partition.
212-
* @return RDD[Vector] with vectors containing i.i.d samples ~ U[0.0, 1.0].
211+
* @return RDD[Vector] with vectors containing i.i.d samples ~ `U(0.0, 1.0)`.
213212
*/
214213
def uniformVectorRDD(
215214
sc: SparkContext,
@@ -263,7 +262,7 @@ object RandomRDDs {
263262
* @param numCols Number of elements in each Vector.
264263
* @param numPartitions Number of partitions in the RDD (default: `sc.defaultParallelism`).
265264
* @param seed Random seed (default: a random long integer).
266-
* @return RDD[Vector] with vectors containing i.i.d. samples ~ N(0.0, 1.0).
265+
* @return RDD[Vector] with vectors containing i.i.d. samples ~ `N(0.0, 1.0)`.
267266
*/
268267
def normalVectorRDD(
269268
sc: SparkContext,

python/pyspark/mllib/random.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def uniformRDD(sc, size, numPartitions=None, seed=None):
3737
Generates an RDD comprised of i.i.d. samples from the
3838
uniform distribution on [0.0, 1.0].
3939
40-
To transform the distribution in the generated RDD from U[0.0, 1.0]
41-
to U[a, b], use
40+
To transform the distribution in the generated RDD from U(0.0, 1.0)
41+
to U(a, b), use
4242
C{RandomRDDs.uniformRDD(sc, n, p, seed)\
4343
.map(lambda v: a + (b - a) * v)}
4444
@@ -60,11 +60,11 @@ def uniformRDD(sc, size, numPartitions=None, seed=None):
6060
@staticmethod
6161
def normalRDD(sc, size, numPartitions=None, seed=None):
6262
"""
63-
Generates an RDD comprised of i.i.d samples from the standard normal
63+
Generates an RDD comprised of i.i.d. samples from the standard normal
6464
distribution.
6565
6666
To transform the distribution in the generated RDD from standard normal
67-
to some other normal N(mean, sigma), use
67+
to some other normal N(mean, sigma^2), use
6868
C{RandomRDDs.normal(sc, n, p, seed)\
6969
.map(lambda v: mean + sigma * v)}
7070
@@ -84,7 +84,7 @@ def normalRDD(sc, size, numPartitions=None, seed=None):
8484
@staticmethod
8585
def poissonRDD(sc, mean, size, numPartitions=None, seed=None):
8686
"""
87-
Generates an RDD comprised of i.i.d samples from the Poisson
87+
Generates an RDD comprised of i.i.d. samples from the Poisson
8888
distribution with the input mean.
8989
9090
>>> mean = 100.0
@@ -105,8 +105,8 @@ def poissonRDD(sc, mean, size, numPartitions=None, seed=None):
105105
@staticmethod
106106
def uniformVectorRDD(sc, numRows, numCols, numPartitions=None, seed=None):
107107
"""
108-
Generates an RDD comprised of vectors containing i.i.d samples drawn
109-
from the uniform distribution on [0.0 1.0].
108+
Generates an RDD comprised of vectors containing i.i.d. samples drawn
109+
from the uniform distribution U(0.0 1.0).
110110
111111
>>> import numpy as np
112112
>>> mat = np.matrix(RandomRDDs.uniformVectorRDD(sc, 10, 10).collect())
@@ -125,7 +125,7 @@ def uniformVectorRDD(sc, numRows, numCols, numPartitions=None, seed=None):
125125
@staticmethod
126126
def normalVectorRDD(sc, numRows, numCols, numPartitions=None, seed=None):
127127
"""
128-
Generates an RDD comprised of vectors containing i.i.d samples drawn
128+
Generates an RDD comprised of vectors containing i.i.d. samples drawn
129129
from the standard normal distribution.
130130
131131
>>> import numpy as np
@@ -145,7 +145,7 @@ def normalVectorRDD(sc, numRows, numCols, numPartitions=None, seed=None):
145145
@staticmethod
146146
def poissonVectorRDD(sc, mean, numRows, numCols, numPartitions=None, seed=None):
147147
"""
148-
Generates an RDD comprised of vectors containing i.i.d samples drawn
148+
Generates an RDD comprised of vectors containing i.i.d. samples drawn
149149
from the Poisson distribution with the input mean.
150150
151151
>>> import numpy as np

0 commit comments

Comments
 (0)