Skip to content

Commit

Permalink
fixed swing accuracy error
Browse files Browse the repository at this point in the history
  • Loading branch information
panagiotisl committed Apr 7, 2022
1 parent b42cbc3 commit fe07fad
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;

import gr.aueb.compression.gorilla.PmcMR.Constant;
import gr.aueb.compression.gorilla.SwingFilter.SwingSegment;

public class DecompressorSwingFilter {
Expand All @@ -12,7 +11,7 @@ public class DecompressorSwingFilter {
private boolean endOfStream = false;
private int currentElement = 0;
private int currentTimestampOffset = 0;

public DecompressorSwingFilter(List<SwingSegment> swingSegments) {
this.swingSegments = swingSegments;
}
Expand Down Expand Up @@ -40,6 +39,7 @@ private void next() {
if (currentElement < swingSegments.size()) {
swingSegment = swingSegments.get(currentElement);
storedVal = swingSegment.getLine().get(swingSegment.getInitialTimestamp());

currentTimestampOffset = 1;
} else {
endOfStream = true;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gr/aueb/compression/gorilla/LinearFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public LinearFunction(long ts, float vs, long te, float ve) {

/** Public Methods **/
public float get(long ts) {
return this.a * ts + this.b;
return (float) (this.a * ts + this.b);
}

/** Instance Variables **/
public final float a, b;
public final double a, b;

@Override
public String toString() {
return String.format("%fx+%f", a, b);
Expand Down
78 changes: 39 additions & 39 deletions src/main/java/gr/aueb/compression/gorilla/SwingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

public class SwingFilter {



public List<SwingSegment> filter(Collection<Point> points, float epsilon) {

List<SwingSegment> swingSegments = new ArrayList<>();

Point first = null;
LinearFunction uiOld = null;
LinearFunction liOld = null;
Point last = null;

for (Point point : points) {
last = point;
if (first == null) {
Expand All @@ -25,27 +25,27 @@ public List<SwingSegment> filter(Collection<Point> points, float epsilon) {
else {
if (uiOld != null && liOld !=null && (uiOld.get(point.getTimestamp()) < point.getValue() || liOld.get(point.getTimestamp()) > point.getValue())) {
LinearFunction line = new LinearFunction(first.getTimestamp(), first.getValue(), point.getTimestamp(), (uiOld.get(point.getTimestamp()) + liOld.get(point.getTimestamp())) / 2);
// System.out.println("need to start new line: " + line.toString());
// System.out.println("need to start new line: " + line.toString() + " : " + first.getTimestamp() + " " + (point.getTimestamp() - 1));
swingSegments.add(new SwingSegment(first.getTimestamp(), point.getTimestamp() - 1, line));
uiOld = null;
liOld = null;
first = point;
} else {
LinearFunction uiNew = new LinearFunction(first.getTimestamp(), first.getValue(), point.getTimestamp(), point.getValue() + epsilon);
LinearFunction liNew = new LinearFunction(first.getTimestamp(), first.getValue(), point.getTimestamp(), point.getValue() - epsilon);

if (uiOld == null || uiOld.get(point.getTimestamp()) > uiNew.get(point.getTimestamp())) {
uiOld = uiNew;
// System.out.println("resetting upper: " + uiOld);
}
if (liOld == null || liOld.get(point.getTimestamp()) < liNew.get(point.getTimestamp())) {
liOld = liNew;
// System.out.println("resetting lower: " + liOld);
}
}
}
}
}

if (uiOld != null && liOld !=null) {
// System.out.println("need to start new line");
LinearFunction line = new LinearFunction(first.getTimestamp(), first.getValue(), last.getTimestamp(), (uiOld.get(last.getTimestamp()) + liOld.get(last.getTimestamp())) / 2);
Expand All @@ -54,45 +54,45 @@ public List<SwingSegment> filter(Collection<Point> points, float epsilon) {
LinearFunction line = new LinearFunction(first.getTimestamp(), first.getValue(), first.getTimestamp() + 1, first.getValue());
swingSegments.add(new SwingSegment(first.getTimestamp(), first.getTimestamp(), line));
}

return swingSegments;
}


public class SwingSegment {

private long initialTimestamp;
private long finalTimestamp;
private LinearFunction line;

public SwingSegment(long initialTimestamp, long finalTimestamp, LinearFunction line) {
this.initialTimestamp = initialTimestamp;
this.finalTimestamp = finalTimestamp;
this.line = line;
}

public long getFinalTimestamp() {
return finalTimestamp;
}

public long getInitialTimestamp() {
return initialTimestamp;
}

public LinearFunction getLine() {
return line;
}

@Override
public String toString() {
return String.format("%d-%d: %f", getInitialTimestamp(), getFinalTimestamp(), getLine());
}

}

/**
*
*
*
* // initialization
1. (t1,X1) = getNext();(t2,X2) = getNext();
2. Make a recording: (t0’,X0’) = (t1,X1);
Expand Down Expand Up @@ -122,22 +122,22 @@ public String toString() {
17. if (tj,Xj) falls more than εi below uik in the xi dimension
18. “Swing down” uik such that it passes through (tk,xk)
and (tj,Xj+Vd(i,εi));
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
lines = []
line_first_timestamp, line_first_value = None, None
coefficients_up, coefficients_down = None, None
Expand Down Expand Up @@ -182,7 +182,7 @@ public String toString() {
# Raises a warning if there is one point only, line_first_timestamp == timestamp
lines.append([line_first_timestamp, np.polyfit(x=[line_first_timestamp, timestamp], y=[line_first_value, value], deg=1)])
*
*
* */

}
Loading

0 comments on commit fe07fad

Please sign in to comment.