ScaledErrorBasedMeasure hinzugefügt mit den naiven algorithmen berechnet.
This commit is contained in:
parent
30ff17328e
commit
b1c026e574
|
@ -20,7 +20,7 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
private ArrayList<Point> set = new ArrayList<>();
|
private ArrayList<Point> set = new ArrayList<>();
|
||||||
|
|
||||||
private Integer n;
|
private Integer n;
|
||||||
private Double ds,as,bs;
|
private Double ds, b, m;
|
||||||
|
|
||||||
public NaivLeastMedianOfSquaresEstimator(LinkedList<Line> lines) {
|
public NaivLeastMedianOfSquaresEstimator(LinkedList<Line> lines) {
|
||||||
for (Line l :lines){
|
for (Line l :lines){
|
||||||
|
@ -31,8 +31,8 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
|
|
||||||
private void crudeAlg(){
|
private void crudeAlg(){
|
||||||
ds = Double.MAX_VALUE;
|
ds = Double.MAX_VALUE;
|
||||||
as = 0d;
|
b = 0d;
|
||||||
bs = 0d;
|
m = 0d;
|
||||||
ArrayList<Point> triple = new ArrayList<>();
|
ArrayList<Point> triple = new ArrayList<>();
|
||||||
Double beta;
|
Double beta;
|
||||||
Double alpha;
|
Double alpha;
|
||||||
|
@ -49,15 +49,15 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
dijk = f(alpha, beta);
|
dijk = f(alpha, beta);
|
||||||
if (dijk < ds){
|
if (dijk < ds){
|
||||||
ds = dijk;
|
ds = dijk;
|
||||||
as = alpha;
|
b = alpha;
|
||||||
bs = beta;
|
m = beta;
|
||||||
// System.out.printf("Distanz: %6.2f\tAlpha: %6.2f\tBeta: %6.2f",ds,as,bs);
|
// System.out.printf("Distanz: %6.2f\tAlpha: %6.2f\tBeta: %6.2f",ds,b,m);
|
||||||
}
|
}
|
||||||
triple.clear();
|
triple.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.printf("Naiv LMS: %6.2f * x + %6.3f\n",bs, as);
|
System.out.printf("Naiv LMS: %6.2f * x + %6.3f\n", m, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,11 +80,11 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getAs() {
|
public Double getB() {
|
||||||
return as;
|
return b * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getBs() {
|
public Double getM() {
|
||||||
return bs;
|
return m * -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,11 +111,11 @@ public class NaivRepeatedMedianEstimator implements Algorithm{
|
||||||
return new Point(m,b);
|
return new Point(m,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getMedianX() {
|
public Double getM() {
|
||||||
return medianX;
|
return medianX * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getMedianY() {
|
public Double getB() {
|
||||||
return medianY;
|
return medianY * -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,11 +65,11 @@ public class NaivTheilSenEstimator implements Algorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Double getSlope() {
|
public Double getM() {
|
||||||
return slope;
|
return slope * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getyInterception() {
|
public Double getB() {
|
||||||
return yInterception;
|
return yInterception * -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class EvaluateAlgorithms extends Observable {
|
||||||
|
|
||||||
private DatasetGenerator generator;
|
private DatasetGenerator generator;
|
||||||
|
|
||||||
private String[][] names = {{"MSE", "RMSE", "MAE", "MDAE","Steigung","y-Achsenabschnitt"}, {"MAPE", "MDAPE", "RMSPE", "RMDSPE","Steigung","y-Achsenabschnitt"}};
|
private String[][] names = {{"MSE", "RMSE", "MAE", "MDAE","Steigung","y-Achsenabschnitt", "S-MSE", "S-RMSE", "S-MAE", "S-MDAE", "Brute-force Steigung", "Brute-force y-Achsenabschnitt"}, {"MAPE", "MDAPE", "RMSPE", "RMDSPE","Steigung","y-Achsenabschnitt"}};
|
||||||
|
|
||||||
//übergebene Parameter
|
//übergebene Parameter
|
||||||
private int type;
|
private int type;
|
||||||
|
@ -103,8 +103,7 @@ public class EvaluateAlgorithms extends Observable {
|
||||||
ArrayList<String> result;
|
ArrayList<String> result;
|
||||||
ArrayList<ArrayList<String>> multipleResults = new ArrayList<>();
|
ArrayList<ArrayList<String>> multipleResults = new ArrayList<>();
|
||||||
|
|
||||||
/* DEBUG */
|
/* DEBUG
|
||||||
|
|
||||||
NaivLeastMedianOfSquaresEstimator l = new NaivLeastMedianOfSquaresEstimator(arrangement.getLines());
|
NaivLeastMedianOfSquaresEstimator l = new NaivLeastMedianOfSquaresEstimator(arrangement.getLines());
|
||||||
NaivRepeatedMedianEstimator r = new NaivRepeatedMedianEstimator(arrangement.getLines());
|
NaivRepeatedMedianEstimator r = new NaivRepeatedMedianEstimator(arrangement.getLines());
|
||||||
NaivTheilSenEstimator t = new NaivTheilSenEstimator(arrangement.getLines());
|
NaivTheilSenEstimator t = new NaivTheilSenEstimator(arrangement.getLines());
|
||||||
|
@ -113,9 +112,8 @@ public class EvaluateAlgorithms extends Observable {
|
||||||
r.run();
|
r.run();
|
||||||
t.run();
|
t.run();
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
DEBUG */
|
||||||
|
|
||||||
|
|
||||||
/* DEBUG */
|
|
||||||
startLMS();
|
startLMS();
|
||||||
startRM();
|
startRM();
|
||||||
startTS();
|
startTS();
|
||||||
|
@ -123,17 +121,52 @@ public class EvaluateAlgorithms extends Observable {
|
||||||
case 0:
|
case 0:
|
||||||
//der alg der gewählt wurde
|
//der alg der gewählt wurde
|
||||||
if (alg == 0) {
|
if (alg == 0) {
|
||||||
|
final double[] m = new double[1];
|
||||||
|
final double[] b = new double[1];
|
||||||
|
Thread t = new Thread(() -> {
|
||||||
|
NaivLeastMedianOfSquaresEstimator l = new NaivLeastMedianOfSquaresEstimator(arrangement.getLines());
|
||||||
|
l.run();
|
||||||
|
m[0] = l.getM();
|
||||||
|
b[0] = l.getB();
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
startLMS();
|
startLMS();
|
||||||
|
t.join();
|
||||||
|
|
||||||
result = getScaleDependentMeasure(arrangement.getLines(), lmsRes[0], lmsRes[1]);
|
result = getScaleDependentMeasure(arrangement.getLines(), lmsRes[0], lmsRes[1]);
|
||||||
sendPlotLineResults(lmsRes, 0);
|
result.addAll(getScaledErrorBasedMeasure(arrangement.getLines(), lmsRes[0], lmsRes[1],m[0], b[0]));
|
||||||
|
Double[] tmp = {lmsRes[0], lmsRes[1],m[0], b[0]};
|
||||||
|
sendPlotLineResults(tmp, 0);
|
||||||
} else if (alg == 1) {
|
} else if (alg == 1) {
|
||||||
|
final double[] m = new double[1];
|
||||||
|
final double[] b = new double[1];
|
||||||
|
Thread t = new Thread(() -> {
|
||||||
|
NaivRepeatedMedianEstimator r = new NaivRepeatedMedianEstimator(arrangement.getLines());
|
||||||
|
r.run();
|
||||||
|
m[0] = r.getM();
|
||||||
|
b[0] = r.getB();
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
startRM();
|
startRM();
|
||||||
result = getScaleDependentMeasure(arrangement.getLines(), rmRes[0], rmRes[1]);
|
result = getScaleDependentMeasure(arrangement.getLines(), rmRes[0], rmRes[1]);
|
||||||
sendPlotLineResults(rmRes, 1);
|
result.addAll(getScaledErrorBasedMeasure(arrangement.getLines(), rmRes[0], rmRes[1],m[0], b[0]));
|
||||||
|
Double[] tmp = {rmRes[0], rmRes[1],m[0], b[0]};
|
||||||
|
sendPlotLineResults(tmp, 1);
|
||||||
} else {
|
} else {
|
||||||
|
final double[] m = new double[1];
|
||||||
|
final double[] b = new double[1];
|
||||||
|
Thread t = new Thread(() -> {
|
||||||
|
NaivTheilSenEstimator ts = new NaivTheilSenEstimator(arrangement.getLines());
|
||||||
|
ts.run();
|
||||||
|
m[0] = ts.getM();
|
||||||
|
b[0] = ts.getB();
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
startTS();
|
startTS();
|
||||||
result = getScaleDependentMeasure(arrangement.getLines(), tsRes[0], tsRes[1]);
|
result = getScaleDependentMeasure(arrangement.getLines(), tsRes[0], tsRes[1]);
|
||||||
sendPlotLineResults(tsRes, 2);
|
result.addAll(getScaledErrorBasedMeasure(arrangement.getLines(), tsRes[0], tsRes[1],m[0], b[0]));
|
||||||
|
Double[] tmp = {tsRes[0], tsRes[1],m[0], b[0]};
|
||||||
|
sendPlotLineResults(tmp, 2);
|
||||||
}
|
}
|
||||||
sendTableApproximationTypes();
|
sendTableApproximationTypes();
|
||||||
sendTableApproximationData(result, alg);
|
sendTableApproximationData(result, alg);
|
||||||
|
@ -265,9 +298,9 @@ public class EvaluateAlgorithms extends Observable {
|
||||||
lines.add("lines-res");
|
lines.add("lines-res");
|
||||||
lines.add("" + alg);
|
lines.add("" + alg);
|
||||||
//lms res
|
//lms res
|
||||||
lines.add(res[0] + "");
|
for (int i=0;i<res.length;i++) {
|
||||||
lines.add(res[1] + "");
|
lines.add(res[i] + "");
|
||||||
|
}
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(lines.stream().toArray(String[]::new));
|
notifyObservers(lines.stream().toArray(String[]::new));
|
||||||
}
|
}
|
||||||
|
@ -325,6 +358,7 @@ public class EvaluateAlgorithms extends Observable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<String> getScaleDependentMeasure(final LinkedList<Line> lines, final Double m, final Double b) {
|
public ArrayList<String> getScaleDependentMeasure(final LinkedList<Line> lines, final Double m, final Double b) {
|
||||||
ScaleDependentMeasure scaleDependentMeasure = new ScaleDependentMeasure(lines, m, b);
|
ScaleDependentMeasure scaleDependentMeasure = new ScaleDependentMeasure(lines, m, b);
|
||||||
ArrayList<String> ret = new ArrayList<>();
|
ArrayList<String> ret = new ArrayList<>();
|
||||||
|
@ -350,15 +384,15 @@ public class EvaluateAlgorithms extends Observable {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getScaledErrorBasedMeasure(final LinkedList<Line> lines, final Double m, final Double b) {
|
public ArrayList<String> getScaledErrorBasedMeasure(final LinkedList<Line> lines, final Double m, final Double b, final Double nM, final Double nB) {
|
||||||
ScaledErrorBasedMeasure scaledErrorBasedMeasure = new ScaledErrorBasedMeasure(lines, m, b);
|
ScaledErrorBasedMeasure scaledErrorBasedMeasure = new ScaledErrorBasedMeasure(lines, m, b, nM, nB);
|
||||||
ArrayList<String> ret = new ArrayList<>();
|
ArrayList<String> ret = new ArrayList<>();
|
||||||
ret.add(scaledErrorBasedMeasure.mse().toString());
|
ret.add(scaledErrorBasedMeasure.mse().toString());
|
||||||
ret.add(scaledErrorBasedMeasure.rmse().toString());
|
ret.add(scaledErrorBasedMeasure.rmse().toString());
|
||||||
ret.add(scaledErrorBasedMeasure.mae().toString());
|
ret.add(scaledErrorBasedMeasure.mae().toString());
|
||||||
ret.add(scaledErrorBasedMeasure.mdae().toString());
|
ret.add(scaledErrorBasedMeasure.mdae().toString());
|
||||||
ret.add(m.toString());
|
ret.add(nM.toString());
|
||||||
ret.add(b.toString());
|
ret.add(nB.toString());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,25 +16,29 @@ import java.util.LinkedList;
|
||||||
public class ScaledErrorBasedMeasure {
|
public class ScaledErrorBasedMeasure {
|
||||||
|
|
||||||
|
|
||||||
|
private ArrayList<Double> sampsonError;
|
||||||
|
private ArrayList<Double> naivSampsonError;
|
||||||
private ArrayList<Double> scaledError;
|
private ArrayList<Double> scaledError;
|
||||||
|
|
||||||
public ScaledErrorBasedMeasure(final LinkedList<Line> lines, Double m, Double b) {
|
public ScaledErrorBasedMeasure(final LinkedList<Line> lines, Double m, Double b, Double naivSlope, Double naivInterception) {
|
||||||
//Liste mit den Fehler zu jedem Punkt
|
|
||||||
ArrayList<Double> sampson = new ArrayList<>();
|
this.sampsonError = new ArrayList<>();
|
||||||
|
this.naivSampsonError = new ArrayList<>();
|
||||||
|
this.scaledError = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
Double denum = 0d;
|
for (Line line : lines) {
|
||||||
for (int i = 2; i < lines.size(); i++) {
|
Double e = Math.pow(naivSlope * line.getM() - line.getB() + naivInterception, 2) / (Math.pow(naivSlope, 2) + 1);
|
||||||
denum += Math.abs(lines.get(i).getM() - lines.get(i - 1).getM());
|
naivSampsonError.add(e);
|
||||||
}
|
}
|
||||||
denum *= 1 / (lines.size() - 1);
|
|
||||||
|
|
||||||
for (Line line : lines) {
|
for (Line line : lines) {
|
||||||
Double e = Math.pow(m * line.getM() - line.getB() + b, 2) / (Math.pow(m, 2) + 1);
|
Double e = Math.pow(m * line.getM() - line.getB() + b, 2) / (Math.pow(m, 2) + 1);
|
||||||
sampson.add(e);
|
sampsonError.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
Double val = e / (denum);
|
for (int i=0;i<sampsonError.size();i++){
|
||||||
scaledError.add(val);
|
scaledError.add(sampsonError.get(i) / naivSampsonError.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -303,10 +303,15 @@ public class EvaluationPanel extends JPanel {
|
||||||
String[] castedResults = Arrays.copyOf(results, results.length, String[].class);
|
String[] castedResults = Arrays.copyOf(results, results.length, String[].class);
|
||||||
Paint[] color = {Color.ORANGE, Color.RED, Color.MAGENTA};
|
Paint[] color = {Color.ORANGE, Color.RED, Color.MAGENTA};
|
||||||
String[] name = {"LMS", "RM", "TS"};
|
String[] name = {"LMS", "RM", "TS"};
|
||||||
|
String[] nName = {"Brute-force LMS", "Brute-force RM", "Brute-force TS"};
|
||||||
|
|
||||||
Double m = Double.parseDouble(castedResults[0]);
|
Double m = Double.parseDouble(castedResults[0]);
|
||||||
Double b = Double.parseDouble(castedResults[1]);
|
Double b = Double.parseDouble(castedResults[1]);
|
||||||
plotPanel.addLineToPlot(m, b, color[alg], name[alg]);
|
plotPanel.addLineToPlot(m, b, color[alg], name[alg]);
|
||||||
|
|
||||||
|
Double nM = Double.parseDouble(castedResults[2]);
|
||||||
|
Double nB = Double.parseDouble(castedResults[3]);
|
||||||
|
plotPanel.addLineToPlot(nM, nB, Color.BLACK, nName[alg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDualPoints(LinkedList<Line> points) {
|
public void setDualPoints(LinkedList<Line> points) {
|
||||||
|
|
Loading…
Reference in New Issue