|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jstatcom.util.UMatrix
public final class UMatrix
A collection of static methods that are related to arrays of numbers. This set of methods contains mainly general array manipulation routines as well as some light-weight mathematical functions.
All methods implemented do not modify the original input. Results are always newly created arrays. If the input is somehow wrong an appropriate exception is thrown. All methods require that the input arrays have the same number of elements in each row.
| Method Summary | |
|---|---|
static double[][] |
add(double[][] arg,
double toAdd)
Adds the scalar toAdd to a copy of the array
arg. |
static double[][] |
appendDoubleCols(double[][] orig,
double[][] toAppend)
Appends toAppend to the columns of orig and
returns the new merged array. |
static double[][] |
appendDoubleRows(double[][] orig,
double[][] toAppend)
Appends toAppend to the rows of orig and
returns the new merged array. |
static void |
checkRowLengths(double[][] arg)
Checks whether all rows of arg have the same number of
columns. |
static void |
checkRowLengths(int[][] arg)
Checks whether all rows of arg have the same number of
columns. |
static double[][] |
cloneDoubleArray(double[][] x)
Gets an identical copy of x. |
static int[][] |
cloneIntArray(int[][] x)
Gets an identical copy of x. |
static boolean |
compareDoubleArrays(double[][] arg1,
double[][] arg2)
Compares two double arrays and returns true. if the
dimensions are the same and all elements are equal. |
static boolean |
compareIntArrays(int[][] arg1,
int[][] arg2)
Compares two int arrays and returns true. if the
dimensions are the same and all elements are equal. |
static double[] |
conv(double[] x,
double[] z,
int start,
int end)
Computes the discrete convolution function for the vectors x
and z from start to end. |
static double[][] |
delCol(double[][] arg,
int colIndex)
Deletes the col colIndex from arg. |
static double[][] |
delColsIf(double[][] arg,
int... index)
Deletes columns of arg that have been selected by
index and returns a new array with the remaining columns. |
static double[][] |
delRow(double[][] arg,
int rowIndex)
Deletes the row rowIndex from arg. |
static double[][] |
delRowsIf(double[][] arg,
int... index)
Deletes rows of arg that have been selected by
index and returns a new array with the remaining rows. |
static double[][] |
eye(int dim)
Gets an identity matrix of dimension dim. |
static int[] |
flipIndex(int... arg)
Gets a new array with all zero elements of arg set to one
and all nonzero elements set to zero. |
static java.lang.String |
format(double[][] arg)
Gets a string that contains a printed version of arg. |
static double[] |
fracdiff(double[] y,
double d)
Implementation of the fractional difference operator, see J. |
static double[] |
getDoubleCol(double[][] arg,
int colIndex)
Gets the column of the array arg specified with
colIndex. |
static double[][] |
getDoubleCols(double[][] arg,
int startCol,
int endCol)
Gets all columns of the array arg defined by
startCol:endCol. |
static double[] |
getDoubleRow(double[][] arg,
int rowIndex)
Gets the row of the array arg specified with
rowIndex. |
static double[][] |
getDoubleRows(double[][] arg,
int startRow,
int endRow)
Gets all rows of the array arg defined by
startRow:endRow. |
static int |
getFirstNonzeroIndex(double[] arg)
Gets the index of the first nonzero element in arg. |
static int |
getLastNonzeroIndex(double[] arg)
Gets the index of the last nonzero element in arg. |
static int |
getNonzeroDoubleCount(double[] arg)
Gets the number of nonzero elements in arg. |
static int |
getNonzeroIntCount(int[] arg)
Gets the number of nonzero elements in arg. |
static double[][] |
lowerTringular(double value,
int dim)
Gets a quadratic double array of dimension dim with all
elements on and below the diagonal set to value. |
static double[] |
maxc(double[][] arg)
Gets a vector with the maxima of all columns of arg. |
static double[] |
meanc(double[][] arg)
Gets a vector with the mean of all columns of arg. |
static double[] |
minc(double[][] arg)
Gets a vector with the minima of all columns of arg. |
static double[][] |
missings(int r,
int c)
Gets a double array filled with NaN's. |
static double[][] |
multiply(double[][] arg,
double toMult)
Multiplies the scalar toMult with a copy of the array
arg. |
static double[][] |
ones(int r,
int c)
Gets a double array filled with 1's. |
static double[][] |
pow(double[][] arg,
double power)
Applies Math.pow(arg[i][j], power) to all elements of
arg. |
static int |
rank(double[][] arg)
Get the rank of arg. |
static double[][] |
rndu(int r,
int c)
Gets a double array filled with random numbers generated by Math.random(). |
static double[][] |
selColsIf(double[][] arg,
int... index)
Gets all columns of the array arg that have a nonzero
corresponding element in index. |
static double[][] |
selRowsIf(double[][] arg,
int... index)
Gets all rows of the array arg that have a nonzero
corresponding element in index. |
static double[] |
seqa(double start,
double increment,
int n)
Gets an array with the sequence of numbers starting from start being n - 1 times incremented by
increment. |
static double[][] |
standardize(double[][] arg)
Gets a new array with the elements of arg divided by the
standard devitation of the respective columns of arg. |
static double[] |
stdc(double[][] arg)
Gets a vector with the standard deviations of all columns of arg. |
static double[] |
sumc(double[][] arg)
Gets a vector with the sum of all elements in the single columns of arg. |
static double[][] |
toDoubleMatrix(double[] arg)
Transforms a one-dimensional array into a K x 1 pseudo-two-dimensional array. |
static double[][] |
toDoubleMatrix(int[] arg)
Transforms a one-dimensional array into a K x 1 pseudo-two-dimensional array. |
static double[][] |
toDoubleMatrix(int[][] arg)
Transforms an int array into a double
array. |
static int[][] |
toIntMatrix(double[][] arg)
Transforms arg into an int array by applying a cast to int
from double to each element of arg. |
static double[][] |
transpose(double[][] arg)
Gets a new array which is the transpose arg, which means
that all columns of arg are now the rows of the new array. |
static double[] |
vec(double[][] arg)
Get a one dimensional array with to columns of arg stacked
into it. |
static int[] |
vec(int[][] arg)
Get a one dimensional array with to columns of arg stacked
into it. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static double[][] add(double[][] arg,
double toAdd)
toAdd to a copy of the array
arg.
arg - the original arraytoAdd - the number to add to all elements of arg
toAdd added; if
toAdd is NaN, then the resulting
array will contain only NaN's
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengths
public static double[][] appendDoubleCols(double[][] orig,
double[][] toAppend)
toAppend to the columns of orig and
returns the new merged array. This only works, if orig and
toAppend have the same number of rows.
orig - the array to append the columns of toAppend totoAppend - the arrays to be appended to orig
java.lang.IllegalArgumentException - if (orig.length != toAppend.length) or
if (orig == null || toAppend == null) or if
rows of an argument have different lengths
public static double[][] appendDoubleRows(double[][] orig,
double[][] toAppend)
toAppend to the rows of orig and
returns the new merged array. This only works, if orig and
toAppend have the same number of columns.
orig - the array to append the rows of toAppend totoAppend - the arrays to be appended to orig
java.lang.IllegalArgumentException - if (orig[0].length != toAppend[0].length) or
if (orig == null || toAppend == null) or if
rows of an argument have different lengthspublic static void checkRowLengths(double[][] arg)
arg have the same number of
columns. If the check fails, an exception is thrown. This is to enforce
the mathematical definition of a matrix.
arg - the double[][] to check
java.lang.IllegalArgumentException - if the rows of arg have different lengthspublic static void checkRowLengths(int[][] arg)
arg have the same number of
columns. If the check fails, an exception is thrown. This is to enforce
the mathematical definition of a matrix.
arg - the int[][] to check
java.lang.IllegalArgumentException - if the rows of arg have different lengthspublic static double[][] cloneDoubleArray(double[][] x)
x.
null if (x == null)
new double[0][0] if (x.length == 0 || x[0].length == 0)
public static int[][] cloneIntArray(int[][] x)
x.
null if (x == null)
new int[0][0] if (x.length == 0 || x[0].length == 0)
public static boolean compareDoubleArrays(double[][] arg1,
double[][] arg2)
true. if the
dimensions are the same and all elements are equal. If two elements of
arg1 and arg2 are Double.NaN,
they are considered to be equal, whereas arg1, arg2 are
considered to be unequal if at least one of them is null.
arg1 - double array to comparearg2 - double array to compare
true if dimensions and all elements are equal or
if arg1, arg2 have both at least one dimension of
zero, false otherwise
java.lang.IllegalArgumentException - if rows of an argument have different lengths
public static boolean compareIntArrays(int[][] arg1,
int[][] arg2)
true. if the
dimensions are the same and all elements are equal.
arg1 - int array to comparearg2 - int array to compare
true if dimensions and all elements are equal or
if arg1, arg2 have both at least one dimension of
zero, false otherwise or if at least one argument is
null
java.lang.IllegalArgumentException - if rows of an argument have different lengths
public static double[][] delCol(double[][] arg,
int colIndex)
colIndex from arg.
arg - the array to delete the col fromcolIndex - index of the col
new double[0][0] if the array would be empty
afterwards
java.lang.IllegalArgumentException - if (arg == null) or
if (colIndex < 0 || arg[0].length < colIndex)
or if (arg.length == 0 || arg[0].length == 0)
or if rows of argument have different lengths
public static double[][] delColsIf(double[][] arg,
int... index)
arg that have been selected by
index and returns a new array with the remaining columns.
A column is selected for deletion if the corresponding index entry is
nonzero.
arg - the array to delete columns fromindex - the arg[0].length x 1 int array
new double[0][0] if all columns where selected for
deletion or if arg.length == 0
java.lang.IllegalArgumentException - if (arg == null || index == null) or
if ((arg.length == 0 || arg[0].length == 0) && index.length > 0)
or if (arg.length == 0 || arg[0].length == 0)
or if rows of argument have different lengths
public static double[][] delRow(double[][] arg,
int rowIndex)
rowIndex from arg.
arg - the array to delete the row fromrowIndex - index of the row
new double[0][0] if the array would be empty
afterwards
java.lang.IllegalArgumentException - if (arg == null) or
if (rowIndex < 0 || arg.length < rowIndex)
or if (arg.length == 0 || arg[0].length == 0)
or if rows of argument have different lengths
public static double[][] delRowsIf(double[][] arg,
int... index)
arg that have been selected by
index and returns a new array with the remaining rows. A
row is selected for deletion if the corresponding index entry is nonzero.
arg - the array to delete rows fromindex - the arg[0].length x 1 int array
new double[0][0] if all rows where selected for
deletion or if arg.length == 0
java.lang.IllegalArgumentException - if (arg == null || index == null) or
if ((arg.length == 0 || arg[0].length == 0) && index.length > 0)
or if (arg.length == 0 || arg[0].length == 0)
or if rows of arg have different lengthspublic static double[][] eye(int dim)
dim.
dim - the dimension of the quadratic matrix to create
java.lang.IllegalArgumentException - if (dim < 0)public static int[] flipIndex(int... arg)
arg set to one
and all nonzero elements set to zero. If arg is a
selection index then this just reverses the selection.
arg - the original index, usually with 1's and 0's, but any values !=
0 are set to 0
new int[0] if
arg.length == 0
java.lang.IllegalArgumentException - if (arg == null)public static java.lang.String format(double[][] arg)
arg.
arg - the array to print
arg
java.lang.IllegalArgumentException - if rows of argument have different lengths
public static double[] getDoubleCol(double[][] arg,
int colIndex)
arg specified with
colIndex. The index starts with 0 as usual.
arg - the array to extract a column fromcolIndex - the index of the column to extract (starting from 0)
java.lang.IllegalArgumentException - if (arg == null) or
if (arg.length == 0) or if the index is
outside the valid array bounds or if rows of argument have
different lengths
public static double[] getDoubleRow(double[][] arg,
int rowIndex)
arg specified with
rowIndex. The index starts with 0 as usual.
arg - the array to extract a row fromrowIndex - the index of the row to extract (starting from 0)
java.lang.IllegalArgumentException - if (arg == null) or
if (arg.length == 0) or if the index is
outside the valid array bounds or if rows of argument have
different lengths
public static double[][] getDoubleCols(double[][] arg,
int startCol,
int endCol)
arg defined by
startCol:endCol. The indices start with 0 as usual.
arg - the array to extract columns fromstartCol - the index of the first column to extract (starting from 0)endCol - the index of the last column to extract (starting from 0)
java.lang.IllegalArgumentException - if (arg == null) or
if (arg.length == 0) or
if (startCol > endCol) or if the indices
are outside the valid array bounds or if rows of argument
have different lengths
public static double[][] getDoubleRows(double[][] arg,
int startRow,
int endRow)
arg defined by
startRow:endRow. The indices start with 0 as usual.
arg - the array to extract rows fromstartRow - the index of the first row to extract (starting from 0)endRow - the index of the last row to extract (starting from 0)
java.lang.IllegalArgumentException - if (arg == null) or
if (arg.length == 0) or
if (startRow > endRow) or if the indices
are outside the valid array bounds or if rows of argument
have different lengthspublic static int getFirstNonzeroIndex(double[] arg)
arg.
arg - the array to check
java.lang.IllegalArgumentException - if (arg == null)public static int getLastNonzeroIndex(double[] arg)
arg.
arg - the array to check
java.lang.IllegalArgumentException - if (arg == null)public static int getNonzeroDoubleCount(double[] arg)
arg.
arg - the array to check
arg that are != 0
java.lang.IllegalArgumentException - if (arg == null)public static int getNonzeroIntCount(int[] arg)
arg.
arg - the array to check, usually an index
arg that are != 0
java.lang.IllegalArgumentException - if (arg == null)
public static double[][] lowerTringular(double value,
int dim)
dim with all
elements on and below the diagonal set to value.
value - the double to store in the lower part of the
arraydim - the dimension of the quadratic array
dim x dim lower triangular array
java.lang.IllegalArgumentException - if (dim < 0),public static double[] maxc(double[][] arg)
arg.
arg - the original array
arg[0].length vector the maxima of
arg, if a column contains Double.NaN
and other double values, then the smallest double value that is
not a Double.NaN is returned
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static double[] meanc(double[][] arg)
arg.
arg - the original array
arg[0].length vector the mean of
arg
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static double[] minc(double[][] arg)
arg.
arg - the original array
arg[0].length vector the minima of
arg, if a column contains Double.NaN
and other double values, then the smallest double value that is
not a Double.NaN is returned
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengths
public static double[][] multiply(double[][] arg,
double toMult)
toMult with a copy of the array
arg.
arg - the original arraytoMult - the number to multiply all elements of arg with
toMult; if
toMult is NaN, then the resulting
array will contain only NaN's
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengths
public static double[][] missings(int r,
int c)
r - rows of array to createc - cols of array to create
r x c double array filled with NaN's or
new double[0][0] if (r == 0 || c == 0)
java.lang.IllegalArgumentException - if (r < 0 || c < 0)
public static double[][] ones(int r,
int c)
r - rows of array to createc - cols of array to create
r x c double array filled with 1's or
new double[0][0] if (r == 0 || c == 0)
java.lang.IllegalArgumentException - if (r < 0 || c < 0)
public static double[][] pow(double[][] arg,
double power)
Math.pow(arg[i][j], power) to all elements of
arg.
arg - the original arraypower - the 2nd argument to be applied with Math.pow()
power
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static int rank(double[][] arg)
arg.
arg - the array to compute the rank from
Jama, 0
if (arg.length == 0 || arg[0].length == 0)
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengths
public static double[][] rndu(int r,
int c)
Math.random(). The random numbers are equally distributed
between 0 and 1.
r - rows of array to createc - cols of array to create
r x c double array filled with
Math.random() or
new double[0][0] if (r == 0 || c == 0)
java.lang.IllegalArgumentException - if (r < 0 || c < 0)
public static double[][] selColsIf(double[][] arg,
int... index)
arg that have a nonzero
corresponding element in index.
arg - the array to extract columns fromindex - arg[0].length x 1 vector selecting columns from
arg
new double[0][0] if index contains only 0's, a
copy of arg if index contains only
nonzero elements
java.lang.IllegalArgumentException - if (arg == null || index == null) or
if ((arg.length == 0 || arg[0].length == 0) && index.length > 0)
or if (arg[0].length != index.length) or if
rows of argument have different lengths
public static double[][] selRowsIf(double[][] arg,
int... index)
arg that have a nonzero
corresponding element in index.
arg - the array to extract rows fromindex - arg.length x 1 vector selecting rows from
arg
new double[0][0]
if index contains only 0's, a copy of arg if
index contains only nonzero elements
java.lang.IllegalArgumentException - if (arg == null || index == null) or
if ((arg.length == 0 || arg[0].length == 0) && index.length > 0)
or if (arg.length != index.length) or if rows
of argument have different lengths
public static double[] seqa(double start,
double increment,
int n)
start being n - 1 times incremented by
increment.
start - the first element of the sequenceincrement - the difference between two successive elements of the sequencen - the number of elements in the sequence
n x 1 double array
java.lang.IllegalArgumentException - if (n < 0), or if
start || increment are either
Double.NaN,
Double.NEGATIVE_INFINITY or
Double.POSITIVE_INFINITY,public static double[][] standardize(double[][] arg)
arg divided by the
standard devitation of the respective columns of arg.
arg - the original array
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static double[] stdc(double[][] arg)
arg. The standard deviation divisor is
arg.length.
arg - the original array
arg[0].length vector the std. dev. of
arg
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static double[] sumc(double[][] arg)
arg.
arg - the original array
arg[0].length vector the column sums of
arg
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static double[][] toDoubleMatrix(int[][] arg)
int array into a double
array. This is sometimes needed to prepare arguments for methods that
take double[][] instead of int[][].
arg - the int array to transform
double array or
null if (arg == null)
new double[0][0] if (arg.length == 0 || arg[0].length == 0)
java.lang.IllegalArgumentException - if rows of argument have different lengthspublic static double[][] toDoubleMatrix(double[] arg)
double[][] instead of double[].
arg - the vector-like array to transform
arg.length x 1
or
null if (arg == null)
new double[0][0] if (arg.length == 0)
public static double[][] toDoubleMatrix(int[] arg)
double[][] instead of int[].
arg - the vector-like array to transform
arg.length x 1
or
null if (arg == null)
new double[0][0] if (arg.length == 0)
public static int[][] toIntMatrix(double[][] arg)
arg into an int array by applying a cast to int
from double to each element of arg. Note that during this
operation information is potentially lost. Only the integer part is
preserved, which is different from rounding. The following special
int values are returned:
value == Double.NaN
Integer.MAX_VALUE if value == Double.POSITIVE_INFINITY
Integer.MIN_VALUE if value == Double.NEGATIVE_INFINITY
arg - the array to transform
null if (arg == null)
new int[0][0] if (g.length == 0 || g[0].length == 0)
java.lang.IllegalArgumentException - if rows of argument have different lengthspublic static double[][] transpose(double[][] arg)
arg, which means
that all columns of arg are now the rows of the new array.
arg - the original array
arg, or
new double[0][0]
if (arg.length == 0 || arg[0].length == 0)
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static double[] vec(double[][] arg)
arg stacked
into it.
arg - the array with data
arg.length * arg[0].length x 1 array with the
columns of arg stacked into a vector
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengthspublic static int[] vec(int[][] arg)
arg stacked
into it.
arg - the array with data
arg.length * arg[0].length x 1 array with the
columns of arg stacked into a vector
java.lang.IllegalArgumentException - if (arg == null) or if rows of argument have
different lengths
public static double[] conv(double[] x,
double[] z,
int start,
int end)
x
and z from start to end.
The function is defined as
(x*z)[m] = sum_n ( x[n]z[m-n] ); m, n start with 0.
x - Nx1 vectorz - Lx1 vectorstart - the first convolution to compute, zero basedend - the last convolution to compute, zero based, max number is
x.length + z.length - 2;end < 0, then max number is used
end - start+ 1), if
end < 0, the start 'th to the last
convolutions are computed
java.lang.IllegalArgumentException - if (x == null || z == null) or
if (x.length == 0 || z.length == 0) or
if (start < 0) or
if (start > end && end >= 0) or
if (end > x.length + z.length - 2)
public static double[] fracdiff(double[] y,
double d)
y - Tx1 time series to be differencesd - order of differencing
java.lang.IllegalArgumentException - if (y == null) or if d equals
Double.NaN
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||