130 lines
3.6 KiB
Java
130 lines
3.6 KiB
Java
package Presenter.Algorithms;
|
|
|
|
import Model.Coordinates;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.LinkedList;
|
|
import java.util.Set;
|
|
import java.util.TreeSet;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 28.05.2017.
|
|
*/
|
|
public class LeastMedianOfSquaresEstimator extends Algorithm {
|
|
|
|
|
|
private LinkedList<Coordinates> set = new LinkedList<>();
|
|
private int n;
|
|
private double quantile = 0.5;
|
|
private double quantileError;
|
|
private double qPlus;
|
|
private double qMinus;
|
|
private double kPlus;
|
|
private double kMinus;
|
|
private Set<Slab> slab;
|
|
private Slab activeSlab;
|
|
private Slab subSlabU1;
|
|
private Slab subSlabU2;
|
|
private double umin;
|
|
private double umax;
|
|
private double heightsigmaMin;
|
|
private int numberOfIntersections;
|
|
private final int constant = 1;
|
|
private Coordinates kMinusBracelet;
|
|
private double intersectionsPoint;
|
|
|
|
/**
|
|
* Hilfsklasse um die Slabs zu verteilen, private Klasse da sonst nicht verwendett wird und somit eine
|
|
* äußere Klasse überflüssig ist...
|
|
*/
|
|
private static class Slab {
|
|
private double upper;
|
|
private double lower;
|
|
|
|
public Slab(double lower, double upper) {
|
|
this.upper = upper;
|
|
this.lower = lower;
|
|
}
|
|
|
|
public double getUpper() {
|
|
return upper;
|
|
}
|
|
|
|
public void setUpper(double upper) {
|
|
this.upper = upper;
|
|
}
|
|
|
|
public double getLower() {
|
|
return lower;
|
|
}
|
|
|
|
public void setLower(double lower) {
|
|
this.lower = lower;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public void approximateLMS(){
|
|
//(1.) Let n <- |S|; q+ <- q; q- <- q+ * (1 - quantileError);....
|
|
n = set.size();
|
|
qPlus = quantile;
|
|
qMinus = qPlus * (1 - quantileError);
|
|
kMinus = Math.ceil(n * qMinus);
|
|
kPlus = Math.ceil(n * qPlus);
|
|
|
|
//(2.) Let U <- (-inf, inf) be the initial active slab...
|
|
slab = new TreeSet<>();
|
|
slab.add(new Slab(Double.MAX_VALUE, Double.MIN_VALUE));
|
|
heightsigmaMin = Double.MAX_VALUE;
|
|
|
|
//(3.) Apply the following steps as long as the exists active slabs
|
|
for(Iterator<Slab> it = slab.iterator(); it.hasNext();){
|
|
//(a.) Select any active Slab and calc. the inversions
|
|
activeSlab = it.next();
|
|
numberOfIntersections = countInversions(activeSlab);
|
|
|
|
//(b.) apply plane sweep
|
|
if ( numberOfIntersections < (constant * n)){
|
|
kMinusBracelet = planeSweep(activeSlab);
|
|
} else {//(c.) otherwise....
|
|
//get random intersections point...
|
|
splitActiveSlab(intersectionsPoint);
|
|
}
|
|
//(d.) this may update sigma min
|
|
upperBound(intersectionsPoint);
|
|
|
|
//(e.) for i={1,2}, call lower bound(Ui)
|
|
lowerBound(subSlabU1);
|
|
lowerBound(subSlabU2);
|
|
}
|
|
}
|
|
|
|
//Parameter anpassen
|
|
public int countInversions(Slab slab){
|
|
return 0;
|
|
}
|
|
|
|
public Coordinates planeSweep(Slab slab){
|
|
return new Coordinates(.0, .0);
|
|
}
|
|
|
|
public void splitActiveSlab(double point){
|
|
subSlabU1 = new Slab(activeSlab.getLower(), point);
|
|
subSlabU2 = new Slab(point, activeSlab.getUpper());
|
|
}
|
|
|
|
public void upperBound(double point){
|
|
|
|
}
|
|
|
|
public void lowerBound(Slab slab){
|
|
|
|
// if Ui is active on return add it to the list of active slabs..!!!
|
|
}
|
|
}
|