From 937357e4bc55610f116f66d15a8e0fc1e260c02c Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Tue, 12 Oct 2021 13:08:16 +0200 Subject: Implemented ndpi_ses_fitting() and ndpi_des_fitting() for comuting the best alpha/beta values for exponential smoothing --- src/lib/ndpi_analyze.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) (limited to 'src/lib') diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index b8e009c6f..4879954ab 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -1232,6 +1232,61 @@ int ndpi_ses_add_value(struct ndpi_ses_struct *ses, const u_int64_t _value, doub return(rc); } +/* *********************************************************** */ + +/* + Computes the best alpha value using the specified values used for training +*/ +void ndpi_ses_fitting(double *values, u_int32_t num_values, float *ret_alpha) { + u_int i; + float alpha, best_alpha; + double sse, lowest_sse; + int trace = 0; + + lowest_sse = 0, best_alpha = 0; + + for(alpha=0.1; alpha<0.99; alpha += 0.05) { + struct ndpi_ses_struct ses; + + ndpi_ses_init(&ses, alpha, 0.05); + + if(trace) + printf("\nDouble Exponential Smoothing [alpha: %.2f]\n", alpha); + + sse = 0; + + for(i=0; i