2020-03-21 00:37:09 +00:00
|
|
|
package de.wwwu.awolf.presenter.algorithms.advanced;
|
2017-09-10 15:45:47 +00:00
|
|
|
|
2020-04-05 17:28:38 +00:00
|
|
|
import de.wwwu.awolf.model.Line;
|
|
|
|
import de.wwwu.awolf.presenter.algorithms.Algorithm;
|
|
|
|
import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
2017-09-10 15:45:47 +00:00
|
|
|
/**
|
|
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
|
|
*
|
|
|
|
* @Author: Armin Wolf
|
|
|
|
* @Email: a_wolf28@uni-muenster.de
|
2017-10-23 15:48:36 +00:00
|
|
|
* @Date: 23.10.2017.
|
2017-09-10 15:45:47 +00:00
|
|
|
*/
|
|
|
|
public class LeastMedianOfSquaresEstimatorTest {
|
|
|
|
|
2020-04-05 17:28:38 +00:00
|
|
|
private LeastMedianOfSquaresEstimator lms;
|
|
|
|
private Set<Line> lines;
|
|
|
|
private Line line;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp(){
|
|
|
|
Double[] x = {18d, 24d, 30d, 34d, 38d};
|
|
|
|
Double[] y = {18d, 26d, 30d, 40d, 70d};
|
|
|
|
|
|
|
|
|
|
|
|
lines = new HashSet<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
lines.add(new Line(x[i], y[i]));
|
|
|
|
}
|
|
|
|
line = AlgorithmHandler.getInstance().runAlgorithmByType(Algorithm.Type.LMS, lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void geEjValues() throws Exception {
|
|
|
|
|
|
|
|
Double[] expected = {36d, 50d, 60d, 74d, 108d};
|
|
|
|
List<Double> actual = lms.getEjValues(1d);
|
|
|
|
assertArrayEquals(expected, actual.toArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void upperBound() throws Exception {
|
|
|
|
|
|
|
|
Line expected = new Line(5, 5, 146, 210);
|
|
|
|
|
|
|
|
assertEquals(expected.getX1(), line.getX1(), 0.01);
|
|
|
|
assertEquals(expected.getX2(), line.getX2(), 0.01);
|
|
|
|
assertEquals(expected.getY1(), line.getY1(), 0.01);
|
|
|
|
assertEquals(expected.getY2(), line.getY2(), 0.01);
|
|
|
|
}
|
|
|
|
|
2017-09-10 15:45:47 +00:00
|
|
|
|
|
|
|
}
|