Skip to content

Commit 719d8cc

Browse files
committed
Added scala test suite with basic test
1 parent c1a8e16 commit 719d8cc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.mllib.clustering
19+
20+
import org.scalatest.FunSuite
21+
22+
import org.apache.spark.mllib.linalg.{Vectors, Matrices}
23+
import org.apache.spark.mllib.util.LocalSparkContext
24+
import org.apache.spark.mllib.util.TestingUtils._
25+
26+
class GMMExpectationMaximizationSuite extends FunSuite with LocalSparkContext {
27+
test("single cluster") {
28+
val data = sc.parallelize(Array(
29+
Vectors.dense(6.0, 9.0),
30+
Vectors.dense(5.0, 10.0),
31+
Vectors.dense(4.0, 11.0)
32+
))
33+
34+
// expectations
35+
val Ew = 1.0;
36+
val Emu = Vectors.dense(5.0, 10.0)
37+
val Esigma = Matrices.dense(2, 2, Array(2.0 / 3.0, -2.0 / 3.0, -2.0 / 3.0, 2.0 / 3.0))
38+
39+
val gmm = GMMExpectationMaximization.train(data, 1)
40+
assert(gmm.w(0) ~== Ew absTol 1E-5)
41+
assert(gmm.mu(0) ~== Emu absTol 1E-5)
42+
assert(gmm.sigma(0) ~== Esigma absTol 1E-5)
43+
}
44+
}

0 commit comments

Comments
 (0)