Exemple #1
0
        public static RealType[] ConvolveUniform <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> list_base, IList <RealType> list_kernel, bool corrected, int offset, int lenght)
        {
            if ((list_base.Count == 0) || (list_kernel.Count == 0))
            {
                throw new Exception("list_base and list_kernel must at least be of size 1");
            }
            RealType kernel_total = algebra.AddIdentity;

            if (corrected)
            {
                for (int kernel_index = 0; kernel_index < list_kernel.Count; kernel_index++)
                {
                    kernel_total = algebra.Add(kernel_total, list_kernel[kernel_index]);
                }
            }

            RealType[] result = new RealType[lenght];
            for (int result_index = 0; result_index < result.Length; result_index++)
            {
                RealType kernel_part = algebra.AddIdentity;
                for (int kernel_index = 0; kernel_index < list_kernel.Count; kernel_index++)
                {
                    if ((0 <= result_index + offset - kernel_index) && (result_index + offset - kernel_index < list_base.Count))
                    {
                        result[result_index] = algebra.Add(result[result_index], algebra.Multiply(list_base[result_index + offset - kernel_index], list_kernel[kernel_index]));
                        kernel_part          = algebra.Add(kernel_part, list_kernel[kernel_index]);
                    }
                }
                if (corrected)
                {
                    result[result_index] = algebra.Multiply(result[result_index], (algebra.Divide(kernel_total, kernel_part)));
                }
            }
            return(result);
        }
        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));
        }
 public static void AddRBA <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> array_0, IList <RealType> array_1, IList <RealType> array_destination)
 {
     for (int index = 0; index < array_0.Count; index++)
     {
         array_destination[index] = algebra.Add(array_0[index], array_1[index]);
     }
 }
        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)));
            }
        }
 public static RealType[] AddMultiple <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> values_source, IList <RealType> values_add, RealType multiple)
 {
     RealType[] result = new RealType[values_source.Count];
     for (int index = 0; index < values_source.Count; index++)
     {
         result[index] = algebra.Add(values_source[index], algebra.Multiply(values_add[index], multiple));
     }
     return(result);
 }
        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));
        }
        public static RealType WeightedMean <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> values, IList <RealType> weights)
        {
            RealType value = algebra.AddIdentity;

            for (int index = 0; index < values.Count; index++)
            {
                value = algebra.Add(value, algebra.Multiply(values[index], weights[index]));
            }
            return(algebra.Divide(value, Sum(algebra, weights)));
        }
        public static RealType Sum <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> array)
        {
            RealType sum = algebra.AddIdentity;

            for (int index = 0; index < array.Count; index++)
            {
                sum = algebra.Add(sum, array[index]);
            }
            return(sum);
        }
        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))));
        }
        public RealType Compute(DomainType domain_value_0)
        {
            RealType value = algebra.AddIdentity;

            for (int index = 0; index < basis_function_list.Count; index++)
            {
                value = algebra.Add(value, algebra.Multiply(basis_function_list[index].Compute(domain_value_0), weight_list[index]));
            }
            return(value);
        }
 public ElementType[] GetDisplayValues()
 {
     ElementType[] display_values     = new ElementType[this.max_tree.RealElementCount];
     ElementType[] display_values_max = this.max_tree.GetDisplayValues();
     ElementType[] display_values_min = this.min_tree.GetDisplayValues();
     for (int index = 0; index < display_values.Length; index++)
     {
         display_values[index] = algebra.Subtract(algebra.Add(display_values_max[index], display_values_min[index]), element_values[index]);
     }
     return(display_values);
 }
 public static RealType[] Sums1 <RealType>(IAlgebraReal <RealType> algebra, IList <IList <RealType> > list_list)
 {
     RealType[] sums_1 = new RealType[list_list[0].Count];
     for (int index_0 = 0; index_0 < list_list.Count; index_0++)
     {
         for (int index_1 = 0; index_1 < list_list[0].Count; index_1++)
         {
             sums_1[index_1] = algebra.Add(sums_1[index_1], list_list[index_0][index_1]);
         }
     }
     return(sums_1);
 }
 public static RealType[] Sums1 <RealType>(IAlgebraReal <RealType> algebra, RealType[,] array2d)
 {
     RealType[] sums_1 = new RealType[array2d.GetLength(1)];
     for (int index_0 = 0; index_0 < array2d.GetLength(0); index_0++)
     {
         for (int index_1 = 0; index_1 < array2d.GetLength(1); index_1++)
         {
             sums_1[index_1] = algebra.Add(sums_1[index_1], array2d[index_0, index_1]);
         }
     }
     return(sums_1);
 }
 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));
     }
 }
        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));
            }
        }
 public static RealType Interpolation1DLinear <RealType>(IAlgebraReal <RealType> algebra, RealType fraction_0, RealType value_0, RealType value_1)
 {
     return(algebra.Add(algebra.Multiply(value_0, fraction_0),
                        algebra.Multiply(value_1, algebra.Subtract(algebra.MultiplyIdentity, fraction_0))));
 }