In this example three sets of data, X0 , X1 , and X2 are scaled using the methods described in the following table:
Variables and Scaling Methods
Variable | Method | Description |
X0 |
0 |
No Scaling |
X1 |
4 |
Bounded Z-score scaling using the mean and standard deviation of X1 |
X2 |
5 |
Bounded Z-score scaling� using the median and MAD of X2 |
The bounds, measures�of center and spread�for X1 and X2 are:
Scaling Limits and Measures of Center and Spread
Variable |
Real Limits |
Target Limits |
Measure of Center |
Measure of Spread |
X1 |
(-6, +6) |
(-3, +3) |
3.4 |
1.7421 |
X2 |
(-3, +3) |
(-3, +3) |
2.4 |
1.3343 |
The real and target limits are used for bounded scaling.� The measures of center and spread are used to calculate z-scores. Using these values for� x1 [0]=3.5 � yields the following calculations:
For x1 [0] , the scale factor is calculated using the real and target limits in the above table:
r = (3-(-3))/(6-(-6)) = 0.5
The z-score for x1 [0] is calculated using the measures of center and spread:
z1 [0] = (3.5 - 3.4)/1.7421 = 0.057402
Since method=4 is used for x1 , this z-score is bounded (scaled) using the real and target limits:
z1
(bounded)
= r
(z1
[0]
) - r(realMin) + (targetMin)
����������� ����������� ����� = 0.5(0.057402) - 0.5(-6) + (-3) = 0.029
The�calculations for x2 [0] are nearly identical, except that since method=5 for x2 , the median and MAD replace the mean and standard deviation used to calculate z1 (bounded):
r = (3-(-3))/(3-(-3)) = 1,
z2 [0] = (3.1 - 2.4)/1.3343 = 0.525, and
z2
(bounded)
= r
(z2
[0]
) - r(realMin) + (targetMin)
����������� ��� = 1(0.525) - 1(-3) + (-3) = 0.525
using System; using Imsl.Stat; using Imsl.Math; using Imsl.DataMining.Neural; public class ScaleFilterEx1 { public static void Main(System.String[] args) { ScaleFilter[] scaleFilter = new ScaleFilter[3]; scaleFilter[0] = new ScaleFilter(ScaleFilter.ScalingMethod.None); scaleFilter[1] = new ScaleFilter( ScaleFilter.ScalingMethod.BoundedZScoreMeanStdev); scaleFilter[1].SetBounds(- 6.0, 6.0, - 3.0, 3.0); scaleFilter[2] = new ScaleFilter( ScaleFilter.ScalingMethod.BoundedZScoreMedianMAD); scaleFilter[2].SetBounds(- 3.0, 3.0, - 3.0, 3.0); double[] y0, y1, y2; double[] x0 = new double[]{1.2, 0.0, - 1.4, 1.5, 3.2}; double[] x1 = new double[]{3.5, 2.4, 4.4, 5.6, 1.1}; double[] x2 = new double[]{3.1, 1.5, - 1.5, 2.4, 4.2}; // Perform forward filtering y0 = scaleFilter[0].Encode(x0); y1 = scaleFilter[1].Encode(x1); y2 = scaleFilter[2].Encode(x2); // Display x0 System.Console.Out.Write("X0 = {"); for (int i = 0; i < 4; i++) System.Console.Out.Write(x0[i] + ", "); System.Console.Out.WriteLine(x0[4] + "}"); // Display summary statistics for X1 System.Console.Out.Write("\nX1 = {"); for (int i = 0; i < 4; i++) System.Console.Out.Write(x1[i] + ", "); System.Console.Out.WriteLine(x1[4] + "}"); System.Console.Out.WriteLine("X1 Mean: " + scaleFilter[1].Center); System.Console.Out.WriteLine("X1 Std. Dev.: " + scaleFilter[1].Spread); // Display summary statistics for X2 System.Console.Out.Write("\nX2 = {"); for (int i = 0; i < 4; i++) System.Console.Out.Write(x2[i] + ", "); System.Console.Out.WriteLine(x2[4] + "}"); System.Console.Out.WriteLine("X2 Median: " + scaleFilter[2].Center); System.Console.Out.WriteLine("X2 MAD/0.6745: " + scaleFilter[2].Spread); System.Console.Out.WriteLine(""); PrintMatrix pm = new PrintMatrix(); pm.SetTitle("Filtered X0 Using Method=0 (no scaling)"); pm.Print(y0); pm.SetTitle("Filtered X1 Using Bounded Z-score Scaling\n" + "with Center=Mean and Spread=Std. Dev."); pm.Print(y1); pm.SetTitle("Filtered X2 Using Bounded Z-score Scaling\n" + "with Center=Median and Spread=MAD/0.6745"); pm.Print(y2); // Perform inverse filtering double[] z0, z1, z2; z0 = scaleFilter[0].Decode(y0); z1 = scaleFilter[1].Decode(y1); z2 = scaleFilter[2].Decode(y2); pm.SetTitle("Decoded Z0"); pm.Print(z0); pm.SetTitle("Decoded Z1"); pm.Print(z1); pm.SetTitle("Decoded Z2"); pm.Print(z2); } }
X0 = {1.2, 0, -1.4, 1.5, 3.2} X1 = {3.5, 2.4, 4.4, 5.6, 1.1} X1 Mean: 3.4 X1 Std. Dev.: 1.74212513901843 X2 = {3.1, 1.5, -1.5, 2.4, 4.2} X2 Median: 2.4 X2 MAD/0.6745: 1.33434199665504 Filtered X0 Using Method=0 (no scaling) 0 0 1.2 1 0 2 -1.4 3 1.5 4 3.2 Filtered X1 Using Bounded Z-score Scaling with Center=Mean and Spread=Std. Dev. 0 0 0.0287005788965145 1 -0.287005788965146 2 0.287005788965146 3 0.631412735723321 4 -0.660113314619835 Filtered X2 Using Bounded Z-score Scaling with Center=Median and Spread=MAD/0.6745 0 0 0.524603139041397 1 -0.674489750196082 2 -2.92278891751635 3 0 4 1.34897950039216 Decoded Z0 0 0 1.2 1 0 2 -1.4 3 1.5 4 3.2 Decoded Z1 0 0 3.5 1 2.4 2 4.4 3 5.6 4 1.1 Decoded Z2 0 0 3.1 1 1.5 2 -1.5 3 2.4 4 4.2Link to C# source.