Skip to content

Commit

Permalink
Last commit introduced a bug in the Kmean test class
Browse files Browse the repository at this point in the history
  • Loading branch information
noobii committed Apr 17, 2012
1 parent 62e205a commit 053fbf6
Show file tree
Hide file tree
Showing 28 changed files with 18 additions and 15 deletions.
Binary file modified .cache
Binary file not shown.
Binary file modified plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions src/main/scala/ch/epfl/em/Kmean.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ object Kmean {
* WARNING ! crapy code ahead, will rewrite it but must test if it works first
*/
def covarianceOfClusters(clusters: Seq[(Int, DenseVector[Double])]): Seq[DenseMatrix[Double]] = {

def agregatedMatrix(vects: Seq[(Int, DenseVector[Double])]): DenseMatrix[Double] = {
val matrix = DenseMatrix.zeros[Double](vects.length, vects(0)._2.size) // not verry pretty
val matrix = DenseMatrix.zeros[Double](vects.length, vects(0)._2.size) // not very pretty

for(i <- 0 until vects.length) matrix(i, ::) := vects(i)._2

matrix
}

val groupedClusters = clusters groupBy(_._1)
val groupedClusters = clusters groupBy(_._1) toSeq

val orderedClusters = groupedClusters sortBy(_._1)

val matrixClusters = groupedClusters map (x => agregatedMatrix(x._2))
val matrixClusters = orderedClusters map (x => agregatedMatrix(x._2))

val covariances = matrixClusters map (covariance(_, Axis.Vertical)._1)

Expand Down
14 changes: 7 additions & 7 deletions src/test/scala/ch/epfl/em/KmeanSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ class KmeanSuite extends AssertionsForJUnit {

val vects = Seq(
(1, DenseVector(1.0, 2.0, 3.0)),
(2, DenseVector(3.0, 2.0, 1.0)),
(0, DenseVector(3.0, 2.0, 1.0)),
(1, DenseVector(3.0, 2.0, 1.0)),
(2, DenseVector(3.0, 2.0, 1.0)),
(2, DenseVector(6.0, 4.0, 2.0))
(0, DenseVector(3.0, 2.0, 1.0)),
(0, DenseVector(6.0, 4.0, 2.0))
)

val cov = Kmean.covarianceOfClusters(vects)

val matlabVal1 = DenseMatrix((2.0, 0.0, -2.0), (0.0, 0.0, 0.0), (-2.0, 0.0, 2.0))
val matlabVal2 = DenseMatrix((3.0, 2.0, 1.0), (2.0, 4.0/3.0, 2.0/3.0), (1.0, 2.0/3.0, 1.0/3.0))
val matlabVal0 = DenseMatrix((3.0, 2.0, 1.0), (2.0, 4.0/3.0, 2.0/3.0), (1.0, 2.0/3.0, 1.0/3.0))

val deltaMatrix = DenseMatrix.fill(3, 3)(0.01)

assert(cov.exists(areEqual(_, matlabVal1)))
assert(cov.exists(areEqual(_, matlabVal2)))
assert(areEqual(cov(1), matlabVal1))
assert(areEqual(cov(0), matlabVal0))

}

Expand Down Expand Up @@ -177,7 +177,7 @@ class KmeanSuite extends AssertionsForJUnit {
}

def areEqual(matA: DenseMatrix[Double], matB: DenseMatrix[Double]): Boolean = {
val delta = 0.001
val delta = 0.00001

if(matA.numCols != matB.numCols || matA.numRows != matB.numRows) return false

Expand Down
Binary file modified target/scala-2.9.0/cache/compile/compile
Binary file not shown.
Binary file modified target/scala-2.9.0/cache/compile/test/compile
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$1.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$2.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$3.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$4.class
Binary file not shown.
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$5.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$6.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$7.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$8.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$$anonfun$9.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean$.class
Binary file not shown.
Binary file modified target/scala-2.9.0/classes/ch/epfl/em/Kmean.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified target/scala-2.9.0/test-classes/ch/epfl/em/KmeanSuite.class
Binary file not shown.
4 changes: 2 additions & 2 deletions target/streams/test/defined-tests/$global/out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[debug] Subclass fingerprints: Stream((org.scalatest.Suite,false,org.scalatest.tools.ScalaTestFramework$$anon$1@58adc70d), ?)
[debug] Annotation fingerprints: Stream((org.scalatest.WrapWith,false,org.scalatest.tools.ScalaTestFramework$$anon$2@78e753f6), ?)
[debug] Subclass fingerprints: Stream((org.scalatest.Suite,false,org.scalatest.tools.ScalaTestFramework$$anon$1@1259c133), ?)
[debug] Annotation fingerprints: Stream((org.scalatest.WrapWith,false,org.scalatest.tools.ScalaTestFramework$$anon$2@429b04ae), ?)
2 changes: 1 addition & 1 deletion target/streams/test/test-only/$global/out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[debug] Running Test ch.epfl.em.KmeanSuite : annotation(false, org.junit.Test) with arguments -q, -v
[debug] Running Test ch.epfl.em.GaussianTest : annotation(false, org.junit.Test) with arguments -q, -v
[debug] Running Test ch.epfl.em.KmeanSuite : annotation(false, org.junit.Test) with arguments -q, -v
[info] Passed: : Total 11, Failed 0, Errors 0, Passed 11, Skipped 0
[debug] Passed tests:
[debug]  ch.epfl.em.GaussianTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
[info] Test ch.epfl.em.GaussianTest.testExpectation started
[info] Test ch.epfl.em.GaussianTest.testMaximization started
[info] Test ch.epfl.em.GaussianTest.testLoglikelihood started
[info] Test run finished: 0 failed, 0 ignored, 4 total, 0.37s
[info] Test run finished: 0 failed, 0 ignored, 4 total, 0.25s
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
[info] Test ch.epfl.em.KmeanSuite.testInitializeClusters started
[info] Test ch.epfl.em.KmeanSuite.testCovarianceOfClusters started
[info] Test ch.epfl.em.KmeanSuite.testKmean started
[info] Test run finished: 0 failed, 0 ignored, 7 total, 0.98s
[info] Test run finished: 0 failed, 0 ignored, 7 total, 0.74s

0 comments on commit 053fbf6

Please sign in to comment.