This is an automated email from the ASF dual-hosted git repository. leirui pushed a commit to branch research/LTS-visualization in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 658399851f2f1ff239ea0cca809ed2b262e09951 Author: Lei Rui <[email protected]> AuthorDate: Wed Oct 2 20:46:22 2024 +0800 add --- .gitignore | 1 + .../org/apache/iotdb/db/query/simpiece/DWT.java | 9 +- .../{MySample_fsw.java => MySample_dwt.java} | 53 ++++-- ...ample_fsw_full.java => MySample_dwt_full2.java} | 159 +++++++---------- .../iotdb/db/query/simpiece/MySample_fsw.java | 77 +++++++- .../db/query/simpiece/MySample_fsw_full2.java | 198 ++++++++++----------- ...full.java => MySample_fsw_full_deprecated.java} | 96 +++++----- .../db/query/simpiece/MySample_shrinkingcone.java | 81 ++++++++- .../simpiece/MySample_shrinkingcone_full2.java | 193 ++++++++++---------- ...=> MySample_shrinkingcone_full_deprecated.java} | 95 +++++----- .../iotdb/db/query/simpiece/MySample_simpiece.java | 84 ++++++++- .../db/query/simpiece/MySample_simpiece_full2.java | 179 +++++++++---------- ...java => MySample_simpiece_full_deprecated.java} | 53 +++--- .../iotdb/db/query/simpiece/TimeSeriesReader.java | 4 +- .../transforms/AncientEgyptianDecomposition.java | 10 +- 15 files changed, 762 insertions(+), 530 deletions(-) diff --git a/.gitignore b/.gitignore index 61879eebd8b..0ef69acceab 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ src/main/resources/metadata/mlog.txt tsfile-jdbc/src/main/resources/output/queryRes.csv *.txt +*.csv *.gz *.tar.gz diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/DWT.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/DWT.java index 9c50376892c..32d5d73c7ad 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/DWT.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/DWT.java @@ -20,7 +20,9 @@ package org.apache.iotdb.db.query.simpiece; import org.apache.iotdb.db.query.simpiece.jwave.Transform; -import org.apache.iotdb.db.query.simpiece.jwave.TransformBuilder; +import org.apache.iotdb.db.query.simpiece.jwave.transforms.AncientEgyptianDecomposition; +import org.apache.iotdb.db.query.simpiece.jwave.transforms.FastWaveletTransform; +import org.apache.iotdb.db.query.simpiece.jwave.transforms.wavelets.haar.Haar1; import java.util.ArrayList; import java.util.List; @@ -28,7 +30,10 @@ import java.util.List; public class DWT { public static List<Point> reducePoints(double[] values, double threshold) { - Transform transform = TransformBuilder.create("Fast Wavelet Transform", "Haar"); + // Transform transform = TransformBuilder.create("Fast Wavelet Transform", "Haar"); + Transform transform = + new Transform(new AncientEgyptianDecomposition(new FastWaveletTransform(new Haar1()))); + double[] arrHilb = transform.forward(values); List<Point> result = new ArrayList<>(); diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_dwt.java similarity index 70% copy from server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw.java copy to server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_dwt.java index 3dfd5cecb9b..fc1aacc221f 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_dwt.java @@ -27,7 +27,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.List; -public class MySample_fsw { +public class MySample_dwt { public static void main(String[] args) { String fileDir = "D:\\desktop\\NISTPV\\"; @@ -36,7 +36,12 @@ public class MySample_fsw { double[] r = new double[] {0.1, 0.5, 1.3, 0}; int[] NList = new int[] {2500000, 2500000, 2500000, 500000}; double[] epsilonList = - new double[] {9.999999E-4, 284.4034399986267, 6.428162097930908, 10.814893245697021}; + new double[] { + 0.01922464370727539, 15034.107696056366, 552.0329060554504, 67.42263174057007 + }; + // double[] epsilonList = + // new + // double[]{0.019301805417701563,15411.426927099063,552.0329062500005,67.35937500000003}; for (int y = 0; y < datasetNameList.length; y++) { String datasetName = datasetNameList[y]; int start = (int) (10000000 / 2 - NList[y] * r[y]); // 从0开始计数 @@ -50,9 +55,15 @@ public class MySample_fsw { TimeSeries ts = TimeSeriesReader.getMyTimeSeries( inputStream, delimiter, false, N, start, hasHeader, true); - // double epsilon = getFSWParam(nout, ts, 1e-6); - double epsilon = epsilonList[y]; - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); + + double[] values = new double[ts.length()]; + int k = 0; + for (Point p : ts.data) { + values[k++] = p.getValue(); + } + double epsilon = getDWTParam(nout, values, 1e-6); + // double epsilon = epsilonList[y]; + List<Point> reducedPoints = DWT.reducePoints(values, epsilon); System.out.println( datasetName + ": n=" @@ -66,7 +77,7 @@ public class MySample_fsw { try (PrintWriter writer = new PrintWriter( new FileWriter( - datasetName + "-" + N + "-" + reducedPoints.size() + "-fsw.csv"))) { + datasetName + "-" + N + "-" + reducedPoints.size() + "-dwt.csv"))) { for (Point p : reducedPoints) { writer.println(p.getTimestamp() + "," + p.getValue()); } @@ -78,14 +89,19 @@ public class MySample_fsw { } } - public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException { + public static double getDWTParam(int nout, double[] values, double accuracy) throws IOException { double epsilon = 1; boolean directLess = false; boolean directMore = false; + boolean skip = false; + int threshold = 2; while (true) { - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); + List<Point> reducedPoints = DWT.reducePoints(values, epsilon); if (reducedPoints.size() > nout) { if (directMore) { + if (Math.abs(reducedPoints.size() - nout) <= threshold) { + skip = true; + } break; } if (!directLess) { @@ -94,6 +110,9 @@ public class MySample_fsw { epsilon *= 2; } else { if (directLess) { + if (Math.abs(nout - reducedPoints.size()) <= threshold) { + skip = true; + } break; } if (!directMore) { @@ -102,6 +121,11 @@ public class MySample_fsw { epsilon /= 2; } } + if (skip) { + return epsilon; + } + + // begin dichotomy double left = 0; double right = 0; if (directLess) { @@ -114,13 +138,22 @@ public class MySample_fsw { } while (Math.abs(right - left) > accuracy) { double mid = (left + right) / 2; - List<Point> reducedPoints = FSW.reducePoints(ts.data, mid); + List<Point> reducedPoints = DWT.reducePoints(values, mid); if (reducedPoints.size() > nout) { left = mid; } else { right = mid; } } - return (left + right) / 2; + + List<Point> reducedPoints = DWT.reducePoints(values, left); + int n1 = reducedPoints.size(); + reducedPoints = DWT.reducePoints(values, right); + int n2 = reducedPoints.size(); + if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { + return left; + } else { + return right; + } } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_dwt_full2.java similarity index 53% copy from server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full.java copy to server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_dwt_full2.java index 706e140a1fd..16f64fd271b 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_dwt_full2.java @@ -27,57 +27,66 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.List; -public class MySample_fsw_full { +public class MySample_dwt_full2 { + // After running this, + // output sample csv and copy them into lts-exp/notebook/segmentResults/. + // output epsilonArray_*.txt and copy them into lts-exp/tools/. public static void main(String[] args) { String fileDir = "D:\\desktop\\NISTPV\\"; + // do not change the order of datasets below, as the output is used in exp bash String[] datasetNameList = new String[] {"WindSpeed", "Qloss", "Pyra1", "RTD"}; - int[] noutList = new int[] {320, 360, 400, 440, 480, 520, 560, 600, 640}; + int[] noutList = + new int[] { + 320, 400, 480, 580, 720, 960, 1200, 1600, 2000, 2400, 3000, 3600, 4000, 4400, 5000 + }; double[][] epsilonArray = { { - 9.618271350860596, - 9.101282596588135, - 8.991526126861572, - 8.62817907333374, - 8.374999523162842, - 8.202636241912842, - 7.999906063079834, - 7.947059154510498, - 7.858933925628662 + 98.84062576293945, + 83.28593826293945, + 71.22443580627441, + 59.164398193359375, + 48.10093879699707, + 37.6534366607666, + 31.448437690734863, + 25.480151176452637, + 22.1484375, + 19.969138145446777, + 17.644524574279785, + 16.02500057220459, + 15.221578598022461, + 14.512500762939453, + 13.687499046325684, }, { - 9.999275207519531E-4, - 9.989738464355469E-4, - 9.980201721191406E-4, - 9.970664978027344E-4, - 9.961128234863281E-4, - 9.951591491699219E-4, - 9.942054748535156E-4, - 9.932518005371094E-4, - 9.922981262207031E-4 + 0.01904773712158203, 0.01746368408203125, 0.01591014862060547, 0.015031814575195312, + 0.013813018798828125, 0.011875152587890625, 0.010687828063964844, 0.009125709533691406, + 0.007843017578125, 0.007071495056152344, 0.0059661865234375, 0.005126953125, + 0.0046844482421875, 0.004241943359375, 0.0037126541137695312, }, { - 440.0235962867737, - 432.0247492790222, - 423.55674982070923, - 414.65001153945923, - 405.77113008499146, - 401.21820974349976, - 396.7935194969177, - 393.2065939903259, - 392.30953645706177 + 17456.15777873993, 13712.626691818237, 10876.021079063416, 9463.918528556824, + 7767.749307632446, 5635.975116729736, 4259.744117736816, 3277.170015335083, + 2655.061099052429, 2169.5194940567017, 1751.8307266235352, 1485.040364265442, + 1367.6178674697876, 1255.3692474365234, 1127.6510620117188, }, { - 9.295397281646729, - 8.096678256988525, - 7.536666393280029, - 6.961357593536377, - 6.473535060882568, - 6.064479351043701, - 5.743286609649658, - 5.5219340324401855, - 5.185042858123779 + 849.467981338501, + 703.4278907775879, + 556.0022611618042, + 456.47415828704834, + 345.5801601409912, + 241.60498523712158, + 184.83848667144775, + 128.0, + 97.61968803405762, + 77.68981170654297, + 58.74324989318848, + 47.012436866760254, + 41.456562995910645, + 36.50571346282959, + 31.0604829788208, } }; @@ -96,15 +105,22 @@ public class MySample_fsw_full { String delimiter = ","; TimeSeries ts = TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, false); + inputStream, delimiter, false, N, start, hasHeader, true); + double[] values = new double[ts.length()]; + int k = 0; + for (Point p : ts.data) { + values[k++] = p.getValue(); + } + for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; - // double epsilon = getFSWParam(nout, ts, 1e-6); + + // double epsilon = MySample_dwt.getDWTParam(nout, values, 1e-6); // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); + List<Point> reducedPoints = DWT.reducePoints(values, epsilon); System.out.println( datasetName + ": n=" @@ -125,7 +141,7 @@ public class MySample_fsw_full { + nout + "-" + reducedPoints.size() - + "-fsw.csv"))) { + + "-dwt.csv"))) { for (Point p : reducedPoints) { writer.println(p.getTimestamp() + "," + p.getValue()); } @@ -136,57 +152,18 @@ public class MySample_fsw_full { } } - for (int i = 0; i < epsilonArray.length; i++) { - for (int j = 0; j < epsilonArray[i].length; j++) { - System.out.print(epsilonArray[i][j] + ","); - } - System.out.println(); - } - } - - public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException { - double epsilon = 1; - boolean directLess = false; - boolean directMore = false; - while (true) { - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); - if (reducedPoints.size() > nout) { - if (directMore) { - break; + // do not change name of the output file, as the output is used in exp bash + try (FileWriter writer = new FileWriter("epsilonArray_dwt.txt")) { + for (double[] row : epsilonArray) { + for (double element : row) { + writer.write(element + " "); + System.out.print(element + ","); } - if (!directLess) { - directLess = true; - } - epsilon *= 2; - } else { - if (directLess) { - break; - } - if (!directMore) { - directMore = true; - } - epsilon /= 2; - } - } - double left = 0; - double right = 0; - if (directLess) { - left = epsilon / 2; - right = epsilon; - } - if (directMore) { - left = epsilon; - right = epsilon * 2; - } - while (Math.abs(right - left) > accuracy) { - double mid = (left + right) / 2; - List<Point> reducedPoints = FSW.reducePoints(ts.data, mid); - if (reducedPoints.size() > nout) { - left = mid; - } else { - right = mid; + writer.write("\n"); + System.out.println(); } + } catch (IOException e) { + e.printStackTrace(); } - return (left + right) / 2; } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw.java index 3dfd5cecb9b..b7756c7d744 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw.java @@ -36,7 +36,9 @@ public class MySample_fsw { double[] r = new double[] {0.1, 0.5, 1.3, 0}; int[] NList = new int[] {2500000, 2500000, 2500000, 500000}; double[] epsilonList = - new double[] {9.999999E-4, 284.4034399986267, 6.428162097930908, 10.814893245697021}; + new double[] { + 9.999999992942321E-4, 284.40344031846143, 6.428162015438829, 10.818711800659003 + }; for (int y = 0; y < datasetNameList.length; y++) { String datasetName = datasetNameList[y]; int start = (int) (10000000 / 2 - NList[y] * r[y]); // 从0开始计数 @@ -50,7 +52,7 @@ public class MySample_fsw { TimeSeries ts = TimeSeriesReader.getMyTimeSeries( inputStream, delimiter, false, N, start, hasHeader, true); - // double epsilon = getFSWParam(nout, ts, 1e-6); + // double epsilon = getFSWParam(nout, ts, 1e-12); double epsilon = epsilonList[y]; List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); System.out.println( @@ -78,14 +80,66 @@ public class MySample_fsw { } } + // public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException + // { + // double epsilon = 1; + // boolean directLess = false; + // boolean directMore = false; + // while (true) { + // List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); + // if (reducedPoints.size() > nout) { + // if (directMore) { + // break; + // } + // if (!directLess) { + // directLess = true; + // } + // epsilon *= 2; + // } else { + // if (directLess) { + // break; + // } + // if (!directMore) { + // directMore = true; + // } + // epsilon /= 2; + // } + // } + // double left = 0; + // double right = 0; + // if (directLess) { + // left = epsilon / 2; + // right = epsilon; + // } + // if (directMore) { + // left = epsilon; + // right = epsilon * 2; + // } + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // List<Point> reducedPoints = FSW.reducePoints(ts.data, mid); + // if (reducedPoints.size() > nout) { + // left = mid; + // } else { + // right = mid; + // } + // } + // return (left + right) / 2; + // } + public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException { double epsilon = 1; boolean directLess = false; boolean directMore = false; + boolean skip = false; + int threshold = 2; while (true) { List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); if (reducedPoints.size() > nout) { if (directMore) { + if (Math.abs(reducedPoints.size() - nout) <= threshold) { + skip = true; + } break; } if (!directLess) { @@ -94,6 +148,9 @@ public class MySample_fsw { epsilon *= 2; } else { if (directLess) { + if (Math.abs(nout - reducedPoints.size()) <= threshold) { + skip = true; + } break; } if (!directMore) { @@ -102,6 +159,11 @@ public class MySample_fsw { epsilon /= 2; } } + if (skip) { + return epsilon; + } + + // begin dichotomy double left = 0; double right = 0; if (directLess) { @@ -121,6 +183,15 @@ public class MySample_fsw { right = mid; } } - return (left + right) / 2; + + List<Point> reducedPoints = FSW.reducePoints(ts.data, left); + int n1 = reducedPoints.size(); + reducedPoints = FSW.reducePoints(ts.data, right); + int n2 = reducedPoints.size(); + if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { + return left; + } else { + return right; + } } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2.java index e8d8cb58a44..1ca532ffe1d 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2.java @@ -43,39 +43,39 @@ public class MySample_fsw_full2 { double[][] epsilonArray = { { - 9.618271827697754, - 8.991525650024414, + 9.618214055872158, + 8.99153642953479, 8.375, - 7.99461555480957, - 7.615596771240234, - 7.172431945800781, - 6.877520561218262, - 6.408135414123535, - 6.219999313354492, - 5.977571487426758, - 5.679183006286621, - 5.499468803405762, - 5.387459754943848, - 5.299999237060547, - 5.1635847091674805, + 7.994615384615827, + 7.615596330275366, + 7.172755905511622, + 6.8775202380129485, + 6.408134920635348, + 6.219821826281077, + 5.977595190380271, + 5.678260869564838, + 5.499468085106855, + 5.387459854014196, + 5.299999999999272, + 5.1635087719305375, }, { - 9.9945068359375E-4, 9.984970092773438E-4, 9.965896606445312E-4, 9.937286376953125E-4, - 9.899139404296875E-4, 9.813308715820312E-4, 9.6893310546875E-4, 9.42230224609375E-4, - 8.983612060546875E-4, 8.268356323242188E-4, 6.685256958007812E-4, 5.197525024414062E-4, - 4.99725341796875E-4, 4.987716674804688E-4, 4.8732757568359375E-4, + 9.99588181002764E-4, 9.9792019045708E-4, 9.960159368347377E-4, 9.93464052953641E-4, + 9.900738350552274E-4, 9.817607760851388E-4, 9.688081945569138E-4, 9.424000008948497E-4, + 8.978153637144715E-4, 8.259669120889157E-4, 6.680341875835438E-4, 5.191545578782097E-4, + 4.996619345547515E-4, 4.989106755601824E-4, 4.871794872087776E-4, }, { - 440.0235958099365, 423.5567502975464, 405.7711305618286, 396.31347465515137, - 380.6776990890503, 358.0119905471802, 336.5447692871094, 303.85207748413086, - 279.7541666030884, 257.3554916381836, 232.57367420196533, 211.35449981689453, - 200.9514446258545, 192.0128345489502, 178.28646087646484, + 439.5207473666851, 425.8416748119398, 405.7711305285957, 396.33365325326304, + 380.677698415484, 358.4453466879504, 336.54477008704634, 304.11544481893816, + 279.7037549556544, 257.61061704471194, 232.59544346653, 211.35450069313174, + 201.14805889728268, 192.1216488917953, 178.6315376164921, }, { - 9.295397758483887, 7.5366668701171875, 6.473535537719727, 5.6244354248046875, - 4.713288307189941, 3.7258691787719727, 3.078885078430176, 2.4637460708618164, - 2.0368423461914062, 1.7683038711547852, 1.4741735458374023, 1.266657829284668, - 1.1668891906738281, 1.071258544921875, 0.9608230590820312, + 9.297997111218137, 7.471379310345583, 6.473535325328157, 5.616272926722559, + 4.701954477981417, 3.7258684097114383, 3.078884904984079, 2.4637460027415727, + 2.0368421052635313, 1.7683037779497681, 1.473529411765412, 1.2658022184905349, + 1.166260869566031, 1.0711538461546297, 0.9613079019081852, } }; @@ -94,11 +94,11 @@ public class MySample_fsw_full2 { String delimiter = ","; TimeSeries ts = TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, false); + inputStream, delimiter, false, N, start, hasHeader, true); for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; - // double epsilon = getFSWParam(nout, ts, 1e-6); + // double epsilon = MySample_fsw.getFSWParam(nout, ts, 1e-12); // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; @@ -157,78 +157,72 @@ public class MySample_fsw_full2 { } } - public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException { - double epsilon = 1; - boolean directLess = false; - boolean directMore = false; - boolean skip = false; // TODO - int threshold = 2; // TODO - while (true) { - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); - if (reducedPoints.size() > nout) { - if (directMore) { - // TODO - if (Math.abs(reducedPoints.size() - nout) <= threshold) { - skip = true; - } - // - break; - } - if (!directLess) { - directLess = true; - } - epsilon *= 2; - } else { - if (directLess) { - // TODO - if (Math.abs(nout - reducedPoints.size()) <= threshold) { - skip = true; - } - // - break; - } - if (!directMore) { - directMore = true; - } - epsilon /= 2; - } - } - // TODO - if (skip) { - return epsilon; - } - // - // begin dichotomy - double left = 0; - double right = 0; - if (directLess) { - left = epsilon / 2; - right = epsilon; - } - if (directMore) { - left = epsilon; - right = epsilon * 2; - } - while (Math.abs(right - left) > accuracy) { - double mid = (left + right) / 2; - List<Point> reducedPoints = FSW.reducePoints(ts.data, mid); - if (reducedPoints.size() > nout) { - left = mid; - } else { - right = mid; - } - } - - // TODO - List<Point> reducedPoints = FSW.reducePoints(ts.data, left); - int n1 = reducedPoints.size(); - reducedPoints = FSW.reducePoints(ts.data, right); - int n2 = reducedPoints.size(); - if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { - return left; - } else { - return right; - } - // - } + // public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException + // { + // double epsilon = 1; + // boolean directLess = false; + // boolean directMore = false; + // boolean skip = false; + // int threshold = 2; + // while (true) { + // List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); + // if (reducedPoints.size() > nout) { + // if (directMore) { + // if (Math.abs(reducedPoints.size() - nout) <= threshold) { + // skip = true; + // } + // break; + // } + // if (!directLess) { + // directLess = true; + // } + // epsilon *= 2; + // } else { + // if (directLess) { + // if (Math.abs(nout - reducedPoints.size()) <= threshold) { + // skip = true; + // } + // break; + // } + // if (!directMore) { + // directMore = true; + // } + // epsilon /= 2; + // } + // } + // if (skip) { + // return epsilon; + // } + // + // // begin dichotomy + // double left = 0; + // double right = 0; + // if (directLess) { + // left = epsilon / 2; + // right = epsilon; + // } + // if (directMore) { + // left = epsilon; + // right = epsilon * 2; + // } + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // List<Point> reducedPoints = FSW.reducePoints(ts.data, mid); + // if (reducedPoints.size() > nout) { + // left = mid; + // } else { + // right = mid; + // } + // } + // + // List<Point> reducedPoints = FSW.reducePoints(ts.data, left); + // int n1 = reducedPoints.size(); + // reducedPoints = FSW.reducePoints(ts.data, right); + // int n2 = reducedPoints.size(); + // if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { + // return left; + // } else { + // return right; + // } + // } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full_deprecated.java similarity index 75% rename from server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full.java rename to server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full_deprecated.java index 706e140a1fd..184be70aaed 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full_deprecated.java @@ -23,11 +23,10 @@ package org.apache.iotdb.db.query.simpiece; import java.io.FileInputStream; import java.io.FileWriter; -import java.io.IOException; import java.io.PrintWriter; import java.util.List; -public class MySample_fsw_full { +public class MySample_fsw_full_deprecated { public static void main(String[] args) { String fileDir = "D:\\desktop\\NISTPV\\"; @@ -99,7 +98,7 @@ public class MySample_fsw_full { inputStream, delimiter, false, N, start, hasHeader, false); for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; - // double epsilon = getFSWParam(nout, ts, 1e-6); + // double epsilon = MySample_fsw.getFSWParam(nout, ts, 1e-6); // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; @@ -144,49 +143,50 @@ public class MySample_fsw_full { } } - public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException { - double epsilon = 1; - boolean directLess = false; - boolean directMore = false; - while (true) { - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); - if (reducedPoints.size() > nout) { - if (directMore) { - break; - } - if (!directLess) { - directLess = true; - } - epsilon *= 2; - } else { - if (directLess) { - break; - } - if (!directMore) { - directMore = true; - } - epsilon /= 2; - } - } - double left = 0; - double right = 0; - if (directLess) { - left = epsilon / 2; - right = epsilon; - } - if (directMore) { - left = epsilon; - right = epsilon * 2; - } - while (Math.abs(right - left) > accuracy) { - double mid = (left + right) / 2; - List<Point> reducedPoints = FSW.reducePoints(ts.data, mid); - if (reducedPoints.size() > nout) { - left = mid; - } else { - right = mid; - } - } - return (left + right) / 2; - } + // public static double getFSWParam(int nout, TimeSeries ts, double accuracy) throws IOException + // { + // double epsilon = 1; + // boolean directLess = false; + // boolean directMore = false; + // while (true) { + // List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); + // if (reducedPoints.size() > nout) { + // if (directMore) { + // break; + // } + // if (!directLess) { + // directLess = true; + // } + // epsilon *= 2; + // } else { + // if (directLess) { + // break; + // } + // if (!directMore) { + // directMore = true; + // } + // epsilon /= 2; + // } + // } + // double left = 0; + // double right = 0; + // if (directLess) { + // left = epsilon / 2; + // right = epsilon; + // } + // if (directMore) { + // left = epsilon; + // right = epsilon * 2; + // } + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // List<Point> reducedPoints = FSW.reducePoints(ts.data, mid); + // if (reducedPoints.size() > nout) { + // left = mid; + // } else { + // right = mid; + // } + // } + // return (left + right) / 2; + // } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone.java index 8c269f5d6b6..5bb1e0158fe 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone.java @@ -35,8 +35,7 @@ public class MySample_shrinkingcone { int[] noutList = new int[] {100}; double[] r = new double[] {0.1, 0.5, 1.3, 0}; int[] NList = new int[] {2500000, 2500000, 2500000, 500000}; - double[] epsilonList = - new double[] {0.001, 408.55843019485474, 7.996772289276123, 14.692305088043213}; + double[] epsilonList = new double[] {0.001, 408.55843019485474, 8, 14.692305415804185}; for (int y = 0; y < datasetNameList.length; y++) { String datasetName = datasetNameList[y]; int start = (int) (10000000 / 2 - NList[y] * r[y]); // 从0开始计数 @@ -50,7 +49,7 @@ public class MySample_shrinkingcone { TimeSeries ts = TimeSeriesReader.getMyTimeSeries( inputStream, delimiter, false, N, start, hasHeader, true); - // double epsilon = getSCParam(nout, ts, 1e-6); + // double epsilon = getSCParam(nout, ts, 1e-12); double epsilon = epsilonList[y]; List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); System.out.println( @@ -77,14 +76,67 @@ public class MySample_shrinkingcone { } } + // public static double getSCParam(int nout, TimeSeries ts, double accuracy) throws IOException { + // double epsilon = 1; + // boolean directLess = false; + // boolean directMore = false; + // while (true) { + // List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); + // if (reducedPoints.size() > nout) { + // if (directMore) { + // break; + // } + // if (!directLess) { + // directLess = true; + // } + // epsilon *= 2; + // } else { + // if (directLess) { + // break; + // } + // if (!directMore) { + // directMore = true; + // } + // epsilon /= 2; + // } + // } + // double left = 0; + // double right = 0; + // if (directLess) { + // left = epsilon / 2; + // right = epsilon; + // } + // if (directMore) { + // left = epsilon; + // right = epsilon * 2; + // } + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, mid); + // if (reducedPoints.size() > nout) { + // left = mid; + // } else { + // right = mid; + // } + // } + // return (left + right) / 2; + // } + public static double getSCParam(int nout, TimeSeries ts, double accuracy) throws IOException { double epsilon = 1; boolean directLess = false; boolean directMore = false; + boolean skip = false; // TODO + int threshold = 2; // TODO while (true) { List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); if (reducedPoints.size() > nout) { if (directMore) { + // TODO + if (Math.abs(reducedPoints.size() - nout) <= threshold) { + skip = true; + } + // break; } if (!directLess) { @@ -93,6 +145,11 @@ public class MySample_shrinkingcone { epsilon *= 2; } else { if (directLess) { + // TODO + if (Math.abs(nout - reducedPoints.size()) <= threshold) { + skip = true; + } + // break; } if (!directMore) { @@ -101,6 +158,12 @@ public class MySample_shrinkingcone { epsilon /= 2; } } + // TODO + if (skip) { + return epsilon; + } + // + // begin dichotomy double left = 0; double right = 0; if (directLess) { @@ -120,6 +183,16 @@ public class MySample_shrinkingcone { right = mid; } } - return (left + right) / 2; + // TODO + List<Point> reducedPoints = FSW.reducePoints(ts.data, left); + int n1 = reducedPoints.size(); + reducedPoints = FSW.reducePoints(ts.data, right); + int n2 = reducedPoints.size(); + if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { + return left; + } else { + return right; + } + // } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2.java index 25e44198e64..1d525f4b832 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2.java @@ -43,28 +43,39 @@ public class MySample_shrinkingcone_full2 { double[][] epsilonArray = { { - 14.388325691223145, 13.343345642089844, 12.697674751281738, 12.053359985351562, - 11.411823272705078, 10.700932502746582, 10.222302436828613, 9.640463829040527, - 9.169320106506348, 8.824727058410645, 8.389120101928711, 8.050561904907227, - 7.84444522857666, 7.675000190734863, 7.441162109375, + 14.388325263280421, 13.34334554336965, 12.697674418624956, 12.053359143726993, + 11.411823799891863, 10.700932090578135, 10.222302158304956, 9.64046321529895, + 9.169320066343062, 8.824726661085151, 8.38911917101359, 8.050000000046566, + 7.844965517288074, 7.675000000046566, 7.4411764705437236, }, { - 0.001, 0.001, 0.001, 0.001, - 0.001, 0.001, 0.001, 9.9945068359375E-4, - 9.9945068359375E-4, 9.9945068359375E-4, 9.984970092773438E-4, 9.946823120117188E-4, - 9.927749633789062E-4, 9.8419189453125E-4, 9.088516235351562E-4, + 0.001, + 0.001, + 0.001, + 0.001, + 0.001, + 0.001, + 0.001, + 9.999999892897904E-4, + 9.999999892897904E-4, + 9.999999892897904E-4, + 9.986772784031928E-4, + 9.954648558050394E-4, + 9.931506938301027E-4, + 9.859154815785587E-4, + 9.090908570215106E-4, }, { - 680.2196474075317, 650.261082649231, 620.9016036987305, 586.952600479126, - 547.2381553649902, 493.3626317977905, 453.35704135894775, 404.6129741668701, - 368.50129795074463, 342.09704971313477, 305.65501976013184, 276.0216178894043, - 257.88243865966797, 242.78428554534912, 223.49278926849365, + 680.4174693996902, 650.2610825433512, 621.0945158457616, 586.9638199705514, + 547.4329924675985, 494.63679197325837, 454.7579276354518, 406.4603661468718, + 368.9741049989243, 342.1729954186012, 305.74686436593765, 276.5570874213008, + 258.8369336259784, 243.3460398996831, 224.25107966241194, }, { - 11.259881019592285, 9.402754783630371, 8.384316444396973, 7.238059043884277, - 5.794983863830566, 4.60251522064209, 3.8171539306640625, 3.0447826385498047, - 2.526477813720703, 2.1706619262695312, 1.816070556640625, 1.5562095642089844, - 1.4302129745483398, 1.3176708221435547, 1.1894960403442383, + 11.258956845791545, 9.40259607497137, 8.384315740317106, 7.238058144459501, + 5.828739010321442, 4.60251481551677, 3.8172692629741505, 3.0447826087474823, + 2.523470887565054, 2.170023310056422, 1.8160594796063378, 1.556580246950034, + 1.4294884910923429, 1.3174383605946787, 1.1894954767194577, } }; @@ -83,11 +94,11 @@ public class MySample_shrinkingcone_full2 { String delimiter = ","; TimeSeries ts = TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, false); + inputStream, delimiter, false, N, start, hasHeader, true); for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; - // double epsilon = getSCParam(nout, ts, 1e-15); + // double epsilon = MySample_shrinkingcone.getSCParam(nout, ts, 1e-10); // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; @@ -146,77 +157,77 @@ public class MySample_shrinkingcone_full2 { } } - public static double getSCParam(int nout, TimeSeries ts, double accuracy) throws IOException { - double epsilon = 1; - boolean directLess = false; - boolean directMore = false; - boolean skip = false; // TODO - int threshold = 2; // TODO - while (true) { - List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); - if (reducedPoints.size() > nout) { - if (directMore) { - // TODO - if (Math.abs(reducedPoints.size() - nout) <= threshold) { - skip = true; - } - // - break; - } - if (!directLess) { - directLess = true; - } - epsilon *= 2; - } else { - if (directLess) { - // TODO - if (Math.abs(nout - reducedPoints.size()) <= threshold) { - skip = true; - } - // - break; - } - if (!directMore) { - directMore = true; - } - epsilon /= 2; - } - } - // TODO - if (skip) { - return epsilon; - } - // - // begin dichotomy - double left = 0; - double right = 0; - if (directLess) { - left = epsilon / 2; - right = epsilon; - } - if (directMore) { - left = epsilon; - right = epsilon * 2; - } - while (Math.abs(right - left) > accuracy) { - double mid = (left + right) / 2; - List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, mid); - if (reducedPoints.size() > nout) { - left = mid; - } else { - right = mid; - } - } - // TODO - List<Point> reducedPoints = FSW.reducePoints(ts.data, left); - int n1 = reducedPoints.size(); - reducedPoints = FSW.reducePoints(ts.data, right); - int n2 = reducedPoints.size(); - if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { - return left; - } else { - return right; - } - // - } + // public static double getSCParam(int nout, TimeSeries ts, double accuracy) throws IOException { + // double epsilon = 1; + // boolean directLess = false; + // boolean directMore = false; + // boolean skip = false; // TODO + // int threshold = 2; // TODO + // while (true) { + // List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); + // if (reducedPoints.size() > nout) { + // if (directMore) { + // // TODO + // if (Math.abs(reducedPoints.size() - nout) <= threshold) { + // skip = true; + // } + // // + // break; + // } + // if (!directLess) { + // directLess = true; + // } + // epsilon *= 2; + // } else { + // if (directLess) { + // // TODO + // if (Math.abs(nout - reducedPoints.size()) <= threshold) { + // skip = true; + // } + // // + // break; + // } + // if (!directMore) { + // directMore = true; + // } + // epsilon /= 2; + // } + // } + // // TODO + // if (skip) { + // return epsilon; + // } + // // + // // begin dichotomy + // double left = 0; + // double right = 0; + // if (directLess) { + // left = epsilon / 2; + // right = epsilon; + // } + // if (directMore) { + // left = epsilon; + // right = epsilon * 2; + // } + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, mid); + // if (reducedPoints.size() > nout) { + // left = mid; + // } else { + // right = mid; + // } + // } + // // TODO + // List<Point> reducedPoints = FSW.reducePoints(ts.data, left); + // int n1 = reducedPoints.size(); + // reducedPoints = FSW.reducePoints(ts.data, right); + // int n2 = reducedPoints.size(); + // if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { + // return left; + // } else { + // return right; + // } + // // + // } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full_deprecated.java similarity index 74% rename from server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full.java rename to server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full_deprecated.java index 3ab602021f9..bc0004c1b54 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full_deprecated.java @@ -23,11 +23,10 @@ package org.apache.iotdb.db.query.simpiece; import java.io.FileInputStream; import java.io.FileWriter; -import java.io.IOException; import java.io.PrintWriter; import java.util.List; -public class MySample_shrinkingcone_full { +public class MySample_shrinkingcone_full_deprecated { public static void main(String[] args) { String fileDir = "D:\\desktop\\NISTPV\\"; @@ -90,7 +89,7 @@ public class MySample_shrinkingcone_full { for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; - // double epsilon = getSCParam(nout, ts, 1e-6); + // double epsilon = MySample_shrinkingcone.getSCParam(nout, ts, 1e-6); // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; @@ -135,49 +134,49 @@ public class MySample_shrinkingcone_full { } } - public static double getSCParam(int nout, TimeSeries ts, double accuracy) throws IOException { - double epsilon = 1; - boolean directLess = false; - boolean directMore = false; - while (true) { - List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); - if (reducedPoints.size() > nout) { - if (directMore) { - break; - } - if (!directLess) { - directLess = true; - } - epsilon *= 2; - } else { - if (directLess) { - break; - } - if (!directMore) { - directMore = true; - } - epsilon /= 2; - } - } - double left = 0; - double right = 0; - if (directLess) { - left = epsilon / 2; - right = epsilon; - } - if (directMore) { - left = epsilon; - right = epsilon * 2; - } - while (Math.abs(right - left) > accuracy) { - double mid = (left + right) / 2; - List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, mid); - if (reducedPoints.size() > nout) { - left = mid; - } else { - right = mid; - } - } - return (left + right) / 2; - } + // public static double getSCParam(int nout, TimeSeries ts, double accuracy) throws IOException { + // double epsilon = 1; + // boolean directLess = false; + // boolean directMore = false; + // while (true) { + // List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); + // if (reducedPoints.size() > nout) { + // if (directMore) { + // break; + // } + // if (!directLess) { + // directLess = true; + // } + // epsilon *= 2; + // } else { + // if (directLess) { + // break; + // } + // if (!directMore) { + // directMore = true; + // } + // epsilon /= 2; + // } + // } + // double left = 0; + // double right = 0; + // if (directLess) { + // left = epsilon / 2; + // right = epsilon; + // } + // if (directMore) { + // left = epsilon; + // right = epsilon * 2; + // } + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, mid); + // if (reducedPoints.size() > nout) { + // left = mid; + // } else { + // right = mid; + // } + // } + // return (left + right) / 2; + // } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece.java index 35ced19e20c..eb5ebe1d16a 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece.java @@ -36,7 +36,9 @@ public class MySample_simpiece { int[] noutList = new int[] {100}; double[] r = new double[] {0.1, 0.5, 1.3, 0}; double[] epsilonList = - new double[] {0.0009999, 316.5642651891633, 9.186667042922977, 11.162719900131227}; + new double[] { + 9.999999992942321E-4, 316.5642651891633, 9.186667042922977, 11.162719900131227 + }; int[] NList = new int[] {2500000, 2500000, 2500000, 500000}; for (int y = 0; y < datasetNameList.length; y++) { String datasetName = datasetNameList[y]; @@ -52,7 +54,7 @@ public class MySample_simpiece { TimeSeries ts = TimeSeriesReader.getMyTimeSeries( inputStream, delimiter, false, N, start, hasHeader, true); - // double epsilon = getSimPieceParam(nout, ts, 1e-6); + // double epsilon = getSimPieceParam(nout, ts, 1e-12); double epsilon = epsilonList[y]; SimPiece simPiece = new SimPiece(ts.data, epsilon); System.out.println( @@ -99,19 +101,79 @@ public class MySample_simpiece { } } + // public static double getSimPieceParam(int nout, TimeSeries ts, double accuracy) + // throws IOException { + // double epsilon = ts.range * 0.001; + // while (true) { + // SimPiece simPiece = new SimPiece(ts.data, epsilon); + // if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint + // epsilon *= 2; + // } else { + // break; + // } + // } + // double left = epsilon / 2; + // double right = epsilon; + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // SimPiece simPiece = new SimPiece(ts.data, mid); + // if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint + // left = mid; + // } else { + // right = mid; + // } + // } + // return (left + right) / 2; + // } + public static double getSimPieceParam(int nout, TimeSeries ts, double accuracy) throws IOException { - double epsilon = ts.range * 0.001; + double epsilon = 1; + boolean directLess = false; + boolean directMore = false; + boolean skip = false; + int threshold = 2; while (true) { SimPiece simPiece = new SimPiece(ts.data, epsilon); if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint + if (directMore) { + if (Math.abs(simPiece.segments.size() * 2 - nout) <= threshold) { + skip = true; + } + break; + } + if (!directLess) { + directLess = true; + } epsilon *= 2; } else { - break; + if (directLess) { + if (Math.abs(nout - simPiece.segments.size() * 2) <= threshold) { + skip = true; + } + break; + } + if (!directMore) { + directMore = true; + } + epsilon /= 2; } } - double left = epsilon / 2; - double right = epsilon; + if (skip) { + return epsilon; + } + + // begin dichotomy + double left = 0; + double right = 0; + if (directLess) { + left = epsilon / 2; + right = epsilon; + } + if (directMore) { + left = epsilon; + right = epsilon * 2; + } while (Math.abs(right - left) > accuracy) { double mid = (left + right) / 2; SimPiece simPiece = new SimPiece(ts.data, mid); @@ -121,6 +183,14 @@ public class MySample_simpiece { right = mid; } } - return (left + right) / 2; + SimPiece simPiece = new SimPiece(ts.data, left); + int n1 = simPiece.segments.size() * 2; + simPiece = new SimPiece(ts.data, right); + int n2 = simPiece.segments.size() * 2; + if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { + return left; + } else { + return right; + } } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2.java index e0d3eaccdf2..e1cd6519507 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2.java @@ -44,28 +44,28 @@ public class MySample_simpiece_full2 { double[][] epsilonArray = { { - 10.421952322125435, 9.571347452700138, 9.122375220060349, 8.709278352558613, - 8.077139288187027, 7.495633184909821, 7.083636365830898, 6.733693778514862, - 6.403274565935135, 6.160000003874302, 5.93758013099432, 5.787152819335461, - 5.647759035229683, 5.5742857083678246, 5.444876328110695, + 10.421952322125435, 9.571148289031044, 9.123788145707294, 8.709278350515888, + 8.077139287945101, 7.49563318777291, 7.083431952662977, 6.733693776602195, + 6.40327455919396, 6.160000000000764, 5.937580128205809, 5.787373737373855, + 5.64775903311147, 5.574285714284997, 5.457306590258668, }, { - 9.987801313400269E-4, 9.798482060432434E-4, 9.232386946678162E-4, 8.238255977630615E-4, - 7.013455033302307E-4, 6.666630506515503E-4, 6.311237812042236E-4, 5.687475204467773E-4, - 5.405843257904053E-4, 5.235522985458374E-4, 5.015432834625244E-4, 4.99919056892395E-4, - 4.997774958610535E-4, 4.995688796043396E-4, 4.983171820640564E-4, + 9.988254314521328E-4, 9.798434293770697E-4, 9.232312522726716E-4, 8.290353398479056E-4, + 7.01342141837813E-4, 6.666666658929898E-4, 6.310499056780827E-4, 5.685331507265801E-4, + 5.405860865721479E-4, 5.232102530499105E-4, 5.01524178616819E-4, 4.999221064281301E-4, + 4.997711675969185E-4, 4.995523740944918E-4, 4.984227125532925E-4, }, { - 502.05052164942026, 485.91779258847237, 464.11991154402494, 436.75185588002205, - 411.17336819320917, 383.33036886900663, 366.5155046656728, 334.26181526482105, - 308.3470098376274, 288.7738408744335, 260.332594871521, 242.4736728295684, - 229.66440346837044, 219.4005109295249, 205.81142588704824, + 500.25713642584833, 485.6798042813498, 462.5099852368403, 438.8223129853304, + 411.2180253415381, 383.33036886855643, 366.5155046623204, 334.3895290761275, + 308.34700983663697, 288.773840881483, 260.33259486916086, 242.47727504848808, + 229.664403461019, 219.6421213228923, 205.81142588513376, }, { - 13.637416116893291, 11.293272890150547, 9.741776660084724, 8.293842449784279, - 6.9908598735928535, 5.493516407907009, 4.693962275981903, 3.6259122267365456, - 2.9906081929802895, 2.5887924432754517, 2.1600354313850403, 1.8493054434657097, - 1.689537525177002, 1.5635392591357231, 1.3930133953690529, + 13.63730886850226, 11.131924092409463, 9.725488211197444, 8.293842443340509, + 6.990965127238269, 5.49330590055888, 4.7039837191559855, 3.6282148184991456, + 2.9906666666674937, 2.5889655172422863, 2.1600180365130655, 1.849353021440038, + 1.6895299145307945, 1.5650976138831538, 1.3930370860935, } }; @@ -85,11 +85,11 @@ public class MySample_simpiece_full2 { String delimiter = ","; TimeSeries ts = TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, false); + inputStream, delimiter, false, N, start, hasHeader, true); for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; - // - // double epsilon = getSimPieceParam(nout, ts, 1e-8); + + // double epsilon = MySample_simpiece.getSimPieceParam(nout, ts, 1e-12); // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; @@ -167,78 +167,71 @@ public class MySample_simpiece_full2 { } } - public static double getSimPieceParam(int nout, TimeSeries ts, double accuracy) - throws IOException { - double epsilon = 1; - boolean directLess = false; - boolean directMore = false; - boolean skip = false; // TODO - int threshold = 2; // TODO - while (true) { - SimPiece simPiece = new SimPiece(ts.data, epsilon); - if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint - if (directMore) { - // TODO - if (Math.abs(simPiece.segments.size() * 2 - nout) <= threshold) { - skip = true; - } - // - break; - } - if (!directLess) { - directLess = true; - } - epsilon *= 2; - } else { - if (directLess) { - // TODO - if (Math.abs(nout - simPiece.segments.size() * 2) <= threshold) { - skip = true; - } - // - break; - } - if (!directMore) { - directMore = true; - } - epsilon /= 2; - } - } - // TODO - if (skip) { - return epsilon; - } - // - // begin dichotomy - double left = 0; - double right = 0; - if (directLess) { - left = epsilon / 2; - right = epsilon; - } - if (directMore) { - left = epsilon; - right = epsilon * 2; - } - while (Math.abs(right - left) > accuracy) { - double mid = (left + right) / 2; - SimPiece simPiece = new SimPiece(ts.data, mid); - if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint - left = mid; - } else { - right = mid; - } - } - // TODO - SimPiece simPiece = new SimPiece(ts.data, left); - int n1 = simPiece.segments.size() * 2; - simPiece = new SimPiece(ts.data, right); - int n2 = simPiece.segments.size() * 2; - if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { - return left; - } else { - return right; - } - // - } + // public static double getSimPieceParam(int nout, TimeSeries ts, double accuracy) + // throws IOException { + // double epsilon = 1; + // boolean directLess = false; + // boolean directMore = false; + // boolean skip = false; + // int threshold = 2; + // while (true) { + // SimPiece simPiece = new SimPiece(ts.data, epsilon); + // if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint + // if (directMore) { + // if (Math.abs(simPiece.segments.size() * 2 - nout) <= threshold) { + // skip = true; + // } + // break; + // } + // if (!directLess) { + // directLess = true; + // } + // epsilon *= 2; + // } else { + // if (directLess) { + // if (Math.abs(nout - simPiece.segments.size() * 2) <= threshold) { + // skip = true; + // } + // break; + // } + // if (!directMore) { + // directMore = true; + // } + // epsilon /= 2; + // } + // } + // if (skip) { + // return epsilon; + // } + // + // // begin dichotomy + // double left = 0; + // double right = 0; + // if (directLess) { + // left = epsilon / 2; + // right = epsilon; + // } + // if (directMore) { + // left = epsilon; + // right = epsilon * 2; + // } + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // SimPiece simPiece = new SimPiece(ts.data, mid); + // if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint + // left = mid; + // } else { + // right = mid; + // } + // } + // SimPiece simPiece = new SimPiece(ts.data, left); + // int n1 = simPiece.segments.size() * 2; + // simPiece = new SimPiece(ts.data, right); + // int n2 = simPiece.segments.size() * 2; + // if (Math.abs(n1 - nout) < Math.abs(n2 - nout)) { + // return left; + // } else { + // return right; + // } + // } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full_deprecated.java similarity index 85% rename from server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full.java rename to server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full_deprecated.java index 16876b2886b..397bc838e13 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full_deprecated.java @@ -23,12 +23,11 @@ package org.apache.iotdb.db.query.simpiece; import java.io.FileInputStream; import java.io.FileWriter; -import java.io.IOException; import java.io.PrintWriter; import java.util.Comparator; import java.util.List; -public class MySample_simpiece_full { +public class MySample_simpiece_full_deprecated { public static void main(String[] args) { String fileDir = "D:\\desktop\\NISTPV\\"; @@ -102,7 +101,7 @@ public class MySample_simpiece_full { for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; - // double epsilon = getSimPieceParam(nout, ts, 1e-6); + // double epsilon = MySample_simpiece.getSimPieceParam(nout, ts, 1e-6); // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; @@ -166,28 +165,28 @@ public class MySample_simpiece_full { } } - public static double getSimPieceParam(int nout, TimeSeries ts, double accuracy) - throws IOException { - double epsilon = ts.range * 0.001; - while (true) { - SimPiece simPiece = new SimPiece(ts.data, epsilon); - if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint - epsilon *= 2; - } else { - break; - } - } - double left = epsilon / 2; - double right = epsilon; - while (Math.abs(right - left) > accuracy) { - double mid = (left + right) / 2; - SimPiece simPiece = new SimPiece(ts.data, mid); - if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint - left = mid; - } else { - right = mid; - } - } - return (left + right) / 2; - } + // public static double getSimPieceParam(int nout, TimeSeries ts, double accuracy) + // throws IOException { + // double epsilon = ts.range * 0.001; + // while (true) { + // SimPiece simPiece = new SimPiece(ts.data, epsilon); + // if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint + // epsilon *= 2; + // } else { + // break; + // } + // } + // double left = epsilon / 2; + // double right = epsilon; + // while (Math.abs(right - left) > accuracy) { + // double mid = (left + right) / 2; + // SimPiece simPiece = new SimPiece(ts.data, mid); + // if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint + // left = mid; + // } else { + // right = mid; + // } + // } + // return (left + right) / 2; + // } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/TimeSeriesReader.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/TimeSeriesReader.java index f43b9189f0c..e996c080b87 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/TimeSeriesReader.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/TimeSeriesReader.java @@ -214,6 +214,8 @@ public class TimeSeriesReader { boolean seriesTimeColumn) { // N<0 means read all lines + System.out.println("seriesTimeColumn=" + seriesTimeColumn); + ArrayList<Point> ts = new ArrayList<>(); double max = Double.MIN_VALUE; double min = Double.MAX_VALUE; @@ -243,7 +245,7 @@ public class TimeSeriesReader { if (!seriesTimeColumn) { timestamp = (long) Double.parseDouble(elements[0]); } else { - timestamp = cnt; // for DFT, DWT, OM3 + timestamp = cnt; // because DWT, OM3 timestamp starting from 0 } double value = Double.parseDouble(elements[1]); ts.add(new Point(timestamp, value)); diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/jwave/transforms/AncientEgyptianDecomposition.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/jwave/transforms/AncientEgyptianDecomposition.java index c97ef47ef84..ca5bcfd60f2 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/jwave/transforms/AncientEgyptianDecomposition.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/jwave/transforms/AncientEgyptianDecomposition.java @@ -22,6 +22,7 @@ package org.apache.iotdb.db.query.simpiece.jwave.transforms; import org.apache.iotdb.db.query.simpiece.jwave.exceptions.JWaveException; import org.apache.iotdb.db.query.simpiece.jwave.tools.MathToolKit; +import org.apache.iotdb.tsfile.read.common.IOMonitor2; /** * A wavelet transform method for arrays and signals of arbitrary lengths, even odd lengths. The @@ -36,8 +37,8 @@ import org.apache.iotdb.db.query.simpiece.jwave.tools.MathToolKit; * For an "orthonormal" wavelet this holds. See: * http://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication * - * @date 14.08.2010 10:43:28 * @author Christian ([email protected]) + * @date 14.08.2010 10:43:28 */ public class AncientEgyptianDecomposition extends BasicTransform { @@ -81,9 +82,9 @@ public class AncientEgyptianDecomposition extends BasicTransform { * transform and the resulting wavelet coefficients are copied back to their original discrete * positions. * + * @throws JWaveException * @date 14.08.2010 10:43:28 * @author Christian ([email protected]) - * @throws JWaveException * @see jwave.transforms.BasicTransform#forward(double[]) */ @Override @@ -105,6 +106,9 @@ public class AncientEgyptianDecomposition extends BasicTransform { double[] arrTimeSub = new double[arrTimeSubLength]; for (int i = 0; i < arrTimeSub.length; i++) { + + IOMonitor2.DCP_D_getAllSatisfiedPageData_traversedPointNum++; // note + arrTimeSub[i] = arrTime[i + offSet]; } @@ -126,9 +130,9 @@ public class AncientEgyptianDecomposition extends BasicTransform { * arrays of length 2^p is reverse transformed by the selected basic transform and the resulting * coefficients of time domain are copied back to their original discrete positions. * + * @throws JWaveException * @date 14.08.2010 10:43:28 * @author Christian ([email protected]) - * @throws JWaveException * @see jwave.transforms.BasicTransform#reverse(double[]) */ @Override
