Exemplo n.º 1
0
        /// <summary>
        /// Calculates margins
        /// </summary>
        public static Dictionary <int, double> CalculateMargins <TObj>(IGammaAlgorithm <TObj> alg)
        {
            var result = new Dictionary <int, double>();
            int idx    = -1;

            foreach (var pData in alg.TrainingSample)
            {
                idx++;
                double maxi = double.MinValue;
                double si   = 0;

                foreach (var cls in alg.TrainingSample.Classes)
                {
                    var proximity = alg.CalculateClassScore(pData.Key, cls);
                    if (cls.Equals(pData.Value))
                    {
                        si = proximity;
                    }
                    else
                    {
                        if (maxi < proximity)
                        {
                            maxi = proximity;
                        }
                    }
                }

                result.Add(idx, si - maxi);
            }

            return(result.OrderBy(r => r.Value).ToDictionary(r => r.Key, r => r.Value));
        }
Exemplo n.º 2
0
        private void calculateMargin(IGammaAlgorithm <double[]> algorithm)
        {
            var res = StatUtils.CalculateMargins(algorithm);

            foreach (var r in res)
            {
                Console.WriteLine("{0}\t{1}", r.Key, r.Value);
            }
        }