Examples - pi.science.smoothing.PIMovingAverageSmoothing
1. How to perform simple centered moving average ?
/* - prepare variable for source data */
PIVariable var = new PIVariable();
var.AddValues( new int[] { 9, 8, 9, 12, 9, 12, 11 } );
/* - calc CENTERED moving average, length = 4 */
PIMovingAverageSmoothing MA = new PIMovingAverageSmoothing( var );
MA.SetCalculationType( CalculationType.SIMPLE_CENTERED );
MA.SetWindowLength( 4 );
MA.Calc();
/* - show results */
Console.WriteLine( MA.GetOutputVariable().AsString( 2 ) );
Output:
<null>;<null>;9.50;10.00;10.75;<null>;<null>
2. How to compute simple moving average ?
/* - calc SIMPLE moving average, length = 3 */
PIVariable var1 = new PIVariable();
var1.AddValues( new int[] { 3, 5, 9, 20, 12, 17, 22, 23, 51, 41, 56, 75, 60, 75, 88 } );
PIMovingAverageSmoothing MA1 = new PIMovingAverageSmoothing( var1 );
MA1.SetCalculationType( CalculationType.SIMPLE );
MA1.SetWindowLength( 3 );
MA1.Calc();
/* - show results (3) */
Console.WriteLine( MA1.GetOutputVariable().AsString( 2 ) );
Console.WriteLine( "MAE = " + MA1.GetMAE() );
Console.WriteLine( "MSE = " + MA1.GetMSE() );
Output:
<null>;<null>;<null>;5.67;11.33;13.67;16.33;17.00;20.67;32.00;38.33;49.33;57.33;63.67;70.00
MAE = 13,4722222222222
MSE = 235,972222222222