コード例 #1
0
        public static RealType QuantileSorted <RealType>(
            IAlgebraReal <RealType> algebra,
            IList <RealType> array_sorted,
            double quantile)
        {
            if ((quantile < 0.0f) || (1.0f < quantile))
            {
                throw new Exception("Out of range");
            }

            double index_real = array_sorted.Count * quantile;
            int    index_low  = (int)Math.Floor(index_real);

            if (index_low == array_sorted.Count)
            {
                return(array_sorted[array_sorted.Count - 1]);
            }
            else
            {
                RealType index_low_weight  = algebra.ToDomain(index_real - (double)index_low);
                RealType index_high_weight = algebra.Subtract(algebra.ToDomain(index_low + 1), algebra.ToDomain(index_real));

                return(algebra.Add(
                           algebra.Multiply(array_sorted[index_low], index_low_weight),
                           algebra.Multiply(array_sorted[index_low + 1], index_high_weight)));
            }
        }
コード例 #2
0
        public static RealType MeanAll <RealType>(IAlgebraReal <RealType> algebra, IList <IList <RealType> > samples)
        {
            RealType total_count = algebra.AddIdentity;
            RealType total_sum   = algebra.AddIdentity;

            foreach (IList <RealType> sample in samples)
            {
                total_count = algebra.Add(total_count, algebra.ToDomain((float)sample.Count));
                total_sum   = algebra.Add(total_sum, ToolsMathCollection.Sum(algebra, sample));
            }
            return(algebra.Divide(total_sum, total_count));
        }
コード例 #3
0
 public static void Means1RBA <RealType>(
     IAlgebraReal <RealType> algebra,
     RealType[,] array_2d,
     IList <RealType> means)
 {
     for (int index_0 = 0; index_0 < array_2d.Length; index_0++)
     {
         for (int index_1 = 0; index_1 < means.Count; index_1++)
         {
             means[index_1] = algebra.Add(means[index_1], array_2d[index_0, index_1]);
         }
     }
     for (int index_1 = 0; index_1 < means.Count; index_1++)
     {
         means[index_1] = algebra.Divide(means[index_1], algebra.ToDomain((float)array_2d.Length));
     }
 }
コード例 #4
0
        public static void Means1RBA <RealType>(
            IAlgebraReal <RealType> algebra,
            IList <IList <RealType> > list_list,
            IList <RealType> means)
        {
            for (int index_0 = 0; index_0 < list_list.Count; index_0++)
            {
                for (int index_1 = 0; index_1 < means.Count; index_1++)
                {
                    means[index_1] = algebra.Add(means[index_1], list_list[index_0][index_1]);
                }
            }

            for (int index_1 = 0; index_1 < means.Count; index_1++)
            {
                means[index_1] = algebra.Divide(means[index_1], algebra.ToDomain((float)list_list.Count));
            }
        }
コード例 #5
0
        public static RealType VariancePooled <RealType>(
            IAlgebraReal <RealType> algebra,
            IList <IList <RealType> > samples)
        {
            RealType variance           = algebra.AddIdentity;
            RealType degrees_of_freedom = algebra.AddIdentity;

            foreach (IList <RealType> sample in samples)
            {
                RealType mean_0 = Mean(algebra, sample);
                for (int index = 0; index < sample.Count; index++)
                {
                    variance = algebra.Add(variance, algebra.Sqr(algebra.Subtract(sample[index], mean_0)));
                }
                degrees_of_freedom = algebra.Add(degrees_of_freedom, algebra.ToDomain((float)(sample.Count - 1)));
            }
            return(algebra.Divide(variance, degrees_of_freedom));
        }
コード例 #6
0
        public static RealType VariancePooled <RealType>(
            IAlgebraReal <RealType> algebra,
            IList <RealType> sample_0,
            IList <RealType> sample_1)
        {
            RealType mean_0   = Mean(algebra, sample_0);
            RealType mean_1   = Mean(algebra, sample_1);
            RealType variance = algebra.AddIdentity;

            for (int index = 0; index < sample_0.Count; index++)
            {
                variance = algebra.Add(variance, algebra.Sqr(algebra.Subtract(sample_0[index], mean_0)));
            }
            for (int index = 0; index < sample_1.Count; index++)
            {
                variance = algebra.Add(variance, algebra.Sqr(algebra.Subtract(sample_1[index], mean_1)));
            }
            return(algebra.Divide(variance, algebra.ToDomain((float)(sample_0.Count + sample_1.Count - 2))));
        }
コード例 #7
0
        public void Filter(IList <MaxTreeNode <ElementType> > list_bottom_to_top)
        {
            list_bottom_to_top.Reverse();
            foreach (IMaxTreeNode <ElementType> current_node in list_bottom_to_top)
            {
                ElementType mean = this.algebra.AddIdentity;
                foreach (IMaxTreeNode <ElementType> child_node in current_node.GetNodeChildren())
                {
                    mean = this.algebra.Multiply(this.algebra.Add(mean, child_node.DisplayValue), algebra.ToDomain((float)child_node.CulmativeRealSize));
                }

                foreach (int element_index in current_node.GetElementIndexArrayNodeReal())
                {
                    mean = this.algebra.Add(mean, this.source_values[element_index]);
                }
                current_node.DisplayValue = this.algebra.Divide(mean, this.algebra.ToDomain((float)current_node.CulmativeRealSize));
            }

            list_bottom_to_top.Reverse();
            foreach (IMaxTreeNode <ElementType> current_node in list_bottom_to_top)
            {
                if (filter_function.Compute(current_node) && (current_node.Parent != null))
                {
                    current_node.DisplayValue = current_node.Parent.DisplayValue;
                }
                else
                {
                    current_node.DisplayValue = current_node.Value;
                }
            }
        }
コード例 #8
0
 public static RealType Mean <RealType>(
     IAlgebraReal <RealType> algebra,
     IList <RealType> sample_0)
 {
     return(algebra.Divide(ToolsMathCollection.Sum(algebra, sample_0), algebra.ToDomain((float)sample_0.Count)));
 }