Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/4495#discussion_r24392633
--- Diff:
examples/src/main/scala/org/apache/spark/examples/mllib/PowerIterationClusteringExample.scala
---
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.examples.mllib
+
+import org.apache.log4j.{Level, Logger}
+import org.apache.spark.mllib.clustering.PowerIterationClustering
+import org.apache.spark.rdd.RDD
+import org.apache.spark.{SparkConf, SparkContext}
+import scopt.OptionParser
+
+/**
+ * An example Power Iteration Clustering app. Takes an input of K
concentric circles
+ * with a total of "n" sampled points (total here means "across ALL of the
circles").
+ * The output should be K clusters - each cluster containing precisely the
points associated
+ * with each of the input circles.
+ *
+ * Run with
+ * {{{
+ * ./bin/run-example
org.apache.spark.examples.mllib.PowerIterationClusteringExample [options]
+ *
+ * Where options include:
+ * k: Number of circles/ clusters
+ * n: Total number of sampled points. There are proportionally more
points within the
+ * outer/larger circles
+ * numIterations: Number of Power Iterations
+ * outerRadius: radius of the outermost of the concentric circles
+ * }}}
+ *
+ * Here is a sample run and output:
+ *
+ * ./bin/run-example
org.apache.spark.examples.mllib.PowerIterationClusteringExample -k 3 --n 30
--numIterations 15
+ *
+ * Cluster assignments: 1 -> [0,1,2,3,4],2 -> [5,6,7,8,9,10,11,12,13,14],
+ * 0 -> [15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
+ *
+ *
+ * If you use it as a template to create your own app, please use
`spark-submit` to submit your app.
+ */
+object PowerIterationClusteringExample {
+
+ case class Params(
+ input: String = null,
+ k: Int = 3,
+ numPoints: Int = 30,
+ numIterations: Int = 10,
+ outerRadius: Double = 3.0
+ ) extends AbstractParams[Params]
+
+ def main(args: Array[String]) {
+ val defaultParams = Params()
+
+ val parser = new OptionParser[Params]("PIC Circles") {
+ head("PowerIterationClusteringExample: an example PIC app using
concentric circles.")
+ opt[Int]('k', "k")
+ .text(s"number of circles (/clusters), default:
${defaultParams.k}")
+ .action((x, c) => c.copy(k = x))
+ opt[Int]('n', "n")
+ .text(s"number of points, default: ${defaultParams.numPoints}")
+ .action((x, c) => c.copy(numPoints = x))
+ opt[Int]("numIterations")
+ .text(s"number of iterations, default:
${defaultParams.numIterations}")
+ .action((x, c) => c.copy(numIterations = x))
+ }
+
+ parser.parse(args, defaultParams).map { params =>
+ run(params)
+ }.getOrElse {
+ sys.exit(1)
+ }
+ }
+
+ def generateCircle(n: Int, r: Double): Array[(Double, Double)] = {
+ val pi2 = 2 * math.Pi
+ (0.0 until pi2 by pi2 / n).map { x =>
+ (r * math.cos(x), r * math.sin(x))
+ }.toArray
+ }
+
+ def generateCirclesRdd(sc: SparkContext, nCircles: Int = 3,
nTotalPoints: Int = 30,
--- End diff --
chop down the arguments and use 4-space indentation
---
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]