Skip to content

Commit

Permalink
work on swing filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Panagiotis Liakos committed Apr 1, 2022
1 parent 909e6b0 commit b42cbc3
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/main/java/gr/aueb/compression/gorilla/LinearFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public float get(long ts) {

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

@Override
public String toString() {
return String.format("%fx+%f", a, b);
}
}
42 changes: 22 additions & 20 deletions src/main/java/gr/aueb/compression/gorilla/SwingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,35 @@ 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())) {
System.out.println("need to start new line");
LinearFunction line = new LinearFunction(first.getTimestamp(), first.getValue(), point.getTimestamp(), (uiOld.get(point.getTimestamp()) + liOld.get(point.getTimestamp()) / 2));
swingSegments.add(new SwingSegment(first.getTimestamp(), point.getTimestamp(), line));
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());
swingSegments.add(new SwingSegment(first.getTimestamp(), point.getTimestamp() - 1, line));
uiOld = null;
liOld = null;
}

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");
}
if (liOld == null || liOld.get(point.getTimestamp()) < liNew.get(point.getTimestamp())) {
liOld = liNew;
System.out.println("resetting lower");
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 && (uiOld.get(last.getTimestamp()) < last.getValue() || liOld.get(last.getTimestamp()) > last.getValue())) {
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));
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);
swingSegments.add(new SwingSegment(first.getTimestamp(), last.getTimestamp(), line));
uiOld = null;
liOld = null;
} else {
LinearFunction line = new LinearFunction(first.getTimestamp(), first.getValue(), first.getTimestamp() + 1, first.getValue());
swingSegments.add(new SwingSegment(first.getTimestamp(), first.getTimestamp(), line));
}

return swingSegments;
Expand Down
83 changes: 81 additions & 2 deletions src/test/java/gr/aueb/compression/gorilla/CompressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,86 @@ public void testPmcMRFilterForBaselTemp() throws IOException {

}

@Test
public void testSwingFilterForBaselWindSpeed() throws IOException {
for (int logOfError = -10; logOfError < 10; logOfError++) {
String filename = "/basel-wind-speed.csv.gz";
TimeseriesFileReader timeseriesFileReader = new TimeseriesFileReader(this.getClass().getResourceAsStream(filename));
Collection<Double> values;
double maxValue = Double.MIN_VALUE;
double minValue = Double.MAX_VALUE;
int timestamp = 0;
double maxPrecisionError = 0;
int totalSize = 0;
float totalBlocks = 0;
while ((values = timeseriesFileReader.nextBlock()) != null) {
Collection<Point> points = new ArrayList<>();
for (Double value : values) {
points.add(new Point(timestamp++, value.floatValue()));
}
List<SwingSegment> segments = new SwingFilter().filter(points, ((float) Math.pow(2, logOfError)));

totalBlocks += 1;
totalSize += segments.size() * 3 * 32;

DecompressorSwingFilter d = new DecompressorSwingFilter(segments);

for(Double value : values) {
maxValue = value > maxValue ? value : maxValue;
minValue = value < minValue ? value : minValue;
Float decompressedValue = d.readValue();
double precisionError = Math.abs(value.doubleValue() - decompressedValue);
maxPrecisionError = (precisionError > maxPrecisionError) ? precisionError : maxPrecisionError;
assertEquals(value.doubleValue(), decompressedValue, Math.pow(2, logOfError + 10), "Value did not match");
}

}
System.out.println(String.format("SwingFilter %s - Size : %d, Bits/value: %.2f, error: %f, Range: %.2f, (%.2f%%)",
filename, totalSize, totalSize / (totalBlocks * TimeseriesFileReader.DEFAULT_BLOCK_SIZE), maxPrecisionError, (maxValue - minValue), 100* maxPrecisionError / (maxValue - minValue)));
}

}

@Test
public void testSwingFilterForBaselTemp() throws IOException {
for (int logOfError = -10; logOfError < 10; logOfError++) {
String filename = "/basel-temp.csv.gz";
TimeseriesFileReader timeseriesFileReader = new TimeseriesFileReader(this.getClass().getResourceAsStream(filename));
Collection<Double> values;
double maxValue = Double.MIN_VALUE;
double minValue = Double.MAX_VALUE;
int timestamp = 0;
double maxPrecisionError = 0;
int totalSize = 0;
float totalBlocks = 0;
while ((values = timeseriesFileReader.nextBlock()) != null) {
Collection<Point> points = new ArrayList<>();
for (Double value : values) {
points.add(new Point(timestamp++, value.floatValue()));
}
List<SwingSegment> segments = new SwingFilter().filter(points, ((float) Math.pow(2, logOfError)));

totalBlocks += 1;
totalSize += segments.size() * 3 * 32;

DecompressorSwingFilter d = new DecompressorSwingFilter(segments);

for(Double value : values) {
maxValue = value > maxValue ? value : maxValue;
minValue = value < minValue ? value : minValue;
Float decompressedValue = d.readValue();
double precisionError = Math.abs(value.doubleValue() - decompressedValue);
maxPrecisionError = (precisionError > maxPrecisionError) ? precisionError : maxPrecisionError;
assertEquals(value.doubleValue(), decompressedValue, Math.pow(2, logOfError + 6), "Value did not match");
}

}
System.out.println(String.format("SwingFilter %s - Size : %d, Bits/value: %.2f, error: %f, Range: %.2f, (%.2f%%)",
filename, totalSize, totalSize / (totalBlocks * TimeseriesFileReader.DEFAULT_BLOCK_SIZE), maxPrecisionError, (maxValue - minValue), 100* maxPrecisionError / (maxValue - minValue)));
}

}

@Test
public void testSwingFilterSimple() throws IOException {
for (int logOfError = -1; logOfError < 0; logOfError++) {
Expand Down Expand Up @@ -449,10 +529,9 @@ public void testSwingFilterSimple() throws IOException {
Float decompressedValue = d.readValue();
double precisionError = Math.abs(value.doubleValue() - decompressedValue);
maxPrecisionError = (precisionError > maxPrecisionError) ? precisionError : maxPrecisionError;
System.out.println(value.doubleValue() + " " + decompressedValue);
assertEquals(value.doubleValue(), decompressedValue, Math.pow(2, logOfError), "Value did not match");

System.out.println(String.format("Lossy32 %s - Size : %d, Bits/value: %.2f",
System.out.println(String.format("SwingFilter %s - Size : %d, Bits/value: %.2f",
"simple", totalSize, totalSize / (totalBlocks * TimeseriesFileReader.DEFAULT_BLOCK_SIZE)));
}
}
Expand Down

0 comments on commit b42cbc3

Please sign in to comment.