/// <summary> /// Applies min-max normalization to the feature set /// </summary> /// <param name="aFeatureList"></param> /// <returns>The return value contains the normalized Feature set, as well the min and max values used for normaziation</returns> public static NormalizedFeatures NormalizeFeatures(List <SignatureFeatures> aFeatureList) { //Initialize Normalized With list. This will contain the min anf max values used at the normalization of the features List <NormalizedWith> lNormalizedWith = new List <NormalizedWith>(); for (var i = 0; i < aFeatureList.ElementAt(0).Count; ++i) { lNormalizedWith.Add(new NormalizedWith(9999, -9999)); } for (int i = 0; i < aFeatureList.Count; ++i) { SignatureFeatures lFeatures = new SignatureFeatures(); for (int j = 0; j < aFeatureList.ElementAt(i).Count; ++j) { var lCurrentFeatureValue = aFeatureList.ElementAt(i).ElementAt(j).Value; if (lNormalizedWith.ElementAt(j).Min > lCurrentFeatureValue) { lNormalizedWith.ElementAt(j).Min = lCurrentFeatureValue; } if (lNormalizedWith.ElementAt(j).Max < lCurrentFeatureValue) { lNormalizedWith.ElementAt(j).Max = lCurrentFeatureValue; } } } for (int i = 0; i < aFeatureList.Count; ++i) { SignatureFeatures lNormalizedFeatures = new SignatureFeatures(); for (int j = 0; j < aFeatureList.ElementAt(i).Count; ++j) { var lCurrentFeature = aFeatureList.ElementAt(i).ElementAt(j); if (lNormalizedWith.ElementAt(j).Min != lNormalizedWith.ElementAt(j).Max) { lNormalizedFeatures[lCurrentFeature.Key] = 2 * ((lCurrentFeature.Value - lNormalizedWith.ElementAt(j).Min) / (lNormalizedWith.ElementAt(j).Max - lNormalizedWith.ElementAt(j).Min)) - 1; } else { lNormalizedFeatures[lCurrentFeature.Key] = lCurrentFeature.Value; } } aFeatureList.RemoveAt(i); aFeatureList.Insert(i, lNormalizedFeatures); } NormalizedFeatures lNormalized = new NormalizedFeatures(aFeatureList, lNormalizedWith); return(lNormalized); }
public Detector(List <SignatureFeatures> aFeatures) { mNormalized = FeatureNormalizer.NormalizeFeatures(aFeatures); foreach (var featureSet in mNormalized.ListOfFeatureSets) { foreach (var feature in featureSet) { mTemplate[feature.Key] += feature.Value; } } foreach (var feature in mTemplate.ToList()) { mTemplate[feature.Key] /= mNormalized.ListOfFeatureSets.Count; } }