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 cd4bed2a3377723a261c3859211dccf62d4f8db2 Author: Lei Rui <[email protected]> AuthorDate: Sun Oct 27 23:36:42 2024 +0800 add --- README.md | 9 +- .../iotdb/db/query/simpiece/MySample_fsw2.java | 61 +----- .../db/query/simpiece/MySample_fsw_deprecated.java | 197 ----------------- .../db/query/simpiece/MySample_fsw_full2.java | 78 +++---- .../simpiece/MySample_fsw_full2_deprecated.java | 228 -------------------- .../simpiece/MySample_fsw_full_deprecated.java | 192 ----------------- .../simpiece/MySample_shrinkingcone_full2.java | 83 ++++---- .../MySample_shrinkingcone_full2_deprecated.java | 233 -------------------- .../MySample_shrinkingcone_full_deprecated.java | 182 ---------------- .../db/query/simpiece/MySample_simpiece2.java | 43 +--- .../simpiece/MySample_simpiece_deprecated.java | 196 ----------------- .../db/query/simpiece/MySample_simpiece_full2.java | 76 +++---- .../MySample_simpiece_full2_deprecated.java | 237 --------------------- .../MySample_simpiece_full_deprecated.java | 192 ----------------- 14 files changed, 148 insertions(+), 1859 deletions(-) diff --git a/README.md b/README.md index f4b5b8681fc..0e986824656 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,17 @@ --> # ILTS -- The code for ILTS and other baselines compared in experiments are available in this repository. +- The code for ILTS and other baselines compared in query efficiency experiments are available in this repository. - ILTS is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_ILTS.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_ILTS.java) with convex hull precomputation in [tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java](tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java). - LTTB is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_LTTB.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_LTTB.java). - MinMaxLTTB is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_MinMaxPreselection.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_MinMaxPreselection.java) and [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/GroupByWithoutValueFilterDataSet.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/GroupByWithoutValueFilterDataSet.java). - - Visval is implemented in [server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval.java](server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval.java). - MinMax is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_MinMax.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_MinMax.java). - M4 is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_M4.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_M4.java). + - OM3 is implemented by storing the OM3 coefficient table as regular time series and querying them with a `WHERE timestamp in (%s)` clause. +- For the README of [Apache IoTDB](https://iotdb.apache.org/) itself, please see [README_IOTDB.md](README_IOTDB.md). To build this repository, run `mvn clean package -DskipTests -pl -distribution`. +- Others: + - Visval is implemented in [server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval.java](server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval.java). - Uniform is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_Uniform.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_Uniform.java). - FSW is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_FSW.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_FSW.java) and [server/src/main/java/org/apache/iotdb/db/query/simpiece/FSW.java](server/src/main/java/org/apache/iotdb/db/query/simpiece/FSW.java). - - SC is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_SC.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_SC.java) and [server/src/main/java/org/apache/iotdb/db/query/simpiece/ShrinkingCone.java](server/src/main/java/org/apache/iotdb/db/query/simpiece/ShrinkingCone.java). - Sim-Piece is implemented in [server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_SimPiece.java](server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutorTri_SimPiece.java) and [server/src/main/java/org/apache/iotdb/db/query/simpiece/SimPiece.java](server/src/main/java/org/apache/iotdb/db/query/simpiece/SimPiece.java). - Some integration tests for correctness are in [server/src/test/java/org/apache/iotdb/db/integration/tri/MyTest_ILTS.java](server/src/test/java/org/apache/iotdb/db/integration/tri/MyTest_ILTS.java). -- For the README of [Apache IoTDB](https://iotdb.apache.org/) itself, please see [README_IOTDB.md](README_IOTDB.md). To build this repository, run `mvn clean package -DskipTests -pl -distribution`. diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java index ed82643d7a8..6c42a7d13b7 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java @@ -31,13 +31,13 @@ public class MySample_fsw2 { public static void main(String[] args) { String fileDir = "D:\\desktop\\NISTPV\\"; - String[] datasetNameList = new String[]{"Qloss", "Pyra1", "RTD", "WindSpeed"}; - int[] noutList = new int[]{100}; - double[] r = new double[]{0.1, 0.5, 1.3, 0}; - int[] NList = new int[]{2500000, 2500000, 2500000, 2500000}; + String[] datasetNameList = new String[] {"Qloss", "Pyra1", "RTD", "WindSpeed"}; + int[] noutList = new int[] {100}; + double[] r = new double[] {0.1, 0.5, 1.3, 0}; + int[] NList = new int[] {2500000, 2500000, 2500000, 2500000}; double[] epsilonList = - new double[]{ - 9.999999992942321E-4, 284.40344031846143, 6.428162015438829, 8.361764705882706 + new double[] { + 9.999999992942321E-4, 284.40344031846143, 6.428162015438829, 8.361764705882706 }; for (int y = 0; y < datasetNameList.length; y++) { String datasetName = datasetNameList[y]; @@ -55,7 +55,7 @@ public class MySample_fsw2 { TimeSeries ts = TimeSeriesReader.getMyTimeSeries( inputStream, delimiter, false, N, start, hasHeader, true); -// double epsilon = getFSWParam(nout, ts, 1e-12); + // double epsilon = getFSWParam(nout, ts, 1e-12); double epsilon = epsilonList[y]; List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); System.out.println( @@ -83,53 +83,6 @@ public class MySample_fsw2 { } } - // 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; diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_deprecated.java deleted file mode 100644 index 6794acca0dd..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_deprecated.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -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_deprecated { - - public static void main(String[] args) { - String fileDir = "D:\\desktop\\NISTPV\\"; - String[] datasetNameList = new String[] {"Qloss", "Pyra1", "RTD", "WindSpeed"}; - 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[] { - 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开始计数 - int end = (int) (10000000 / 2 + NList[y] * (1 - r[y])); - int N = end - start; - - for (int nout : noutList) { - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, true); - // double epsilon = getFSWParam(nout, ts, 1e-12); - double epsilon = epsilonList[y]; - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + reducedPoints.size()); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName + "-" + N + "-" + reducedPoints.size() + "-fsw.csv"))) { - for (Point p : reducedPoints) { - writer.println(p.getTimestamp() + "," + p.getValue()); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - // 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) { - 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_full2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2.java index 0aa48c0f0ba..fb867829759 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 @@ -35,44 +35,48 @@ public class MySample_fsw_full2 { 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, 480, 740, 1200, 2000, 3500, 6000, 10000, 15000 - }; + String[] datasetNameList = new String[] {"WindSpeed", "Qloss", "Pyra1", "RTD"}; + int[] noutList = new int[] {320, 480, 740, 1200, 2000, 3500, 6000, 10000, 15000}; double[][] epsilonArray = { - { - 18.988672256469727, 17.742149353027344, 15.250774383544922, 5.240921974182129, - 4.0604248046875, 3.5127735137939453, 3.09999942779541, 2.782364845275879, - 2.5470895767211914, - }, - { - 9.9945068359375E-4, 9.984970092773438E-4, 9.946823120117188E-4, 9.822845458984375E-4, - 9.49859619140625E-4, 8.344650268554688E-4, 4.949569702148438E-4, 0.0, 0.0, - }, - { - 566.705379486084, 526.4058027267456, 489.42593574523926, 454.6960153579712, - 420.31038188934326, 375.1610279083252, 320.00675773620605, 254.37902355194092, - 196.95625495910645, - }, - { - 14.356999397277832, 10.442278861999512, 8.121441841125488, 5.849754333496094, - 3.919279098510742, 2.444706916809082, 1.4873542785644531, 0.9297647476196289, - 0.6465520858764648, - } + { + 18.988672256469727, 17.742149353027344, 15.250774383544922, 5.240921974182129, + 4.0604248046875, 3.5127735137939453, 3.09999942779541, 2.782364845275879, + 2.5470895767211914, + }, + { + 9.9945068359375E-4, + 9.984970092773438E-4, + 9.946823120117188E-4, + 9.822845458984375E-4, + 9.49859619140625E-4, + 8.344650268554688E-4, + 4.949569702148438E-4, + 0.0, + 0.0, + }, + { + 566.705379486084, 526.4058027267456, 489.42593574523926, 454.6960153579712, + 420.31038188934326, 375.1610279083252, 320.00675773620605, 254.37902355194092, + 196.95625495910645, + }, + { + 14.356999397277832, 10.442278861999512, 8.121441841125488, 5.849754333496094, + 3.919279098510742, 2.444706916809082, 1.4873542785644531, 0.9297647476196289, + 0.6465520858764648, + } }; -// double[][] epsilonArray = new double[datasetNameList.length][]; -// for (int i = 0; i < datasetNameList.length; i++) { -// epsilonArray[i] = new double[noutList.length]; -// } + // double[][] epsilonArray = new double[datasetNameList.length][]; + // for (int i = 0; i < datasetNameList.length; i++) { + // epsilonArray[i] = new double[noutList.length]; + // } for (int y = 0; y < datasetNameList.length; y++) { -// if (y != 1) { -// System.out.println("only for Qloss"); -// continue; -// } + // if (y != 1) { + // System.out.println("only for Qloss"); + // continue; + // } String datasetName = datasetNameList[y]; int start = 0; int end = 1000_0000; @@ -85,14 +89,14 @@ public class MySample_fsw_full2 { inputStream, delimiter, false, N, start, hasHeader, true); for (int x = 0; x < noutList.length; x++) { -// if (y == 1 && x > 6) { -// continue; // because FSW on Qloss special -// } + // if (y == 1 && x > 6) { + // continue; // because FSW on Qloss special + // } int nout = noutList[x]; -// double epsilon = MySample_fsw2.getFSWParam(nout, ts, 1e-6); -// epsilonArray[y][x] = epsilon; + // double epsilon = MySample_fsw2.getFSWParam(nout, ts, 1e-6); + // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2_deprecated.java deleted file mode 100644 index adbb3e3074e..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full2_deprecated.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -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_full2_deprecated { - // 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, 400, 480, 580, 720, 960, 1200, 1600, 2000, 2400, 3000, 3600, 4000, 4400, 5000 - }; - - double[][] epsilonArray = { - { - 9.618214055872158, - 8.99153642953479, - 8.375, - 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.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, - }, - { - 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.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, - } - }; - - // double[][] epsilonArray = new double[datasetNameList.length][]; - // for (int i = 0; i < datasetNameList.length; i++) { - // epsilonArray[i] = new double[noutList.length]; - // } - - for (int y = 0; y < datasetNameList.length; y++) { - String datasetName = datasetNameList[y]; - int start = 0; - int end = 1000_0000; - int N = end - start; - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, true); - for (int x = 0; x < noutList.length; x++) { - int nout = noutList[x]; - - // double epsilon = MySample_fsw.getFSWParam(nout, ts, 1e-12); - // epsilonArray[y][x] = epsilon; - - double epsilon = epsilonArray[y][x]; - - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + reducedPoints.size()); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName - + "-" - + N - + "-" - + nout - + "-" - + reducedPoints.size() - + "-fsw.csv"))) { - for (Point p : reducedPoints) { - writer.println(p.getTimestamp() + "," + p.getValue()); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - // 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(); - // } - - // do not change name of the output file, as the output is used in exp bash - try (FileWriter writer = new FileWriter("epsilonArray_fsw.txt")) { - for (double[] row : epsilonArray) { - for (double element : row) { - writer.write(element + " "); - System.out.print(element + ","); - } - writer.write("\n"); - System.out.println(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - // 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_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full_deprecated.java deleted file mode 100644 index 184be70aaed..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_full_deprecated.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -package org.apache.iotdb.db.query.simpiece; - -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.util.List; - -public class MySample_fsw_full_deprecated { - - public static void main(String[] args) { - String fileDir = "D:\\desktop\\NISTPV\\"; - String[] datasetNameList = new String[] {"WindSpeed", "Qloss", "Pyra1", "RTD"}; - int[] noutList = new int[] {320, 360, 400, 440, 480, 520, 560, 600, 640}; - - double[][] epsilonArray = { - { - 9.618271350860596, - 9.101282596588135, - 8.991526126861572, - 8.62817907333374, - 8.374999523162842, - 8.202636241912842, - 7.999906063079834, - 7.947059154510498, - 7.858933925628662 - }, - { - 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 - }, - { - 440.0235962867737, - 432.0247492790222, - 423.55674982070923, - 414.65001153945923, - 405.77113008499146, - 401.21820974349976, - 396.7935194969177, - 393.2065939903259, - 392.30953645706177 - }, - { - 9.295397281646729, - 8.096678256988525, - 7.536666393280029, - 6.961357593536377, - 6.473535060882568, - 6.064479351043701, - 5.743286609649658, - 5.5219340324401855, - 5.185042858123779 - } - }; - - // double[][] epsilonArray = new double[datasetNameList.length][]; - // for (int i = 0; i < datasetNameList.length; i++) { - // epsilonArray[i] = new double[noutList.length]; - // } - - for (int y = 0; y < datasetNameList.length; y++) { - String datasetName = datasetNameList[y]; - int start = 0; - int end = 1000_0000; - int N = end - start; - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, false); - for (int x = 0; x < noutList.length; x++) { - int nout = noutList[x]; - // double epsilon = MySample_fsw.getFSWParam(nout, ts, 1e-6); - // epsilonArray[y][x] = epsilon; - - double epsilon = epsilonArray[y][x]; - - List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + reducedPoints.size()); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName - + "-" - + N - + "-" - + nout - + "-" - + reducedPoints.size() - + "-fsw.csv"))) { - for (Point p : reducedPoints) { - writer.println(p.getTimestamp() + "," + p.getValue()); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - 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; - // } - // 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_full2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2.java index 26cc9572324..3731f91e955 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 @@ -35,42 +35,53 @@ public class MySample_shrinkingcone_full2 { 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, 480, 740, 1200, 2000, 3500, 6000, 10000, 15000 - }; + String[] datasetNameList = new String[] {"WindSpeed", "Qloss", "Pyra1", "RTD"}; + int[] noutList = new int[] {320, 480, 740, 1200, 2000, 3500, 6000, 10000, 15000}; double[][] epsilonArray = { - { - 28.350000381469727, 24.75, 20.15000057220459, 7.495454788208008, 5.978656768798828, - 5.123478889465332, 4.4909868240356445, 3.9743595123291016, 3.59999942779541, - }, - { - 0.001, 9.9945068359375E-4, 9.9945068359375E-4, 9.9945068359375E-4, - 9.9945068359375E-4, 9.984970092773438E-4, 9.517669677734375E-4, 0.0, 0.0, - }, - { - 868.2230234146118, 824.095006942749, 772.8191223144531, 709.9235706329346, - 632.2311534881592, 527.634295463562, 421.8133182525635, 322.99202156066895, - 247.5426368713379, - }, - { - 17.567204475402832, 13.436342239379883, 10.276226997375488, 7.288450241088867, - 4.86691951751709, 2.9565000534057617, 1.8069705963134766, 1.1284055709838867, - 0.8002557754516602, - } + { + 28.350000381469727, + 24.75, + 20.15000057220459, + 7.495454788208008, + 5.978656768798828, + 5.123478889465332, + 4.4909868240356445, + 3.9743595123291016, + 3.59999942779541, + }, + { + 0.001, + 9.9945068359375E-4, + 9.9945068359375E-4, + 9.9945068359375E-4, + 9.9945068359375E-4, + 9.984970092773438E-4, + 9.517669677734375E-4, + 0.0, + 0.0, + }, + { + 868.2230234146118, 824.095006942749, 772.8191223144531, 709.9235706329346, + 632.2311534881592, 527.634295463562, 421.8133182525635, 322.99202156066895, + 247.5426368713379, + }, + { + 17.567204475402832, 13.436342239379883, 10.276226997375488, 7.288450241088867, + 4.86691951751709, 2.9565000534057617, 1.8069705963134766, 1.1284055709838867, + 0.8002557754516602, + } }; -// double[][] epsilonArray = new double[datasetNameList.length][]; -// for (int i = 0; i < datasetNameList.length; i++) { -// epsilonArray[i] = new double[noutList.length]; -// } + // double[][] epsilonArray = new double[datasetNameList.length][]; + // for (int i = 0; i < datasetNameList.length; i++) { + // epsilonArray[i] = new double[noutList.length]; + // } for (int y = 0; y < datasetNameList.length; y++) { -// if (y != 1) { -// continue; -// } + // if (y != 1) { + // continue; + // } String datasetName = datasetNameList[y]; int start = 0; @@ -83,14 +94,14 @@ public class MySample_shrinkingcone_full2 { TimeSeriesReader.getMyTimeSeries( inputStream, delimiter, false, N, start, hasHeader, true); for (int x = 0; x < noutList.length; x++) { -// if (y == 1 && x > 6) { -// continue; // because SC on Qloss special? -// } + // if (y == 1 && x > 6) { + // continue; // because SC on Qloss special? + // } int nout = noutList[x]; -// -// double epsilon = MySample_shrinkingcone.getSCParam(nout, ts, 1e-6); -// epsilonArray[y][x] = epsilon; + // + // double epsilon = MySample_shrinkingcone.getSCParam(nout, ts, 1e-6); + // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2_deprecated.java deleted file mode 100644 index 7243d184a7c..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full2_deprecated.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -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_full2_deprecated { - // 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, 400, 480, 580, 720, 960, 1200, 1600, 2000, 2400, 3000, 3600, 4000, 4400, 5000 - }; - - double[][] epsilonArray = { - { - 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.999999892897904E-4, - 9.999999892897904E-4, - 9.999999892897904E-4, - 9.986772784031928E-4, - 9.954648558050394E-4, - 9.931506938301027E-4, - 9.859154815785587E-4, - 9.090908570215106E-4, - }, - { - 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.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, - } - }; - - // double[][] epsilonArray = new double[datasetNameList.length][]; - // for (int i = 0; i < datasetNameList.length; i++) { - // epsilonArray[i] = new double[noutList.length]; - // } - - for (int y = 0; y < datasetNameList.length; y++) { - String datasetName = datasetNameList[y]; - int start = 0; - int end = 1000_0000; - int N = end - start; - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, true); - for (int x = 0; x < noutList.length; x++) { - int nout = noutList[x]; - - // double epsilon = MySample_shrinkingcone.getSCParam(nout, ts, 1e-10); - // epsilonArray[y][x] = epsilon; - - double epsilon = epsilonArray[y][x]; - - List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + reducedPoints.size()); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName - + "-" - + N - + "-" - + nout - + "-" - + reducedPoints.size() - + "-sc.csv"))) { - for (Point p : reducedPoints) { - writer.println(p.getTimestamp() + "," + p.getValue()); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - // 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(); - // } - - // do not change name of the output file, as the output is used in exp bash - try (FileWriter writer = new FileWriter("epsilonArray_sc.txt")) { - for (double[] row : epsilonArray) { - for (double element : row) { - writer.write(element + " "); - System.out.print(element + ","); - } - writer.write("\n"); - System.out.println(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - // 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_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full_deprecated.java deleted file mode 100644 index bc0004c1b54..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_shrinkingcone_full_deprecated.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -package org.apache.iotdb.db.query.simpiece; - -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.util.List; - -public class MySample_shrinkingcone_full_deprecated { - - public static void main(String[] args) { - String fileDir = "D:\\desktop\\NISTPV\\"; - String[] datasetNameList = new String[] {"WindSpeed", "Qloss", "Pyra1", "RTD"}; - int[] noutList = new int[] {320, 360, 400, 440, 480, 520, 560, 600, 640}; - - double[][] epsilonArray = { - { - 14.388325214385986, - 13.768231868743896, - 13.343345165252686, - 13.091249942779541, - 12.69767427444458, - 12.391706943511963, - 12.167190074920654, - 11.972727298736572, - 11.756273746490479 - }, - {0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.0009999999999999999}, - { - 680.2196469306946, - 665.2842917442322, - 650.2610821723938, - 636.7945942878723, - 620.9016032218933, - 604.7394433021545, - 592.9867577552795, - 578.6471419334412, - 570.5106825828552 - }, - { - 11.259880542755127, - 10.37297010421753, - 9.402754306793213, - 8.867334842681885, - 8.384315967559814, - 7.915340900421143, - 7.39516019821167, - 6.892223834991455, - 6.5178914070129395 - } - }; - - // double[][] epsilonArray = new double[datasetNameList.length][]; - // for (int i = 0; i < datasetNameList.length; i++) { - // epsilonArray[i] = new double[noutList.length]; - // } - - for (int y = 0; y < datasetNameList.length; y++) { - String datasetName = datasetNameList[y]; - int start = 0; - int end = 1000_0000; - int N = end - start; - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, false); - for (int x = 0; x < noutList.length; x++) { - int nout = noutList[x]; - - // double epsilon = MySample_shrinkingcone.getSCParam(nout, ts, 1e-6); - // epsilonArray[y][x] = epsilon; - - double epsilon = epsilonArray[y][x]; - - List<Point> reducedPoints = ShrinkingCone.reducePoints(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + reducedPoints.size()); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName - + "-" - + N - + "-" - + nout - + "-" - + reducedPoints.size() - + "-sc.csv"))) { - for (Point p : reducedPoints) { - writer.println(p.getTimestamp() + "," + p.getValue()); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - 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 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_simpiece2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece2.java index d09e81dc543..2982fd600ef 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece2.java +++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece2.java @@ -32,14 +32,14 @@ public class MySample_simpiece2 { public static void main(String[] args) { String fileDir = "D:\\desktop\\NISTPV\\"; - String[] datasetNameList = new String[]{"Qloss", "Pyra1", "RTD", "WindSpeed"}; - int[] noutList = new int[]{100}; - double[] r = new double[]{0.1, 0.5, 1.3, 0}; + String[] datasetNameList = new String[] {"Qloss", "Pyra1", "RTD", "WindSpeed"}; + int[] noutList = new int[] {100}; + double[] r = new double[] {0.1, 0.5, 1.3, 0}; double[] epsilonList = - new double[]{ - 9.999999992942321E-4, 316.5640427571989, 9.186666666667406, 8.968221799290404 + new double[] { + 9.999999992942321E-4, 316.5640427571989, 9.186666666667406, 8.968221799290404 }; - int[] NList = new int[]{2500000, 2500000, 2500000, 2500000}; + int[] NList = new int[] {2500000, 2500000, 2500000, 2500000}; for (int y = 0; y < datasetNameList.length; y++) { String datasetName = datasetNameList[y]; int start = (int) (10000000 / 2 - NList[y] * r[y]); // 从0开始计数 @@ -57,7 +57,7 @@ public class MySample_simpiece2 { TimeSeries ts = TimeSeriesReader.getMyTimeSeries( inputStream, delimiter, false, N, start, hasHeader, true); -// double epsilon = getSimPieceParam(nout, ts, 1e-12); + // double epsilon = getSimPieceParam(nout, ts, 1e-12); double epsilon = epsilonList[y]; SimPiece simPiece = new SimPiece(ts.data, epsilon); System.out.println( @@ -82,7 +82,7 @@ public class MySample_simpiece2 { // end point of this segment double v = (segments.get(i + 1).getInitTimestamp() - segments.get(i).getInitTimestamp()) - * segments.get(i).getA() + * segments.get(i).getA() + segments.get(i).getB(); writer.println(segments.get(i + 1).getInitTimestamp() + "," + v); } @@ -93,7 +93,7 @@ public class MySample_simpiece2 { + segments.get(segments.size() - 1).getB()); double v = (simPiece.lastTimeStamp - segments.get(segments.size() - 1).getInitTimestamp()) - * segments.get(segments.size() - 1).getA() + * segments.get(segments.size() - 1).getA() + segments.get(segments.size() - 1).getB(); writer.println(simPiece.lastTimeStamp + "," + v); } @@ -104,31 +104,6 @@ public class MySample_simpiece2 { } } - // 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 = 1; diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_deprecated.java deleted file mode 100644 index e7d9a698262..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_deprecated.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -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_deprecated { - - public static void main(String[] args) { - String fileDir = "D:\\desktop\\NISTPV\\"; - String[] datasetNameList = new String[] {"Qloss", "Pyra1", "RTD", "WindSpeed"}; - int[] noutList = new int[] {100}; - double[] r = new double[] {0.1, 0.5, 1.3, 0}; - double[] epsilonList = - 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]; - int start = (int) (10000000 / 2 - NList[y] * r[y]); // 从0开始计数 - int end = (int) (10000000 / 2 + NList[y] * (1 - r[y])); - int N = end - start; - - for (int nout : noutList) { - // apply Sim-Piece on the input file, outputting nout points saved in csvFile - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, true); - // double epsilon = getSimPieceParam(nout, ts, 1e-12); - double epsilon = epsilonList[y]; - SimPiece simPiece = new SimPiece(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + simPiece.segments.size() * 2); - List<SimPieceSegment> segments = simPiece.segments; - segments.sort(Comparator.comparingLong(SimPieceSegment::getInitTimestamp)); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName + "-" + N + "-" + segments.size() * 2 + "-simpiece.csv"))) { - for (int i = 0; i < segments.size() - 1; i++) { - // start point of this segment - writer.println(segments.get(i).getInitTimestamp() + "," + segments.get(i).getB()); - // end point of this segment - double v = - (segments.get(i + 1).getInitTimestamp() - segments.get(i).getInitTimestamp()) - * segments.get(i).getA() - + segments.get(i).getB(); - writer.println(segments.get(i + 1).getInitTimestamp() + "," + v); - } - // the two end points of the last segment - writer.println( - segments.get(segments.size() - 1).getInitTimestamp() - + "," - + segments.get(segments.size() - 1).getB()); - double v = - (simPiece.lastTimeStamp - segments.get(segments.size() - 1).getInitTimestamp()) - * segments.get(segments.size() - 1).getA() - + segments.get(segments.size() - 1).getB(); - writer.println(simPiece.lastTimeStamp + "," + v); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - // 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 = 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_full2.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2.java index 324a0881341..3c917a17fdc 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 @@ -36,45 +36,47 @@ public class MySample_simpiece_full2 { 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, 480, 740, 1200, 2000, 3500, 6000, 10000, 15000 - }; + String[] datasetNameList = new String[] {"WindSpeed", "Qloss", "Pyra1", "RTD"}; + int[] noutList = new int[] {320, 480, 740, 1200, 2000, 3500, 6000, 10000, 15000}; double[][] epsilonArray = { - { - 17.286434173583984, 15.812178611755371, 13.160140037536621, 8.928653717041016, - 4.689850807189941, 3.816372871398926, 3.328960418701172, 2.950345993041992, - 2.692307472229004, - }, - { - 9.9945068359375E-4, 9.698867797851562E-4, 7.89642333984375E-4, 6.666183471679688E-4, - 5.626678466796875E-4, 5.07354736328125E-4, 4.987716674804688E-4, - 4.2351647362715017E-22, - 4.2351647362715017E-22, - }, - { - 643.1565141677856, 606.646897315979, 559.2596483230591, 519.0886516571045, - 460.05999660491943, 400.9924087524414, 343.4447431564331, 283.27570056915283, - 229.07614612579346, - }, - { - 19.49333381652832, 14.994223594665527, 11.001291275024414, 7.752982139587402, - 5.533552169799805, 3.6270971298217773, 2.286458969116211, 1.4204912185668945, - 0.9623184204101562, - } + { + 17.286434173583984, 15.812178611755371, 13.160140037536621, 8.928653717041016, + 4.689850807189941, 3.816372871398926, 3.328960418701172, 2.950345993041992, + 2.692307472229004, + }, + { + 9.9945068359375E-4, + 9.698867797851562E-4, + 7.89642333984375E-4, + 6.666183471679688E-4, + 5.626678466796875E-4, + 5.07354736328125E-4, + 4.987716674804688E-4, + 4.2351647362715017E-22, + 4.2351647362715017E-22, + }, + { + 643.1565141677856, 606.646897315979, 559.2596483230591, 519.0886516571045, + 460.05999660491943, 400.9924087524414, 343.4447431564331, 283.27570056915283, + 229.07614612579346, + }, + { + 19.49333381652832, 14.994223594665527, 11.001291275024414, 7.752982139587402, + 5.533552169799805, 3.6270971298217773, 2.286458969116211, 1.4204912185668945, + 0.9623184204101562, + } }; -// double[][] epsilonArray = new double[datasetNameList.length][]; -// for (int i = 0; i < datasetNameList.length; i++) { -// epsilonArray[i] = new double[noutList.length]; -// } + // double[][] epsilonArray = new double[datasetNameList.length][]; + // for (int i = 0; i < datasetNameList.length; i++) { + // epsilonArray[i] = new double[noutList.length]; + // } for (int y = 0; y < datasetNameList.length; y++) { -// if (y != 1) { -// continue; -// } + // if (y != 1) { + // continue; + // } String datasetName = datasetNameList[y]; int start = 0; @@ -90,8 +92,8 @@ public class MySample_simpiece_full2 { for (int x = 0; x < noutList.length; x++) { int nout = noutList[x]; -// double epsilon = MySample_simpiece2.getSimPieceParam(nout, ts, 1e-6); -// epsilonArray[y][x] = epsilon; + // double epsilon = MySample_simpiece2.getSimPieceParam(nout, ts, 1e-6); + // epsilonArray[y][x] = epsilon; double epsilon = epsilonArray[y][x]; @@ -125,7 +127,7 @@ public class MySample_simpiece_full2 { // end point of this segment double v = (segments.get(i + 1).getInitTimestamp() - segments.get(i).getInitTimestamp()) - * segments.get(i).getA() + * segments.get(i).getA() + segments.get(i).getB(); writer.println(segments.get(i + 1).getInitTimestamp() + "," + v); } @@ -136,7 +138,7 @@ public class MySample_simpiece_full2 { + segments.get(segments.size() - 1).getB()); double v = (simPiece.lastTimeStamp - segments.get(segments.size() - 1).getInitTimestamp()) - * segments.get(segments.size() - 1).getA() + * segments.get(segments.size() - 1).getA() + segments.get(segments.size() - 1).getB(); writer.println(simPiece.lastTimeStamp + "," + v); } diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2_deprecated.java deleted file mode 100644 index 8a6c7c0382f..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full2_deprecated.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -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_full2_deprecated { - // 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, 400, 480, 580, 720, 960, 1200, 1600, 2000, 2400, 3000, 3600, 4000, 4400, 5000 - }; - - double[][] epsilonArray = { - { - 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.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, - }, - { - 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.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, - } - }; - - // double[][] epsilonArray = new double[datasetNameList.length][]; - // for (int i = 0; i < datasetNameList.length; i++) { - // epsilonArray[i] = new double[noutList.length]; - // } - - for (int y = 0; y < datasetNameList.length; y++) { - String datasetName = datasetNameList[y]; - int start = 0; - int end = 1000_0000; - int N = end - start; - // apply Sim-Piece on the input file, outputting nout points saved in csvFile - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, true); - for (int x = 0; x < noutList.length; x++) { - int nout = noutList[x]; - - // double epsilon = MySample_simpiece.getSimPieceParam(nout, ts, 1e-12); - // epsilonArray[y][x] = epsilon; - - double epsilon = epsilonArray[y][x]; - - SimPiece simPiece = new SimPiece(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + simPiece.segments.size() * 2); - List<SimPieceSegment> segments = simPiece.segments; - segments.sort(Comparator.comparingLong(SimPieceSegment::getInitTimestamp)); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName - + "-" - + N - + "-" - + nout - + "-" - + segments.size() * 2 - + "-simpiece.csv"))) { - for (int i = 0; i < segments.size() - 1; i++) { - // start point of this segment - writer.println(segments.get(i).getInitTimestamp() + "," + segments.get(i).getB()); - // end point of this segment - double v = - (segments.get(i + 1).getInitTimestamp() - segments.get(i).getInitTimestamp()) - * segments.get(i).getA() - + segments.get(i).getB(); - writer.println(segments.get(i + 1).getInitTimestamp() + "," + v); - } - // the two end points of the last segment - writer.println( - segments.get(segments.size() - 1).getInitTimestamp() - + "," - + segments.get(segments.size() - 1).getB()); - double v = - (simPiece.lastTimeStamp - segments.get(segments.size() - 1).getInitTimestamp()) - * segments.get(segments.size() - 1).getA() - + segments.get(segments.size() - 1).getB(); - writer.println(simPiece.lastTimeStamp + "," + v); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - // 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(); - // } - - // do not change name of the output file, as the output is used in exp bash - try (FileWriter writer = new FileWriter("epsilonArray_simpiece.txt")) { - for (double[] row : epsilonArray) { - for (double element : row) { - writer.write(element + " "); - System.out.print(element + ","); - } - writer.write("\n"); - System.out.println(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - // 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_deprecated.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full_deprecated.java deleted file mode 100644 index 397bc838e13..00000000000 --- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_full_deprecated.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// Sim-Piece code forked from https://github.com/xkitsios/Sim-Piece.git - -package org.apache.iotdb.db.query.simpiece; - -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.util.Comparator; -import java.util.List; - -public class MySample_simpiece_full_deprecated { - - public static void main(String[] args) { - String fileDir = "D:\\desktop\\NISTPV\\"; - String[] datasetNameList = new String[] {"WindSpeed", "Qloss", "Pyra1", "RTD"}; - int[] noutList = new int[] {320, 360, 400, 440, 480, 520, 560, 600, 640}; - - double[][] epsilonArray = { - { - 10.470000203704831, - 9.973635465240477, - 9.571347576141356, - 9.339938166046142, - 9.208912633514405, - 9.135163892364506, - 8.744444478607178, - 8.61042620162964, - 8.422101323699948 - }, - { - 9.987499999999999E-4, - 9.974999999999997E-4, - 9.784999999999998E-4, - 9.4425E-4, - 9.255E-4, - 8.8375E-4, - 8.4775E-4, - 7.865E-4, - 7.3825E-4 - }, - { - 502.0505219552564, - 493.3274919509581, - 485.91779255051347, - 479.26180967157245, - 463.5216509033579, - 446.88677012006065, - 441.2913785749938, - 435.45897277584766, - 426.0481592410648 - }, - { - 13.678959740142822, - 12.275238493499756, - 11.224719192962645, - 10.475999729766848, - 9.741776887359617, - 9.125823136444094, - 8.625197060394289, - 8.105121862335203, - 7.743280215911865 - } - }; - - // double[][] epsilonArray = new double[datasetNameList.length][]; - // for (int i = 0; i < datasetNameList.length; i++) { - // epsilonArray[i] = new double[noutList.length]; - // } - - for (int y = 0; y < datasetNameList.length; y++) { - String datasetName = datasetNameList[y]; - int start = 0; - int end = 1000_0000; - int N = end - start; - // apply Sim-Piece on the input file, outputting nout points saved in csvFile - boolean hasHeader = false; - try (FileInputStream inputStream = new FileInputStream(fileDir + datasetName + ".csv")) { - String delimiter = ","; - TimeSeries ts = - TimeSeriesReader.getMyTimeSeries( - inputStream, delimiter, false, N, start, hasHeader, false); - for (int x = 0; x < noutList.length; x++) { - int nout = noutList[x]; - - // double epsilon = MySample_simpiece.getSimPieceParam(nout, ts, 1e-6); - // epsilonArray[y][x] = epsilon; - - double epsilon = epsilonArray[y][x]; - - SimPiece simPiece = new SimPiece(ts.data, epsilon); - System.out.println( - datasetName - + ": n=" - + N - + ",m=" - + nout - + ",epsilon=" - + epsilon - + ",actual m=" - + simPiece.segments.size() * 2); - List<SimPieceSegment> segments = simPiece.segments; - segments.sort(Comparator.comparingLong(SimPieceSegment::getInitTimestamp)); - try (PrintWriter writer = - new PrintWriter( - new FileWriter( - datasetName - + "-" - + N - + "-" - + nout - + "-" - + segments.size() * 2 - + "-simpiece.csv"))) { - for (int i = 0; i < segments.size() - 1; i++) { - // start point of this segment - writer.println(segments.get(i).getInitTimestamp() + "," + segments.get(i).getB()); - // end point of this segment - double v = - (segments.get(i + 1).getInitTimestamp() - segments.get(i).getInitTimestamp()) - * segments.get(i).getA() - + segments.get(i).getB(); - writer.println(segments.get(i + 1).getInitTimestamp() + "," + v); - } - // the two end points of the last segment - writer.println( - segments.get(segments.size() - 1).getInitTimestamp() - + "," - + segments.get(segments.size() - 1).getB()); - double v = - (simPiece.lastTimeStamp - segments.get(segments.size() - 1).getInitTimestamp()) - * segments.get(segments.size() - 1).getA() - + segments.get(segments.size() - 1).getB(); - writer.println(simPiece.lastTimeStamp + "," + v); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - 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 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; - // } -}
