-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsmooth_univmon_test.go
More file actions
197 lines (159 loc) · 6.12 KB
/
smooth_univmon_test.go
File metadata and controls
197 lines (159 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package promsketch
import (
"bufio"
"fmt"
"os"
"strconv"
"testing"
"time"
)
// Test cost (compute + memory) and accuracy under sliding window
func TestSmoothHistogramUnivMonCAIDA(t *testing.T) {
cost_query_interval_gsum := int64(2000)
query_window_size := int64(10000)
total_length := int64(200000)
// Create a scenario
t1 := make([]int64, 0)
t2 := make([]int64, 0)
t1 = append(t1, int64(0))
t2 = append(t2, query_window_size-1)
t1 = append(t1, int64(query_window_size/3))
t2 = append(t2, int64(query_window_size/3)*2)
/*
// suffix length
for i := int64(500); i <= int64(1000); i += 100 {
t1 = append(t1, query_window_size-i)
t2 = append(t2, query_window_size-1)
}
*/
fmt.Println("t1:", t1)
fmt.Println("t2:", t2)
readCAIDA()
fmt.Println("Finished reading input timeseries.")
for test_case := 0; test_case < 5; test_case += 1 {
filename := "cost_analysis_results/caida_gsum_sampling_shuniv_larger" + strconv.Itoa(test_case) + ".txt"
fmt.Println(filename)
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
panic(err)
}
defer f.Close()
w := bufio.NewWriter(f)
// PromSketch, SHUniv
beta_input := []float64{0.7071, 0.5, 0.3535, 0.25, 0.177, 0.125, 0.0884, 0.0625, 0.044}
// beta_input := []float64{0.3535}
for _, beta := range beta_input {
fmt.Println("SHUniv", beta)
fmt.Fprintln(w, "SHUniv", beta)
shu := SmoothInitUnivMon(beta, query_window_size)
total_compute := 0.0
insert_compute := 0.0
for t := int64(0); t < total_length; t++ {
start := time.Now()
shu.Update(t, strconv.FormatFloat(cases[0].vec[t].F, 'f', -1, 64))
elapsed := time.Since(start)
insert_compute += float64(elapsed.Microseconds())
if t == total_length-1 || (t >= query_window_size-1 && (t+1)%cost_query_interval_gsum == 0) {
for j := range len(t1) {
start_t := t1[j] + t - query_window_size + 1
end_t := t2[j] + t - query_window_size + 1
start := time.Now()
merged_univ, _ := shu.QueryIntervalMergeUniv(t-end_t, t-start_t, t)
distinct := merged_univ.calcCard()
l1 := merged_univ.calcL1()
l2 := merged_univ.calcL2()
entropy := merged_univ.calcEntropy()
elapsed := time.Since(start)
total_compute += float64(elapsed.Microseconds())
fmt.Println("start_t, end_t:", start_t, end_t)
fmt.Println("estimate:", distinct, l1, entropy, l2)
// fmt.Fprintln(w, t, j, distinct, l1, entropy, l2)
values := make([]float64, 0)
for tt := start_t; tt < end_t; tt++ {
values = append(values, float64(cases[0].vec[tt].F))
}
gt_distinct, gt_l1, gt_entropy, gt_l2 := gsum(values)
fmt.Println("true:", gt_distinct, gt_l1, gt_entropy, gt_l2)
distinct_err := AbsFloat64(gt_distinct-distinct) / gt_distinct * 100
l1_err := AbsFloat64(gt_l1-l1) / gt_l1 * 100
entropy_err := AbsFloat64(gt_entropy-entropy) / gt_entropy * 100
l2_err := AbsFloat64(gt_l2-l2) / gt_l2 * 100
// fmt.Fprintln(w, t, j, "errors:", distinct_err, l1_err, entropy_err, l2_err)
fmt.Println(t, j, "errors:", distinct_err, l1_err, entropy_err, l2_err)
fmt.Println()
w.Flush()
// distinct_rel_err := AbsFloat64(ground_truth[t][j].distinct-distinct) / (ground_truth[t][j].distinct) * 100
// l1_rel_err := AbsFloat64(ground_truth[t][j].l1-l1) / (ground_truth[t][j].l1) * 100
// entropy_rel_err := AbsFloat64(ground_truth[t][j].entropy-entropy) / (ground_truth[t][j].entropy) * 100
// l2_rel_err := AbsFloat64(ground_truth[t][j].l2-l2) / (ground_truth[t][j].l2) * 100
// fmt.Fprintln(w,t, j, distinct_rel_err, l1_rel_err, entropy_rel_err, l2_rel_err)
}
}
}
// fmt.Fprintln(w,"distinct error:", shu_distinct_error)
// fmt.Fprintln(w,"l1 error:", shu_l1_error)
// fmt.Fprintln(w,"entropy error:", shu_entropy_error)
// fmt.Fprintln(w,"l2 error:", shu_l2_error)
fmt.Println("insert compute:", insert_compute)
fmt.Println("query compute:", total_compute, "us")
fmt.Println("total compute:", total_compute+insert_compute, "us")
fmt.Println("memory:", shu.GetMemory(), "KB")
fmt.Fprintln(w, "insert compute:", insert_compute)
fmt.Fprintln(w, "query compute:", total_compute, "us")
fmt.Fprintln(w, "total compute:", total_compute+insert_compute, "us")
fmt.Fprintln(w, "memory:", shu.GetMemory(), "KB")
}
}
}
func TestSmoothHistogramUnivMonCAIDAUpdateTime(t *testing.T) {
query_window_size := int64(1000000)
total_length := int64(2000000)
// Create a scenario
t1 := make([]int64, 0)
t2 := make([]int64, 0)
t1 = append(t1, int64(0))
t2 = append(t2, query_window_size-1)
t1 = append(t1, int64(query_window_size/3))
t2 = append(t2, int64(query_window_size/3)*2)
/*
// suffix length
for i := int64(500); i <= int64(1000); i += 100 {
t1 = append(t1, query_window_size-i)
t2 = append(t2, query_window_size-1)
}
*/
fmt.Println("t1:", t1)
fmt.Println("t2:", t2)
readCAIDA()
fmt.Println("Finished reading input timeseries.")
for test_case := 0; test_case < 5; test_case += 1 {
filename := "cost_analysis_results/caida_gsum_sampling_shuniv_larger" + strconv.Itoa(test_case) + ".txt"
fmt.Println(filename)
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
panic(err)
}
defer f.Close()
w := bufio.NewWriter(f)
// PromSketch, SHUniv
// beta_input := []float64{0.7071, 0.5, 0.3535, 0.25, 0.177, 0.125, 0.0884, 0.0625, 0.044}
beta_input := []float64{0.3535}
for _, beta := range beta_input {
fmt.Println("SHUniv", beta)
fmt.Fprintln(w, "SHUniv", beta)
shu := SmoothInitUnivMon(beta, query_window_size)
insert_compute := 0.0
for t := int64(0); t < total_length; t++ {
start := time.Now()
shu.Update(t, strconv.FormatFloat(cases[0].vec[t].F, 'f', -1, 64))
elapsed := time.Since(start)
insert_compute += float64(elapsed.Microseconds())
fmt.Println("insert time per item:", insert_compute/float64(t+1), "us")
fmt.Println("s_count:", shu.s_count)
}
fmt.Println("insert time per item:", insert_compute/float64(total_length), "us")
fmt.Println("s_count:", shu.s_count)
fmt.Println("memory:", shu.GetMemory(), "KB")
}
}
}