package presenter.algorithms.naiv; import model.Line; import presenter.algorithms.Algorithm; import presenter.algorithms.util.FastElementSelector; import java.util.ArrayList; import java.util.LinkedList; /** * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden. * * @Author: Armin Wolf * @Email: a_wolf28@uni-muenster.de * @Date: 15.09.2017. */ public class NaivTheilSenEstimator implements Algorithm { private LinkedList lines; private Double slope; private Double yInterception; public NaivTheilSenEstimator(LinkedList lines) { this.lines = lines; this.slope = 0d; this.yInterception = 0d; } @Override public void run() { ArrayList slopesList = new ArrayList<>(); int cnt = 0; for (int i = 0; i < lines.size(); i++) { double x = lines.get(i).getM(); double y = lines.get(i).getB(); for (int j = i + 1; j < lines.size(); j++) { if (x != lines.get(j).getM()) { // x must be different, otherwise slope becomes infinite Double slope = (lines.get(j).getB() - y) / (lines.get(j).getM() - x); slopesList.add(slope); ++cnt; } } } ArrayList list1 = new ArrayList<>(); ArrayList list2 = new ArrayList<>(); for (int i=0;i