Github user javadba commented on a diff in the pull request: https://github.com/apache/spark/pull/4254#discussion_r23807449 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/clustering/PowerIterationClustering.scala --- @@ -0,0 +1,220 @@ +/* + * 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.mllib.clustering + +import breeze.linalg.{DenseMatrix => BDM, DenseVector => BDV} +import org.apache.log4j.Logger +import org.apache.spark.SparkContext +import org.apache.spark.graphx._ +import org.apache.spark.mllib.linalg.{Vector, Vectors} +import org.apache.spark.rdd.RDD + +import scala.language.existentials + +/** + * Implements the scalable graph clustering algorithm Power Iteration Clustering (see + * www.icml2010.org/papers/387.pdf). From the abstract: + * + * The input data is first transformed to a normalized Affinity Matrix via Gaussian pairwise + * distance calculations. Power iteration is then used to find a dimensionality-reduced + * representation. The resulting pseudo-eigenvector provides effective clustering - as + * performed by Parallel KMeans. + */ +object PowerIterationClustering { + + private val logger = Logger.getLogger(getClass.getName()) + + type LabeledPoint = (VertexId, BDV[Double]) + type Points = Seq[LabeledPoint] + type DGraph = Graph[Double, Double] + type IndexedVector[Double] = (Long, BDV[Double]) + + // Terminate iteration when norm changes by less than this value + val defaultMinNormChange: Double = 1e-11 + + // Default number of iterations for PIC loop + val defaultIterations: Int = 20 + + // Do not allow divide by zero: change to this value instead + val defaultDivideByZeroVal: Double = 1e-15 + + // Default number of runs by the KMeans.run() method + val defaultKMeansRuns = 10 + + /** + * + * Run a Power Iteration Clustering + * + * @param sc Spark Context + * @param G Affinity Matrix in a Sparse Graph structure + * @param nClusters Number of clusters to create + * @param nIterations Number of iterations of the PIC algorithm + * that calculates primary PseudoEigenvector and Eigenvalue + * @param nRuns Number of runs for the KMeans clustering + * @return Tuple of (Seq[(Cluster Id,Cluster Center)], + * Seq[(VertexId, ClusterID Membership)] + */ + def run(sc: SparkContext, --- End diff -- yes, got it: use the rdd.sparkContext. RE: changing input type from Graph to RDD[(Long,Long,Double)]: OK - that does give more flexibility if we choose to have different backends (e.g. not graphx) for this implementation.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org