Start: Repeated Median Estimator

This commit is contained in:
Armin Wolf 2017-06-16 18:06:50 +02:00
parent 962960c509
commit c352ed6a64
4 changed files with 141 additions and 64 deletions

View File

@ -0,0 +1,50 @@
package Model;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 16.06.2017.
*/
public class Slab {
private double upper;
private double lower;
private Boolean activity;
public Slab(double lower, double upper) {
this.upper = upper;
this.lower = lower;
this.activity = true;
}
public Boolean getActivity() {
return activity;
}
public void setActivity(Boolean isActive) {
this.activity = isActive;
}
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 Double getDistance(){
return Math.abs(this.upper - this.lower);
}
}

View File

@ -2,6 +2,7 @@ package Presenter.Algorithms;
import Model.Line;
import Model.Point;
import Model.Slab;
import Presenter.Presenter;
import View.MainFrame;
import javafx.beans.*;
@ -34,6 +35,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
private Line sigmaMin;
private double heightsigmaMin;
private Double intersectionsPoint;
private Double constant = 1d;
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, LinkedList<Point> intersections, Presenter presenter) {
this.set = set;
@ -43,6 +45,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
n = set.size();
double quantile = 0.5;
double qPlus = quantile;
quantileError = 0.1;
double qMinus = qPlus * (1 - quantileError);
kMinus = (int) Math.ceil(n * qMinus);
kPlus = (int) Math.ceil(n * qPlus);
@ -50,17 +53,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
}
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, LinkedList<Point> intersections) {
this.set = set;
this.intersections = intersections;
//(1.) Let n <- |S|; q+ <- q; q- <- q+ * (1 - quantileError);....
n = set.size();
double quantile = 0.5;
double qPlus = quantile;
double qMinus = qPlus * (1 - quantileError);
kMinus = (int) Math.ceil(n * qMinus);
kPlus = (int) Math.ceil(n * qPlus);
new LeastMedianOfSquaresEstimator(set, intersections, null);
}
public void printResult(){
@ -70,7 +63,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
/**
*
*/
public void approximateLMS() {
public void run() {
//(2.) Let U <- (-inf, inf) be the initial active slabs...
@ -100,7 +93,6 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
int numberOfIntersections = countInversions(slab);
//(b.) apply plane sweep
int constant = 1;
if ((constant * n) >= numberOfIntersections) {
sigmaMin = planeSweep(slab);
} else {
@ -143,7 +135,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
}
if (presenter != null){
setChanged();
double m = (getSigmaMin().getX2() + getSigmaMin().getX1()) * 0.5;
double m = (getSigmaMin().getX2() + getSigmaMin().getX1()) * -0.5;
double b = (getSigmaMin().getY2() + getSigmaMin().getY1()) * 0.5;
notifyObservers(new Line(m,b));
}
@ -405,53 +397,6 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
}
/**
* Hilfsklasse um die Slabs zu verteilen, private Klasse da sonst nicht verwendett wird und somit eine
* äußere Klasse überflüssig ist...
*/
protected static class Slab {
private double upper;
private double lower;
private Boolean activity;
public Slab(double lower, double upper) {
this.upper = upper;
this.lower = lower;
this.activity = true;
}
public Boolean getActivity() {
return activity;
}
public void setActivity(Boolean isActive) {
this.activity = isActive;
}
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 Double getDistance(){
return Math.abs(this.upper - this.lower);
}
}
/**
* Im Allgemeinen werden keine Getter und Setter Methoden benötigt aber sie sind nützlich bei den JUnit Testfällen.
*/
@ -543,4 +488,12 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
public void setIntersectionsPoint(double intersectionsPoint) {
this.intersectionsPoint = intersectionsPoint;
}
public Double getConstant() {
return constant;
}
public void setConstant(Double constant) {
this.constant = constant;
}
}

View File

@ -1,5 +1,11 @@
package Presenter.Algorithms;
import Model.Line;
import Model.Slab;
import java.util.ArrayList;
import java.util.LinkedList;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
@ -8,4 +14,69 @@ package Presenter.Algorithms;
* @Date: 28.05.2017.
*/
public class RepeatedMedianEstimator implements Algorithm {
private LinkedList<Line> set;
private Slab interval;
//in der Literatur als L_i, C_i, und R_i bekannt
private Integer countLeftSlab;
private Integer countCenterSlab;
private Integer countRightSlab;
//die Mengen L,C und R
private ArrayList<Line> linesInLeftSlab;
private ArrayList<Line> linesInCenterSlab;
private ArrayList<Line> linesInRightSlab;
private Double r;
private Integer n;
private Double k;
private Double kLow;
private Double kHigh;
private Double beta;
public RepeatedMedianEstimator(LinkedList<Line> set) {
this.set = set;
interval = new Slab(-10000,10000);
n = set.size();
beta = 1.0;
countLeftSlab = 0;
countCenterSlab = n - 1;
countRightSlab = 0;
linesInLeftSlab = new ArrayList<>();
linesInCenterSlab = new ArrayList<>(set);
linesInRightSlab = new ArrayList<>();
}
public void run(){
while (linesInCenterSlab.size() != 1){
r = Math.floor(Math.pow(n, beta));
ArrayList<Line> lines = sampleLines(linesInCenterSlab, r);
//TODO: hier kommt der neue Ansatz vom zweiten Algorithmus hin
k = (Math.floor(n * 0.5) - linesInLeftSlab.size());
computeSlabBorders();
fastSelectionAlg();
countNumberOfIntersectionsAbscissas();
}
}
public ArrayList<Line> sampleLines(ArrayList<Line> set, Double r){return null;}
public void computeSlabBorders(){
kLow = Math.max(1, Math.ceil(((r * k)/(linesInCenterSlab.size()))-((3 * Math.sqrt(r))/(2))));
kHigh = Math.max(1, Math.ceil(((r * k)/(linesInCenterSlab.size()))+((3 * Math.sqrt(r))/(2))));
}
public void fastSelectionAlg(){}
public void countNumberOfIntersectionsAbscissas(){}
}

View File

@ -72,7 +72,6 @@ public class Presenter implements Observer {
SwingUtilities.invokeLater(()->{
getView().createPlot(result.getM(), result.getB());
getView().setLmsIsComplete(true);
getView().getPlotButton().setEnabled(true);
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
getView().log("m: "+result.getM()+" b: "+result.getB());
});
@ -84,10 +83,14 @@ public class Presenter implements Observer {
view.createArrangement();
}
public void startScatterPlotVisualization() {
public void startScatterPlotVisualization(String[] input) {
Double constant =Double.parseDouble(input[0]);
Double error = Double.parseDouble(input[1]);
lms = new LeastMedianOfSquaresEstimator(model.getLines(), model.getNodes(), this);
lms.setConstant(constant);
lms.setQuantileError(error);
lms.addObserver(this);
lms.approximateLMS();
lms.run();
}