|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.knowceans.util.Vectors
public class Vectors
Static vector manipulation routines for Matlab porting and other numeric operations. The routines work for int and double partly; the class is extended as needed.
TODO: The question remains whether it makes sense to have a formal IntVector, analoguous to IntMatrix that allows performing search and indexing operations, such as views, etc.
Constructor Summary | |
---|---|
Vectors()
|
Method Summary | ||
---|---|---|
static void |
add(double[][] mat,
double scalar)
add a scalar to the matrix |
|
static void |
add(double[] vec,
double scalar)
add a scalar to the vector |
|
static void |
add(double[] a,
double[] b)
a+=b |
|
static void |
add(double[] a,
int[] b)
a+=b |
|
static double[] |
add(int[] vec,
double scalar)
add a scalar to the vector. |
|
static void |
add(int[] vec,
int scalar)
add a scalar to the vector |
|
static void |
add(int[] a,
int[] b)
a+=b |
|
static int[] |
cast(double[] vec)
cast a double[] to an int[] |
|
static double[] |
cast(int[] vec)
cast a double[] to an int[] |
|
static double[] |
chooseColumn(double[][] matrix,
int col)
Extract the column from the 2-dim matrix / array (stored row-wise in Java) |
|
static double[][] |
chooseElements(double[][] matrix,
int[] rows,
int[] cols)
Create a matrix that contains the rows and columns of the argument matrix in the order given by rows and cols |
|
static double[] |
chooseElements(double[] vector,
int[] keep)
Create vector that contains the elements of the argument in the order as given by keep |
|
static int[][] |
chooseElements(int[][] matrix,
int[] rows)
Create a matrix that contains the rows of the argument matrix in the order given by rows. |
|
static int[][] |
chooseElements(int[][] matrix,
int[] rows,
int[] cols)
Create a matrix that contains the rows and columns of the argument matrix in the order given by rows and cols |
|
static int[] |
chooseElements(int[] vector,
int[] keep)
Create vector that contains the elements of the argument in the order as given by keep |
|
static double[][] |
concat(double[][] x,
double[][] y,
boolean rowwise)
|
|
static double[][] |
concat(double[][] x,
double[] y,
boolean rowwise)
|
|
static double[] |
concat(double[] x,
double[] y)
|
|
static double[] |
concat(double[] x,
double[] y,
double[] z)
w = [x y z] |
|
static int[][] |
concat(int[][] x,
int[][] y,
boolean rowwise)
|
|
static int[] |
concat(int[] x,
int[] y)
|
|
static double[] |
copy(double[] source)
copies a the source to the destination |
|
static void |
copy(double[] source,
double[] dest)
copy source to dest (no generics to keep performant) |
|
static void |
copy(double[] source,
int[] dest)
copy source to dest (no generics to keep performant) |
|
static float[] |
copy(float[] source)
|
|
static int[] |
copy(int[] source)
copies a the source to the destination |
|
static void |
copy(int[] source,
double[] dest)
copy source to dest (no generics to keep performant) |
|
static void |
copy(int[] source,
int[] dest)
copy source to dest (no generics to keep performant) |
|
static java.lang.Object |
copy(java.lang.Object source)
copies the vector of int or double |
|
static double[] |
copyDouble(int[] source)
copies a the source to the destination |
|
static double[] |
cumsum(double[] vec)
cumulative sum of the elements, starting at element 0. |
|
static float[] |
cumsum(float[] vec)
|
|
static void |
dotmult(double[] a,
double[] b)
a *= b |
|
static int[] |
find(int[] vec,
int val)
find indices with val |
|
static double[] |
getColumn(double[][] matrix,
int col)
get the column of the matrix |
|
static int[] |
getColumn(int[][] matrix,
int col)
get the column of the matrix |
|
static int[] |
getFormat()
Get the format settings for doubles. |
|
static double[][] |
increaseSize(double[][] matrix,
int morerows,
int morecols)
Create new matrix of larger size and data of the argument. |
|
static double[] |
increaseSize(double[] vector,
int moreelements)
Create new vector of larger size and data of the argument. |
|
static int[][] |
increaseSize(int[][] matrix,
int morerows,
int morecols)
Create new matrix of larger size and data of the argument. |
|
static int[] |
increaseSize(int[] vector,
int moreelements)
Create new vector of larger size and data of the argument. |
|
static boolean |
isDegenerate(double alpha)
check if argument is nan or infinity |
|
static boolean |
isDegenerate(double[] ds)
check if argument contains nan or infinity |
|
static boolean |
isDegenerate(double[][] pp)
check if argument contains nan or infinity |
|
static boolean |
isEqual(int[] a,
int[] b)
checks equality |
|
static boolean |
isNegative(double[] ds)
check if argument contains positive |
|
static boolean |
isNegative(double[][] pp)
check if argument positive |
|
static boolean |
isNegative(int[] ds)
check if argument contains positive |
|
static boolean |
isNegative(int[][] pp)
check if argument positive |
|
static
|
isNegative(T ds)
|
|
static boolean |
isPositive(double[] ds)
check if argument contains positive |
|
static boolean |
isPositive(double[][] pp)
check if argument positive |
|
static boolean |
isPositive(int[] ds)
check if argument contains positive |
|
static boolean |
isPositive(int[][] pp)
check if argument positive |
|
static
|
isPositive(T ds)
|
|
static double |
max(double[] vec)
maximum value in vec |
|
static double |
max(float[] vec)
|
|
static int |
max(int[] vec)
maximum value in vec |
|
static double |
min(double[] vec)
minimum value in vec |
|
static float |
min(float[] vec)
|
|
static int |
min(int[] vec)
minimum value in vec |
|
static void |
mult(double[] ds,
double d)
multiplicates the vector with a scalar. |
|
static double |
mult(double[] ds,
double[] dt)
multiplicates the vector with a vector (inner product). |
|
static int[] |
ones(int len)
|
|
static double[] |
ones(int len,
double factor)
|
|
static int[] |
ones(int len,
int factor)
|
|
static java.lang.String |
print(double[] x)
prints a double representation of the vector. |
|
static java.lang.String |
print(double[][] x)
prints a double representation of an array. |
|
static java.lang.String |
print(float[] x)
|
|
static java.lang.String |
print(float[][] x)
|
|
static java.lang.String |
print(int[] x)
prints a double representation of the vector. |
|
static java.lang.String |
print(int[][] x)
prints a double representation of an array. |
|
static java.lang.String |
print(int[][] x,
java.lang.String delim)
prints a double representation of an array. |
|
static java.lang.String |
print(java.lang.Object x)
|
|
static java.lang.String |
print(java.lang.Object[] x)
Print the array of objects via their toString() methods. |
|
static java.lang.String |
print(java.lang.Object[] x,
java.lang.String delim)
Print the array of objects via their toString() methods, using the delimiter. |
|
static
|
printf(T x,
java.lang.String format,
java.lang.String delim)
Print the double array of objects via their toString() methods, using the delimiter. |
|
static double |
product(double[] vec)
product of the values in vec |
|
static double[] |
range(double start,
double end)
|
|
static double[] |
range(double start,
double end,
double step)
create sequence [start : step : end] of double values. |
|
static int[] |
range(int start,
int end)
|
|
static int[] |
range(int start,
int end,
int step)
|
|
static int[] |
rangeComplement(int[] set,
int length)
return the complement of the sorted subset of the set 0:length-1 in Matlab notation |
|
static double[] |
removeElement(double[] vector,
int element)
Create new vector with data of the argument and removed element. |
|
static int[] |
removeElement(int[] vector,
int element)
Create new vector with data of the argument and removed element. |
|
static double[][] |
removeElements(double[][] matrix,
int[] rows,
int[] cols)
Create new matrix with data of the argument and removed rows and columns. |
|
static double[] |
removeElements(double[] vector,
int[] elements)
Create new vector with data of the argument and removed elements. |
|
static int[][] |
removeElements(int[][] matrix,
int[] rows,
int[] cols)
Create new matrix with data of the argument and removed rows and columns. |
|
static int[] |
removeElements(int[] vector,
int[] elements)
Create new vector with data of the argument and removed elements. |
|
static double[][] |
repmat(double[][] a,
int rows,
int cols)
create matroid with matrix a as element repeated for rows and cols |
|
static int[][] |
repmat(int[][] a,
int rows,
int cols)
create matroid with matrix a as element repeated for rows and cols |
|
static int[] |
round(double[] x)
rounds vector and converts to integer |
|
static int[][] |
round(double[][] x)
rounds matrix and converts to integer |
|
static int[] |
round(float[] x)
|
|
static int[][] |
round(float[][] x)
|
|
static void |
setFormat(int colwidth,
int ndigits)
Set the format of the following double print calls to the column width and number of digits. |
|
static void |
setSubVector(int[] vec,
int[] indices,
int replacement)
set the elements of vec at indices with the replacement. |
|
static void |
setSubVector(int[] vec,
int[] indices,
int[] replacements)
set the elements of vec at indices with the respective replacements. |
|
static int[] |
setSubVectorCopy(int[] vec,
int[] indices,
int[] replacements)
set the elements of a copy of vec at indices with the respective replacements. |
|
static double |
sqabs(double[] a)
squared absolute value of vector |
|
static double |
sqdist(double[] a,
double[] b)
squared euclidean distance between vectors. |
|
static double[] |
sub(double[] vec,
int start,
int length)
|
|
static int[] |
sub(int[] vec,
int start,
int length)
|
|
static void |
subtract(double[] a,
double[] b)
a-=b |
|
static void |
subtract(double[] a,
int[] b)
a-=b |
|
static void |
subtract(int[] a,
double[] b)
a-=b |
|
static void |
subtract(int[] a,
int[] b)
a-=b |
|
static double[] |
subVector(double[] vec,
int[] indices)
returns a copy of the vector elements with the given indices in the original vector. |
|
static double[] |
subVector(double[] vec,
int start,
int end)
|
|
static int[] |
subVector(int[] vec,
int[] indices)
returns a copy of the vector elements with the given indices in the original vector. |
|
static double |
sum(double[] vec)
sum the elements of vec |
|
static double |
sum(float[] vec)
sum the elements of vec |
|
static int |
sum(int[] vec)
sum the elements of vec |
|
static double[][] |
transpose(double[][] mat)
transpose the matrix |
|
static int[][] |
transpose(int[][] mat)
transpose the matrix |
|
static void |
unsetFormat()
Unset the format settings for doubles. |
|
static double[] |
zeros(int len)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Vectors()
Method Detail |
---|
public static final void setFormat(int colwidth, int ndigits)
colwidth
- ndigits
- public static final int[] getFormat()
public static final void unsetFormat()
public static int[] range(int start, int end, int step)
start
- end
- step
-
public static int[] range(int start, int end)
start
- end
-
public static double[] range(double start, double end, double step)
start
- double value of start, if integer, use "1.0" notation.end
- double value of end, if integer, use "1.0" notation.step
- double value of step size
public static double[] range(double start, double end)
start
- end
-
public static double sum(double[] vec)
vec
-
public static double product(double[] vec)
vec
-
public static double sum(float[] vec)
vec
-
public static int sum(int[] vec)
vec
-
public static double[] cumsum(double[] vec)
vec
-
public static float[] cumsum(float[] vec)
public static int max(int[] vec)
vec
-
public static double max(double[] vec)
vec
-
public static double max(float[] vec)
public static int min(int[] vec)
vec
-
public static double min(double[] vec)
vec
-
public static float min(float[] vec)
public static int[][] round(double[][] x)
x
-
public static int[][] round(float[][] x)
public static int[] round(double[] x)
x
-
public static int[] round(float[] x)
public static double[] concat(double[] x, double[] y)
x
- y
-
public static int[] concat(int[] x, int[] y)
x
- y
-
public static double[][] concat(double[][] x, double[] y, boolean rowwise)
x
- y
- rowwise
- ? [x; y] : [x, y]
public static double[][] concat(double[][] x, double[][] y, boolean rowwise)
x
- y
- rowwise
- ? [x; y] : [x, y]
public static int[][] concat(int[][] x, int[][] y, boolean rowwise)
x
- y
- rowwise
- ? [x; y] : [x, y]
public static double[][] repmat(double[][] a, int rows, int cols)
a
- rows
- cols
-
public static int[][] repmat(int[][] a, int rows, int cols)
a
- rows
- cols
-
public static double[] concat(double[] x, double[] y, double[] z)
x
- y
-
public static double[] increaseSize(double[] vector, int moreelements)
vector
- source arraymoreelements
- number of elements to add
public static double[][] increaseSize(double[][] matrix, int morerows, int morecols)
matrix
- more
- rowsmore
- cols
public static double[] removeElement(double[] vector, int element)
vector
- element
-
public static double[][] removeElements(double[][] matrix, int[] rows, int[] cols)
matrix
- rows
- ordered vector of rows to removecols
- ordered vector of cols to remove
public static double[] removeElements(double[] vector, int[] elements)
vector
- elements
- ordered elements to remove
public static int[] rangeComplement(int[] set, int length)
set
- sorted set of elements < lengthlength
- of superset of set and its returned complement
public static int[] getColumn(int[][] matrix, int col)
public static double[] getColumn(double[][] matrix, int col)
public static double[][] chooseElements(double[][] matrix, int[] rows, int[] cols)
matrix
- rows
- cols
-
public static double[] chooseElements(double[] vector, int[] keep)
vector
- keep
-
public static double[] chooseColumn(double[][] matrix, int col)
matrix
- col
- column number to choose (must exist in each row of the matrix)
public static int[] increaseSize(int[] vector, int moreelements)
vector
- source arraymoreelements
- number of elements to add
public static int[][] increaseSize(int[][] matrix, int morerows, int morecols)
matrix
- more
- rowsmore
- cols
public static int[] removeElement(int[] vector, int element)
vector
- element
-
public static int[][] removeElements(int[][] matrix, int[] rows, int[] cols)
matrix
- rows
- ordered vector of rows to removecols
- ordered vector of cols to remove
public static int[] removeElements(int[] vector, int[] elements)
vector
- elements
- ordered elements to remove
public static int[][] chooseElements(int[][] matrix, int[] rows, int[] cols)
matrix
- rows
- cols
-
public static int[][] chooseElements(int[][] matrix, int[] rows)
matrix
- rows
-
public static int[] chooseElements(int[] vector, int[] keep)
vector
- keep
-
public static java.lang.String print(double[] x)
x
-
public static java.lang.String print(float[] x)
public static java.lang.String print(java.lang.Object x)
public static java.lang.String print(java.lang.Object[] x)
x
-
public static java.lang.String print(java.lang.Object[] x, java.lang.String delim)
x
- delim
-
public static <T> java.lang.String printf(T x, java.lang.String format, java.lang.String delim)
x
- delim
-
public static java.lang.String print(double[][] x)
x
-
public static java.lang.String print(float[][] x)
public static java.lang.String print(int[] x)
x
-
public static java.lang.String print(int[][] x)
x
-
public static java.lang.String print(int[][] x, java.lang.String delim)
x
-
public static double[] ones(int len, double factor)
len
- factor
-
public static int[] ones(int len, int factor)
len
- factor
-
public static double[] zeros(int len)
len
-
public static int[] ones(int len)
len
-
public static int[] cast(double[] vec)
vec
-
public static double[] cast(int[] vec)
vec
-
public static int[] find(int[] vec, int val)
vec
- val
-
public static double[] subVector(double[] vec, int[] indices)
indices
-
public static int[] subVector(int[] vec, int[] indices)
cols
-
public static double[] subVector(double[] vec, int start, int end)
weights
- i
- j
-
public static double[] sub(double[] vec, int start, int length)
weights
- i
- j
-
public static int[] sub(int[] vec, int start, int length)
weights
- i
- j
-
public static void setSubVector(int[] vec, int[] indices, int[] replacements)
vec
- indices
- replacements
- public static void setSubVector(int[] vec, int[] indices, int replacement)
vec
- indices
- replacement
- public static void add(int[] vec, int scalar)
vec
- scalar
- public static double[] add(int[] vec, double scalar)
vec
- scalar
- public static void add(double[][] mat, double scalar)
vec
- scalar
- public static void add(double[] vec, double scalar)
vec
- scalar
- public static void add(double[] a, int[] b)
a
- b
- public static void add(double[] a, double[] b)
a
- b
- public static void add(int[] a, int[] b)
a
- b
- public static void subtract(int[] a, int[] b)
a
- b
- public static void subtract(double[] a, int[] b)
a
- b
- public static void subtract(int[] a, double[] b)
a
- b
- public static void subtract(double[] a, double[] b)
a
- b
- public static double sqdist(double[] a, double[] b)
a
- b
-
public static double sqabs(double[] a)
a
-
public static int[] setSubVectorCopy(int[] vec, int[] indices, int[] replacements)
vec
- indices
- replacements
-
public static java.lang.Object copy(java.lang.Object source)
source
-
public static double[] copy(double[] source)
alpha
-
public static float[] copy(float[] source)
public static int[] copy(int[] source)
alpha
-
public static double[] copyDouble(int[] source)
alpha
-
public static void copy(int[] source, double[] dest)
source
- dest
- public static void copy(double[] source, int[] dest)
source
- dest
- public static void copy(int[] source, int[] dest)
source
- dest
- public static void copy(double[] source, double[] dest)
source
- dest
- public static void mult(double[] ds, double d)
ds
- d
- public static void dotmult(double[] a, double[] b)
a
- scalar
- public static double mult(double[] ds, double[] dt)
ds
- d
-
public static double[][] transpose(double[][] mat)
mat
-
public static int[][] transpose(int[][] mat)
mat
-
public static boolean isDegenerate(double alpha)
alpha
-
public static boolean isDegenerate(double[] ds)
pp
-
public static boolean isDegenerate(double[][] pp)
pp
-
public static <T> boolean isPositive(T ds)
public static boolean isPositive(double[] ds)
pp
-
public static boolean isPositive(double[][] pp)
pp
-
public static <T> boolean isNegative(T ds)
public static boolean isNegative(double[] ds)
pp
-
public static boolean isNegative(double[][] pp)
pp
-
public static boolean isPositive(int[] ds)
pp
-
public static boolean isPositive(int[][] pp)
pp
-
public static boolean isNegative(int[] ds)
pp
-
public static boolean isNegative(int[][] pp)
pp
-
public static boolean isEqual(int[] a, int[] b)
a
- b
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |