medusa.georgios.enhanced_mcl
Class Vectors
- java.lang.Object
-
- medusa.georgios.enhanced_mcl.Vectors
-
public class Vectors extends java.lang.ObjectStatic 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
Constructors Constructor and Description Vectors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static voidadd(int[] vec, int scalar)add a scalar to the vectorstatic int[]cast(double[] vec)cast a double[] to an int[]static double[]cast(int[] vec)cast a double[] to an int[]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 colsstatic double[]chooseElements(double[] vector, int[] keep)Create vector that contains the elements of the argument in the order as given by keepstatic 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 colsstatic int[]chooseElements(int[] vector, int[] keep)Create vector that contains the elements of the argument in the order as given by keepstatic double[]concat(double[] x, double[] y)static double[]concat(double[] x, double[] y, double[] z)w = [x y z]static double[]copy(double[] source)copies a the source to the destinationstatic int[]copy(int[] source)copies a the source to the destinationstatic double[]cumsum(double[] vec)cumulative sum of the elements, starting at element 0.static int[]find(int[] vec, int val)find indices with valstatic 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 doublemax(double[] vec)maximum value in vecstatic intmax(int[] vec)maximum value in vecstatic doublemin(double[] vec)minimum value in vecstatic intmin(int[] vec)minimum value in vecstatic double[]mult(double[] ds, double d)multiplicates the vector with a scalar.static doublemult(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.Stringprint(double[] x)prints a double representation of the vector.static java.lang.Stringprint(double[][] x)prints a double representation of an array.static java.lang.Stringprint(int[] x)prints a double representation of the vector.static java.lang.Stringprint(int[][] x)prints a double representation of an array.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 notationstatic 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 voidsetSubVector(int[] vec, int[] indices, int replacement)set the elements of vec at indices with the replacement.static voidsetSubVector(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[]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 doublesum(double[] vec)sum the elements of vecstatic intsum(int[] vec)sum the elements of vecstatic double[][]transpose(double[][] mat)transpose the matrixstatic int[][]transpose(int[][] mat)transpose the matrixstatic double[]zeros(int len)
-
-
-
Method Detail
-
range
public static int[] range(int start, int end, int step)- Parameters:
start-end-step-- Returns:
- [start : step : end]
-
range
public static int[] range(int start, int end)- Parameters:
start-end-- Returns:
- [start : end]
-
range
public static double[] range(double start, double end, double step)create sequence [start : step : end] of double values. TODO: check precision.- Parameters:
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- Returns:
-
range
public static double[] range(double start, double end)- Parameters:
start-end-- Returns:
- [start : end]
-
sum
public static double sum(double[] vec)
sum the elements of vec- Parameters:
vec-- Returns:
-
sum
public static int sum(int[] vec)
sum the elements of vec- Parameters:
vec-- Returns:
-
cumsum
public static double[] cumsum(double[] vec)
cumulative sum of the elements, starting at element 0.- Parameters:
vec-- Returns:
- vector containing the cumulative sum of the elements of vec
-
max
public static int max(int[] vec)
maximum value in vec- Parameters:
vec-- Returns:
-
max
public static double max(double[] vec)
maximum value in vec- Parameters:
vec-- Returns:
-
min
public static int min(int[] vec)
minimum value in vec- Parameters:
vec-- Returns:
-
min
public static double min(double[] vec)
minimum value in vec- Parameters:
vec-- Returns:
-
concat
public static double[] concat(double[] x, double[] y)- Parameters:
x-y-- Returns:
- [x y]
-
concat
public static double[] concat(double[] x, double[] y, double[] z)w = [x y z]- Parameters:
x-y-- Returns:
- [x y z]
-
increaseSize
public static double[] increaseSize(double[] vector, int moreelements)Create new vector of larger size and data of the argument.- Parameters:
vector- source arraymoreelements- number of elements to add- Returns:
- larger vector
-
increaseSize
public static double[][] increaseSize(double[][] matrix, int morerows, int morecols)Create new matrix of larger size and data of the argument.- Parameters:
matrix-more- rowsmore- cols- Returns:
- larger matrix
-
removeElement
public static double[] removeElement(double[] vector, int element)Create new vector with data of the argument and removed element.- Parameters:
vector-element-- Returns:
- shorter vector
-
removeElements
public static double[][] removeElements(double[][] matrix, int[] rows, int[] cols)Create new matrix with data of the argument and removed rows and columns.- Parameters:
matrix-rows- ordered vector of rows to removecols- ordered vector of cols to remove- Returns:
- smaller matrix
-
removeElements
public static double[] removeElements(double[] vector, int[] elements)Create new vector with data of the argument and removed elements.- Parameters:
vector-elements- ordered elements to remove- Returns:
- smaller vector
-
rangeComplement
public static int[] rangeComplement(int[] set, int length)return the complement of the sorted subset of the set 0:length-1 in Matlab notation- Parameters:
set- sorted set of elements < lengthlength- of superset of set and its returned complement- Returns:
-
chooseElements
public 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- Parameters:
matrix-rows-cols-- Returns:
-
chooseElements
public static double[] chooseElements(double[] vector, int[] keep)Create vector that contains the elements of the argument in the order as given by keep- Parameters:
vector-keep-- Returns:
-
increaseSize
public static int[] increaseSize(int[] vector, int moreelements)Create new vector of larger size and data of the argument.- Parameters:
vector- source arraymoreelements- number of elements to add- Returns:
- larger vector
-
increaseSize
public static int[][] increaseSize(int[][] matrix, int morerows, int morecols)Create new matrix of larger size and data of the argument.- Parameters:
matrix-more- rowsmore- cols- Returns:
- larger matrix
-
removeElement
public static int[] removeElement(int[] vector, int element)Create new vector with data of the argument and removed element.- Parameters:
vector-element-- Returns:
- shorter vector
-
removeElements
public static int[][] removeElements(int[][] matrix, int[] rows, int[] cols)Create new matrix with data of the argument and removed rows and columns.- Parameters:
matrix-rows- ordered vector of rows to removecols- ordered vector of cols to remove- Returns:
- smaller matrix
-
removeElements
public static int[] removeElements(int[] vector, int[] elements)Create new vector with data of the argument and removed elements.- Parameters:
vector-elements- ordered elements to remove- Returns:
- smaller vector
-
chooseElements
public 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- Parameters:
matrix-rows-cols-- Returns:
-
chooseElements
public static int[] chooseElements(int[] vector, int[] keep)Create vector that contains the elements of the argument in the order as given by keep- Parameters:
vector-keep-- Returns:
-
print
public static java.lang.String print(double[] x)
prints a double representation of the vector.- Parameters:
x-- Returns:
-
print
public static java.lang.String print(double[][] x)
prints a double representation of an array.- Parameters:
x-- Returns:
-
print
public static java.lang.String print(int[] x)
prints a double representation of the vector.- Parameters:
x-- Returns:
-
print
public static java.lang.String print(int[][] x)
prints a double representation of an array.- Parameters:
x-- Returns:
-
ones
public static double[] ones(int len, double factor)- Parameters:
len-factor-- Returns:
- factor * ones(1, len);
-
ones
public static int[] ones(int len, int factor)- Parameters:
len-factor-- Returns:
- factor * ones(1, len);
-
zeros
public static double[] zeros(int len)
- Parameters:
len-- Returns:
- zeros(1, len)
-
ones
public static int[] ones(int len)
- Parameters:
len-- Returns:
- ones(1, len)
-
cast
public static int[] cast(double[] vec)
cast a double[] to an int[]- Parameters:
vec-- Returns:
-
cast
public static double[] cast(int[] vec)
cast a double[] to an int[]- Parameters:
vec-- Returns:
-
find
public static int[] find(int[] vec, int val)find indices with val- Parameters:
vec-val-- Returns:
- vector with 0-based indices.
-
subVector
public static double[] subVector(double[] vec, int[] indices)returns a copy of the vector elements with the given indices in the original vector.- Parameters:
indices-- Returns:
-
subVector
public static int[] subVector(int[] vec, int[] indices)returns a copy of the vector elements with the given indices in the original vector.- Parameters:
cols-- Returns:
-
subVector
public static double[] subVector(double[] vec, int start, int end)- Parameters:
weights-i-j-- Returns:
-
setSubVector
public static void setSubVector(int[] vec, int[] indices, int[] replacements)set the elements of vec at indices with the respective replacements. TODO: implement views as in the colt library- Parameters:
vec-indices-replacements-
-
setSubVector
public static void setSubVector(int[] vec, int[] indices, int replacement)set the elements of vec at indices with the replacement. TODO: implement views as in the colt library- Parameters:
vec-indices-replacement-
-
add
public static void add(int[] vec, int scalar)add a scalar to the vector- Parameters:
vec-scalar-
-
setSubVectorCopy
public static int[] setSubVectorCopy(int[] vec, int[] indices, int[] replacements)set the elements of a copy of vec at indices with the respective replacements. TODO: implement views as in the colt library- Parameters:
vec-indices-replacements-- Returns:
- the copied vector with the replacements;
-
copy
public static double[] copy(double[] source)
copies a the source to the destination- Parameters:
alpha-- Returns:
-
copy
public static int[] copy(int[] source)
copies a the source to the destination- Parameters:
alpha-- Returns:
-
mult
public static double[] mult(double[] ds, double d)multiplicates the vector with a scalar. The argument is modified.- Parameters:
ds-d-- Returns:
-
mult
public static double mult(double[] ds, double[] dt)multiplicates the vector with a vector (inner product). The argument is not modified.- Parameters:
ds-d-- Returns:
-
transpose
public static double[][] transpose(double[][] mat)
transpose the matrix- Parameters:
mat-- Returns:
-
transpose
public static int[][] transpose(int[][] mat)
transpose the matrix- Parameters:
mat-- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG