示例#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 void DivideElementsRBA <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> divided, RealType divisor, IList <RealType> result)
 {
     Parallel.For(0, result.Count, index =>
     {
         result[index] = algebra.Divide(divided[index], divisor);
     });
 }
        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 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 RealType[] DivideElements <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> divided, IList <RealType> divisors)
 {
     if (divided.Count != divisors.Count)
     {
         throw new Exception("Size mismatch: " + divided.Count + " does not match with " + divisors.Count);
     }
     RealType[] result = new RealType[divided.Count];
     Parallel.For(0, result.Length, index =>
     {
         result[index] = algebra.Divide(divided[index], divisors[index]);
     });
     return(result);
 }
 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 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 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))));
        }
示例#10
0
        public Bitmap Render(IImageRaster <IRaster3DInteger, ElementType> source_image)
        {
            IRaster3DInteger raster            = source_image.Raster;
            Bitmap           destination_image = new Bitmap(raster.Size0, raster.Size1);

            for (int index_y = 0; index_y < raster.Size1; index_y++)
            {
                for (int index_x = 0; index_x < raster.Size0; index_x++)
                {
                    ElementType mean_value = source_image.GetElementValue(raster.GetElementIndex(index_x, index_y, 0));
                    for (int index_z = 1; index_z < raster.Size2; index_z++)
                    {
                        mean_value = this.algebra.Add(mean_value, source_image.GetElementValue(raster.GetElementIndex(index_x, index_y, index_z)));
                    }
                    mean_value = algebra.Divide(mean_value, this.algebra.ToDomain(raster.Size2));
                    destination_image.SetPixel(index_x, index_y, this.converter.Compute(mean_value));
                }
            }
            return(destination_image);
        }
 public static RealType Interpolation1DLinear <RealType>(IAlgebraReal <RealType> algebra, RealType domain_0, RealType value_0, RealType domain_1, RealType value_1, RealType domain_new)
 {
     return(Interpolation1DLinear(algebra, algebra.Divide(algebra.Subtract(domain_new, domain_0), algebra.Subtract(domain_1, domain_0)), value_0, value_1));
 }
 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)));
 }
示例#13
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)));
        }