示例#1
0
        public void rowSigmaNormalization(int sigmaMultiplier)
        {
            PatternTools.pTools ptool = new PatternTools.pTools();

            foreach (sparseMatrixRow row in matrix)
            {
                //Calculate the row sigma

                List <double> rowValues = new List <double>();
                foreach (double v in row.Values)
                {
                    rowValues.Add(v);
                }

                double rowSigma    = Math.Sqrt(PatternTools.pTools.variance(rowValues, true));
                double rowAverage  = PatternTools.pTools.Average(rowValues);
                double sigmaFactor = rowSigma * sigmaMultiplier;

                //divide each item in the row
                for (int dimIndex = 0; dimIndex < row.Values.Count; dimIndex++)
                {
                    row.Values[dimIndex] /= (sigmaFactor + rowAverage);
                }
            }
        }
示例#2
0
        public void zNormalization()
        {
            List <int> allDims = this.allDims();

            PatternTools.pTools ptool = new PatternTools.pTools();

            for (int dimIndex = 0; dimIndex < allDims.Count; dimIndex++)
            {
                //Calculate mean and standard deviation
                List <double> theNumbers = this.ExtractDimValues(allDims[dimIndex], 0, true);

                double mean   = PatternTools.pTools.Average(theNumbers);
                double stdDev = Math.Sqrt(PatternTools.pTools.variance(theNumbers, true));


                //Finaly Manipulate the matrix

                foreach (sparseMatrixRow row in matrix)
                {
                    //find in what index our value is located
                    int index = getDimIndexFromValue(row, allDims[dimIndex]);
                    //MessageBox.Show("Working on row " + matrix.IndexOf(row) + " the index is " + index );

                    //modify the value
                    if (index >= 0)
                    {
                        double value = (row.Values[index] - mean) / stdDev;
                        if (value.Equals(double.NaN))
                        {
                            row.Values[index] = 0;
                        }
                        else
                        {
                            row.Values[index] = value;
                        }
                    }
                }
            }
        }