Skip to content
mikerabat edited this page Sep 27, 2023 · 2 revisions

Higher matrix functions

All the functions that do not do any simple matrix functions are listed here e.g. Sorting and such.

Sorting a matrix

The matrix sorting is based on a simple QuickSort algorithm. In addition there exists a multithreaded version which is applied on the rows - for each row a thread.

   procedure SortInPlace(RowWise : boolean); virtual;
   function Sort(RowWise : boolean) : TDoubleMatrix;

The parameter rowwise defines if rows (true) or columns are sorted. The resulting matrix dimension is the same as the input matrix.

Median function

Calculation of the Median value of either the row or column. The threaded version utilizes threads for each column/row.

There is also a "rolling" Median implemented that does a median filtered version of the matrix (row or column wise) with a given order. The resulting matrix has the same size as the input matrix. The element i,j in the resulting matrix is the median(i - order:i, j).

   function Median(RowWise : boolean) : TDoubleMatrix; virtual;
   procedure MedianInPlace(RowWise : boolean);

   function RollMedian(RowWise : boolean; order : integer) : TDoubleMatrix;
   procedure RollMedianInPlace(RowWise : boolean; order : integer); virtual;

The resulting matrix is either (width x height) 1xheight for RowWise=False; width x 1 for RowWise=True

Sum, Cumulative sum and differentiation

There are a few functions to calculate the row/column sum, the cumulative sum and simple differentiation.

   function Diff(RowWise : boolean) : TDoubleMatrix;
   procedure DiffInPlace(RowWise : boolean);
   function Sum(RowWise : boolean) : TDoubleMatrix;
   procedure SumInPlace(RowWise : boolean); overload;
   procedure SumInPlace(RowWise : boolean; keepMemory : boolean); overload;
   function CumulativeSum(RowWise : boolean) : TDoubleMatrix;
   procedure CumulativeSumInPlace(RowWise : boolean);

Output size for the Cumulative Sum is the same as the input matrix. The output of the Sum functions is a vector (1 x height or width x 1 depending on the direction paramter) The output of the differention operator is the same as the input matrix minus one in the sorting direction (e.g.: width - 1 x height rowWise = True)

Variance and Mean

Calculation of the mean and variance is based on the 2 sweep standard calculation scheme: first calculate the mean then apply the variance calculation. The unbiased parameter steers if the variance is normalized either by n (biased) or n - 1 (unbiased). In addition the matrix is treaded as a set of vectors on which the variance and mean is calculated.

   function Mean(RowWise : boolean) : TDoubleMatrix;
   procedure MeanInPlace(RowWise : boolean);
   function Variance(RowWise : boolean; unbiased : boolean = True) : TDoubleMatrix;
   procedure VarianceInPlace(RowWise : boolean; unbiased : boolean = True);
   function Std(RowWise : boolean; unbiased : boolean = True) : TDoubleMatrix;
   procedure StdInPlace(RowWise : boolean; unbiased : boolean = True);

   function MeanVariance(RowWise : boolean; unbiased : boolean = True) : TDoubleMatrix;
   procedure MeanVarianceInPlace(RowWise : boolean; unbiased : boolean = True);

The resulting matrix is either a vector based on the direction parameter.

Simultaneous Mean and variance calculation create a matrix of 2 x height, rowwise=False; width x 2, rowwise=True.

Clone this wiki locally