-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the Guassian/ Affinity matrix calcs out of PIC. Presently in the…
… test suite
- Loading branch information
1 parent
7ebd149
commit 92d4752
Showing
4 changed files
with
337 additions
and
213 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...ples/src/main/scala/org/apache/spark/examples/mllib/PowerIterationClusteringExample.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.apache.spark.examples.mllib | ||
|
||
import org.apache.log4j.{Level, Logger} | ||
import org.apache.spark.mllib.clustering.PowerIterationClustering | ||
import org.apache.spark.mllib.linalg.Vectors | ||
import org.apache.spark.{SparkConf, SparkContext} | ||
import scopt.OptionParser | ||
import breeze.linalg.{DenseVector => BDV} | ||
|
||
import scala.util.Random | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
|
||
/** | ||
* An example k-means app. Run with | ||
* {{{ | ||
* ./bin/run-example org.apache.spark.examples.mllib.DenseKMeans [options] <input> | ||
* }}} | ||
* If you use it as a template to create your own app, please use `spark-submit` to submit your app. | ||
*/ | ||
object PowerIterationClusteringExample { | ||
|
||
|
||
} |
88 changes: 88 additions & 0 deletions
88
.../src/main/scala/org/apache/spark/examples/mllib/PowerIterationClusteringForGaussian.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.apache.spark.examples.mllib | ||
|
||
import org.apache.log4j.{Level, Logger} | ||
import org.apache.spark.mllib.linalg.Vectors | ||
import org.apache.spark.{SparkContext, SparkConf} | ||
import org.apache.spark.mllib.clustering.PowerIterationClustering | ||
import scopt.OptionParser | ||
|
||
import scala.util.Random | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
|
||
/** | ||
* An example k-means app. Run with | ||
* {{{ | ||
* ./bin/run-example org.apache.spark.examples.mllib.DenseKMeans [options] <input> | ||
* }}} | ||
* If you use it as a template to create your own app, please use `spark-submit` to submit your app. | ||
*/ | ||
object PowerIterationClusteringForGaussian { | ||
|
||
|
||
val PIC = PowerIterationClustering | ||
|
||
case class Params( | ||
input: String = null, | ||
k: Int = -1, | ||
numIterations: Int = PIC.defaultIterations | ||
) extends AbstractParams[Params] | ||
|
||
def main(args: Array[String]) { | ||
val defaultParams = Params() | ||
|
||
val parser = new OptionParser[Params]("DenseKMeans") { | ||
head("Power Iteration Clustering for Gaussian Similarity inputs.") | ||
opt[Int]('k', "k") | ||
.required() | ||
.text(s"number of clusters, required") | ||
.action((x, c) => c.copy(k = x)) | ||
opt[Int]("numIterations") | ||
.text(s"number of iterations, default; ${defaultParams.numIterations}") | ||
.action((x, c) => c.copy(numIterations = x)) | ||
arg[String]("<input>") | ||
.text("input paths to examples") | ||
.required() | ||
.action((x, c) => c.copy(input = x)) | ||
} | ||
|
||
parser.parse(args, defaultParams).map { params => | ||
run(params) | ||
}.getOrElse { | ||
sys.exit(1) | ||
} | ||
} | ||
|
||
def run(params: Params) { | ||
val conf = new SparkConf().setAppName(s"DenseKMeans with $params") | ||
val sc = new SparkContext(conf) | ||
|
||
Logger.getRootLogger.setLevel(Level.WARN) | ||
|
||
val examples = sc.textFile(params.input).map { line => | ||
Vectors.dense(line.split(' ').map(_.toDouble)) | ||
}.cache() | ||
|
||
val numExamples = examples.count() | ||
|
||
|
||
sc.stop() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.