C++ Template of Exponential Smoothing

Introduction

This is a simple C++ template library of Exponential Smoothing implemented by Shuo Jin.

In current version, single and double exponential smoothing methods are implemented with consistent and simple functions.

Date Structure:

All smoothing constants in the above data structures are set to 0.5 by default. Users can change their value by calling the corresponding functions. Optimization based determination of optimal smoothing constants is not included at present. The current implementation is mainly used for forecasting, which is very easy to use with the only core function push_to_pop. In order to further filter data noise, a vacillation tolerance (0 by default) can be set. Only when the difference (L2 norm) of current smoothed vector and the last one is bigger than the specified tolerance, the current one will be returned. Otherwise, the last smoothed vector will be returned.

Example

#include <exponential_smoothing.h>

#define DIMENSION 3

int main(int argc, char* argv[])
{   
    // declare an object
    double_exponential_smoothing<double, DIMENSION> dbexpsmth; // or single_exponential_smoothing

    // change the value accordingly
    dbexpsmth.set_1st_smoothing_constant(0.8);
    dbexpsmth.set_2nd_smoothing_constant(0.5);

    //dbexpsmth.set_vacillation_tolerance(0.1);

    while(...) 
    {        
        // declare a vector
        es_vec<double, DIMENSION> curr_query;

        // value assignment
        for (size_t i = 0; i < DIMENSION; ++i) curr_query[i] = ...;

        // smoothing
        es_vec<double, DIMENSION> smth_result = dbexpsmth.push_to_pop(curr_query);
    }
}

Download

The code is available here.

Reference

  1. Wikipedia - Exponential Smoothing
  2. A online handbook - Exponential Smoothing