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)));
            }
        }
Exemple #2
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[] 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 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 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 static List <Tuple <int, int> > FindPeakIntervals <ValueType>(IAlgebraReal <ValueType> algebra, IFunction <int, ValueType> function, int min_index, int max_index, ValueType peak_rate)
        {
            int temp_index  = min_index - 1;
            int start_index = min_index - 1;
            int index       = min_index - 1;
            List <Tuple <int, int> > intervals = new List <Tuple <int, int> >();

            while (index < max_index)
            {
                if ((algebra.Compare(function.Compute(index + 1), algebra.Multiply(peak_rate, function.Compute(start_index))) == -1) &&
                    (algebra.Compare(function.Compute(temp_index), (algebra.Multiply(peak_rate, function.Compute(start_index)))) == 1))
                {
                    int peak_index = start_index;
                    while (algebra.Compare(function.Compute(peak_index - 1), (algebra.Multiply(peak_rate, function.Compute(start_index)))) != -1)
                    {
                        peak_index = peak_index - 1;
                    }
                    intervals.Add(new Tuple <int, int>(peak_index, index));
                }

                if ((algebra.Compare(function.Compute(index + 1), function.Compute(temp_index)) == -1) ||
                    (algebra.Compare(function.Compute(index + 1), algebra.Multiply(peak_rate, function.Compute(start_index))) == -1))
                {
                    temp_index  = index + 1;
                    start_index = index + 1;
                    index       = index + 1;
                }
                else if (algebra.Compare(function.Compute(index + 1), function.Compute(start_index)) == -1)
                {
                    start_index = index + 1;
                    index       = index + 1;
                }
                else
                {
                    index = index + 1;
                }
            }

            return(intervals);
        }
 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))));
 }
Exemple #8
0
        //Richardson Extrapolation http://en.wikipedia.org/wiki/Richardson_extrapolation
        //
        // @param value  *            original value
        // @param refined_value     *            with base times smaller intervals
        // @param base     *            refinement factor of value
        // @param power     *            order of scale
        //@return
        public static RealType RichardsonExtrapolation <RealType>(IAlgebraReal <RealType> algebra, RealType value, RealType refined_value, RealType base_value, RealType power)
        {
            RealType scale = algebra.Pow(base_value, power);

            return(algebra.Divide(algebra.Subtract(algebra.Multiply(scale, refined_value), value), algebra.Subtract(scale, algebra.MultiplyIdentity)));
        }