From 9f4d7e48fd0ec83646eafd24d718ddf46360db90 Mon Sep 17 00:00:00 2001 From: Panagiotis Liakos Date: Wed, 27 Jul 2022 21:33:32 +0300 Subject: [PATCH] connected swing --- .../chimp/DecompressorSwingFilter.java | 7 +- .../aueb/delorean/chimp/LinearFunction.java | 4 +- .../java/gr/aueb/delorean/chimp/Point.java | 14 +- .../gr/aueb/delorean/chimp/SwingFilter.java | 239 +++++------------- .../delorean/chimp/SwingFilterDisjoint.java | 158 ++++++++++++ .../gr/aueb/delorean/chimp/SwingSegment.java | 37 +++ .../delorean/chimp/benchmarks/TestLossy.java | 17 +- 7 files changed, 278 insertions(+), 198 deletions(-) create mode 100644 src/main/java/gr/aueb/delorean/chimp/SwingFilterDisjoint.java create mode 100644 src/main/java/gr/aueb/delorean/chimp/SwingSegment.java diff --git a/src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilter.java b/src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilter.java index ec19bfa..c2df276 100644 --- a/src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilter.java +++ b/src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilter.java @@ -2,8 +2,6 @@ import java.util.List; -import gr.aueb.delorean.chimp.SwingFilter.SwingSegment; - public class DecompressorSwingFilter { private List swingSegments; @@ -32,13 +30,14 @@ public Float readValue() { private void next() { SwingSegment swingSegment = swingSegments.get(currentElement); if (swingSegment.getFinalTimestamp() >= (swingSegment.getInitialTimestamp() + currentTimestampOffset)) { - storedVal = swingSegment.getLine().get(swingSegment.getInitialTimestamp() + currentTimestampOffset); + storedVal = (float) swingSegment.getLine().get(swingSegment.getInitialTimestamp() + currentTimestampOffset); +// System.out.println("LineDec: " + swingSegment.getLine() + "\t" + (swingSegment.getInitialTimestamp() + currentTimestampOffset) + "\t" + storedVal); currentTimestampOffset++; } else { currentElement++; if (currentElement < swingSegments.size()) { swingSegment = swingSegments.get(currentElement); - storedVal = swingSegment.getLine().get(swingSegment.getInitialTimestamp()); + storedVal = (float) swingSegment.getLine().get(swingSegment.getInitialTimestamp()); currentTimestampOffset = 1; } else { diff --git a/src/main/java/gr/aueb/delorean/chimp/LinearFunction.java b/src/main/java/gr/aueb/delorean/chimp/LinearFunction.java index b59363f..1d4597c 100644 --- a/src/main/java/gr/aueb/delorean/chimp/LinearFunction.java +++ b/src/main/java/gr/aueb/delorean/chimp/LinearFunction.java @@ -17,7 +17,7 @@ public class LinearFunction { /** Constructors **/ - public LinearFunction(long ts, float vs, long te, float ve) { + public LinearFunction(long ts, double vs, long te, double ve) { this.a = (ve - vs) / (te - ts); this.b = vs - a * ts; } @@ -32,6 +32,6 @@ public float get(long ts) { @Override public String toString() { - return String.format("%fx+%f", a, b); + return String.format("%.15fx+%f", a, b); } } diff --git a/src/main/java/gr/aueb/delorean/chimp/Point.java b/src/main/java/gr/aueb/delorean/chimp/Point.java index a8ad536..0c82cec 100644 --- a/src/main/java/gr/aueb/delorean/chimp/Point.java +++ b/src/main/java/gr/aueb/delorean/chimp/Point.java @@ -3,19 +3,23 @@ public class Point { private final long timestamp; - private final float value; - + private float value; + public Point(long timestamp, float value) { this.timestamp = timestamp; this.value = value; } - + public long getTimestamp() { return timestamp; } - + public float getValue() { return value; } - + + public void setValue(float value) { + this.value = value; + } + } diff --git a/src/main/java/gr/aueb/delorean/chimp/SwingFilter.java b/src/main/java/gr/aueb/delorean/chimp/SwingFilter.java index 031b340..892d807 100644 --- a/src/main/java/gr/aueb/delorean/chimp/SwingFilter.java +++ b/src/main/java/gr/aueb/delorean/chimp/SwingFilter.java @@ -2,187 +2,68 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; public class SwingFilter { - - - public List filter(Collection points, float epsilon) { - - List swingSegments = new ArrayList<>(); - - Point first = null; - LinearFunction uiOld = null; - LinearFunction liOld = null; - Point last = null; - - for (Point point : points) { - last = point; - if (first == null) { - first = point; - } - 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() + " : " + 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); - swingSegments.add(new SwingSegment(first.getTimestamp(), last.getTimestamp(), line)); - } 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; - } - - - 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); -3. Start a new filtering interval with ui1 passing through (t1,X1) -and (t2,X2+Vd(i,εi)); and li1 passing through (t1,X1) and (t2,X2- -Vd(i,εi)), for every dimension xi, i∈[1,d]; -4. set k = 1; -//main loop -5. while (true) -6. (tj,Xj) = getNext(); -7. if (tj,Xj) is null or (tj,Xj) is more than εi above uik or below lik -in the xi dimension for any i∈[1,d] //recording mechanism -8. Make a new recording: (tk,Xk), such that tk=tj-1, xik falls -between uik and lik, and xik minimizes Eik, for every -dimension xi, i∈[1,d]; -9. Start a new filtering interval with ui(k+1) passing through -(tk,Xk) and (tj,Xj+Vd(i,εi)); and li(k+1) passing through (tk,xk) -and (tj,Xj-Vd(i,εi)); -10. set k = k+1; -11. if (tj,Xj) is null //end of signal -12. return; -13. else //filtering mechanism -14. for each dimension xi, i∈[1,d] -15. if (tj,Xj) falls more than εi above lik in the xi dimension -16. “Swing up” lik such that it passes through (tk,xk) and -(tj,Xj-Vd(i,εi)); -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 - polynomial_up, polynomial_down = None, None - for timestamp, value in ts.items(): - if polynomial_up is not None and polynomial_down is not None: - up_val = value + epsilon - down_val = value - epsilon - up_lim = polynomial_up(timestamp) - down_lim = polynomial_down(timestamp) - - if (not math.isclose(up_val, up_lim) and up_val > up_lim and not math.isclose(down_val, up_lim) and down_val > up_lim) or\ - (not math.isclose(up_val, down_lim) and up_val < down_lim and not math.isclose(down_val, down_lim) and down_val < down_lim): - lines.append([line_first_timestamp, np.polyfit(x=[line_first_timestamp, previous_timestamp], y=[line_first_value, previous_value], deg=1)]) - line_first_timestamp, line_first_value = None, None - coefficients_up, coefficients_down = None, None - polynomial_up, polynomial_down = None, None - - if line_first_timestamp is None and line_first_value is None: - line_first_timestamp, line_first_value = timestamp, value - continue - - coefficients_up_temp = np.polyfit(x=[line_first_timestamp, timestamp], y=[line_first_value, value + epsilon], deg=1) - coefficients_down_temp = np.polyfit(x=[line_first_timestamp, timestamp], y=[line_first_value, value - epsilon], deg=1) - polynomial_up_temp = np.poly1d(coefficients_up_temp) - polynomial_down_temp = np.poly1d(coefficients_down_temp) - - if coefficients_up is None or coefficients_down is None: - coefficients_up = coefficients_up_temp - coefficients_down = coefficients_down_temp - polynomial_up = np.poly1d(coefficients_up) - polynomial_down = np.poly1d(coefficients_down) - if polynomial_up_temp(timestamp) < polynomial_up(timestamp): - coefficients_up = coefficients_up_temp - polynomial_up = np.poly1d(coefficients_up) - if polynomial_down_temp(timestamp) > polynomial_down(timestamp): - coefficients_down = coefficients_down_temp - polynomial_down = np.poly1d(coefficients_down) - previous_timestamp = timestamp - previous_value = value - - # 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)]) - - * - * */ - + public List filter(Collection points, float epsilon) { + + List swingSegments = new ArrayList<>(); + + Point first = null; + LinearFunction uiOld = null; + LinearFunction liOld = null; + + Iterator iterator = points.iterator(); + + Point previous = first = iterator.next(); + Point current = iterator.next(); + uiOld = new LinearFunction(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), + current.getValue() + epsilon); + liOld = new LinearFunction(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), + current.getValue() - epsilon); + + while (true) { + if (!iterator.hasNext()) { + if (uiOld != null && liOld != null) { +// System.out.println("need to start new line"); + LinearFunction line = new LinearFunction(first.getTimestamp(), first.getValue(), + current.getTimestamp(), + (uiOld.get(current.getTimestamp()) + liOld.get(current.getTimestamp())) / 2); + swingSegments.add(new SwingSegment(first.getTimestamp(), current.getTimestamp(), line)); + } else { + swingSegments.add(new SwingSegment(first.getTimestamp(), first.getTimestamp(), first.getValue(), first.getValue())); + } + return swingSegments; + } + previous = current; + current = iterator.next(); +// System.out.println("Points: " + first.getValue() + "\t" + previous.getValue() + "\t" + current.getValue() + "\t" + uiOld + "\t" + liOld); + if (uiOld.get(current.getTimestamp()) < current.getValue() - epsilon + || liOld.get(current.getTimestamp()) > current.getValue() + epsilon) { +// System.out.println("need to start new line: " + first.getValue() + "\t" + (uiOld.get(previous.getTimestamp()) + liOld.get(previous.getTimestamp())) / 2 + "\t" + line + "\t" + previous.getTimestamp()); + swingSegments.add(new SwingSegment(first.getTimestamp(), previous.getTimestamp() - 1, first.getValue(), (uiOld.get(previous.getTimestamp()) + liOld.get(previous.getTimestamp())) / 2)); +// swingSegments.add(new SwingSegment(first.getTimestamp(), previous.getTimestamp() - 1, first.getValue(), (uiOld.get(previous.getTimestamp()) + liOld.get(previous.getTimestamp())) / 2)); + previous = first = new Point(previous.getTimestamp(), (uiOld.get(previous.getTimestamp()) + liOld.get(previous.getTimestamp())) / 2); + uiOld = new LinearFunction(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), + current.getValue() + epsilon); + liOld = new LinearFunction(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), + current.getValue() - epsilon); +// System.out.println("New range: " + current.getValue() + "\t" + current.getTimestamp() + "\t" + uiOld + "\t" + liOld); + } else { + LinearFunction uiNew = new LinearFunction(first.getTimestamp(), first.getValue(), + current.getTimestamp(), current.getValue() + epsilon); + LinearFunction liNew = new LinearFunction(first.getTimestamp(), first.getValue(), + current.getTimestamp(), current.getValue() - epsilon); +// System.out.println("Cand: " + current.getValue() + "\t" + current.getTimestamp() + "\t" + uiNew + "\t" + liNew); + if (uiOld == null || uiOld.get(current.getTimestamp()) > uiNew.get(current.getTimestamp())) { + uiOld = uiNew; + } + if (liOld == null || liOld.get(current.getTimestamp()) < liNew.get(current.getTimestamp())) { + liOld = liNew; + } + } + } + } } diff --git a/src/main/java/gr/aueb/delorean/chimp/SwingFilterDisjoint.java b/src/main/java/gr/aueb/delorean/chimp/SwingFilterDisjoint.java new file mode 100644 index 0000000..a7cb8d7 --- /dev/null +++ b/src/main/java/gr/aueb/delorean/chimp/SwingFilterDisjoint.java @@ -0,0 +1,158 @@ +package gr.aueb.delorean.chimp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class SwingFilterDisjoint { + + + + public List filter(Collection points, float epsilon) { + + List swingSegments = new ArrayList<>(); + + Point first = null; + LinearFunction uiOld = null; + LinearFunction liOld = null; + Point last = null; + + for (Point point : points) { + last = point; + if (first == null) { + first = point; + } + 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() + " : " + 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); + swingSegments.add(new SwingSegment(first.getTimestamp(), last.getTimestamp(), line)); + } 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; + } + + + + /** + * + * + * // initialization +1. (t1,X1) = getNext();(t2,X2) = getNext(); +2. Make a recording: (t0’,X0’) = (t1,X1); +3. Start a new filtering interval with ui1 passing through (t1,X1) +and (t2,X2+Vd(i,εi)); and li1 passing through (t1,X1) and (t2,X2- +Vd(i,εi)), for every dimension xi, i∈[1,d]; +4. set k = 1; +//main loop +5. while (true) +6. (tj,Xj) = getNext(); +7. if (tj,Xj) is null or (tj,Xj) is more than εi above uik or below lik +in the xi dimension for any i∈[1,d] //recording mechanism +8. Make a new recording: (tk,Xk), such that tk=tj-1, xik falls +between uik and lik, and xik minimizes Eik, for every +dimension xi, i∈[1,d]; +9. Start a new filtering interval with ui(k+1) passing through +(tk,Xk) and (tj,Xj+Vd(i,εi)); and li(k+1) passing through (tk,xk) +and (tj,Xj-Vd(i,εi)); +10. set k = k+1; +11. if (tj,Xj) is null //end of signal +12. return; +13. else //filtering mechanism +14. for each dimension xi, i∈[1,d] +15. if (tj,Xj) falls more than εi above lik in the xi dimension +16. “Swing up” lik such that it passes through (tk,xk) and +(tj,Xj-Vd(i,εi)); +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 + polynomial_up, polynomial_down = None, None + for timestamp, value in ts.items(): + if polynomial_up is not None and polynomial_down is not None: + up_val = value + epsilon + down_val = value - epsilon + up_lim = polynomial_up(timestamp) + down_lim = polynomial_down(timestamp) + + if (not math.isclose(up_val, up_lim) and up_val > up_lim and not math.isclose(down_val, up_lim) and down_val > up_lim) or\ + (not math.isclose(up_val, down_lim) and up_val < down_lim and not math.isclose(down_val, down_lim) and down_val < down_lim): + lines.append([line_first_timestamp, np.polyfit(x=[line_first_timestamp, previous_timestamp], y=[line_first_value, previous_value], deg=1)]) + line_first_timestamp, line_first_value = None, None + coefficients_up, coefficients_down = None, None + polynomial_up, polynomial_down = None, None + + if line_first_timestamp is None and line_first_value is None: + line_first_timestamp, line_first_value = timestamp, value + continue + + coefficients_up_temp = np.polyfit(x=[line_first_timestamp, timestamp], y=[line_first_value, value + epsilon], deg=1) + coefficients_down_temp = np.polyfit(x=[line_first_timestamp, timestamp], y=[line_first_value, value - epsilon], deg=1) + polynomial_up_temp = np.poly1d(coefficients_up_temp) + polynomial_down_temp = np.poly1d(coefficients_down_temp) + + if coefficients_up is None or coefficients_down is None: + coefficients_up = coefficients_up_temp + coefficients_down = coefficients_down_temp + polynomial_up = np.poly1d(coefficients_up) + polynomial_down = np.poly1d(coefficients_down) + if polynomial_up_temp(timestamp) < polynomial_up(timestamp): + coefficients_up = coefficients_up_temp + polynomial_up = np.poly1d(coefficients_up) + if polynomial_down_temp(timestamp) > polynomial_down(timestamp): + coefficients_down = coefficients_down_temp + polynomial_down = np.poly1d(coefficients_down) + previous_timestamp = timestamp + previous_value = value + + # 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)]) + + * + * */ + +} diff --git a/src/main/java/gr/aueb/delorean/chimp/SwingSegment.java b/src/main/java/gr/aueb/delorean/chimp/SwingSegment.java new file mode 100644 index 0000000..af3d1c2 --- /dev/null +++ b/src/main/java/gr/aueb/delorean/chimp/SwingSegment.java @@ -0,0 +1,37 @@ +package gr.aueb.delorean.chimp; +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 SwingSegment(long initialTimestamp, long finalTimestamp, float first, float last) { + this.initialTimestamp = initialTimestamp; + this.finalTimestamp = finalTimestamp; + this.line = new LinearFunction(initialTimestamp, first, finalTimestamp + 1, last); + } + + 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()); + } + +} \ No newline at end of file diff --git a/src/test/java/gr/aueb/delorean/chimp/benchmarks/TestLossy.java b/src/test/java/gr/aueb/delorean/chimp/benchmarks/TestLossy.java index 8a0c6c9..851be21 100644 --- a/src/test/java/gr/aueb/delorean/chimp/benchmarks/TestLossy.java +++ b/src/test/java/gr/aueb/delorean/chimp/benchmarks/TestLossy.java @@ -16,7 +16,7 @@ import gr.aueb.delorean.chimp.PmcMR.Constant; import gr.aueb.delorean.chimp.Point; import gr.aueb.delorean.chimp.SwingFilter; -import gr.aueb.delorean.chimp.SwingFilter.SwingSegment; +import gr.aueb.delorean.chimp.SwingSegment; /** * These are generic tests to test that input matches the output after compression + decompression cycle, using @@ -58,7 +58,7 @@ public void testPmcMr() throws IOException { List constants = new PmcMR().filter(points, ((float) Math.pow(2, logOfError))); encodingDuration += System.nanoTime() - start; - totalStdev += TimeseriesFileReader.sd(points.stream().map(l -> l.getValue()).collect(Collectors.toList())); + totalStdev += TimeseriesFileReader.sd(points.stream().map(l -> (float) l.getValue()).collect(Collectors.toList())); totalBlocks += 1; totalSize += constants.size() * 2 * 32; @@ -75,7 +75,7 @@ public void testPmcMr() throws IOException { } } System.out.println(String.format( - "Swing: %s - Bits/value: %.2f, Compression time per block: %.2f, Decompression time per block: %.2f, Error: %.8f, STDEV: %.2f, Error/STDEV: %.2f, Range: %.2f (%.2f)", + "PMC-MR: %s - Bits/value: %.2f, Compression time per block: %.2f, Decompression time per block: %.2f, Error: %.8f, STDEV: %.2f, Error/STDEV: %.2f, Range: %.2f (%.2f)", filename, totalSize / (totalBlocks * TimeseriesFileReader.DEFAULT_BLOCK_SIZE), encodingDuration / totalBlocks, decodingDuration / totalBlocks, maxPrecisionError, totalStdev / totalBlocks, maxPrecisionError / (totalStdev / totalBlocks), (maxValue - minValue), 100* maxPrecisionError / (maxValue - minValue))); @@ -94,7 +94,7 @@ public void testSwing() throws IOException { double minValue = Double.MAX_VALUE; int timestamp = 0; double maxPrecisionError = 0; - long totalSize = 0; + long totalSize = 32; float totalBlocks = 0; double totalStdev = 0D; long encodingDuration = 0; @@ -106,12 +106,12 @@ public void testSwing() throws IOException { } long start = System.nanoTime(); - List constants = new SwingFilter().filter(points, ((float) Math.pow(2, logOfError))); + List constants = new SwingFilter().filter(points, (float) (Math.pow(2, logOfError))); encodingDuration += System.nanoTime() - start; - totalStdev += TimeseriesFileReader.sd(points.stream().map(l -> l.getValue()).collect(Collectors.toList())); + totalStdev += TimeseriesFileReader.sd(points.stream().map(l -> (float) l.getValue()).collect(Collectors.toList())); totalBlocks += 1; - totalSize += constants.size() * ( 2 * 64 + 32); + totalSize += constants.size() * (2 * 32); DecompressorSwingFilter d = new DecompressorSwingFilter(constants); for (Double value : values) { @@ -122,7 +122,8 @@ public void testSwing() throws IOException { decodingDuration += System.nanoTime() - start; double precisionError = Math.abs(value.doubleValue() - decompressedValue); maxPrecisionError = (precisionError > maxPrecisionError) ? precisionError : maxPrecisionError; - assertEquals(value.floatValue(), decompressedValue.floatValue(), ((float) Math.pow(2, logOfError)), "Value did not match"); +// System.out.println(value.floatValue() + "\t" + decompressedValue.floatValue()); + assertEquals(value.floatValue(), decompressedValue.floatValue(), ((float) Math.pow(2, logOfError)+0.00001), "Value did not match"); } } System.out.println(String.format(