[SPARK-13816][GRAPHX] Add parameter checks for algorithms in Graphx
JIRA: https://issues.apache.org/jira/browse/SPARK-13816 ## What changes were proposed in this pull request? Add parameter checks for algorithms in Graphx: Pregel,LabelPropagation,PageRank,SVDPlusPlus ## How was this patch tested? manual tests Author: Zheng RuiFeng <ruifengz@foxmail.com> Closes #11655 from zhengruifeng/graphx_param_check.
This commit is contained in:
parent
d9670f8473
commit
91984978e7
|
@ -119,6 +119,9 @@ object Pregel extends Logging {
|
|||
mergeMsg: (A, A) => A)
|
||||
: Graph[VD, ED] =
|
||||
{
|
||||
require(maxIterations > 0, s"Maximum of iterations must be greater than 0," +
|
||||
s" but got ${maxIterations}")
|
||||
|
||||
var g = graph.mapVertices((vid, vdata) => vprog(vid, vdata, initialMsg)).cache()
|
||||
// compute the messages
|
||||
var messages = GraphXUtils.mapReduceTriplets(g, sendMsg, mergeMsg)
|
||||
|
|
|
@ -36,7 +36,9 @@ object ConnectedComponents {
|
|||
*/
|
||||
def run[VD: ClassTag, ED: ClassTag](graph: Graph[VD, ED],
|
||||
maxIterations: Int): Graph[VertexId, ED] = {
|
||||
require(maxIterations > 0)
|
||||
require(maxIterations > 0, s"Maximum of iterations must be greater than 0," +
|
||||
s" but got ${maxIterations}")
|
||||
|
||||
val ccGraph = graph.mapVertices { case (vid, _) => vid }
|
||||
def sendMessage(edge: EdgeTriplet[VertexId, ED]): Iterator[(VertexId, VertexId)] = {
|
||||
if (edge.srcAttr < edge.dstAttr) {
|
||||
|
|
|
@ -43,6 +43,8 @@ object LabelPropagation {
|
|||
* @return a graph with vertex attributes containing the label of community affiliation
|
||||
*/
|
||||
def run[VD, ED: ClassTag](graph: Graph[VD, ED], maxSteps: Int): Graph[VertexId, ED] = {
|
||||
require(maxSteps > 0, s"Maximum of steps must be greater than 0, but got ${maxSteps}")
|
||||
|
||||
val lpaGraph = graph.mapVertices { case (vid, _) => vid }
|
||||
def sendMessage(e: EdgeTriplet[VertexId, ED]): Iterator[(VertexId, Map[VertexId, Long])] = {
|
||||
Iterator((e.srcId, Map(e.dstAttr -> 1L)), (e.dstId, Map(e.srcAttr -> 1L)))
|
||||
|
|
|
@ -104,6 +104,11 @@ object PageRank extends Logging {
|
|||
graph: Graph[VD, ED], numIter: Int, resetProb: Double = 0.15,
|
||||
srcId: Option[VertexId] = None): Graph[Double, Double] =
|
||||
{
|
||||
require(numIter > 0, s"Number of iterations must be greater than 0," +
|
||||
s" but got ${numIter}")
|
||||
require(resetProb >= 0 && resetProb <= 1, s"Random reset probability must belong" +
|
||||
s" to [0, 1], but got ${resetProb}")
|
||||
|
||||
val personalized = srcId isDefined
|
||||
val src: VertexId = srcId.getOrElse(-1L)
|
||||
|
||||
|
@ -197,6 +202,10 @@ object PageRank extends Logging {
|
|||
graph: Graph[VD, ED], tol: Double, resetProb: Double = 0.15,
|
||||
srcId: Option[VertexId] = None): Graph[Double, Double] =
|
||||
{
|
||||
require(tol >= 0, s"Tolerance must be no less than 0, but got ${tol}")
|
||||
require(resetProb >= 0 && resetProb <= 1, s"Random reset probability must belong" +
|
||||
s" to [0, 1], but got ${resetProb}")
|
||||
|
||||
val personalized = srcId.isDefined
|
||||
val src: VertexId = srcId.getOrElse(-1L)
|
||||
|
||||
|
|
|
@ -56,6 +56,11 @@ object SVDPlusPlus {
|
|||
def run(edges: RDD[Edge[Double]], conf: Conf)
|
||||
: (Graph[(Array[Double], Array[Double], Double, Double), Double], Double) =
|
||||
{
|
||||
require(conf.maxIters > 0, s"Maximum of iterations must be greater than 0," +
|
||||
s" but got ${conf.maxIters}")
|
||||
require(conf.maxVal > conf.minVal, s"MaxVal must be greater than MinVal," +
|
||||
s" but got {maxVal: ${conf.maxVal}, minVal: ${conf.minVal}}")
|
||||
|
||||
// Generate default vertex attribute
|
||||
def defaultF(rank: Int): (Array[Double], Array[Double], Double, Double) = {
|
||||
// TODO: use a fixed random seed
|
||||
|
|
|
@ -36,7 +36,9 @@ object StronglyConnectedComponents {
|
|||
* @return a graph with vertex attributes containing the smallest vertex id in each SCC
|
||||
*/
|
||||
def run[VD: ClassTag, ED: ClassTag](graph: Graph[VD, ED], numIter: Int): Graph[VertexId, ED] = {
|
||||
require(numIter > 0, s"Number of iterations ${numIter} must be greater than 0.")
|
||||
require(numIter > 0, s"Number of iterations must be greater than 0," +
|
||||
s" but got ${numIter}")
|
||||
|
||||
// the graph we update with final SCC ids, and the graph we return at the end
|
||||
var sccGraph = graph.mapVertices { case (vid, _) => vid }
|
||||
// graph we are going to work with in our iterations
|
||||
|
|
Loading…
Reference in a new issue