JavaDoc erweitert.
This commit is contained in:
parent
5b177b36e3
commit
80d132516e
|
@ -15,17 +15,6 @@ public class YOrderLineComparatorBegin implements Comparator<Line> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Line o1, Line o2) {
|
public int compare(Line o1, Line o2) {
|
||||||
// if (o1.getY1() == o2.getY1()) {
|
|
||||||
// if (o1.getX1() <= o2.getX1()) {
|
|
||||||
// return -1;
|
|
||||||
// } else {
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
// } else if (o1.getY1() < o2.getY1()) {
|
|
||||||
// return -1;
|
|
||||||
// } else {
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
return o1.getY1().compareTo(o2.getY1());
|
return o1.getY1().compareTo(o2.getY1());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,17 +15,6 @@ public class YOrderLineComparatorEnd implements Comparator<Line> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Line o1, Line o2) {
|
public int compare(Line o1, Line o2) {
|
||||||
// if (o1.getY2() == o2.getY2()) {
|
|
||||||
// if (o1.getX2() <= o2.getX2()) {
|
|
||||||
// return -1;
|
|
||||||
// } else {
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
// } else if (o1.getY2() < o2.getY2()) {
|
|
||||||
// return -1;
|
|
||||||
// } else {
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
return o1.getY2().compareTo(o2.getY2());
|
return o1.getY2().compareTo(o2.getY2());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,19 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
private Double slope;
|
private Double slope;
|
||||||
private Double yInterception;
|
private Double yInterception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param set Liste der Geraden
|
||||||
|
* @param intersections Liste der Schnittpunkte
|
||||||
|
* @param presenter Presenter (Beobachter)
|
||||||
|
*/
|
||||||
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, ArrayList<Point> intersections,
|
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, ArrayList<Point> intersections,
|
||||||
Presenter presenter) {
|
Presenter presenter) {
|
||||||
this.set = set;
|
this.set = set;
|
||||||
this.intersections = intersections;
|
this.intersections = intersections;
|
||||||
|
|
||||||
//(1.) Let n <- |S|; q+ <- q; q- <- q+ * (1 - quantileError);....
|
|
||||||
n = set.size();
|
n = set.size();
|
||||||
double quantile = 0.5;
|
double qPlus = 0.5;
|
||||||
double qPlus = quantile;
|
|
||||||
quantileError = 0.1;
|
quantileError = 0.1;
|
||||||
double qMinus = qPlus * (1 - quantileError);
|
double qMinus = qPlus * (1 - quantileError);
|
||||||
kMinus = (int) Math.ceil(n * qMinus);
|
kMinus = (int) Math.ceil(n * qMinus);
|
||||||
|
@ -55,12 +59,22 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
this.presenter = presenter;
|
this.presenter = presenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param set Liste der Geraden
|
||||||
|
* @param intersections Liste der Schnittpunkte
|
||||||
|
*/
|
||||||
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, ArrayList<Point> intersections) {
|
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, ArrayList<Point> intersections) {
|
||||||
this(set, intersections, null);
|
this(set, intersections, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Algorithmus zum berechnen des LMS-Schätzers
|
||||||
*
|
*
|
||||||
|
* Paper:
|
||||||
|
* Mount, David M, Nathan S Netanyahu, Kathleen Romanik, Ruth Silverman und Angela Y Wu
|
||||||
|
* „A practical approximation algorithm for the LMS line estimator“. 2007
|
||||||
|
* Computational statistics & data Analysis 51.5, S. 2461–2486
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
|
@ -110,7 +124,6 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
intersectionsPoint = null;
|
intersectionsPoint = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intersectionsPoint != null) {
|
if (intersectionsPoint != null) {
|
||||||
splitActiveSlab(intersectionsPoint, interval);
|
splitActiveSlab(intersectionsPoint, interval);
|
||||||
//(d.) this may update sigma min
|
//(d.) this may update sigma min
|
||||||
|
@ -130,8 +143,6 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
this.intervals.poll();
|
this.intervals.poll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.intervals.remove(interval);
|
this.intervals.remove(interval);
|
||||||
}
|
}
|
||||||
|
@ -141,23 +152,21 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param interval
|
* Liefert die Anzahl der Schnittpunkte in einem Intervall
|
||||||
* @return
|
* @param interval Intervall
|
||||||
|
* @return Anzahl der Schnittpunkte
|
||||||
*/
|
*/
|
||||||
public int countInversions(Interval interval) {
|
public int countInversions(Interval interval) {
|
||||||
|
return invCounter.run(set, interval);
|
||||||
int numberOfInversions = 0;
|
|
||||||
// debug
|
|
||||||
//for (int i=0;i<listA.size();i++){
|
|
||||||
// System.out.println(listA.get(i)+", "+listB.get(i));
|
|
||||||
//}
|
|
||||||
numberOfInversions = invCounter.run(set, interval);
|
|
||||||
|
|
||||||
return numberOfInversions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* In der Literatur wird ein planesweep vorrausgesetzt um in einem Intervall das minimale kMinus Segment zu
|
||||||
|
* identifizieren. An dieser Stelle wird eine naivere Lösung verwendet, mithilfe der Schleife werden alle
|
||||||
|
* Schnittpunkte betrachtet und bei passenden x-Koordinaten werden wird die vertikale Gerade auf kMinus Segmente
|
||||||
|
* untersucht.
|
||||||
|
*
|
||||||
* @param interval
|
* @param interval
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -204,7 +213,9 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param point
|
* Zu einer vertikalen Gerade werden kMinus Segmente erzeugt und geprüft ob eine bessere Lösung
|
||||||
|
* als SigmaMin vorliegt.
|
||||||
|
* @param point x-Koordinate zur Konstruktion der vertikalen Gerade
|
||||||
*/
|
*/
|
||||||
public void upperBound(double point) {
|
public void upperBound(double point) {
|
||||||
|
|
||||||
|
@ -234,8 +245,8 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param pslab
|
* Die Methode prüft ob das übergebene Intervall die untere Schranke einer potenziellen Lösung erfüllt.
|
||||||
* @return
|
* @param pslab übergebene Intervall
|
||||||
*/
|
*/
|
||||||
public void lowerBound(Interval pslab) {
|
public void lowerBound(Interval pslab) {
|
||||||
|
|
||||||
|
@ -368,110 +379,71 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Im Allgemeinen werden keine Getter und Setter Methoden benötigt aber sie sind nützlich bei den
|
* @return Anzahl der Geraden
|
||||||
* JUnit Testfällen.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public LinkedList<Line> getSet() {
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSet(LinkedList<Line> set) {
|
|
||||||
this.set = set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Point> getIntersections() {
|
|
||||||
return intersections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntersections(ArrayList<Point> intersections) {
|
|
||||||
this.intersections = intersections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getN() {
|
public int getN() {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param n Anzahl der Geraden
|
||||||
|
*/
|
||||||
public void setN(int n) {
|
public void setN(int n) {
|
||||||
this.n = n;
|
this.n = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getQuantileError() {
|
/**
|
||||||
return quantileError;
|
* @param quantileError Parameter quantile Fehler
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setQuantileError(double quantileError) {
|
public void setQuantileError(double quantileError) {
|
||||||
this.quantileError = quantileError;
|
this.quantileError = quantileError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getkPlus() {
|
/**
|
||||||
return kPlus;
|
* @param kMinus kMinus index
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setkPlus(int kPlus) {
|
|
||||||
this.kPlus = kPlus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getkMinus() {
|
|
||||||
return kMinus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setkMinus(int kMinus) {
|
public void setkMinus(int kMinus) {
|
||||||
this.kMinus = kMinus;
|
this.kMinus = kMinus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Interval getSubSlabU1() {
|
/**
|
||||||
return subSlabU1;
|
* @return duale Streifen Sigma_min
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setSubSlabU1(Interval subSlabU1) {
|
|
||||||
this.subSlabU1 = subSlabU1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Interval getSubSlabU2() {
|
|
||||||
return subSlabU2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubSlabU2(Interval subSlabU2) {
|
|
||||||
this.subSlabU2 = subSlabU2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Line getSigmaMin() {
|
public Line getSigmaMin() {
|
||||||
return sigmaMin;
|
return sigmaMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sigmaMin duale Streifen Sigma_min
|
||||||
|
*/
|
||||||
public void setSigmaMin(Line sigmaMin) {
|
public void setSigmaMin(Line sigmaMin) {
|
||||||
this.sigmaMin = sigmaMin;
|
this.sigmaMin = sigmaMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHeightsigmaMin() {
|
/**
|
||||||
return heightsigmaMin;
|
* @param heightsigmaMin höhe von Sigma_min
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setHeightsigmaMin(double heightsigmaMin) {
|
public void setHeightsigmaMin(double heightsigmaMin) {
|
||||||
this.heightsigmaMin = heightsigmaMin;
|
this.heightsigmaMin = heightsigmaMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getIntersectionsPoint() {
|
/**
|
||||||
return intersectionsPoint;
|
* @param constant Parameter Konstante
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setIntersectionsPoint(double intersectionsPoint) {
|
|
||||||
this.intersectionsPoint = intersectionsPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getConstant() {
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConstant(Double constant) {
|
public void setConstant(Double constant) {
|
||||||
this.constant = constant;
|
this.constant = constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Steigung
|
||||||
|
*/
|
||||||
public Double getSlope() {
|
public Double getSlope() {
|
||||||
return slope;
|
return slope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return y-Achsenabschnitt
|
||||||
|
*/
|
||||||
public Double getyInterception() {
|
public Double getyInterception() {
|
||||||
return yInterception;
|
return yInterception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,11 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
private Double slope;
|
private Double slope;
|
||||||
private Double yInterception;
|
private Double yInterception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param set Liste der Geraden
|
||||||
|
* @param presenter Presenter (Beobachter)
|
||||||
|
*/
|
||||||
public RepeatedMedianEstimator(LinkedList<Line> set, Presenter presenter) {
|
public RepeatedMedianEstimator(LinkedList<Line> set, Presenter presenter) {
|
||||||
this.set = set;
|
this.set = set;
|
||||||
this.presenter = presenter;
|
this.presenter = presenter;
|
||||||
|
@ -78,12 +82,21 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
linePairs = new HashMap<>();
|
linePairs = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param set Liste der Geraden
|
||||||
|
*/
|
||||||
public RepeatedMedianEstimator(LinkedList<Line> set) {
|
public RepeatedMedianEstimator(LinkedList<Line> set) {
|
||||||
this(set, null);
|
this(set, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Führt den Algortihmus zur Berechnung des RM-Schätzers durch.
|
||||||
*
|
*
|
||||||
|
* Paper:
|
||||||
|
* Matousek, Jiri, D. M. Mount und N. S. Netanyahu
|
||||||
|
* „Efficient Randomized Algorithms for the Repeated Median Line Estimator“. 1998
|
||||||
|
* Algorithmica 20.2, S. 136–150
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
|
@ -97,8 +110,8 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
r = Math.ceil(Math.pow(n, beta));
|
r = Math.ceil(Math.pow(n, beta));
|
||||||
ArrayList<Line> lines = RandomSampler.run(linesInCenterSlab, r, linesInCenterSlab.size());
|
ArrayList<Line> lines = RandomSampler.run(linesInCenterSlab, r, linesInCenterSlab.size());
|
||||||
|
|
||||||
|
//Für jede Gerade aus der Stichprobe wird der Schnittpunkt mit der medianen
|
||||||
//For each Sampled Line, compute its median intersection abscissa
|
//x-Koordinate bestimmt
|
||||||
ArrayList<Double> medianIntersectionAbscissas = new ArrayList<>();
|
ArrayList<Double> medianIntersectionAbscissas = new ArrayList<>();
|
||||||
for (Line l : lines) {
|
for (Line l : lines) {
|
||||||
Double abscissa = estimateMedianIntersectionAbscissas(l);
|
Double abscissa = estimateMedianIntersectionAbscissas(l);
|
||||||
|
@ -106,26 +119,20 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
medianIntersectionAbscissas.add(abscissa);
|
medianIntersectionAbscissas.add(abscissa);
|
||||||
}
|
}
|
||||||
|
|
||||||
//rank of the repeated median in C
|
//Rang vom RM-Wert in C
|
||||||
k = Math.max(1, Math.min(set.size(), (Math.ceil(n * 0.5) - linesInLeftSlab.size())));
|
k = Math.max(1, Math.min(set.size(), (Math.ceil(n * 0.5) - linesInLeftSlab.size())));
|
||||||
|
|
||||||
//compute k_lo and k_hi
|
//berechne k_lo und k_hi
|
||||||
computeSlabBorders();
|
computeSlabBorders();
|
||||||
|
|
||||||
|
//Berechne die Elemente mit dem Rang Theta_lo und Theta_hi
|
||||||
// if (medianIntersectionAbscissas.size() < kLow || medianIntersectionAbscissas.size()<kHigh || kLow < 0 || kHigh<0 )
|
|
||||||
// System.err.print("#medianIntersectionAbscissa: "+medianIntersectionAbscissas.size()+"\t\t klow: "+kLow+" kHigh: "+kHigh+"\n\n");
|
|
||||||
|
|
||||||
//Employ fast selection algorithm to determine the Elements Theta_lo and Theta_hi
|
|
||||||
thetaLow = FastElementSelector.randomizedSelect(medianIntersectionAbscissas, kLow);
|
thetaLow = FastElementSelector.randomizedSelect(medianIntersectionAbscissas, kLow);
|
||||||
thetaHigh = FastElementSelector.randomizedSelect(medianIntersectionAbscissas, kHigh);
|
thetaHigh = FastElementSelector.randomizedSelect(medianIntersectionAbscissas, kHigh);
|
||||||
|
|
||||||
//For each dual Line in C count the number of intersection abscissas that lie
|
//Für jede Gerade in C wird die Anzahl der Schnittpunkte die im Intervall liegen hochgezählt
|
||||||
//in each of the intervals.
|
|
||||||
countNumberOfIntersectionsAbscissas();
|
countNumberOfIntersectionsAbscissas();
|
||||||
|
|
||||||
//Based on this 3 counts, determine which of the subintervals contains the repeated median
|
//verkleinere das Intervall
|
||||||
//and contract to this subiinterval.
|
|
||||||
contractIntervals();
|
contractIntervals();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,38 +140,19 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
System.out.println("Zeit: "+ ((end-start)/1000));
|
System.out.println("Zeit: "+ ((end-start)/1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param set
|
|
||||||
* @param r
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ArrayList<Line> sampleLines(ArrayList<Line> set, Double r) {
|
|
||||||
|
|
||||||
ArrayList<Line> sampledLines = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < r; i++) {
|
|
||||||
sampledLines.add(set.get(ThreadLocalRandom.current().nextInt(0, linesInCenterSlab.size())));
|
|
||||||
}
|
|
||||||
|
|
||||||
return sampledLines;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sampledLine
|
* Berechnet die mediane x-Koordinate über den Schnittpunkten.
|
||||||
* @return
|
*
|
||||||
|
* @param sampledLine Stichprobe von Geraden
|
||||||
|
* @return mediane x-Koordinate über den Schnittpunkten
|
||||||
*/
|
*/
|
||||||
public Double estimateMedianIntersectionAbscissas(Line sampledLine) {
|
public Double estimateMedianIntersectionAbscissas(Line sampledLine) {
|
||||||
|
|
||||||
Integer index = Integer.parseInt(sampledLine.getId());
|
Integer index = Integer.parseInt(sampledLine.getId());
|
||||||
ArrayList<Double> intersections = new ArrayList<>();
|
|
||||||
double intersection;
|
|
||||||
|
|
||||||
IntersectionCounter intersectionCounter = new IntersectionCounter();
|
IntersectionCounter intersectionCounter = new IntersectionCounter();
|
||||||
intersections = intersectionCounter.calculateIntersectionAbscissas(linesInCenterSlab, sampledLine);
|
ArrayList<Double> intersections = intersectionCounter.calculateIntersectionAbscissas(linesInCenterSlab, sampledLine);
|
||||||
|
|
||||||
//Collections.sort(intersections);
|
|
||||||
//double ki = Math.ceil((n - 1) / 2) - countLeftSlab.get(index);
|
|
||||||
//double i = (Math.ceil((Math.sqrt(n) * ki) / countCenterSlab.get(index)));
|
|
||||||
double ki = Math.ceil((n - 1) / 2) - FastElementSelector.randomizedSelect(countLeftSlab, index);
|
double ki = Math.ceil((n - 1) / 2) - FastElementSelector.randomizedSelect(countLeftSlab, index);
|
||||||
double i = (Math.ceil((Math.sqrt(n) * ki) / FastElementSelector.randomizedSelect(countCenterSlab, index)));
|
double i = (Math.ceil((Math.sqrt(n) * ki) / FastElementSelector.randomizedSelect(countCenterSlab, index)));
|
||||||
int accessIndex;
|
int accessIndex;
|
||||||
|
@ -175,36 +163,25 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
else
|
else
|
||||||
accessIndex = (int) i;
|
accessIndex = (int) i;
|
||||||
|
|
||||||
//System.out.println(accessIndex);
|
|
||||||
|
|
||||||
//return intersections.get(accessIndex);
|
|
||||||
return FastElementSelector.randomizedSelect(intersections, accessIndex);
|
return FastElementSelector.randomizedSelect(intersections, accessIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Berechnet die potenziell neuen Intervallgrenzen.
|
||||||
*/
|
*/
|
||||||
public void computeSlabBorders() {
|
public void computeSlabBorders() {
|
||||||
kLow = Math
|
kLow = Math.max(1, Math.floor(((r * k) / (linesInCenterSlab.size()))
|
||||||
.max(1, Math.floor(
|
- ((3 * Math.sqrt(r)) / (2))));
|
||||||
((r * k) / (linesInCenterSlab.size()))
|
kHigh = Math.min(r, Math.floor(((r * k) / (linesInCenterSlab.size()))
|
||||||
- ((3 * Math.sqrt(r)) / (2))
|
+ ((3 * Math.sqrt(r)) / (2))));
|
||||||
)
|
|
||||||
);
|
|
||||||
kHigh = Math
|
|
||||||
.min(r, Math.floor(
|
|
||||||
((r * k) / (linesInCenterSlab.size()))
|
|
||||||
+ ((3 * Math.sqrt(r)) / (2))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Berechnet die Anzahl der Schnittpunkte pro Bereich. Insgesammt gibt es drei Bereiche:
|
||||||
|
* Im Intervall => (a,b], vor dem Intervall => (a', a], hinter dem Intervall => (b, b'].
|
||||||
*/
|
*/
|
||||||
public void countNumberOfIntersectionsAbscissas() {
|
public void countNumberOfIntersectionsAbscissas() {
|
||||||
|
|
||||||
for (Line line : linesInCenterSlab) {
|
for (Line line : linesInCenterSlab) {
|
||||||
ArrayList<Double> intersections = intersectionAbscissas.get(line);
|
ArrayList<Double> intersections = intersectionAbscissas.get(line);
|
||||||
Integer index = Integer.parseInt(line.getId());
|
Integer index = Integer.parseInt(line.getId());
|
||||||
|
@ -222,7 +199,6 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//System.out.println("Linie: "+line.getId()+"\tLeft: "+left+"\t Center: "+center+"\t Right: "+right);
|
|
||||||
countLeftSlab.set(index, (double) left);
|
countLeftSlab.set(index, (double) left);
|
||||||
countCenterSlab.set(index, (double) center);
|
countCenterSlab.set(index, (double) center);
|
||||||
countRightSlab.set(index, (double) right);
|
countRightSlab.set(index, (double) right);
|
||||||
|
@ -231,7 +207,8 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Verkleinert das aktuelle Intervall. Eines der drei Bereiche wird als neues Intervall gewählt.
|
||||||
|
* Auf diesem Intervall werden dann in der nächsten Iteration wieder drei Bereiche bestimmt.
|
||||||
*/
|
*/
|
||||||
public void contractIntervals() {
|
public void contractIntervals() {
|
||||||
for (int i = 0; i < linesInCenterSlab.size(); i++) {
|
for (int i = 0; i < linesInCenterSlab.size(); i++) {
|
||||||
|
@ -249,21 +226,6 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
linesInRightSlab.add(linesInCenterSlab.get(i));
|
linesInRightSlab.add(linesInCenterSlab.get(i));
|
||||||
linesInCenterSlab.remove(i);
|
linesInCenterSlab.remove(i);
|
||||||
}
|
}
|
||||||
// if (medianIntersections.get(linesInCenterSlab.get(i)) != null) {
|
|
||||||
// if (medianIntersections.get(linesInCenterSlab.get(i)) <= thetaLow) {
|
|
||||||
// linesInLeftSlab.add(linesInCenterSlab.get(i));
|
|
||||||
// linesInCenterSlab.remove(i);
|
|
||||||
// countLeftSlab.set(i, countLeftSlab.get(i) + 1);
|
|
||||||
// countCenterSlab.set(i, countCenterSlab.get(i) - 1);
|
|
||||||
// } else if (medianIntersections.get(linesInCenterSlab.get(i)) > thetaHigh) {
|
|
||||||
// linesInRightSlab.add(linesInCenterSlab.get(i));
|
|
||||||
// linesInCenterSlab.remove(i);
|
|
||||||
// countRightSlab.set(i, countRightSlab.get(i) + 1);
|
|
||||||
// countCenterSlab.set(i, countCenterSlab.get(i) - 1);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//wähle C als C
|
//wähle C als C
|
||||||
|
@ -305,163 +267,37 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
/*******************************************************************************************************************
|
/*******************************************************************************************************************
|
||||||
* Getter und Setter Methoden
|
* Getter und Setter Methoden
|
||||||
******************************************************************************************************************/
|
******************************************************************************************************************/
|
||||||
public LinkedList<Line> getSet() {
|
/**
|
||||||
return set;
|
* @return Anzahl der Geraden
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setSet(LinkedList<Line> set) {
|
|
||||||
this.set = set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<Line, ArrayList<Line>> getLinePairs() {
|
|
||||||
return linePairs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLinePairs(HashMap<Line, ArrayList<Line>> linePairs) {
|
|
||||||
this.linePairs = linePairs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<Line, Double> getMedianIntersections() {
|
|
||||||
return medianIntersections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMedianIntersections(HashMap<Line, Double> medianIntersections) {
|
|
||||||
this.medianIntersections = medianIntersections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<Line, ArrayList<Double>> getIntersectionAbscissas() {
|
|
||||||
return intersectionAbscissas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntersectionAbscissas(
|
|
||||||
HashMap<Line, ArrayList<Double>> intersectionAbscissas) {
|
|
||||||
this.intersectionAbscissas = intersectionAbscissas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Interval getInterval() {
|
|
||||||
return interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInterval(Interval interval) {
|
|
||||||
this.interval = interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Double> getCountLeftSlab() {
|
|
||||||
return countLeftSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCountLeftSlab(ArrayList<Double> countLeftSlab) {
|
|
||||||
this.countLeftSlab = countLeftSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Double> getCountCenterSlab() {
|
|
||||||
return countCenterSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCountCenterSlab(ArrayList<Double> countCenterSlab) {
|
|
||||||
this.countCenterSlab = countCenterSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Double> getCountRightSlab() {
|
|
||||||
return countRightSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCountRightSlab(ArrayList<Double> countRightSlab) {
|
|
||||||
this.countRightSlab = countRightSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Line> getLinesInLeftSlab() {
|
|
||||||
return linesInLeftSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLinesInLeftSlab(ArrayList<Line> linesInLeftSlab) {
|
|
||||||
this.linesInLeftSlab = linesInLeftSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Line> getLinesInCenterSlab() {
|
|
||||||
return linesInCenterSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLinesInCenterSlab(ArrayList<Line> linesInCenterSlab) {
|
|
||||||
this.linesInCenterSlab = linesInCenterSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Line> getLinesInRightSlab() {
|
|
||||||
return linesInRightSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLinesInRightSlab(ArrayList<Line> linesInRightSlab) {
|
|
||||||
this.linesInRightSlab = linesInRightSlab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getR() {
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setR(Double r) {
|
|
||||||
this.r = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getN() {
|
public Integer getN() {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param n Anzahl der Geraden
|
||||||
|
*/
|
||||||
public void setN(Integer n) {
|
public void setN(Integer n) {
|
||||||
this.n = n;
|
this.n = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getK() {
|
/**
|
||||||
return k;
|
* @param beta Parameter Beta
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setK(Double k) {
|
|
||||||
this.k = k;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getkLow() {
|
|
||||||
return kLow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setkLow(Double kLow) {
|
|
||||||
this.kLow = kLow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getkHigh() {
|
|
||||||
return kHigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setkHigh(Double kHigh) {
|
|
||||||
this.kHigh = kHigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getBeta() {
|
|
||||||
return beta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBeta(Double beta) {
|
public void setBeta(Double beta) {
|
||||||
this.beta = beta;
|
this.beta = beta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getThetaLow() {
|
/**
|
||||||
return thetaLow;
|
* @return Steigung
|
||||||
}
|
*/
|
||||||
|
|
||||||
public void setThetaLow(Double thetaLow) {
|
|
||||||
this.thetaLow = thetaLow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getThetaHigh() {
|
|
||||||
return thetaHigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setThetaHigh(Double thetaHigh) {
|
|
||||||
this.thetaHigh = thetaHigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getSlope() {
|
public Double getSlope() {
|
||||||
return slope;
|
return slope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return y-Achsenabschnitt
|
||||||
|
*/
|
||||||
public Double getyInterception() {
|
public Double getyInterception() {
|
||||||
return yInterception;
|
return yInterception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,12 @@ public class TheilSenEstimator extends Observable implements Algorithm {
|
||||||
private Double slope;
|
private Double slope;
|
||||||
private Double yInterception;
|
private Double yInterception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param setOfLines Liste der Geraden
|
||||||
|
* @param setOfIntersections Liste der Schnittpunkte
|
||||||
|
* @param presenter Presenter (Beobachter)
|
||||||
|
*/
|
||||||
public TheilSenEstimator(LinkedList<Line> setOfLines, ArrayList<Point> setOfIntersections, Presenter presenter) {
|
public TheilSenEstimator(LinkedList<Line> setOfLines, ArrayList<Point> setOfIntersections, Presenter presenter) {
|
||||||
this.presenter = presenter;
|
this.presenter = presenter;
|
||||||
this.setOfLines = new ArrayList<>(setOfLines);
|
this.setOfLines = new ArrayList<>(setOfLines);
|
||||||
|
@ -60,6 +65,11 @@ public class TheilSenEstimator extends Observable implements Algorithm {
|
||||||
this.k = (int) (N / 2);
|
this.k = (int) (N / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param setOfLines Liste der Geraden
|
||||||
|
* @param setOfIntersections Liste der Schnittpunkte
|
||||||
|
*/
|
||||||
public TheilSenEstimator(LinkedList<Line> setOfLines, ArrayList<Point> setOfIntersections) {
|
public TheilSenEstimator(LinkedList<Line> setOfLines, ArrayList<Point> setOfIntersections) {
|
||||||
this(setOfLines, setOfIntersections, null);
|
this(setOfLines, setOfIntersections, null);
|
||||||
}
|
}
|
||||||
|
@ -224,11 +234,16 @@ public class TheilSenEstimator extends Observable implements Algorithm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Steigung
|
||||||
|
*/
|
||||||
public Double getSlope() {
|
public Double getSlope() {
|
||||||
return slope;
|
return slope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return y-Achsenabschnitt
|
||||||
|
*/
|
||||||
public Double getyInterception() {
|
public Double getyInterception() {
|
||||||
return yInterception;
|
return yInterception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,19 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
private Integer n;
|
private Integer n;
|
||||||
private Double ds, b, m;
|
private Double ds, b, m;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param lines Liste des Geraden
|
||||||
|
*/
|
||||||
public NaivLeastMedianOfSquaresEstimator(LinkedList<Line> lines) {
|
public NaivLeastMedianOfSquaresEstimator(LinkedList<Line> lines) {
|
||||||
for (Line l : lines) {
|
for (Line l : lines) {
|
||||||
set.add(new Point(l.getM(), l.getB()));
|
set.add(new Point(l.getM(), l.getB()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crude Algorithmus zum berechnen des LSM-Schätzers.
|
||||||
|
*/
|
||||||
private void crudeAlg() {
|
private void crudeAlg() {
|
||||||
ds = Double.MAX_VALUE;
|
ds = Double.MAX_VALUE;
|
||||||
b = 0d;
|
b = 0d;
|
||||||
|
@ -55,7 +61,6 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
ds = dijk;
|
ds = dijk;
|
||||||
b = alpha;
|
b = alpha;
|
||||||
m = beta;
|
m = beta;
|
||||||
// System.out.printf("Distanz: %6.2f\tAlpha: %6.2f\tBeta: %6.2f",ds,b,m);
|
|
||||||
}
|
}
|
||||||
triple.clear();
|
triple.clear();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +70,12 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
System.out.println("Zeit: "+ ((end-start)/1000));
|
System.out.println("Zeit: "+ ((end-start)/1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Berechnet die Gerade mit dem medianen Fehler
|
||||||
|
* @param a y-Achsenabschnitt
|
||||||
|
* @param b Steigung
|
||||||
|
* @return medianer Fehler
|
||||||
|
*/
|
||||||
private Double f(Double a, Double b) {
|
private Double f(Double a, Double b) {
|
||||||
ArrayList<Double> res = new ArrayList<>();
|
ArrayList<Double> res = new ArrayList<>();
|
||||||
for (Point p : set) {
|
for (Point p : set) {
|
||||||
|
@ -84,10 +94,16 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return y-Achsenabschnitt
|
||||||
|
*/
|
||||||
public Double getB() {
|
public Double getB() {
|
||||||
return b * -1;
|
return b * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Steigung
|
||||||
|
*/
|
||||||
public Double getM() {
|
public Double getM() {
|
||||||
return m * -1;
|
return m * -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@ public class NaivRepeatedMedianEstimator implements Algorithm {
|
||||||
private Double medianX;
|
private Double medianX;
|
||||||
private Double medianY;
|
private Double medianY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param lines Liste der Geraden
|
||||||
|
*/
|
||||||
public NaivRepeatedMedianEstimator(LinkedList<Line> lines) {
|
public NaivRepeatedMedianEstimator(LinkedList<Line> lines) {
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
slopesPerLine = new HashMap<>();
|
slopesPerLine = new HashMap<>();
|
||||||
|
@ -50,18 +54,17 @@ public class NaivRepeatedMedianEstimator implements Algorithm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//calculate all slopes for each line
|
//calculate all slopes for each line
|
||||||
Point ret;
|
Point ret;
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
for (int j = i + 1; j < lines.size(); j++) {
|
for (int j = i + 1; j < lines.size(); j++) {
|
||||||
ret = calculateSlope(lines.get(i), lines.get(j));
|
ret = calculateLine(lines.get(i), lines.get(j));
|
||||||
slopesPerLine.get(lines.get(i).getId()).add(ret.getX());
|
slopesPerLine.get(lines.get(i).getId()).add(ret.getX());
|
||||||
interceptPerLine.get(lines.get(i).getId()).add(ret.getY());
|
interceptPerLine.get(lines.get(i).getId()).add(ret.getY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate median of slopes for each line
|
//berechne mediane Steigung
|
||||||
for (String l : slopesPerLine.keySet()) {
|
for (String l : slopesPerLine.keySet()) {
|
||||||
ArrayList<Double> list = slopesPerLine.get(l);
|
ArrayList<Double> list = slopesPerLine.get(l);
|
||||||
int size = list.size() / 2;
|
int size = list.size() / 2;
|
||||||
|
@ -71,7 +74,7 @@ public class NaivRepeatedMedianEstimator implements Algorithm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate median of slopes for each line
|
//berechne medianen y-Achsenabschnitt
|
||||||
for (String l : interceptPerLine.keySet()) {
|
for (String l : interceptPerLine.keySet()) {
|
||||||
ArrayList<Double> list = interceptPerLine.get(l);
|
ArrayList<Double> list = interceptPerLine.get(l);
|
||||||
int size = list.size() / 2;
|
int size = list.size() / 2;
|
||||||
|
@ -92,22 +95,28 @@ public class NaivRepeatedMedianEstimator implements Algorithm {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point calculateSlope(Line lineA, Line lineB) {
|
/**
|
||||||
|
* Berechnet die Geraden zwischen zwei Punkten im dualen Raum.
|
||||||
|
* @param startPoint Gerade 1 => Startpunkt mit den Koordianten (m,b)
|
||||||
|
* @param endPoint Gerade 2 => Endpunkt mit den Koordianten (m', b')
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Point calculateLine(Line startPoint, Line endPoint) {
|
||||||
Double xi;
|
Double xi;
|
||||||
Double xj;
|
Double xj;
|
||||||
Double yi;
|
Double yi;
|
||||||
Double yj;
|
Double yj;
|
||||||
|
|
||||||
if (lineB.getM() > lineA.getM()) {
|
if (endPoint.getM() > startPoint.getM()) {
|
||||||
xi = lineA.getM();
|
xi = startPoint.getM();
|
||||||
yi = lineA.getB();
|
yi = startPoint.getB();
|
||||||
xj = lineB.getM();
|
xj = endPoint.getM();
|
||||||
yj = lineB.getB();
|
yj = endPoint.getB();
|
||||||
} else {
|
} else {
|
||||||
xj = lineA.getM();
|
xj = startPoint.getM();
|
||||||
yj = lineA.getB();
|
yj = startPoint.getB();
|
||||||
xi = lineB.getM();
|
xi = endPoint.getM();
|
||||||
yi = lineB.getB();
|
yi = endPoint.getB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,10 +125,16 @@ public class NaivRepeatedMedianEstimator implements Algorithm {
|
||||||
return new Point(m, b);
|
return new Point(m, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Steigung
|
||||||
|
*/
|
||||||
public Double getM() {
|
public Double getM() {
|
||||||
return medianX * -1;
|
return medianX * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return y-Achsenabschnitt
|
||||||
|
*/
|
||||||
public Double getB() {
|
public Double getB() {
|
||||||
return medianY * -1;
|
return medianY * -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ public class NaivTheilSenEstimator implements Algorithm {
|
||||||
private Double slope;
|
private Double slope;
|
||||||
private Double yInterception;
|
private Double yInterception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor
|
||||||
|
* @param lines Liste der Geraden
|
||||||
|
*/
|
||||||
public NaivTheilSenEstimator(LinkedList<Line> lines) {
|
public NaivTheilSenEstimator(LinkedList<Line> lines) {
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
this.slope = 0d;
|
this.slope = 0d;
|
||||||
|
@ -69,11 +73,16 @@ public class NaivTheilSenEstimator implements Algorithm {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Steigung
|
||||||
|
*/
|
||||||
public Double getM() {
|
public Double getM() {
|
||||||
return slope * -1;
|
return slope * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return y-Achsenabschnitt
|
||||||
|
*/
|
||||||
public Double getB() {
|
public Double getB() {
|
||||||
return yInterception * -1;
|
return yInterception * -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue