From ca72648c269139cedff459a8cc726450994d4735 Mon Sep 17 00:00:00 2001 From: Armin Wolf Date: Wed, 7 Jun 2017 22:04:54 +0200 Subject: [PATCH] WIP: LeastMedianOfSquaresEstimator - Mount et al - Algorithm #2 --- .../LeastMedianOfSquaresEstimator.java | 118 ++++++++++++++++++ src/main/java/View/MainFrame.java | 4 +- 2 files changed, 120 insertions(+), 2 deletions(-) diff --git a/src/main/java/Presenter/Algorithms/LeastMedianOfSquaresEstimator.java b/src/main/java/Presenter/Algorithms/LeastMedianOfSquaresEstimator.java index b19e69a..3d3752c 100644 --- a/src/main/java/Presenter/Algorithms/LeastMedianOfSquaresEstimator.java +++ b/src/main/java/Presenter/Algorithms/LeastMedianOfSquaresEstimator.java @@ -1,5 +1,12 @@ 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. * @@ -8,4 +15,115 @@ package Presenter.Algorithms; * @Date: 28.05.2017. */ public class LeastMedianOfSquaresEstimator extends Algorithm { + + + private LinkedList 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; + 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 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..!!! + } } diff --git a/src/main/java/View/MainFrame.java b/src/main/java/View/MainFrame.java index 07e959a..f89c533 100644 --- a/src/main/java/View/MainFrame.java +++ b/src/main/java/View/MainFrame.java @@ -114,7 +114,7 @@ public class MainFrame extends JFrame { arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); - this.slider = new JSlider(JSlider.HORIZONTAL, 10, 100, 10); + this.slider = new JSlider(JSlider.HORIZONTAL, 10, 300, 10); this.slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { @@ -123,7 +123,7 @@ public class MainFrame extends JFrame { public void run() { JSlider source = (JSlider) e.getSource(); arrangement.setScale((double) source.getValue() / 10); - int thicknes = 100 / source.getValue(); + int thicknes = 50 / source.getValue(); if (thicknes == 0) { arrangement.setPointThicknes(1); } else {