Skip to content

Commit

Permalink
PCA, improve dbl click variable selection
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenz Gerber <[email protected]>
  • Loading branch information
lorenzgerber committed Nov 15, 2024
1 parent faaefa2 commit 187d68e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,15 @@ public void handleEvent(BaseChart baseChart, Event event) {
* Determine the x|y coordinates.
*/
Rectangle rectangle = baseChart.getPlotArea().getBounds();
int x = event.x;
int y = event.y;
int width = rectangle.width;
int height = rectangle.height;
double x = event.x;
double y = event.y;
double width = rectangle.width;
double height = rectangle.height;
/*
* Calculate the selected point.
*/
Range rangeX = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS).getRange();
Range rangeY = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).getRange();
double pX = rangeX.lower + (rangeX.upper - rangeX.lower) * ((1.0d / width) * x);
double pY = rangeY.lower + (rangeY.upper - rangeY.lower) * ((1.0d / height) * y);
/*
* Map the result deltas.
*/
Expand All @@ -346,15 +344,27 @@ public void handleEvent(BaseChart baseChart, Event event) {
for(int i = 0; i < resultsPCA.getExtractedVariables().size(); i++) {
double[] variableLoading = getVariableLoading(resultsPCA, i);
IPoint pointResult = getPoint(variableLoading, pcX, pcY, i);
double deltaX = Math.abs(pointResult.getX() - pX);
double deltaY = Math.abs(pointResult.getY() + pY);
featureDeltas.add(new FeatureDelta(evaluationPCA.getFeatureDataMatrix().getFeatures().get(i), deltaX, deltaY));
if(pointResult.getX() > rangeX.lower && pointResult.getX() < rangeX.upper && pointResult.getY() > rangeY.lower && pointResult.getY() < rangeY.upper) {
double deltaX = 0;
double deltaY = 0;
if(rangeX.upper < 0 || rangeX.lower > 0) {
deltaX = Math.abs(1.00 / Math.abs((Math.abs(rangeX.upper) - Math.abs(rangeX.lower))) * (pointResult.getX() - rangeX.lower) * width - x);
} else {
deltaX = Math.abs(1.00 / (rangeX.upper - rangeX.lower) * (pointResult.getX() - rangeX.lower) * width - x);
}
if(rangeY.upper < 0 || rangeY.lower > 0) {
deltaY = Math.abs(1.00 / Math.abs((Math.abs(rangeY.upper) - Math.abs(rangeY.lower))) * (pointResult.getY() - rangeY.lower) * height - (height - y));
} else {
deltaY = Math.abs(1.00 / (rangeY.upper - rangeY.lower) * (pointResult.getY() - rangeY.lower) * height - (height - y));
}
featureDeltas.add(new FeatureDelta(evaluationPCA.getFeatureDataMatrix().getFeatures().get(i), deltaX, deltaY));
}
}
/*
* Get the closest result.
*/
if(!featureDeltas.isEmpty()) {
Collections.sort(featureDeltas, Comparator.comparing(FeatureDelta::getDeltaX).thenComparing(FeatureDelta::getDeltaY));
Collections.sort(featureDeltas, Comparator.comparing(FeatureDelta::getDistance));
FeatureDelta featureDelta = featureDeltas.get(0);
List<Feature> featureList = new ArrayList<>();
featureList.add(featureDelta.getFeature());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class FeatureDelta {
private Feature feature = null;
private double deltaX = 0;
private double deltaY = 0;
private double distance = 0;

public FeatureDelta(Feature feature, double deltaX, double deltaY) {

this.feature = feature;
this.deltaX = deltaX;
this.deltaY = deltaY;
this.deltaX = Math.abs(deltaX);
this.deltaY = Math.abs(deltaY);
this.distance = Math.sqrt(Math.pow(this.deltaX, 2) + Math.pow(this.deltaY, 2));
}

public Feature getFeature() {
Expand All @@ -41,6 +43,11 @@ public double getDeltaY() {
return deltaY;
}

public double getDistance() {

return distance;
}

@Override
public int hashCode() {

Expand All @@ -63,6 +70,6 @@ public boolean equals(Object obj) {
@Override
public String toString() {

return "FeatureDelta [featurePCA=" + feature + ", deltaX=" + deltaX + ", deltaY=" + deltaY + "]";
return "FeatureDelta [featurePCA=" + feature + ", deltaX=" + deltaX + ", deltaY=" + deltaY + ", distance=" + distance + "]";
}
}

0 comments on commit 187d68e

Please sign in to comment.