aboutsummaryrefslogtreecommitdiff
path: root/example/ndpiReader.c
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2021-03-14 11:01:19 +0100
committerLuca Deri <deri@ntop.org>2021-03-14 11:01:51 +0100
commit9419015711a78c266f9bf054caf551b88d0ad42d (patch)
tree99684c1affdbc14dacc2fbe4c3da7c26f149d5ed /example/ndpiReader.c
parent7f9a18fd054211de0eb24f2340d4c40026c36c6c (diff)
Implemented square erro rollup to avoid overflow
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r--example/ndpiReader.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index e41cbb21a..a3662c8ab 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -4045,6 +4045,38 @@ void desUnitTest() {
/* *********************************************** */
+void desUnitStressTest() {
+ struct ndpi_des_struct des;
+ u_int8_t trace = 1;
+ u_int num_learning_points = 1;
+ u_int i;
+ float alpha = 0.9, beta = 0.5;
+ double init_value = time(NULL) % 1000;
+
+ assert(ndpi_des_init(&des, alpha, beta, 0.05) == 0);
+
+ if(trace) {
+ printf("\nDouble Exponential Smoothing [alpha: %.1f][beta: %.1f]\n", alpha, beta);
+ }
+
+ for(i=0; i<512; i++) {
+ double prediction, confidence_band;
+ double lower, upper;
+ double value = init_value + rand() % 25;
+ int rc = ndpi_des_add_value(&des, value, &prediction, &confidence_band);
+
+ lower = prediction - confidence_band, upper = prediction + confidence_band;
+
+ if(trace) {
+ printf("%2u)\t%12.3f\t%.3f\t%12.3f\t%12.3f\t %s [%.3f]\n", i, value, prediction, lower, upper,
+ ((rc == 0) || ((value >= lower) && (value <= upper))) ? "OK" : "ANOMALY",
+ confidence_band);
+ }
+ }
+}
+
+/* *********************************************** */
+
void hwUnitTest3() {
struct ndpi_hw_struct hw;
u_int num_learning_points = 3;
@@ -4133,6 +4165,11 @@ int original_main(int argc, char **argv) {
hwUnitTest2();
#endif
+#ifdef STRESS_TEST
+ desUnitStressTest();
+ exit(0);
+#endif
+
sesUnitTest();
desUnitTest();