This is an automated email from the ASF dual-hosted git repository.

leirui pushed a commit to branch research/M4-visualization
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 984bfebaf7d6f3223e9c059b4eb2f03f145105f9
Author: Lei Rui <[email protected]>
AuthorDate: Mon Jul 3 17:45:16 2023 +0800

    add test
---
 .../iotdb/tsfile/encoding/SDTEncoderTest.java      | 204 +++++++++------------
 1 file changed, 89 insertions(+), 115 deletions(-)

diff --git 
a/tsfile/src/test/java/org/apache/iotdb/tsfile/encoding/SDTEncoderTest.java 
b/tsfile/src/test/java/org/apache/iotdb/tsfile/encoding/SDTEncoderTest.java
index c703ed24d04..9f62a16a794 100644
--- a/tsfile/src/test/java/org/apache/iotdb/tsfile/encoding/SDTEncoderTest.java
+++ b/tsfile/src/test/java/org/apache/iotdb/tsfile/encoding/SDTEncoderTest.java
@@ -27,7 +27,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import org.apache.iotdb.tsfile.encoding.encoder.SDTEncoder;
-import org.apache.iotdb.tsfile.utils.Pair;
 import org.junit.Test;
 
 public class SDTEncoderTest {
@@ -113,117 +112,49 @@ public class SDTEncoderTest {
     System.out.println("at=" + selectTimestamps + ";");
     System.out.println("av=" + selectValues + ";");
 
-    System.out.println("LB=av-e;\n"
-        + "UB=av+e;\n"
-        + "plot(t,v)\n"
-        + "hold on,plot(t,v,'+')\n"
-        + "hold on,plot(at,av,'r')\n"
-        + "%hold on,plot(at,av,'r+')\n"
-        + "hold on,plot(at,UB,'g')\n"
-        + "%hold on,plot(at,UB,'g+')\n"
-        + "hold on,plot(at,LB,'g')\n"
-        + "%hold on,plot(at,LB,'g+')\n"
-        + "\n"
-        + "% [val,idx]=max(av-e)\n"
-        + "% yline(val)\n"
-        + "\n"
-        + "[sortedX, sortedInds] = sort(LB,'descend');\n"
-        + "% yline(sortedX(1))\n"
-        + "% yline(sortedX(2))\n"
-        + "\n"
-        + "% 依次计算UB小于Nth-max-LB的点数\n"
+    System.out.println("LB=av-e;\n" + "UB=av+e;\n" + "plot(t,v)\n" + "hold 
on,plot(t,v,'+')\n"
+        + "hold on,plot(at,av,'r')\n" + "%hold on,plot(at,av,'r+')\n" + "hold 
on,plot(at,UB,'g')\n"
+        + "%hold on,plot(at,UB,'g+')\n" + "hold on,plot(at,LB,'g')\n"
+        + "%hold on,plot(at,LB,'g+')\n" + "\n" + "% [val,idx]=max(av-e)\n" + 
"% yline(val)\n" + "\n"
+        + "[sortedX, sortedInds] = sort(LB,'descend');\n" + "% 
yline(sortedX(1))\n"
+        + "% yline(sortedX(2))\n" + "\n" + "% 依次计算UB小于Nth-max-LB的点数\n"
         + "% case 1: 两端都小于threshold,则该段内的点的UB都小于threshold,都可以被剪枝\n"
         + "% case 2: 两端都大于等于threshold,则该段内的点的UB都大于等于threshold,则都不可以被剪枝\n"
         + "% case 3: 一端小于一端大于等于threshold,则该段内有部分点的UB小于threshold可以被剪枝\n"
-        + "% (t1,v1), (t2,v2), t1<t2\n"
-        + "% y=(t-t1)*(v2-v1)/(t2-t1)+v1\n"
+        + "% (t1,v1), (t2,v2), t1<t2\n" + "% y=(t-t1)*(v2-v1)/(t2-t1)+v1\n"
         + "% y<thresold ===> (t-t1)*(v2-v1)/(t2-t1)+v1<threshold\n"
         + "% 如果v2>=threshold>v1: 
则t<(threshold-v1)*(t2-t1)/(v2-v1)+t1,于是[t1,(threshold-v1)*(t2-t1)/(v2-v1)+t1)内的点可剪枝\n"
         + "% 如果v2<threshold<=v1: 
则t>(threshold-v1)*(t2-t1)/(v2-v1)+t1,于是((threshold-v1)*(t2-t1)/(v2-v1)+t1,t2]内的点可剪枝\n"
-        + "rank=5\n"
-        + "threshold=sortedX(rank)\n"
-        + "hold on, yline(threshold);\n"
-        + "hold on, plot(at(sortedInds(rank)),threshold,'o')\n"
-        + "\n"
-        + "prune_t=[]; % point\n"
-        + "prune_v=[]; % point\n"
-        + "prune_interval=[]; % interval\n"
-        + "interval_start=-1;\n"
-        + "for i=2:1:length(av)\n"
-        + "\tt1=at(i-1);\n"
-        + "\tt2=at(i);\n"
-        + "\tv1=UB(i-1);\n"
-        + "\tv2=UB(i);\n"
-        + "\ta=[];\n"
-        + "\tif v1<threshold && v2<threshold\n"
-        + "\t\tif i<length(av)\n"
-        + "\t\t\ta=t1:1:t2-1;\n"
-        + "\t\telse \n"
-        + "\t\t\ta=t1:1:t2;\n"
-        + "\t\tend\n"
-        + "\t\tif interval_start<0\n"
-        + "\t\t\tinterval_start=t1;\n"
-        + "        end\n"
-        + "        interval_end=t2; % continuous\n"
-        + "\telseif v1<threshold && v2>=threshold\n"
+        + "rank=1\n" + "threshold=sortedX(rank)\n" + "hold on, 
yline(threshold);\n"
+        + "hold on, plot(at(sortedInds(rank)),threshold,'o')\n" + "\n" + 
"prune_t=[]; % point\n"
+        + "prune_v=[]; % point\n" + "prune_interval=[]; % interval\n" + 
"interval_start=-1;\n"
+        + "for i=2:1:length(av)\n" + "\tt1=at(i-1);\n" + "\tt2=at(i);\n" + 
"\tv1=UB(i-1);\n"
+        + "\tv2=UB(i);\n" + "\ta=[];\n" + "\tif v1<threshold && v2<threshold\n"
+        + "\t\tif i<length(av)\n" + "\t\t\ta=t1:1:t2-1;\n" + "\t\telse \n" + 
"\t\t\ta=t1:1:t2;\n"
+        + "\t\tend\n" + "\t\tif interval_start<0\n" + 
"\t\t\tinterval_start=t1;\n" + "        end\n"
+        + "        interval_end=t2; % continuous\n" + "\telseif v1<threshold 
&& v2>=threshold\n"
         + "\t\ta=t1:1:floor((threshold-v1)*(t2-t1)/(v2-v1)+t1); % no need -1 
here\n"
-        + "\t\tif interval_start<0\n"
-        + "\t\t\tinterval_start=t1;\n"
-        + "        end\n"
+        + "\t\tif interval_start<0\n" + "\t\t\tinterval_start=t1;\n" + "       
 end\n"
         + "        
prune_interval=[prune_interval;[interval_start,floor((threshold-v1)*(t2-t1)/(v2-v1)+t1)]];\n"
-        + "\t\tinterval_start=-1; % discontinuous\n"
-        + "\telseif v1>=threshold && v2<threshold\n"
-        + "\t\tif i<length(av)\n"
-        + "\t\t\ta=ceil((threshold-v1)*(t2-t1)/(v2-v1)+t1):1:t2-1;\n"
-        + "\t\telse\n"
-        + "\t\t\ta=ceil((threshold-v1)*(t2-t1)/(v2-v1)+t1):1:t2;\n"
-        + "\t\tend\n"
-        + "\t\tinterval_start=ceil((threshold-v1)*(t2-t1)/(v2-v1)+t1);\n"
-        + "\t\tinterval_end=t2;\n"
-        + "\tend\n"
-        + "\tprune_t=[prune_t,a];\n"
-        + "\tprune_v=[prune_v,(a-t1)*(v2-v1)/(t2-t1)+v1];\n"
-        + "end\n"
-        + "if interval_start>0\n"
-        + "\tprune_interval=[prune_interval;[interval_start,interval_end]];\n"
-        + "end\n"
-        + "\n"
-        + "hold on,plot(prune_t,prune_v,'b.')\n"
-        + "disp(length(prune_t)/length(t))\n"
-        + "\n"
+        + "\t\tinterval_start=-1; % discontinuous\n" + "\telseif v1>=threshold 
&& v2<threshold\n"
+        + "\t\tif i<length(av)\n" + 
"\t\t\ta=ceil((threshold-v1)*(t2-t1)/(v2-v1)+t1):1:t2-1;\n"
+        + "\t\telse\n" + 
"\t\t\ta=ceil((threshold-v1)*(t2-t1)/(v2-v1)+t1):1:t2;\n" + "\t\tend\n"
+        + "\t\tinterval_start=ceil((threshold-v1)*(t2-t1)/(v2-v1)+t1);\n" + 
"\t\tinterval_end=t2;\n"
+        + "\tend\n" + "\tprune_t=[prune_t,a];\n"
+        + "\tprune_v=[prune_v,(a-t1)*(v2-v1)/(t2-t1)+v1];\n" + "end\n" + "if 
interval_start>0\n"
+        + "\tprune_interval=[prune_interval;[interval_start,interval_end]];\n" 
+ "end\n" + "\n"
+        + "hold on,plot(prune_t,prune_v,'b.')\n" + 
"disp(length(prune_t)/length(t))\n" + "\n"
         + "%rectangle('Position', [at(1) av(1) at(2) av(2)], 'Facec',[0.5 1 
0.5])\n"
-        + "prune_interval\n"
-        + "\n"
-        + "%for i=1:1:length(prune_interval)\n"
-        + "%\txline(prune_interval(i,1));\n"
-        + "%\txline(prune_interval(i,2));\n"
-        + "%end\n"
-        + "\n"
-        + "% https://se.mathworks.com/help/matlab/ref/xregion.html\n";
-        + "% xregion\n"
-        + "\n"
-        + "for i=1:1:length(prune_interval)\n"
-        + "\tx=prune_interval(i,1):1:prune_interval(i,2);\n"
-        + "\ty=[];\n"
-        + "\tfor j=1:1:length(x)\n"
-        + "\t\tidx=x(j);\n"
-        + "\t\tfor n=2:1:length(at)\n"
-        + "\t\t\tif idx<=at(n)\n"
-        + "\t\t\t\tt1=at(n-1);\n"
-        + "\t\t\t\tt2=at(n);\n"
-        + "\t\t\t\tv1=av(n-1);\n"
-        + "\t\t\t\tv2=av(n);\n"
-        + "\t\t\t\ty=[y,(idx-t1)*(v2-v1)/(t2-t1)+v1];\n"
-        + "\t\t\t\tbreak;\n"
-        + "\t\t\tend\n"
-        + "\t\tend\n"
-        + "\tend\n"
-        + "\ty1=y-e;\n"
-        + "\ty2=y+e;\n"
-        + "\tL1=[x,fliplr(x)];\n"
-        + "\tL2=[y1,fliplr(y2)];\n"
-        + "\tfill(L1,L2,'b','FaceAlpha',0.1);\n"
-        + "end");
+        + "prune_interval\n" + "\n" + "%for i=1:1:length(prune_interval)\n"
+        + "%\txline(prune_interval(i,1));\n" + 
"%\txline(prune_interval(i,2));\n" + "%end\n" + "\n"
+        + "% https://se.mathworks.com/help/matlab/ref/xregion.html\n"; + "% 
xregion\n" + "\n"
+        + "for i=1:1:length(prune_interval)\n" + 
"\tx=prune_interval(i,1):1:prune_interval(i,2);\n"
+        + "\ty=[];\n" + "\tfor j=1:1:length(x)\n" + "\t\tidx=x(j);\n" + 
"\t\tfor n=2:1:length(at)\n"
+        + "\t\t\tif idx<=at(n)\n" + "\t\t\t\tt1=at(n-1);\n" + 
"\t\t\t\tt2=at(n);\n"
+        + "\t\t\t\tv1=av(n-1);\n" + "\t\t\t\tv2=av(n);\n"
+        + "\t\t\t\ty=[y,(idx-t1)*(v2-v1)/(t2-t1)+v1];\n" + "\t\t\t\tbreak;\n" 
+ "\t\t\tend\n"
+        + "\t\tend\n" + "\tend\n" + "\ty1=y-e;\n" + "\ty2=y+e;\n" + 
"\tL1=[x,fliplr(x)];\n"
+        + "\tL2=[y1,fliplr(y2)];\n" + "\tfill(L1,L2,'b','FaceAlpha',0.1);\n" + 
"end");
   }
 
   @Test
@@ -275,24 +206,67 @@ public class SDTEncoderTest {
 
     // 计算maxLB
     long maxVal = Collections.max(selectValues);
-    int maxIdx = selectTimestamps.get(selectValues.indexOf(maxVal));
-    System.out.println(maxIdx);
-    System.out.println(maxVal);
-    double maxLB = maxVal - e;
+//    int maxIdx = selectTimestamps.get(selectValues.indexOf(maxVal));
+    double threshold = maxVal - e; // maxLB
+    System.out.println("threshold(maxLB)=" + threshold);
 
     // 计算UB<maxLB的剪枝段
-    List<Pair<Integer, Integer>> prune_intervals = new ArrayList<>();
-    int interval_start=-1;
+    List<Integer> prune_intervals_start = new ArrayList<>();
+    List<Integer> prune_intervals_end = new ArrayList<>();
+    int interval_start = -1;
+    int interval_end = -1;
     for (int i = 1; i < selectTimestamps.size(); i++) {
-      int t1=selectTimestamps.get(i-1);
-      int t2=selectTimestamps.get(i);
-      long v1=selectValues.get(i-1);
-      long v2=selectValues.get(i);
-
+      int t1 = selectTimestamps.get(i - 1);
+      int t2 = selectTimestamps.get(i);
+      double v1 = selectValues.get(i - 1) + e; // UB
+      double v2 = selectValues.get(i) + e; // UB
+      if (v1 < threshold && v2 < threshold) {
+        if (interval_start < 0) {
+          interval_start = t1;
+        }
+        interval_end = t2; // continuous
+      } else if (v1 < threshold && v2 >= threshold) {
+        if (interval_start < 0) {
+          interval_start = t1;
+        }
+        prune_intervals_start.add(interval_start);
+        prune_intervals_end.add((int) Math.floor((threshold - v1) * (t2 - t1) 
/ (v2 - v1) + t1));
+        interval_start = -1; // discontinuous
+      } else if (v1 >= threshold && v2 < threshold) {
+        interval_start = (int) Math.ceil((threshold - v1) * (t2 - t1) / (v2 - 
v1) + t1);
+        interval_end = t2; // continuous
+      }
+    }
+    if (interval_start > 0) {
+      prune_intervals_start.add(interval_start);
+      prune_intervals_end.add(interval_end);
     }
+    System.out.println("UB<maxLB prune intervals (included ends):");
+    System.out.println(prune_intervals_start);
+    System.out.println(prune_intervals_end);
 
     // 对剪枝段取余后搜索遍历计算TP
-
+    int startIdx = 1;
+    int endIdx = 200;
+    startIdx = startIdx - 1; // as excluded treated
+    endIdx = endIdx + 1; // as excluded treated
+    prune_intervals_start.add(endIdx); // turn into search_intervals_end 
(excluded)
+    prune_intervals_end.add(0, startIdx); // turn into search_intervals_start 
(excluded)
+    long candidateTPvalue = -1;
+    int candidateTPidx = -1;
+    for (int i = 0; i < prune_intervals_start.size(); i++) {
+      int search_interval_start = prune_intervals_end.get(i) + 1; // included
+      int search_interval_end = prune_intervals_start.get(i) - 1; // included
+      System.out.println(search_interval_start + "," + search_interval_end);
+      for (int j = search_interval_start; j <= search_interval_end; j++) {
+        long v = valueList.get(j);
+        if (v > candidateTPvalue) {
+          candidateTPvalue = v;
+          candidateTPidx = j;
+        }
+      }
+    }
+    System.out.println("TP=(" + candidateTPidx + "," + candidateTPvalue + ")");
   }
 
   @Test

Reply via email to