Implemented ndpi_XXX_reset() API calls whre XXX is ses, des, hw
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* ndpiReader.c
|
* ndpiReader.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011-22 - ntop.org
|
* Copyright (C) 2011-23 - ntop.org
|
||||||
*
|
*
|
||||||
* nDPI is free software: you can redistribute it and/or modify
|
* nDPI is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -4880,6 +4880,7 @@ void sesUnitTest() {
|
|||||||
FILE *fd = fopen("/tmp/ses_result.csv", "w");
|
FILE *fd = fopen("/tmp/ses_result.csv", "w");
|
||||||
|
|
||||||
assert(ndpi_ses_init(&ses, alpha, 0.05) == 0);
|
assert(ndpi_ses_init(&ses, alpha, 0.05) == 0);
|
||||||
|
ndpi_ses_reset(&ses);
|
||||||
|
|
||||||
if(trace) {
|
if(trace) {
|
||||||
printf("\nSingle Exponential Smoothing [alpha: %.1f]\n", alpha);
|
printf("\nSingle Exponential Smoothing [alpha: %.1f]\n", alpha);
|
||||||
@@ -4952,6 +4953,7 @@ void desUnitTest() {
|
|||||||
FILE *fd = fopen("/tmp/des_result.csv", "w");
|
FILE *fd = fopen("/tmp/des_result.csv", "w");
|
||||||
|
|
||||||
assert(ndpi_des_init(&des, alpha, beta, 0.05) == 0);
|
assert(ndpi_des_init(&des, alpha, beta, 0.05) == 0);
|
||||||
|
ndpi_des_reset(&des);
|
||||||
|
|
||||||
if(trace) {
|
if(trace) {
|
||||||
printf("\nDouble Exponential Smoothing [alpha: %.1f][beta: %.1f]\n", alpha, beta);
|
printf("\nDouble Exponential Smoothing [alpha: %.1f][beta: %.1f]\n", alpha, beta);
|
||||||
@@ -4994,6 +4996,7 @@ void desUnitStressTest() {
|
|||||||
double init_value = time(NULL) % 1000;
|
double init_value = time(NULL) % 1000;
|
||||||
|
|
||||||
assert(ndpi_des_init(&des, alpha, beta, 0.05) == 0);
|
assert(ndpi_des_init(&des, alpha, beta, 0.05) == 0);
|
||||||
|
ndpi_des_reset(&des);
|
||||||
|
|
||||||
if(trace) {
|
if(trace) {
|
||||||
printf("\nDouble Exponential Smoothing [alpha: %.1f][beta: %.1f]\n", alpha, beta);
|
printf("\nDouble Exponential Smoothing [alpha: %.1f][beta: %.1f]\n", alpha, beta);
|
||||||
@@ -5042,6 +5045,7 @@ void hwUnitTest3() {
|
|||||||
u_int i, num = sizeof(v) / sizeof(double);
|
u_int i, num = sizeof(v) / sizeof(double);
|
||||||
float alpha = 0.5, beta = 0.5, gamma = 0.1;
|
float alpha = 0.5, beta = 0.5, gamma = 0.1;
|
||||||
assert(ndpi_hw_init(&hw, num_learning_points, 0 /* 0=multiplicative, 1=additive */, alpha, beta, gamma, 0.05) == 0);
|
assert(ndpi_hw_init(&hw, num_learning_points, 0 /* 0=multiplicative, 1=additive */, alpha, beta, gamma, 0.05) == 0);
|
||||||
|
ndpi_hw_reset(&hw);
|
||||||
|
|
||||||
if(trace)
|
if(trace)
|
||||||
printf("\nHolt-Winters [alpha: %.1f][beta: %.1f][gamma: %.1f]\n", alpha, beta, gamma);
|
printf("\nHolt-Winters [alpha: %.1f][beta: %.1f][gamma: %.1f]\n", alpha, beta, gamma);
|
||||||
|
|||||||
@@ -1714,12 +1714,14 @@ extern "C" {
|
|||||||
double alpha, double beta, double gamma, float significance);
|
double alpha, double beta, double gamma, float significance);
|
||||||
void ndpi_hw_free(struct ndpi_hw_struct *hw);
|
void ndpi_hw_free(struct ndpi_hw_struct *hw);
|
||||||
int ndpi_hw_add_value(struct ndpi_hw_struct *hw, const u_int64_t value, double *forecast, double *confidence_band);
|
int ndpi_hw_add_value(struct ndpi_hw_struct *hw, const u_int64_t value, double *forecast, double *confidence_band);
|
||||||
|
void ndpi_hw_reset(struct ndpi_hw_struct *hw);
|
||||||
|
|
||||||
/* ******************************* */
|
/* ******************************* */
|
||||||
|
|
||||||
int ndpi_ses_init(struct ndpi_ses_struct *ses, double alpha, float significance);
|
int ndpi_ses_init(struct ndpi_ses_struct *ses, double alpha, float significance);
|
||||||
int ndpi_ses_add_value(struct ndpi_ses_struct *ses, const double _value, double *forecast, double *confidence_band);
|
int ndpi_ses_add_value(struct ndpi_ses_struct *ses, const double _value, double *forecast, double *confidence_band);
|
||||||
void ndpi_ses_fitting(double *values, u_int32_t num_values, float *ret_alpha);
|
void ndpi_ses_fitting(double *values, u_int32_t num_values, float *ret_alpha);
|
||||||
|
void ndpi_ses_reset(struct ndpi_ses_struct *ses);
|
||||||
|
|
||||||
/* ******************************* */
|
/* ******************************* */
|
||||||
|
|
||||||
@@ -1730,6 +1732,7 @@ extern "C" {
|
|||||||
int ndpi_des_init(struct ndpi_des_struct *des, double alpha, double beta, float significance);
|
int ndpi_des_init(struct ndpi_des_struct *des, double alpha, double beta, float significance);
|
||||||
int ndpi_des_add_value(struct ndpi_des_struct *des, const double _value, double *forecast, double *confidence_band);
|
int ndpi_des_add_value(struct ndpi_des_struct *des, const double _value, double *forecast, double *confidence_band);
|
||||||
void ndpi_des_fitting(double *values, u_int32_t num_values, float *ret_alpha, float *ret_beta);
|
void ndpi_des_fitting(double *values, u_int32_t num_values, float *ret_alpha, float *ret_beta);
|
||||||
|
void ndpi_des_reset(struct ndpi_des_struct *des);
|
||||||
|
|
||||||
/* ******************************* */
|
/* ******************************* */
|
||||||
|
|
||||||
|
|||||||
@@ -1206,6 +1206,17 @@ int ndpi_hw_add_value(struct ndpi_hw_struct *hw, const u_int64_t _value, double
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* *********************************************************** */
|
||||||
|
|
||||||
|
void ndpi_hw_reset(struct ndpi_hw_struct *hw) {
|
||||||
|
hw->prev_error.sum_square_error = 0, hw->prev_error.num_values_rollup = 0;
|
||||||
|
hw->num_values = 0;
|
||||||
|
hw->u = hw->v = hw->sum_square_error = 0;
|
||||||
|
|
||||||
|
memset(&hw->y, 0, (hw->params.num_season_periods * sizeof(u_int64_t)));
|
||||||
|
memset(&hw->s, 0, (hw->params.num_season_periods * sizeof(double)));
|
||||||
|
}
|
||||||
|
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
@@ -1348,6 +1359,14 @@ int ndpi_ses_add_value(struct ndpi_ses_struct *ses, const double _value, double
|
|||||||
|
|
||||||
/* *********************************************************** */
|
/* *********************************************************** */
|
||||||
|
|
||||||
|
void ndpi_ses_reset(struct ndpi_ses_struct *ses) {
|
||||||
|
ses->prev_error.sum_square_error = 0, ses->prev_error.num_values_rollup = 0;
|
||||||
|
ses->num_values = 0;
|
||||||
|
ses->sum_square_error = ses->last_forecast = ses->last_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *********************************************************** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Computes the best alpha value using the specified values used for training
|
Computes the best alpha value using the specified values used for training
|
||||||
*/
|
*/
|
||||||
@@ -1430,6 +1449,14 @@ int ndpi_des_init(struct ndpi_des_struct *des, double alpha, double beta, float
|
|||||||
|
|
||||||
/* *********************************************************** */
|
/* *********************************************************** */
|
||||||
|
|
||||||
|
void ndpi_des_reset(struct ndpi_des_struct *des) {
|
||||||
|
des->prev_error.sum_square_error = 0, des->prev_error.num_values_rollup = 0;
|
||||||
|
des->num_values = 0;
|
||||||
|
des->sum_square_error = des->last_forecast = des->last_trend = des->last_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *********************************************************** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Returns the forecast and the band (forecast +/- band are the upper and lower values)
|
Returns the forecast and the band (forecast +/- band are the upper and lower values)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user