public void NormalizeDataSet(KPoint.NormType norm) { if (norm == KPoint.NormType.MaxAttr) { double[] attributes = new double[Dimensions]; for (int i = 0; i < attributes.Length; i++) { attributes[i] = 0.0; } foreach (KPoint p in PointList) { for (int i = 0; i < attributes.Length; i++) { attributes[i] = Math.Max(attributes[i], p[i]); } } foreach (KPoint p in PointList) { p.Normalize(attributes); } } else { foreach (KPoint p in PointList) { p.Normalize(norm); } } }
//This routine will normalize data private void button14_Click(object sender, EventArgs e) { //This code gets the normalization type from the dropdown KPoint.NormType norm = KPoint.NormType.None; if (comboBox4.SelectedIndex == 0) { norm = KPoint.NormType.GeometricMean; } else if (comboBox4.SelectedIndex == 1) { norm = KPoint.NormType.ArithmeticMean; } else if (comboBox4.SelectedIndex == 2) { norm = KPoint.NormType.Max; } else if (comboBox4.SelectedIndex == 3) { norm = KPoint.NormType.MaxAttr; } else if (comboBox4.SelectedIndex == 4) { norm = KPoint.NormType.None; } //This loads a list of datapoints and normalized is var normPoints = new PointSet(pointSetFile); List <int> featureSet = new List <int>(); for (int i = 0; i < normPoints.Dimensions; i++) { if (checkedListBox1.GetItemCheckState(i) == CheckState.Checked) { featureSet.Add(i); } } normPoints = normPoints.GetReducedAttributeSet(featureSet); normPoints.NormalizeDataSet(norm); //This will create a sub directory to place the file in String folder = pointSetFileShort.Substring(0, pointSetFileShort.IndexOf('.')); System.IO.Directory.CreateDirectory(folder); openFileDialog2.InitialDirectory = folder; //now we write the values String normFileName = folder + "/" + folder + "_" + norm.ToString() + featureSet.Count + "features" + ".txt"; normPoints.Save(normFileName); MessageBox.Show("Normalized File Generated! " + normFileName); }
public void NormalizeDataSet(KPoint.NormType norm) { if (norm == KPoint.NormType.MaxAttr) { double[] attributes = new double[Dimensions]; for (int i = 0; i < attributes.Length; i++) { attributes[i] = 0.0; } foreach (KPoint p in PointList) { for (int i = 0; i < attributes.Length; i++) { attributes[i] = Math.Max(attributes[i], p[i]); } } foreach (KPoint p in PointList) { p.Normalize(attributes); } } else if (norm == KPoint.NormType.ZeroMeanOneStd) { //Calculate the mean and std double[] rowMeans = new double[Dimensions]; double[] rowSqrSum = new double[Dimensions]; double[] rowStds = new double[Dimensions]; //Calculate the mean and std foreach (var point in PointList) { for (int d = 0; d < Dimensions; d++) { rowMeans[d] += point[d]; rowSqrSum[d] += point[d] * point[d]; } } for (int d = 0; d < Dimensions; d++) { rowMeans[d] /= PointList.Count; double attrVar = rowSqrSum[d] / PointList.Count - rowMeans[d] * rowMeans[d]; rowStds[d] = Math.Sqrt(attrVar); } //Standardize the data foreach (var point in PointList) { for (int d = 0; d < Dimensions; d++) { point[d] = (point[d] - rowMeans[d]) / rowStds[d]; } } } else { foreach (KPoint p in PointList) { p.Normalize(norm); } } }