Example #1
0
        public object ComputeMeanValue(ArrayList stats, string featureName)
        {
            double sum             = 0;
            double totalSimilarity = 0;

            for (int i = 0; i < stats.Count; i++)
            {
                IStat s = (IStat)stats[i];
                Case  c = s.GetCBRCase();
                if (c != null)
                {
                    Feature f = c.GetFeature(featureName);
                    if (f != null)
                    {
                        if (f.GetFeatureType()
                            == FeatureType.TYPE_FEATURE_FLOAT)
                        {
                            sum             += (double)f.GetFeatureValue() * s.GetCaseSimilarity();
                            totalSimilarity += s.GetCaseSimilarity();
                        }
                        else if (f.GetFeatureType()
                                 == FeatureType.TYPE_FEATURE_INT)
                        {
                            sum             += (int)f.GetFeatureValue() * s.GetCaseSimilarity();
                            totalSimilarity += s.GetCaseSimilarity();
                        }
                        else
                        {
                            throw new Exception("ComputeMeanValue method exception:unsupported type");
                        }
                    }
                }
            }
            if (totalSimilarity == 0)
            {
                throw new Exception("ComputeMeanValue method exception");
            }
            return(sum / totalSimilarity);
        }