summaryrefslogtreecommitdiff
path: root/test/de/lmu/ifi/dbs/elki/math
diff options
context:
space:
mode:
Diffstat (limited to 'test/de/lmu/ifi/dbs/elki/math')
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestAffineTransformation.java40
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestFlexiHistogram.java23
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestKernelDensityFitting.java23
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestLevenbergMarquardtGaussianFitting.java23
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestMatrix.java25
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestQuickSelect.java24
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestReplacingHistogram.java30
-rw-r--r--test/de/lmu/ifi/dbs/elki/math/TestWeightFunctions.java62
8 files changed, 215 insertions, 35 deletions
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestAffineTransformation.java b/test/de/lmu/ifi/dbs/elki/math/TestAffineTransformation.java
index c5616e8d..0ac6b1a6 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestAffineTransformation.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestAffineTransformation.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
@@ -87,19 +110,19 @@ public class TestAffineTransformation implements JUnit4Test {
assertEquals("Vector wasn't translated properly backwards.", v1, v2b);
Vector v1b = t.applyInverse(v1t);
assertEquals("Vector wasn't translated properly back and forward.", v1, v1b);
-
+
// Translation
Vector vd = v1.minus(v2b);
Vector vtd = v1t.minus(v2t);
assertEquals("Translation changed vector difference.", vd, vtd);
-
+
// Translation shouldn't change relative vectors.
assertEquals("Relative vectors weren't left unchanged by translation!", v1, t.applyRelative(v1));
assertEquals("Relative vectors weren't left unchanged by translation!", v2t, t.applyRelative(v2t));
assertEquals("Relative vectors weren't left unchanged by translation!", v1t, t.applyRelative(v1t));
assertEquals("Relative vectors weren't left unchanged by translation!", v2b, t.applyRelative(v2b));
}
-
+
/**
* Test direct inclusion of matrices
*/
@@ -154,7 +177,7 @@ public class TestAffineTransformation implements JUnit4Test {
assertTrue("Forward-Backward didn't work correctly.", v1.minus(v3).euclideanLength() < 0.0001);
Vector v4 = t.apply(t.apply(t.apply(v1)));
assertTrue("Triple-Rotation by 120 degree didn't work", v1.minus(v4).euclideanLength() < 0.0001);
-
+
// Rotation shouldn't disagree for relative vectors.
// (they just are not affected by translation!)
assertEquals("Relative vectors were affected differently by pure rotation!", v2, t.applyRelative(v1));
@@ -180,13 +203,12 @@ public class TestAffineTransformation implements JUnit4Test {
Vector p5 = new Vector(new double[] { 7, 3, 5 });
Vector p6 = new Vector(new double[] { 7, 5, 3 });
Vector[] ps = new Vector[] {
- // with no arguments.
+ // with no arguments.
p1,
- // with just one argument.
+ // with just one argument.
p1, p3, p5,
- // with two arguments.
- p1, p2, p3, p4, p5, p6,
- };
+ // with two arguments.
+ p1, p2, p3, p4, p5, p6, };
// index in reference array
int idx = 0;
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestFlexiHistogram.java b/test/de/lmu/ifi/dbs/elki/math/TestFlexiHistogram.java
index 3ce38f8b..b3db5b85 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestFlexiHistogram.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestFlexiHistogram.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestKernelDensityFitting.java b/test/de/lmu/ifi/dbs/elki/math/TestKernelDensityFitting.java
index cc0a1f5c..7533a235 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestKernelDensityFitting.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestKernelDensityFitting.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestLevenbergMarquardtGaussianFitting.java b/test/de/lmu/ifi/dbs/elki/math/TestLevenbergMarquardtGaussianFitting.java
index 49c84996..46676c9b 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestLevenbergMarquardtGaussianFitting.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestLevenbergMarquardtGaussianFitting.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import static org.junit.Assert.assertEquals;
import org.junit.Test;
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestMatrix.java b/test/de/lmu/ifi/dbs/elki/math/TestMatrix.java
index 49042ceb..0d22d19a 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestMatrix.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestMatrix.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import java.util.Random;
import org.junit.Test;
@@ -38,7 +61,7 @@ public class TestMatrix implements JUnit4Test {
org.junit.Assert.assertTrue("A.transposeTimesTranspose(B) does not equal (B.times(A)).transpose", B.times(A).transpose().almostEquals(AT_BT));
org.junit.Assert.assertTrue("A.transposeTimesTranspose(B) does not equal A.transpose.times(B.transpose)", A.transposeTimesTranspose(B).almostEquals(AT_BT));
}
-
+
private void randomizedTestAsymmetric() {
Random r = new Random();
int dim1 = r.nextInt(30) + 10;
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestQuickSelect.java b/test/de/lmu/ifi/dbs/elki/math/TestQuickSelect.java
index 36ed4521..132be182 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestQuickSelect.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestQuickSelect.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
@@ -81,7 +104,6 @@ public class TestQuickSelect implements JUnit4Test {
assertEquals("Full median incorrect.", 0.95, QuickSelect.median(data), Double.MIN_VALUE);
}
-
@Test
public void testTies() {
double data[] = new double[] { 0.1, 0.1, 0.9, 0.9, 0.5, 0.9, 0.1, 0.1, 0.1, 0.9, 0.9, 0.9, 0.9, 0.1, 0.1 };
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestReplacingHistogram.java b/test/de/lmu/ifi/dbs/elki/math/TestReplacingHistogram.java
index e9e505d2..266a437f 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestReplacingHistogram.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestReplacingHistogram.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -10,13 +33,14 @@ import de.lmu.ifi.dbs.elki.utilities.pairs.Pair;
/**
* JUnit test to test the {@link ReplacingHistogram} class.
+ *
* @author Erich Schubert
*/
public class TestReplacingHistogram implements JUnit4Test {
ReplacingHistogram<Double> hist;
/**
- * Test that adds some data to the histogram and compares results.
+ * Test that adds some data to the histogram and compares results.
*/
@Test
public final void testHistogram() {
@@ -39,10 +63,10 @@ public class TestReplacingHistogram implements JUnit4Test {
hist.replace(-.13, -1.23 + hist.get(-.13));
hist.replace(1.13, -4.56 + hist.get(1.13));
assertArrayEquals("Resized histogram doesn't match", resized, hist.getData().toArray(new Double[0]));
-
+
// compare results via Iterator.
int off = 0;
- for (Pair<Double, Double> pair : hist) {
+ for(Pair<Double, Double> pair : hist) {
assertEquals("Array iterator bin position", -0.15 + 0.1 * off, pair.getFirst(), 0.00001);
assertEquals("Array iterator bin contents", resized[off], pair.getSecond(), 0.00001);
off++;
diff --git a/test/de/lmu/ifi/dbs/elki/math/TestWeightFunctions.java b/test/de/lmu/ifi/dbs/elki/math/TestWeightFunctions.java
index 8164e28e..f07be82a 100644
--- a/test/de/lmu/ifi/dbs/elki/math/TestWeightFunctions.java
+++ b/test/de/lmu/ifi/dbs/elki/math/TestWeightFunctions.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.math;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2011
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import static org.junit.Assert.assertEquals;
import org.junit.Test;
@@ -16,8 +39,9 @@ import de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions.WeightFunction
/**
* JUnit test to assert consistency of a couple of Weight functions
+ *
* @author Erich Schubert
- *
+ *
*/
public class TestWeightFunctions implements JUnit4Test {
/**
@@ -25,30 +49,26 @@ public class TestWeightFunctions implements JUnit4Test {
*/
@Test
public void testGetWeight() {
- WeightFunction[] wf = {new ConstantWeight(), new ErfcWeight(), new ErfcStddevWeight(),
- new GaussWeight(), new GaussStddevWeight(), new LinearWeight(), new ExponentialWeight()};
- double[] at0 = {1.0, 1.0, 1.0, 1.0, 0.3989422804014327, 1.0, 1.0};
- double[] at01 = {1.0, 0.8693490686884612, 0.920344325445942, 0.9772372209558107,
- 0.3969525474770118, 0.91, 0.7943282347242815};
- double[] at09 = {1.0, 0.13877499454059491, 0.36812025069351895, 0.15488166189124816,
- 0.2660852498987548, 0.18999999999999995, 0.12589254117941673};
- double[] at10 = {1.0, 0.10000000000000016, 0.317310507862914, 0.10000000000000002,
- 0.24197072451914337, 0.09999999999999998, 0.10000000000000002};
-
- assert(wf.length == at0.length);
- assert(wf.length == at01.length);
- assert(wf.length == at09.length);
- assert(wf.length == at10.length);
-
- for (int i=0; i < wf.length; i++) {
+ WeightFunction[] wf = { new ConstantWeight(), new ErfcWeight(), new ErfcStddevWeight(), new GaussWeight(), new GaussStddevWeight(), new LinearWeight(), new ExponentialWeight() };
+ double[] at0 = { 1.0, 1.0, 1.0, 1.0, 0.3989422804014327, 1.0, 1.0 };
+ double[] at01 = { 1.0, 0.8693490686884612, 0.920344325445942, 0.9772372209558107, 0.3969525474770118, 0.91, 0.7943282347242815 };
+ double[] at09 = { 1.0, 0.13877499454059491, 0.36812025069351895, 0.15488166189124816, 0.2660852498987548, 0.18999999999999995, 0.12589254117941673 };
+ double[] at10 = { 1.0, 0.10000000000000016, 0.317310507862914, 0.10000000000000002, 0.24197072451914337, 0.09999999999999998, 0.10000000000000002 };
+
+ assert (wf.length == at0.length);
+ assert (wf.length == at01.length);
+ assert (wf.length == at09.length);
+ assert (wf.length == at10.length);
+
+ for(int i = 0; i < wf.length; i++) {
double val0 = wf[i].getWeight(0, 1, 1);
double val01 = wf[i].getWeight(0.1, 1, 1);
double val09 = wf[i].getWeight(0.9, 1, 1);
double val10 = wf[i].getWeight(1.0, 1, 1);
- assertEquals(wf[i].getClass().getSimpleName()+" at 0.0", at0[i], val0, Double.MIN_VALUE);
- assertEquals(wf[i].getClass().getSimpleName()+" at 0.1", at01[i], val01, Double.MIN_VALUE);
- assertEquals(wf[i].getClass().getSimpleName()+" at 0.9", at09[i], val09, Double.MIN_VALUE);
- assertEquals(wf[i].getClass().getSimpleName()+" at 1.0", at10[i], val10, Double.MIN_VALUE);
+ assertEquals(wf[i].getClass().getSimpleName() + " at 0.0", at0[i], val0, Double.MIN_VALUE);
+ assertEquals(wf[i].getClass().getSimpleName() + " at 0.1", at01[i], val01, Double.MIN_VALUE);
+ assertEquals(wf[i].getClass().getSimpleName() + " at 0.9", at09[i], val09, Double.MIN_VALUE);
+ assertEquals(wf[i].getClass().getSimpleName() + " at 1.0", at10[i], val10, Double.MIN_VALUE);
}
}