|
|
@ -93,7 +93,7 @@ object Util extends LazyLogging { |
|
|
|
|
|
|
|
def mstUsingPrims[T: ClassTag]( |
|
|
|
edges: Array[Array[T]] |
|
|
|
)(implicit num: Numeric[T]): Array[Array[T]] = { |
|
|
|
)(implicit num: Numeric[T]): (Array[Array[T]], T) = { |
|
|
|
val n = edges.length |
|
|
|
val selected: ArrayBuffer[Boolean] = ArrayBuffer.fill(n)(false) |
|
|
|
|
|
|
@ -101,6 +101,8 @@ object Util extends LazyLogging { |
|
|
|
|
|
|
|
val mst: Array[Array[T]] = Array.ofDim[T](n, n) |
|
|
|
|
|
|
|
var sum = 0 |
|
|
|
|
|
|
|
for (_ <- 0 until n - 1) { |
|
|
|
var min = 999999 |
|
|
|
var x = 0 |
|
|
@ -121,10 +123,10 @@ object Util extends LazyLogging { |
|
|
|
// println(s"Edge selected $x - $y : ${edges(x)(y)}") |
|
|
|
mst(x)(y) = edges(x)(y) |
|
|
|
mst(y)(x) = edges(x)(y) |
|
|
|
|
|
|
|
sum += num.toInt(edges(x)(y)) |
|
|
|
selected(y) = true |
|
|
|
} |
|
|
|
mst |
|
|
|
(mst, num.fromInt(sum / n)) |
|
|
|
} |
|
|
|
|
|
|
|
def findClusters[T]( |
|
|
@ -166,7 +168,8 @@ object Util extends LazyLogging { |
|
|
|
} |
|
|
|
|
|
|
|
def findCentroids[T]( |
|
|
|
mst: Array[Array[T]] |
|
|
|
mst: Array[Array[T]], |
|
|
|
epsilon: T |
|
|
|
)( |
|
|
|
implicit ev: Numeric[T] |
|
|
|
): (Array[Array[T]], IndexedSeq[Int], IndexedSeq[(Int, Int, T)]) = { |
|
|
@ -175,7 +178,7 @@ object Util extends LazyLogging { |
|
|
|
val removed: ArrayBuffer[(Int, Int, T)] = ArrayBuffer.empty |
|
|
|
for (i <- 0 until n) { |
|
|
|
for (j <- 0 until n) { |
|
|
|
if (ev.gt(mst(i)(j), ev.fromInt(20)) && mst(i)(j) != 0) { |
|
|
|
if (ev.gt(mst(i)(j), epsilon) && mst(i)(j) != 0) { |
|
|
|
// println(s" $i $j = ${mst(i)(j)}") |
|
|
|
centroids += i |
|
|
|
centroids += j |
|
|
|