|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.spark.mllib.random |
| 19 | + |
| 20 | +import org.apache.spark.SparkContext |
| 21 | +import org.apache.spark.mllib.linalg.Vector |
| 22 | +import org.apache.spark.mllib.rdd.{RandomVectorRDD, RandomRDD} |
| 23 | +import org.apache.spark.rdd.RDD |
| 24 | +import org.apache.spark.util.Utils |
| 25 | + |
| 26 | +// TODO add Scaladocs once API fully approved |
| 27 | +object RandomRDDGenerators { |
| 28 | + |
| 29 | + def uniformRDD(sc: SparkContext, size: Long, numPartitions: Int, seed: Long): RDD[Double] = { |
| 30 | + val uniform = new UniformGenerator() |
| 31 | + randomRDD(sc, size, numPartitions, uniform, seed) |
| 32 | + } |
| 33 | + |
| 34 | + def uniformRDD(sc: SparkContext, size: Long, seed: Long): RDD[Double] = { |
| 35 | + uniformRDD(sc, size, sc.defaultParallelism, seed) |
| 36 | + } |
| 37 | + |
| 38 | + def uniformRDD(sc: SparkContext, size: Long, numPartitions: Int): RDD[Double] = { |
| 39 | + uniformRDD(sc, size, numPartitions, Utils.random.nextLong) |
| 40 | + } |
| 41 | + |
| 42 | + def uniformRDD(sc: SparkContext, size: Long): RDD[Double] = { |
| 43 | + uniformRDD(sc, size, sc.defaultParallelism, Utils.random.nextLong) |
| 44 | + } |
| 45 | + |
| 46 | + def normalRDD(sc: SparkContext, size: Long, numPartitions: Int, seed: Long): RDD[Double] = { |
| 47 | + val normal = new StandardNormalGenerator() |
| 48 | + randomRDD(sc, size, numPartitions, normal, seed) |
| 49 | + } |
| 50 | + |
| 51 | + def normalRDD(sc: SparkContext, size: Long, seed: Long): RDD[Double] = { |
| 52 | + normalRDD(sc, size, sc.defaultParallelism, seed) |
| 53 | + } |
| 54 | + |
| 55 | + def normalRDD(sc: SparkContext, size: Long, numPartitions: Int): RDD[Double] = { |
| 56 | + normalRDD(sc, size, numPartitions, Utils.random.nextLong) |
| 57 | + } |
| 58 | + |
| 59 | + def normalRDD(sc: SparkContext, size: Long): RDD[Double] = { |
| 60 | + normalRDD(sc, size, sc.defaultParallelism, Utils.random.nextLong) |
| 61 | + } |
| 62 | + |
| 63 | + def poissonRDD(sc: SparkContext, |
| 64 | + size: Long, |
| 65 | + numPartitions: Int, |
| 66 | + mean: Double, |
| 67 | + seed: Long): RDD[Double] = { |
| 68 | + val poisson = new PoissonGenerator(mean) |
| 69 | + randomRDD(sc, size, numPartitions, poisson, seed) |
| 70 | + } |
| 71 | + |
| 72 | + def poissonRDD(sc: SparkContext, size: Long, mean: Double, seed: Long): RDD[Double] = { |
| 73 | + poissonRDD(sc, size, sc.defaultParallelism, mean, seed) |
| 74 | + } |
| 75 | + |
| 76 | + def poissonRDD(sc: SparkContext, size: Long, numPartitions: Int, mean: Double): RDD[Double] = { |
| 77 | + poissonRDD(sc, size, numPartitions, mean, Utils.random.nextLong) |
| 78 | + } |
| 79 | + |
| 80 | + def poissonRDD(sc: SparkContext, size: Long, mean: Double): RDD[Double] = { |
| 81 | + poissonRDD(sc, size, sc.defaultParallelism, mean, Utils.random.nextLong) |
| 82 | + } |
| 83 | + |
| 84 | + def randomRDD(sc: SparkContext, |
| 85 | + size: Long, |
| 86 | + numPartitions: Int, |
| 87 | + distribution: DistributionGenerator, |
| 88 | + seed: Long): RDD[Double] = { |
| 89 | + new RandomRDD(sc, size, numPartitions, distribution, seed) |
| 90 | + } |
| 91 | + |
| 92 | + def randomRDD(sc: SparkContext, |
| 93 | + size: Long, |
| 94 | + distribution: DistributionGenerator, |
| 95 | + seed: Long): RDD[Double] = { |
| 96 | + randomRDD(sc, size, sc.defaultParallelism, distribution, seed) |
| 97 | + } |
| 98 | + |
| 99 | + def randomRDD(sc: SparkContext, |
| 100 | + size: Long, |
| 101 | + numPartitions: Int, |
| 102 | + distribution: DistributionGenerator): RDD[Double] = { |
| 103 | + randomRDD(sc, size, numPartitions, distribution, Utils.random.nextLong) |
| 104 | + } |
| 105 | + |
| 106 | + def randomRDD(sc: SparkContext, |
| 107 | + size: Long, |
| 108 | + distribution: DistributionGenerator): RDD[Double] = { |
| 109 | + randomRDD(sc, size, sc.defaultParallelism, distribution, Utils.random.nextLong) |
| 110 | + } |
| 111 | + |
| 112 | + // TODO Generator RDD[Vector] from multivariate distribution |
| 113 | + |
| 114 | + def uniformVectorRDD(sc: SparkContext, |
| 115 | + numRows: Long, |
| 116 | + numColumns: Int, |
| 117 | + numPartitions: Int, |
| 118 | + seed: Long): RDD[Vector] = { |
| 119 | + val uniform = new UniformGenerator() |
| 120 | + randomVectorRDD(sc, numRows, numColumns, numPartitions, uniform, seed) |
| 121 | + } |
| 122 | + |
| 123 | + def uniformVectorRDD(sc: SparkContext, |
| 124 | + numRows: Long, |
| 125 | + numColumns: Int, |
| 126 | + seed: Long): RDD[Vector] = { |
| 127 | + uniformVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, seed) |
| 128 | + } |
| 129 | + |
| 130 | + def uniformVectorRDD(sc: SparkContext, |
| 131 | + numRows: Long, |
| 132 | + numColumns: Int, |
| 133 | + numPartitions: Int): RDD[Vector] = { |
| 134 | + uniformVectorRDD(sc, numRows, numColumns, numPartitions, Utils.random.nextLong) |
| 135 | + } |
| 136 | + |
| 137 | + def uniformVectorRDD(sc: SparkContext, numRows: Long, numColumns: Int): RDD[Vector] = { |
| 138 | + uniformVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, Utils.random.nextLong) |
| 139 | + } |
| 140 | + |
| 141 | + def normalVectorRDD(sc: SparkContext, |
| 142 | + numRows: Long, |
| 143 | + numColumns: Int, |
| 144 | + numPartitions: Int, |
| 145 | + seed: Long): RDD[Vector] = { |
| 146 | + val uniform = new StandardNormalGenerator() |
| 147 | + randomVectorRDD(sc, numRows, numColumns, numPartitions, uniform, seed) |
| 148 | + } |
| 149 | + |
| 150 | + def normalVectorRDD(sc: SparkContext, |
| 151 | + numRows: Long, |
| 152 | + numColumns: Int, |
| 153 | + seed: Long): RDD[Vector] = { |
| 154 | + normalVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, seed) |
| 155 | + } |
| 156 | + |
| 157 | + def normalVectorRDD(sc: SparkContext, |
| 158 | + numRows: Long, |
| 159 | + numColumns: Int, |
| 160 | + numPartitions: Int): RDD[Vector] = { |
| 161 | + normalVectorRDD(sc, numRows, numColumns, numPartitions, Utils.random.nextLong) |
| 162 | + } |
| 163 | + |
| 164 | + def normalVectorRDD(sc: SparkContext, numRows: Long, numColumns: Int): RDD[Vector] = { |
| 165 | + normalVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, Utils.random.nextLong) |
| 166 | + } |
| 167 | + |
| 168 | + def poissonVectorRDD(sc: SparkContext, |
| 169 | + numRows: Long, |
| 170 | + numColumns: Int, |
| 171 | + numPartitions: Int, |
| 172 | + mean: Double, |
| 173 | + seed: Long): RDD[Vector] = { |
| 174 | + val poisson = new PoissonGenerator(mean) |
| 175 | + randomVectorRDD(sc, numRows, numColumns, numPartitions, poisson, seed) |
| 176 | + } |
| 177 | + |
| 178 | + def poissonVectorRDD(sc: SparkContext, |
| 179 | + numRows: Long, |
| 180 | + numColumns: Int, |
| 181 | + mean: Double, |
| 182 | + seed: Long): RDD[Vector] = { |
| 183 | + poissonVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, mean, seed) |
| 184 | + } |
| 185 | + |
| 186 | + def poissonVectorRDD(sc: SparkContext, |
| 187 | + numRows: Long, |
| 188 | + numColumns: Int, |
| 189 | + numPartitions: Int, |
| 190 | + mean: Double): RDD[Vector] = { |
| 191 | + poissonVectorRDD(sc, numRows, numColumns, numPartitions, mean, Utils.random.nextLong) |
| 192 | + } |
| 193 | + |
| 194 | + def poissonVectorRDD(sc: SparkContext, |
| 195 | + numRows: Long, |
| 196 | + numColumns: Int, |
| 197 | + mean: Double): RDD[Vector] = { |
| 198 | + val poisson = new PoissonGenerator(mean) |
| 199 | + randomVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, poisson, Utils.random.nextLong) |
| 200 | + } |
| 201 | + |
| 202 | + def randomVectorRDD(sc: SparkContext, |
| 203 | + numRows: Long, |
| 204 | + numColumns: Int, |
| 205 | + numPartitions: Int, |
| 206 | + rng: DistributionGenerator, |
| 207 | + seed: Long): RDD[Vector] = { |
| 208 | + new RandomVectorRDD(sc, numRows, numColumns, numPartitions, rng, seed) |
| 209 | + } |
| 210 | + |
| 211 | + def randomVectorRDD(sc: SparkContext, |
| 212 | + numRows: Long, |
| 213 | + numColumns: Int, |
| 214 | + rng: DistributionGenerator, |
| 215 | + seed: Long): RDD[Vector] = { |
| 216 | + randomVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, rng, seed) |
| 217 | + } |
| 218 | + |
| 219 | + def randomVectorRDD(sc: SparkContext, |
| 220 | + numRows: Long, |
| 221 | + numColumns: Int, |
| 222 | + numPartitions: Int, |
| 223 | + rng: DistributionGenerator): RDD[Vector] = { |
| 224 | + randomVectorRDD(sc, numRows, numColumns, numPartitions, rng, Utils.random.nextLong) |
| 225 | + } |
| 226 | + |
| 227 | + def randomVectorRDD(sc: SparkContext, |
| 228 | + numRows: Long, |
| 229 | + numColumns: Int, |
| 230 | + rng: DistributionGenerator): RDD[Vector] = { |
| 231 | + randomVectorRDD(sc, numRows, numColumns, sc.defaultParallelism, rng, Utils.random.nextLong) |
| 232 | + } |
| 233 | +} |
0 commit comments