Exemple #1
0
        // Convolution returns only space where the tot kernel fits in the base equivalent to matlab conv(a,b, 'valid')
        // Correction is irrelevant as only the portion with no need for correction is returned
        public static RealType[] ConvolveUniformValid <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> list_base, IList <RealType> list_kernel)
        {
            if (list_base.Count < list_kernel.Count)
            {
                throw new Exception("list_base must be must at least be of size of list_kernel");
            }

            int offset = list_kernel.Count - 1;
            int lenght = list_base.Count - (list_kernel.Count - 1);

            return(ConvolveUniform(algebra, list_base, list_kernel, false, offset, lenght));
        }
 public static RealType[] QuantileSorted <RealType>(
     IAlgebraReal <RealType> algebra,
     IList <RealType> list_sorted,
     float[] quantiles)
 {
     //TODO this can be done much faster
     RealType[] values = new RealType[quantiles.Length];
     for (int index = 0; index < quantiles.Length; index++)
     {
         values[index] = QuantileSorted(algebra, list_sorted, quantiles[index]);
     }
     return(values);
 }
 public static RealType[] SubtractElements <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> list_0, IList <RealType> list_1)
 {
     if (list_0.Count != list_1.Count)
     {
         throw new Exception("Size mismatch: " + list_0.Count + " does not match with " + list_1.Count);
     }
     RealType[] result = new RealType[list_0.Count];
     Parallel.For(0, result.Length, index =>
     {
         result[index] = algebra.Subtract(list_0[index], list_1[index]);
     });
     return(result);
 }
 public static RealType[] AbsoluteDifference <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> list_0, IList <RealType> list_1)
 {
     if (list_0.Count != list_1.Count)
     {
         throw new Exception("Sizes do not match");
     }
     RealType[] result = new RealType[list_0.Count];
     Parallel.For(0, result.Length, index =>
     {
         result[index] = algebra.Abs(algebra.Subtract(list_0[index], list_1[index]));
     });
     return(result);
 }
 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 int MaxIndex <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> array)
        {
            int      max_index = 0;
            RealType max_value = array[0];

            for (int index = 1; index < array.Count; index++)
            {
                if (algebra.CompareTo(array[index], max_value) == 1)
                {
                    max_index = index;
                    max_value = array[index];
                }
            }
            return(max_index);
        }
Exemple #7
0
        /// <summary>
        /// Protected method which constructs a new KDNode.
        /// </summary>
        /// <param name="dimension_count">The number of dimensions for this node (all the same in the tree).</param>
        /// <param name="d_bucket_capacity">The initial capacity of the bucket.</param>
        protected KDNode(IAlgebraReal <DomainType> algebra, int dimension_count, int d_bucket_capacity)
        {
            // Algebra
            this.d_algebra = algebra;

            // Variables.
            this.d_dimension_count = dimension_count;
            this.d_bucket_capacity = d_bucket_capacity;
            this.Size         = 0;
            this.bSinglePoint = true;

            // Setup leaf elements.
            this.d_points = new DomainType[d_bucket_capacity + 1][];
            this.d_values = new LabelType[d_bucket_capacity + 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));
     }
 }
Exemple #9
0
        public Tuple <EdgeValueType[], EdgeValueType> CreateAlphaPartitionTreeElementArray <ElementValueType, EdgeValueType>(
            IAlgebraReal <EdgeValueType> algebra,
            IFunctionDissimilarity <ElementValueType, EdgeValueType> edge_function,
            ElementValueType[] element_values)
        {
            int element_count = ElementCount;

            EdgeValueType[] new_image = new EdgeValueType[element_count];
            EdgeValueType   max_value = algebra.MinValue;

            // do x edges
            for (int element_index = d_x_edge_offset; element_index < d_y_edge_offset; element_index++)
            {
                if (element_index % raster_size[0] != raster_size[0] - 1)
                {
                    new_image[element_index] = edge_function.Compute(
                        element_values[element_index - d_x_edge_offset],
                        element_values[element_index - d_x_edge_offset + 1]);
                    max_value = algebra.Max(max_value, new_image[element_index]);
                }
            }

            // do y edges
            for (int element_index = d_y_edge_offset; element_index < (element_count - raster_size[0]); element_index++)
            {
                new_image[element_index] = edge_function.Compute(
                    element_values[element_index - d_y_edge_offset],
                    element_values[element_index - d_y_edge_offset + raster_size[0]]);
                max_value = algebra.Max(max_value, new_image[element_index]);
            }

            // set node values
            for (int element_index = 0; element_index < d_x_edge_offset; element_index++)
            {
                new_image[element_index] = max_value;
            }

            // flip all edges
            for (int element_index = d_x_edge_offset; element_index < element_count; element_index++)
            {
                new_image[element_index] = algebra.Subtract(max_value, new_image[element_index]);
            }

            return(new Tuple <EdgeValueType[], EdgeValueType>(new_image, max_value));
        }
        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 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));
            }
        }
Exemple #12
0
        public ARendererImageSpace3DFloatProjection(
            IFunction <float, Color> converter,
            int[] resolution,
            float[] render_origen,
            float [] render_stride_x,
            float [] render_stride_y,
            float [] render_stride_z)
        {
            this.converter = converter;
            this.comparer  = new ComparerNatural <float>();
            this.algebra   = new AlgebraRealFloat32();

            this.resolution         = resolution;
            this.coordinates_origen = render_origen;

            this.render_stride_x = render_stride_x;
            this.render_stride_y = render_stride_y;
            this.render_stride_z = render_stride_z;
        }
        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 RendererImageSpace3DFloatZMIP(IFunction <float, Color> converter,
                                             int resolution_x, int resolution_y, int resolution_z, float[] render_origen, float render_stride_x, float render_stride_y, float render_stride_z)
        {
            this.converter = converter;
            this.comparer  = new ComparerNatural <float>();
            this.algebra   = new AlgebraRealFloat32();

            this.resolution_x = resolution_x;
            this.resolution_y = resolution_y;
            this.resolution_z = resolution_z;

            this.render_origen = render_origen;

            this.render_stride_x    = new float[3];
            this.render_stride_y    = new float[3];
            this.render_stride_z    = new float[3];
            this.render_stride_x[0] = render_stride_x;
            this.render_stride_y[1] = render_stride_y;
            this.render_stride_z[2] = render_stride_z;
        }
        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);
        }
Exemple #16
0
 /// <summary>
 /// Create a new KD-Tree given a number of dimensions and initial bucket capacity.
 /// </summary>
 /// <param name="dimension_count">The number of data sorting dimensions. i.e. 3 for a 3D point.</param>
 /// <param name="bucket_capacity">The default number of items that can be stored in each node.</param>
 public KDTree(IAlgebraReal <DomainType> algebra, int dimension_count, int bucket_capacity)
     : base(algebra, dimension_count, bucket_capacity)
 {
     this.algebra   = algebra;
     DimensionCount = dimension_count;
 }
 public ConvoluterGenericStepCorrectedUnoffsetted(IAlgebraReal <RealType> algebra, RealType sample_time)
 {
     this.algebra     = algebra;
     this.sample_time = sample_time;
 }
Exemple #18
0
 public AlphaPartitionTreeMinTree(IAlgebraReal <EdgeValueType> algebra, IMaxTree <EdgeValueType> min_tree, EdgeValueType max_edge_value)
 {
     this.algebra        = algebra;
     this.min_tree       = min_tree;
     this.max_edge_value = max_edge_value;
 }
 public static RealType[] DivideElements <RealType>(IAlgebraReal <RealType> algebra, IList <RealType> divided, RealType divisor)
 {
     RealType[] result = new RealType[divided.Count];
     DivideElementsRBA(algebra, divided, divisor, result);
     return(result);
 }
 //should be analogeus to matlab interp1 with method 'linear'
 public static RealType[] Resample <RealType>(IAlgebraReal <RealType> algebra, RealType[] old_sample_times, RealType[] old_values, RealType[] new_sample_times)
 {
     RealType[] new_values = new RealType[new_sample_times.Length];
     ResampleRBA(algebra, old_sample_times, old_values, new_sample_times, new_values);
     return(new_values);
 }
Exemple #21
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)));
        }
 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 #23
0
 public FilterAlfaPartitionMean(IAlgebraReal <ElementType> algebra)
 {
     this.algebra = algebra;
 }
 public AlphaPartitionTreeBuilderMinTree(IAlgebraReal <EdgeValueType> algebra, IMaxTreeBuilder <EdgeValueType> builder)
 {
     this.builder = builder;
     this.algebra = algebra;
 }
 public FunctionWeigthed(IAlgebraReal <RealType> algebra, IList <IFunction <DomainType, RealType> > basis_function_list, IList <RealType> weight_list)
 {
     this.algebra             = algebra;
     this.basis_function_list = basis_function_list;
     this.weight_list         = weight_list;
 }
Exemple #26
0
 public FilterWindow(IAlgebraReal <RealType> algebra, IFilterWindow <RealType> window)
 {
     this.algebra = algebra;
     this.window  = window;
     //d_time_offset_limit = this.algebra.FloorInt(window.HalfWindowWidth);
 }
Exemple #27
0
 /// <summary>
 /// Create a new KD-Tree given a number of dimensions.
 /// </summary>
 /// <param name="dimension_count">The number of data sorting dimensions. i.e. 3 for a 3D point.</param>
 public KDTree(IAlgebraReal <DomainType> algebra, int dimension_count)
     : this(algebra, dimension_count, 24)
 {
 }
 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 MaxTreeFilterMean(IFunction <IMaxTreeNode <ElementType>, bool> filter_function, IAlgebraReal <ElementType> algebra, ElementType[] source_values)
 {
     this.filter_function = filter_function;
     this.source_values   = source_values;
     this.algebra         = algebra;
 }
 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)));
 }