#NEWLINE# @ staticmethod #NEWLINE# def kwayNormalisedCut( W , clustering ) : #NEWLINE# #INDENT# '\n        Do k-way normalised cut. Each cluster should have at least 1 edge. The input\n        matrix W can be either an ndarray or a scipy.sparse matrix.\n        ' #NEWLINE# numVertices = W . shape [ 0 ] #NEWLINE# clusterIds = numpy . unique ( clustering ) #NEWLINE# Q = 0 #NEWLINE# for i in clusterIds : #NEWLINE# #INDENT# inds = numpy . arange ( numVertices ) [ ( i == clustering ) ] #NEWLINE# invInds = numpy . arange ( numVertices ) [ ( i != clustering ) ] #NEWLINE# numClustEdges = float ( W [ inds , : ] . sum ( ) ) #NEWLINE# if ( ( len ( invInds ) != 0 ) and ( numClustEdges != 0 ) ) : #NEWLINE# #INDENT# Q += ( W [ inds , : ] [ : , invInds ] . sum ( ) / numClustEdges ) #NEWLINE# #UNINDENT# #UNINDENT# Q = ( Q / clusterIds . shape [ 0 ] ) #NEWLINE# return Q