public double Evaluate(ITemplateModelDiscrete <DomainType, LabelType> template, IDataSet <DomainType, LabelType> data_set, ISet <int> feature_set)
        {
            IDataSet <DomainType, LabelType> selected_data_set = data_set.SelectFeatures(new List <int>(feature_set));

            double[] scores = new double[this.FoldCount];
            Parallel.For(0, this.FoldCount, fold_index =>
            {
                Tuple <IDataSet <DomainType, LabelType>, IDataSet <DomainType, LabelType> > split = selected_data_set.Split(this.TrainingSetFraction);
                ReportDiscrete <DomainType, LabelType> report = template.GenerateAndTestDiscrete(split.Item1, split.Item2);
                scores[fold_index] = report.CorrectLabelRate;
            });
            return(ToolsMathCollection.Sum(scores) / ((double)this.FoldCount));
        }
        private void InitMembers(double [] factors)
        {
            Debug.Assert(factors.Length == 4);
            argb_integer_weigths = new int[4];
            argb_integer_temp    = new int[4];


            //reduced so it will not go out of uint32 range
            double sum = ToolsMathCollection.Sum(factors);

            double multiplier = (int.MaxValue) / (sum * 255);

            for (int index = 0; index < factors.Length; index++)
            {
                argb_integer_weigths[index] = (ushort)Math.Floor(factors[index] * multiplier);
            }
            argb_integer_divisor = ToolsMathCollectionInteger.Sum(argb_integer_weigths);
        }
Beispiel #3
0
        public static double TestStatic(IList <IList <double> > samples)
        {
            double total_size            = 0.0f;
            double squared_rank_mean_sum = 0.0f;

            double[][] rank_samples = ToolsMathStatistics.ConvertToAccendingRanks(samples);

            foreach (double[] sample in rank_samples)
            {
                total_size += sample.Length;
                double sum = ToolsMathCollection.Sum(sample);

                squared_rank_mean_sum += (sum * sum) / ((double)sample.Length);
            }

            double statistic = (12.0 * squared_rank_mean_sum) / (total_size * (total_size + 1)) - 3 * (total_size + 1);

            return(1 - ChiSquared.CDF(samples.Count - 1, statistic));
        }
Beispiel #4
0
        public static double TestStatic(IList <IList <double> > samples, IList <double> limits)
        {
            // Create to blocks according to limits
            double[,] table = new double[samples.Count, limits.Count + 1];
            for (int index_0 = 0; index_0 < samples.Count; index_0++)
            {
                for (int index_1 = 0; index_1 < samples[index_0].Count; index_1++)
                {
                    double value = samples[index_0][index_1];


                    //for any of the other bins
                    int limit_index = 0;
                    while ((limit_index < limits.Count) && (limits[limit_index] <= value))
                    {
                        limit_index++;
                    }
                    table[index_0, limit_index]++;
                }
            }

            // Compute test for independance
            double[] sums_0 = ToolsMathCollection.Sums0(table);
            double[] sums_1 = ToolsMathCollection.Sums1(table);
            double   total  = ToolsMathCollection.Sum(sums_0);

            double chi_square_statistic = 0;

            for (int index_0 = 0; index_0 < sums_0.Length; index_0++)
            {
                for (int index_1 = 0; index_1 < sums_1.Length; index_1++)
                {
                    double expectation = (sums_0[index_0] * sums_1[index_1]) / total;
                    chi_square_statistic += (ToolsMath.Sqr(table[index_0, index_1] - expectation) / expectation);
                }
            }
            double degrees_of_freedom = (sums_0.Length - 1) * (sums_1.Length - 1);

            return(ChiSquared.CDF(degrees_of_freedom, chi_square_statistic));
        }
        // based on first bigger than second means positive
        public static double ComputeRankSumStatistic(IList <double> sample_0, IList <double> sample_1)
        {
            // compute ranks
            DictionaryCount <double> counts = new DictionaryCount <double>();

            foreach (double item in sample_0)
            {
                counts.Increment(item);
            }

            foreach (double item in sample_1)
            {
                counts.Increment(item);
            }
            Dictionary <double, double> ranks = new Dictionary <double, double>();
            List <double> keys = new List <double>(counts.Keys);

            keys.Sort();
            double rank = 1;

            foreach (double key in keys)
            {
                int count = counts[key];
                ranks[key] = (rank + rank + count - 1) / 2.0;
                rank      += count;
            }

            List <double> rank_list = new List <double>();

            foreach (double item in sample_0)
            {
                rank_list.Add(ranks[item]);
            }

            return(ToolsMathCollection.Sum(rank_list));
        }
 public override int GetHashCode()
 {
     return(ToolsMathCollection.Sum(new AlgebraIntegerInt32(), size));
 }