// https://en.wikipedia.org/wiki/Coefficient_of_variation
        public static double WeightUsingCoefficientOfVariation(IFeatureCollectionWrapper <FeatureBase> featureValues)
        {
            var features = featureValues.Where(feature => !feature.FeatureValue.Equals(-1.0));

            if (!features.Any() || features.Count() < 2)
            {
                return(0);
            }

            var stdDev = features.StandardDeviation(feature => feature.FeatureValue);

            if (stdDev.Equals(0))
            {
                return(1);
            }                                  // /Math.Sqrt(features.Count()); }

            var average = features.Average(feature => feature.FeatureValue);

            if (stdDev.CompareTo(average) > 0)
            {
                return(0);
            }                                               //average / stdDev; }

            return(stdDev / average);
        }
        public static double WeightUsingVarianceAndStandarDeviation(IFeatureCollectionWrapper <FeatureBase> featureValues)
        {
            var features = featureValues.Where(feature => !feature.FeatureValue.Equals(-1.0));

            if (!features.Any() || features.Count() < 2)
            {
                return(0);
            }
            //if (featureValues.Count() < 2) { return 1; }

            var stdDev = features.StandardDeviation(feature => feature.FeatureValue);

            if (stdDev.Equals(0))
            {
                return(1 / Math.Sqrt(features.Count()));
            }

            var variance = features.Variance(feature => feature.FeatureValue);

            if (stdDev.CompareTo(variance) > 0)
            {
                return(1 - (stdDev));
            }
            return(1 - (stdDev / variance));
        }
        public static double WeightUsingStandarDeviation(IFeatureCollectionWrapper <FeatureBase> featureValues)
        {
            var features = featureValues.Where(feature => !feature.FeatureValue.Equals(-1.0));

            if (!features.Any() || features.Count() < 2)
            {
                return(0);
            }
            //if (featureValues.Count() < 2) { return 1; }

            var stdDev = features.StandardDeviation(feature => feature.FeatureValue);

            // if(stdDev.Equals(0)) { return 1;}
            return(1 / Math.Sqrt(1 + stdDev));
        }
        public static double WeightUsingNormEntropy(IFeatureCollectionWrapper <FeatureBase> featureValues)
        {
            var features = featureValues.Where(feature => !feature.FeatureValue.Equals(-1.0));

            if (!features.Any() || features.Count() == 1)
            {
                return(0);
            }

            var values = (from i in featureValues
                          group i by i.FeatureValue
                          into grp
                          orderby grp.Count() descending
                          select grp);
            //if (featureValues.Count() == 1) { return 1; }

            int classes;
            var entropyValue = Entropy.Calculate(features.Select(feature => feature.FeatureValue), out classes);

            if (entropyValue.Equals(0))
            {
                return(1);                       //(double)1 / Math.Sqrt(classes);
            }
            var result = 1 - entropyValue / Math.Log(classes);

            if (result.Equals(0))
            {
                return(result);
            }

            //return WeightUsingCoefficientOfVariation(featureValues);
            if (values.Count() < Math.Sqrt(classes))
            {
                var coeffOfVar = WeightUsingCoefficientOfVariation(featureValues);

                if (!coeffOfVar.Equals(0))
                {
                    return(coeffOfVar);
                }
                //return coeffOfVar;
            }
            return(result);
        }
Esempio n. 5
0
        public static double FeatureMetricAverage(IFeatureCollectionWrapper <FeatureBase> featureValues)
        {
            var features = featureValues.Where(feature => !feature.FeatureValue.Equals(-1.0)).ToArray();

            return(!features.Any()? 0 : features.Average(feature => feature.FeatureValue));
        }