Examples - pi.science.smoothing.PISimpleExponentialSmoothing
1. How to perform simple exponential smoothing ?
/* - prepare variable for source data */
PIVariable var1 = new PIVariable();
var1.AddValues( new double[] { 29.9, 28.9, 29.9, 28.7, 29.6 } );
var1.AddValues( new double[] { 31.6, 28.0, 29.3, 26.4, 27.9 } );
var1.AddValues( new double[] { 30.1, 28.9, 29.4, 29.6, 27.5 } );
var1.AddValues( new double[] { 30.2, 28.3, 29.2, 28.6, 30.7 } );
var1.AddValues( new double[] { 29.0, 28.1 } );
/* - calc simple exponential smoothing, alpha=0.78 */
PISimpleExponentialSmoothing smoothing1 = new PISimpleExponentialSmoothing( var1 );
/* use first 6 values for mean...and use it as the first value */
smoothing1.SetFirstValueCalcType( FirstValueCalcType.MEAN_WINDOWLENGTH );
smoothing1.SetWindowLength( 6 );
smoothing1.SetAlpha( 0.78 );
Console.WriteLine( " New ALPHA = " + smoothing1.GetAlpha() );
smoothing1.Calc();
/* - show results */
PIDebug.Blank();
Console.WriteLine( "After smoothing = " + smoothing1.GetOutputVariable().AsString( 2 ) );
Console.WriteLine( "Errors = " + smoothing1.GetErrors().AsString( 2 ) );
/* ... */
PIDebug.Blank();
Console.WriteLine( "SSE = " + smoothing1.GetSSE() );
Console.WriteLine( "MSE = " + smoothing1.GetMSE() );
Console.WriteLine( "MSE-1 = " + smoothing1.GetErrors().GetSum2() / ( smoothing1.GetSourceVariable().Count() - 1 ) );
Output:
After smoothing = 29.80;29.60;29.67;29.45;29.49;29.95;29.52;29.47;28.80;28.60;
28.93;28.92;29.03;29.15;28.79;29.10;28.92;28.98;28.90;29.30;29.23;28.98
Errors = 0.13;-0.90;0.30;-0.97;0.15;2.11;-1.95;-0.22;-3.07;-0.90;1.50;-0.03;0.48;0.57;-1.65;1.41;-0.80;0.28;-0.38;1.80;-0.30;-1.13
SSE = 33,4366148292871
MSE = 1,51984612860396
MSE-1 = 1,59221975377558