jml.matlab
Class Matlab

java.lang.Object
  extended by jml.matlab.Matlab

public class Matlab
extends java.lang.Object

Matlab provides some frequently used Matlab matrix functions such as sort, sum, max, min, kron, vec, repmat, reshape, and colon.

Version:
1.0 Mar. 9th, 2012, 2.0 Dec. 29th, 2012, 3.0 Jan. 1st, 2013
Author:
Mingjie Qian

Field Summary
static double eps
          A constant holding the smallest positive nonzero value of type double, 2-1074.
static double inf
          A constant holding the positive infinity of type double.
 
Constructor Summary
Matlab()
           
 
Method Summary
static org.apache.commons.math.linear.RealMatrix abs(org.apache.commons.math.linear.RealMatrix A)
          Calculate element-wise absolute value of the elements of matrix.
static org.apache.commons.math.linear.RealMatrix and(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix cat(int dim, org.apache.commons.math.linear.RealMatrix... As)
          Concatenate matrices along specified dimension.
static org.apache.commons.math.linear.RealMatrix ceil(org.apache.commons.math.linear.RealMatrix A)
          Round elements of a matrix A towards plus infinity.
static org.apache.commons.math.linear.RealMatrix colon(double begin, double end)
          Same as colon(begin, 1, end).
static org.apache.commons.math.linear.RealMatrix colon(double begin, double d, double end)
          Generates a linearly spaced vector with distance of D between two consecutive numbers.
static int[] colon(int begin, int end)
          Same as colon(begin, 1, end).
static int[] colon(int begin, int d, int end)
          Generates a linearly spaced integer array with distance of D between two consecutive numbers.
static org.apache.commons.math.linear.RealMatrix diag(double[] V)
          Generate a diagonal matrix with its elements of a 1D double array on its main diagonal.
static org.apache.commons.math.linear.RealMatrix diag(org.apache.commons.math.linear.RealMatrix A)
          If A is a 1-row or 1-column matrix, then diag(A) is a sparse diagonal matrix with elements of A as its main diagonal, else diag(A) is a column matrix holding A's diagonal elements.
static org.apache.commons.math.linear.RealMatrix diag(org.apache.commons.math.linear.RealVector V)
          Generate a diagonal matrix with its elements of a vector V on its main diagonal.
static void disp(org.apache.commons.math.linear.RealMatrix M)
          Display a matrix.
static void disp(org.apache.commons.math.linear.RealMatrix M, int p)
          Display a matrix with a specified precision.
static void disp(java.lang.String str)
          Display a string.
static void display(double v)
          Display a double scalar.
static void display(double[] V)
          Display a 1D double array.
static void display(double[][] M)
          Display a real valued 2D array.
static void display(double[][] M, int p)
          Display a real valued 2D array with a specified precision.
static void display(double[] V, int p)
          Display a 1D double array with a specified precision.
static void display(int[] V)
          Display a 1D integer array.
static void display(int[][] M)
          Display an integer 2D array.
static void display(org.apache.commons.math.linear.RealMatrix M)
          Display a matrix.
static void display(org.apache.commons.math.linear.RealMatrix M, int p)
          Display a matrix with a specified precision.
static void display(org.apache.commons.math.linear.RealVector V)
          Display a vector.
static void display(java.lang.String s)
          Display a string.
static org.apache.commons.math.linear.RealMatrix dotDivide(double v, org.apache.commons.math.linear.RealMatrix X)
          Calculate element by element division between a scalar and a matrix.
static org.apache.commons.math.linear.RealMatrix dotDivide(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Calculate element by element division of two matrices.
static org.apache.commons.math.linear.RealMatrix dotMultiply(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Calculate element by element multiplication of two matrices.
static int[] double1DArray2Int1DArray(double[] x)
          convert a double[] to an int[].
static int[][] double2DArray2Int2DArray(double[][] X)
          convert a double[][] to an int[][].
static org.apache.commons.math.linear.RealMatrix ebeDivide(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Get the element-wise division of two matrix.
static org.apache.commons.math.linear.RealMatrix ebeMultiply(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Get the element-wise multiplication of two matrix.
static org.apache.commons.math.linear.RealMatrix[] eigs(org.apache.commons.math.linear.RealMatrix A, int K, java.lang.String sigma)
          Compute eigenvalues and eigenvectors of a symmetric real matrix.
static org.apache.commons.math.linear.RealMatrix eq(double x, org.apache.commons.math.linear.RealMatrix X)
          Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix eq(org.apache.commons.math.linear.RealMatrix X, double x)
          Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix eq(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix exp(org.apache.commons.math.linear.RealMatrix A)
          Calculate the element-wise exponential of a matrix
static org.apache.commons.math.linear.RealMatrix eye(int... size)
          Generate a sparse identity matrix with its size specified by a two dimensional integer array.
static org.apache.commons.math.linear.RealMatrix eye(int n)
          Construct an n-by-n sparse identity matrix.
static org.apache.commons.math.linear.RealMatrix eye(int m, int n)
          Construct an m-by-n sparse identity matrix.
static FindResult find(org.apache.commons.math.linear.RealMatrix A)
          Find nonzero elements and return their value, row and column indices.
static int[] find(org.apache.commons.math.linear.RealVector V)
          Find nonzero elements and return their indices.
static java.util.HashMap<java.lang.String,org.apache.commons.math.linear.RealMatrix> find2(org.apache.commons.math.linear.RealMatrix A)
          Find nonzero elements and return their value, row and column indices.
static int fix(double x)
          Round towards zero.
static org.apache.commons.math.linear.RealMatrix fix(org.apache.commons.math.linear.RealMatrix A)
          Round elements of a matrix A towards zero to.
static org.apache.commons.math.linear.RealMatrix floor(org.apache.commons.math.linear.RealMatrix A)
          Round towards minus infinity of elements of a matrix A.
static void fprintf(java.lang.String format, java.lang.Object... os)
          Write a formatted string to the standard output (the screen).
static org.apache.commons.math.linear.RealMatrix full(org.apache.commons.math.linear.RealMatrix S)
          Convert a sparse matrix into a dense matrix.
static org.apache.commons.math.linear.RealMatrix ge(double x, org.apache.commons.math.linear.RealMatrix X)
          Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix ge(org.apache.commons.math.linear.RealMatrix X, double x)
          Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix ge(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix getColumns(org.apache.commons.math.linear.RealMatrix A, int... selectedColumns)
          Get the subMatrix containing the elements of the specified columns.
static org.apache.commons.math.linear.RealMatrix getColumns(org.apache.commons.math.linear.RealMatrix A, int startColumn, int endColumn)
          Get the subMatrix containing the elements of the specified columns.
static org.apache.commons.math.linear.RealMatrix getRows(org.apache.commons.math.linear.RealMatrix A, int... selectedRows)
          Get the subMatrix containing the elements of the specified rows.
static org.apache.commons.math.linear.RealMatrix getRows(org.apache.commons.math.linear.RealMatrix A, int startRow, int endRow)
          Get the subMatrix containing the elements of the specified rows.
static org.apache.commons.math.linear.RealMatrix getTFIDF(org.apache.commons.math.linear.RealMatrix docTermCountMatrix)
          Calculate TFIDF of a doc-term-count matrix, each column is a data sample.
static org.apache.commons.math.linear.RealMatrix gt(double x, org.apache.commons.math.linear.RealMatrix X)
          Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix gt(org.apache.commons.math.linear.RealMatrix X, double x)
          Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix gt(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix horzcat(org.apache.commons.math.linear.RealMatrix... As)
          Concatenate matrices horizontally.
static double innerProduct(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Compute the inner product between two matrices (vectors could be viewed as column matrices).
static org.apache.commons.math.linear.RealMatrix inverse(org.apache.commons.math.linear.RealMatrix A)
          Compute the inverse (or pseudo-inverse) of the decomposed matrix A.
static org.apache.commons.math.linear.RealMatrix isinf(org.apache.commons.math.linear.RealMatrix A)
          returns an array that contains 1's where the elements of X are +Inf or -Inf and 0's where they are not.
static org.apache.commons.math.linear.RealMatrix isnan(org.apache.commons.math.linear.RealMatrix A)
          Returns an array that contains 1's where the elements of X are NaN's and 0's where they are not.
static org.apache.commons.math.linear.RealMatrix kron(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B)
          Calculate the Kronecker tensor product of A and B
static org.apache.commons.math.linear.RealMatrix l2Distance(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Compute the l2 distance matrix between column vectors in matrix X and column vectors in matrix Y.
static org.apache.commons.math.linear.RealMatrix l2DistanceSquare(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Compute the squared l2 distance matrix between column vectors in matrix X and column vectors in matrix Y.
static org.apache.commons.math.linear.RealMatrix l2NormByRows(org.apache.commons.math.linear.RealMatrix A)
          Calculate the l_2 norm of a vector or row vectors of a matrix.
static org.apache.commons.math.linear.RealMatrix ldivide(double v, org.apache.commons.math.linear.RealMatrix X)
          Left array division.
static org.apache.commons.math.linear.RealMatrix ldivide(org.apache.commons.math.linear.RealMatrix X, double v)
          Left array division.
static org.apache.commons.math.linear.RealMatrix ldivide(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B)
          Left array division.
static org.apache.commons.math.linear.RealMatrix le(double x, org.apache.commons.math.linear.RealMatrix X)
          Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix le(org.apache.commons.math.linear.RealMatrix X, double x)
          Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix le(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static double[] linearIndexing(double[] V, int[] indices)
          Linear indexing V by an index array.
static int[] linearIndexing(int[] V, int[] indices)
          Linear indexing V by an index array.
static org.apache.commons.math.linear.RealMatrix linearIndexing(org.apache.commons.math.linear.RealMatrix A, int[] indices)
          Linear indexing A by an index array.
static void linearIndexingAssignment(org.apache.commons.math.linear.RealMatrix A, int[] idx, double v)
          Matrix assignment by linear indexing for the syntax A(B) = v.
static void linearIndexingAssignment(org.apache.commons.math.linear.RealMatrix A, int[] idx, org.apache.commons.math.linear.RealMatrix V)
          Matrix assignment by linear indexing for the syntax A(B) = V.
static org.apache.commons.math.linear.RealMatrix linspace(double begin, double end, int n)
          Generates a linearly spaced vector.
static org.apache.commons.math.linear.RealMatrix log(org.apache.commons.math.linear.RealMatrix A)
          Calculate the element-wise logarithm of a matrix.
static org.apache.commons.math.linear.RealMatrix logicalIndexing(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B)
          Logical indexing A by B for the syntax A(B).
static void logicalIndexingAssignment(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B, double v)
          Matrix assignment by logical indexing for the syntax A(B) = v.
static void logicalIndexingAssignment(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B, org.apache.commons.math.linear.RealMatrix V)
          Matrix assignment by logical indexing for the syntax A(B) = V.
static org.apache.commons.math.linear.RealMatrix lt(double x, org.apache.commons.math.linear.RealMatrix X)
          Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix lt(org.apache.commons.math.linear.RealMatrix X, double x)
          Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix lt(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static void main(java.lang.String[] args)
           
static org.apache.commons.math.linear.RealMatrix max(double c, org.apache.commons.math.linear.RealMatrix A)
          Calculate maximum between elements of A and a real number and return as a matrix with the same shape of A.
static org.apache.commons.math.linear.RealMatrix max(org.apache.commons.math.linear.RealMatrix A)
          Calculate the maximum of a row matrix A or its column-wise maximum.
static org.apache.commons.math.linear.RealMatrix max(org.apache.commons.math.linear.RealMatrix A, double c)
          Calculate maximum between elements of A and a real number and return as a matrix with the same shape of A.
static java.util.TreeMap<java.lang.String,org.apache.commons.math.linear.RealMatrix> max(org.apache.commons.math.linear.RealMatrix A, int dim)
          Calculate the maximal value and its row or column index of a matrix A.
static org.apache.commons.math.linear.RealMatrix max(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Calculate element-wise maximum between two matrices X and Y.
static double[] max(org.apache.commons.math.linear.RealVector V)
          Get the maximal value and its index in V.
static java.util.ArrayList<org.apache.commons.math.linear.RealMatrix> max1(org.apache.commons.math.linear.RealMatrix A, int dim)
          Deprecated. 
static java.util.ArrayList<org.apache.commons.math.linear.RealVector> max2(org.apache.commons.math.linear.RealMatrix A, int dim)
          Deprecated. 
static org.apache.commons.math.linear.RealMatrix mean(org.apache.commons.math.linear.RealMatrix X)
          Average or mean value of array.
static org.apache.commons.math.linear.RealMatrix mean(org.apache.commons.math.linear.RealMatrix X, int dim)
          M = mean(A, dim) returns the mean values for elements along the dimension of A specified by scalar dim.
static org.apache.commons.math.linear.RealMatrix min(double c, org.apache.commons.math.linear.RealMatrix A)
          Calculate minimum between elements of A and a real number and return as a matrix with the same shape of A.
static org.apache.commons.math.linear.RealMatrix min(org.apache.commons.math.linear.RealMatrix A)
          Calculate the minimum of a row matrix A or its column-wise minimum.
static org.apache.commons.math.linear.RealMatrix min(org.apache.commons.math.linear.RealMatrix A, double c)
          Calculate minimum between elements of A and a real number and return as a matrix with the same shape of A.
static java.util.TreeMap<java.lang.String,org.apache.commons.math.linear.RealMatrix> min(org.apache.commons.math.linear.RealMatrix A, int dim)
          Calculate the minimal value and its row and column index of a matrix A.
static org.apache.commons.math.linear.RealMatrix min(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Calculate element-wise minimum between two matrices X and Y.
static double[] min(org.apache.commons.math.linear.RealVector V)
          Get the minimal value and its index in V.
static java.util.ArrayList<org.apache.commons.math.linear.RealMatrix> min1(org.apache.commons.math.linear.RealMatrix A, int dim)
          Deprecated. 
static java.util.ArrayList<org.apache.commons.math.linear.RealVector> min2(org.apache.commons.math.linear.RealMatrix A, int dim)
          Deprecated. 
static double minus(double a, double b)
          Subtraction between two scalars a and b.
static org.apache.commons.math.linear.RealMatrix minus(double v, org.apache.commons.math.linear.RealMatrix A)
          Array subtraction between a scalar and a matrix.
static org.apache.commons.math.linear.RealMatrix minus(org.apache.commons.math.linear.RealMatrix A, double v)
          Array subtraction between a matrix and a scalar.
static org.apache.commons.math.linear.RealMatrix minus(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Array subtraction between two matrices.
static org.apache.commons.math.linear.RealMatrix mldivide(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B)
          Calculate the left division of the form A \ B.
static org.apache.commons.math.linear.RealMatrix mrdivide(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B)
          Calculate the right division of B into A, i.e., A / B.
static org.apache.commons.math.linear.RealMatrix mtimes(double v, org.apache.commons.math.linear.RealMatrix X)
          Matrix multiplication.
static org.apache.commons.math.linear.RealMatrix mtimes(org.apache.commons.math.linear.RealMatrix X, double v)
          Matrix multiplication.
static org.apache.commons.math.linear.RealMatrix mtimes(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Matrix multiplication.
static org.apache.commons.math.linear.RealMatrix mvnrnd(double[] MU, double[][] SIGMA, int cases)
          Generate random samples chosen from the multivariate Gaussian distribution with mean MU and covariance SIGMA.
static org.apache.commons.math.linear.RealMatrix mvnrnd(double[] MU, double[] SIGMA, int cases)
          Generate random samples chosen from the multivariate Gaussian distribution with mean MU and a diagonal covariance SIGMA.
static org.apache.commons.math.linear.RealMatrix mvnrnd(org.apache.commons.math.linear.RealMatrix MU, org.apache.commons.math.linear.RealMatrix SIGMA, int cases)
          Generate random samples chosen from the multivariate Gaussian distribution with mean MU and covariance SIGMA.
static org.apache.commons.math.linear.RealMatrix ne(double x, org.apache.commons.math.linear.RealMatrix X)
          Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix ne(org.apache.commons.math.linear.RealMatrix X, double x)
          Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static org.apache.commons.math.linear.RealMatrix ne(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static double norm(org.apache.commons.math.linear.RealMatrix A)
          Calculate the induced 2-norm of a matrix A or 2-norm of a vector.
static double norm(org.apache.commons.math.linear.RealMatrix A, double type)
          Compute the induced vector norm of a matrix or a vector.
static double norm(org.apache.commons.math.linear.RealMatrix A, int type)
          Compute the norm of a matrix or a vector.
static double norm(org.apache.commons.math.linear.RealMatrix A, java.lang.String type)
          Calculate the Frobenius norm of a matrix A.
static org.apache.commons.math.linear.RealMatrix normalizeByColumns(org.apache.commons.math.linear.RealMatrix A)
          Normalize A by columns.
static org.apache.commons.math.linear.RealMatrix normalizeByRows(org.apache.commons.math.linear.RealMatrix A)
          Normalize A by rows.
static org.apache.commons.math.linear.RealMatrix not(org.apache.commons.math.linear.RealMatrix X)
          Performs a logical NOT of input array X, and returns an array containing elements set to either 1 (TRUE) or 0 (FALSE).
static org.apache.commons.math.linear.RealMatrix ones(int n)
          Generate an n by n all one matrix.
static org.apache.commons.math.linear.RealMatrix ones(int[] size)
          Generate an all one matrix with its size specified by a two dimensional integer array.
static org.apache.commons.math.linear.RealMatrix ones(int nRow, int nCol)
          Generate an all one matrix with nRow rows and nCol columns.
static org.apache.commons.math.linear.RealMatrix or(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.
static double plus(double a, double b)
          Addition between two scalars a and b.
static org.apache.commons.math.linear.RealMatrix plus(double v, org.apache.commons.math.linear.RealMatrix A)
          Array addition between a scalar and a matrix.
static org.apache.commons.math.linear.RealMatrix plus(org.apache.commons.math.linear.RealMatrix A, double v)
          Array addition between a matrix and a scalar.
static org.apache.commons.math.linear.RealMatrix plus(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Array addition between two matrices.
static org.apache.commons.math.linear.RealMatrix power(double v, org.apache.commons.math.linear.RealMatrix X)
          Compute element-wise exponentiation of a matrix.
static org.apache.commons.math.linear.RealMatrix power(org.apache.commons.math.linear.RealMatrix X, double v)
          Compute element-wise exponentiation of a matrix.
static org.apache.commons.math.linear.RealMatrix power(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Array power.
static void printMatrix(org.apache.commons.math.linear.RealMatrix M)
          Print a matrix.
static void printMatrix(org.apache.commons.math.linear.RealMatrix M, int p)
          Print a matrix with a specified precision.
private static void printSparseMatrix(org.apache.commons.math.linear.RealMatrix M)
          Print a sparse matrix.
static void printVector(org.apache.commons.math.linear.RealVector V)
          Print a vector.
static void printVector(org.apache.commons.math.linear.RealVector V, int p)
          Print a vector with a specified precision.
static org.apache.commons.math.linear.RealMatrix rand(int n)
          Generate an n-by-n matrix containing pseudo-random values drawn from the standard uniform distribution on the open interval (0,1).
static org.apache.commons.math.linear.RealMatrix rand(int nRow, int nCol)
          Generate an nRow-by-nCol matrix containing pseudo-random values drawn from the standard uniform distribution on the open interval (0,1).
static org.apache.commons.math.linear.RealMatrix randn(int n)
          Generate an n-by-n matrix containing pseudo-random values drawn from the standard normal distribution.
static org.apache.commons.math.linear.RealMatrix randn(int nRow, int nCol)
          Generate an nRow-by-nCol matrix containing pseudo-random values drawn from the standard normal distribution.
static int[] randperm(int n)
          Random permutation.
static int rank(org.apache.commons.math.linear.RealMatrix A)
          The rank function provides an estimate of the number of linearly independent rows or columns of a full matrix.
static int rank(org.apache.commons.math.linear.RealMatrix A, double tol)
          The rank function provides an estimate of the number of linearly independent rows or columns of a full matrix.
static org.apache.commons.math.linear.RealMatrix rdivide(double v, org.apache.commons.math.linear.RealMatrix X)
          Right array division.
static org.apache.commons.math.linear.RealMatrix rdivide(org.apache.commons.math.linear.RealMatrix X, double v)
          Right array division.
static org.apache.commons.math.linear.RealMatrix rdivide(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix B)
          Right array division.
static org.apache.commons.math.linear.RealMatrix repmat(org.apache.commons.math.linear.RealMatrix A, int[] size)
          Replicate and tile an array.
static org.apache.commons.math.linear.RealMatrix repmat(org.apache.commons.math.linear.RealMatrix A, int M, int N)
          Replicate and tile an array.
static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealMatrix A, int[] size)
          Reshape a matrix to a new shape specified by a two dimensional integer array.
static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealMatrix A, int M, int N)
          Reshape a matrix to a new shape specified number of rows and columns.
static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealVector V, int[] size)
          Reshape a vector to a matrix with a shape specified by a two dimensional integer array.
static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealVector V, int M, int N)
          Reshape a vector to a new shape specified number of rows and columns.
static org.apache.commons.math.linear.RealMatrix round(org.apache.commons.math.linear.RealMatrix A)
          Round elements of a matrix A towards nearest integer.
static org.apache.commons.math.linear.RealMatrix scalarDivide(double v, org.apache.commons.math.linear.RealMatrix X)
          Calculate element by element division between a scalar and a matrix.
static void setMatrix(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Set all the elements of X to be those of Y, this is particularly useful when we want to change elements of the object referred by X rather than the reference X itself.
static void setSubMatrix(org.apache.commons.math.linear.RealMatrix A, int[] selectedRows, int[] selectedColumns, org.apache.commons.math.linear.RealMatrix B)
          Set submatrix of A with selected rows and selected columns by elements of B.
static org.apache.commons.math.linear.RealMatrix sigmoid(org.apache.commons.math.linear.RealMatrix A)
          Calculate the sigmoid of a matrix A by rows.
static org.apache.commons.math.linear.RealMatrix sign(org.apache.commons.math.linear.RealMatrix A)
          Signum function.
static int[] size(org.apache.commons.math.linear.RealMatrix A)
          Get a two dimensional integer array for size of a matrix A.
static int size(org.apache.commons.math.linear.RealMatrix A, int dim)
          Get the dimensionality on dim-th dimension for a matrix A.
static SortResult sort(org.apache.commons.math.linear.RealMatrix A, int dim)
          Sort elements of a matrix A on a direction in a increasing order.
static SortResult sort(org.apache.commons.math.linear.RealMatrix A, int dim, java.lang.String order)
          Sort elements of a matrix A on a direction in a specified order.
static int[] sort(org.apache.commons.math.linear.RealVector V, java.lang.String order)
          Sort elements of a real vector V in place in a specified order.
static org.apache.commons.math.linear.RealMatrix sort2(org.apache.commons.math.linear.RealMatrix A)
          Sort elements of a matrix A column-wisely in an increasing order.
static org.apache.commons.math.linear.RealMatrix sort2(org.apache.commons.math.linear.RealMatrix A, int dim)
          Sort elements of a matrix A on a direction in an increasing order.
static org.apache.commons.math.linear.RealMatrix sort2(org.apache.commons.math.linear.RealMatrix A, int dim, java.lang.String order)
          Sort elements of a matrix A on a direction in a specified order.
static org.apache.commons.math.linear.RealMatrix sort3(org.apache.commons.math.linear.RealMatrix A, int dim, java.lang.String order)
          Deprecated. 
static org.apache.commons.math.linear.RealMatrix sparse(org.apache.commons.math.linear.RealMatrix D)
          Convert a dense matrix into a sparse matrix.
static java.lang.String sprintf(java.lang.String format, java.lang.Object... os)
          Format variables into a string.
static org.apache.commons.math.linear.RealMatrix sqrt(org.apache.commons.math.linear.RealMatrix A)
          Calculate square root for all elements of a matrix A.
static org.apache.commons.math.linear.RealMatrix subplus(org.apache.commons.math.linear.RealMatrix A)
          Get the nonnegative part of a matrix A.
static org.apache.commons.math.linear.RealMatrix sum(org.apache.commons.math.linear.RealMatrix A)
          Calculate the sum of a row matrix A or its column-wise sum.
static org.apache.commons.math.linear.RealMatrix sum(org.apache.commons.math.linear.RealMatrix A, int dim)
          Calculate the sum of elements of A on a dimension.
static double sum(org.apache.commons.math.linear.RealVector V)
          Compute the sum of all elements of a vector.
static double sumAll(org.apache.commons.math.linear.RealMatrix A)
          Compute the sum of all elements of a matrix.
static org.apache.commons.math.linear.RealMatrix[] svd(org.apache.commons.math.linear.RealMatrix A)
          Compute the "economy size" matrix singular value decomposition.
static double times(double a, double b)
          Scalar multiplication between two scalars a and b.
static org.apache.commons.math.linear.RealMatrix times(double v, org.apache.commons.math.linear.RealMatrix A)
          Array multiplication between a scalar and a matrix.
static org.apache.commons.math.linear.RealMatrix times(org.apache.commons.math.linear.RealMatrix A, double v)
          Array multiplication between a matrix and a scalar.
static org.apache.commons.math.linear.RealMatrix times(org.apache.commons.math.linear.RealMatrix X, org.apache.commons.math.linear.RealMatrix Y)
          Calculate the element-wise multiplication of two matrices X and Y.
static double trace(org.apache.commons.math.linear.RealMatrix A)
          Calculate the trace of a matrix A.
static org.apache.commons.math.linear.RealMatrix uminus(org.apache.commons.math.linear.RealMatrix A)
          Unary minus.
static org.apache.commons.math.linear.RealMatrix uplus(org.apache.commons.math.linear.RealMatrix A)
          Unary plus.
static org.apache.commons.math.linear.RealMatrix vec(org.apache.commons.math.linear.RealMatrix A)
          Vectorize a matrix A.
static org.apache.commons.math.linear.RealMatrix vertcat(org.apache.commons.math.linear.RealMatrix... As)
          Concatenate matrices vertically.
static org.apache.commons.math.linear.RealMatrix zeros(int n)
          Generate an n by n all zero matrix.
static org.apache.commons.math.linear.RealMatrix zeros(int[] size)
          Generate an all zero matrix with its size specified by a two dimensional integer array.
static org.apache.commons.math.linear.RealMatrix zeros(int nRow, int nCol)
          Generate nRow by nCol all zero matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eps

public static double eps
A constant holding the smallest positive nonzero value of type double, 2-1074.


inf

public static double inf
A constant holding the positive infinity of type double.

Constructor Detail

Matlab

public Matlab()
Method Detail

main

public static void main(java.lang.String[] args)
Parameters:
args -

eigs

public static org.apache.commons.math.linear.RealMatrix[] eigs(org.apache.commons.math.linear.RealMatrix A,
                                                               int K,
                                                               java.lang.String sigma)
Compute eigenvalues and eigenvectors of a symmetric real matrix.

Parameters:
A - a symmetric real matrix
K - number of eigenvalues selected
sigma - either "lm" (largest magnitude) or "sm" (smallest magnitude)
Returns:
a matrix array [V, D], V is the selected K eigenvectors (normalized to 1), and D is a diagonal matrix holding selected K eigenvalues.

svd

public static org.apache.commons.math.linear.RealMatrix[] svd(org.apache.commons.math.linear.RealMatrix A)
Compute the "economy size" matrix singular value decomposition.

Parameters:
A - a real matrix
Returns:
a matrix array [U, S, V] where U is left orthonormal matrix, S is a a diagonal matrix, and V is the right orthonormal matrix such that A = U * S * V'

rank

public static int rank(org.apache.commons.math.linear.RealMatrix A)
The rank function provides an estimate of the number of linearly independent rows or columns of a full matrix.
k = rank(A) returns the number of singular values of A that are larger than the default tolerance, max(size(A))*1e-16.

Parameters:
A - a real matrix
Returns:
the estimated rank of A

rank

public static int rank(org.apache.commons.math.linear.RealMatrix A,
                       double tol)
The rank function provides an estimate of the number of linearly independent rows or columns of a full matrix.
k = rank(A,tol) returns the number of singular values of A that are larger than tol.

Parameters:
A - a real matrix
tol - tolerance to estimate the rank of A
Returns:
the estimated rank of A

randperm

public static int[] randperm(int n)
Random permutation.
randperm(n) returns a random permutation of the integers 1:n.

Parameters:
n - an integer
Returns:
randperm(n)

find

public static int[] find(org.apache.commons.math.linear.RealVector V)
Find nonzero elements and return their indices.

Parameters:
V - a real vector
Returns:
an integer array of indices of nonzero elements of V

find

public static FindResult find(org.apache.commons.math.linear.RealMatrix A)
Find nonzero elements and return their value, row and column indices.

Parameters:
A - a real matrix
Returns:
a FindResult data structure which has three instance data members:
rows: row indices array for non-zero elements of a matrix
cols: column indices array for non-zero elements of a matrix
vals: values array for non-zero elements of a matrix

find2

public static java.util.HashMap<java.lang.String,org.apache.commons.math.linear.RealMatrix> find2(org.apache.commons.math.linear.RealMatrix A)
Find nonzero elements and return their value, row and column indices.

Parameters:
A - a matrix
Returns:
a HashMap<String, RealMatrix>.

"row": a column matrix recording row indices
"col": a column matrix recording dolumn indices
"val": a column matrix recording non-zero values


l2Distance

public static org.apache.commons.math.linear.RealMatrix l2Distance(org.apache.commons.math.linear.RealMatrix X,
                                                                   org.apache.commons.math.linear.RealMatrix Y)
Compute the l2 distance matrix between column vectors in matrix X and column vectors in matrix Y.

Parameters:
X - Data matrix with each column being a feature vector.
Y - Data matrix with each column being a feature vector.
Returns:
an n_x X n_y matrix with its (i, j)th entry being the l2 distance between i-th feature vector in X and j-th feature vector in Y, , i.e., || X(:, i) - Y(:, j) ||_2

l2DistanceSquare

public static org.apache.commons.math.linear.RealMatrix l2DistanceSquare(org.apache.commons.math.linear.RealMatrix X,
                                                                         org.apache.commons.math.linear.RealMatrix Y)
Compute the squared l2 distance matrix between column vectors in matrix X and column vectors in matrix Y.

Parameters:
X - Data matrix with each column being a feature vector.
Y - Data matrix with each column being a feature vector.
Returns:
an n_x X n_y matrix with its (i, j) entry being the squared l2 distance between i-th feature vector in X and j-th feature vector in Y, i.e., || X(:, i) - Y(:, j) ||_2^2

times

public static org.apache.commons.math.linear.RealMatrix times(org.apache.commons.math.linear.RealMatrix X,
                                                              org.apache.commons.math.linear.RealMatrix Y)
Calculate the element-wise multiplication of two matrices X and Y.

Parameters:
X - Matrix X.
Y - Matrix Y.
Returns:
X .* Y

mtimes

public static org.apache.commons.math.linear.RealMatrix mtimes(org.apache.commons.math.linear.RealMatrix X,
                                                               org.apache.commons.math.linear.RealMatrix Y)
Matrix multiplication.

Parameters:
X - a matrix
Y - a matrix
Returns:
X * Y

mtimes

public static org.apache.commons.math.linear.RealMatrix mtimes(org.apache.commons.math.linear.RealMatrix X,
                                                               double v)
Matrix multiplication.

Parameters:
X - a matrix
v - a real scalar
Returns:
X * v

mtimes

public static org.apache.commons.math.linear.RealMatrix mtimes(double v,
                                                               org.apache.commons.math.linear.RealMatrix X)
Matrix multiplication.

Parameters:
v - a real scalar
X - a matrix
Returns:
X * v

times

public static org.apache.commons.math.linear.RealMatrix times(double v,
                                                              org.apache.commons.math.linear.RealMatrix A)
Array multiplication between a scalar and a matrix.

Parameters:
v - a real number
A - a matrix
Returns:
v * A

times

public static org.apache.commons.math.linear.RealMatrix times(org.apache.commons.math.linear.RealMatrix A,
                                                              double v)
Array multiplication between a matrix and a scalar.

Parameters:
A - a matrix
v - a real number
Returns:
A * v

times

public static double times(double a,
                           double b)
Scalar multiplication between two scalars a and b.

Parameters:
a - a real scalar
b - a real scalar
Returns:
a * b

plus

public static org.apache.commons.math.linear.RealMatrix plus(org.apache.commons.math.linear.RealMatrix X,
                                                             org.apache.commons.math.linear.RealMatrix Y)
Array addition between two matrices.

Parameters:
X - a matrix
Y - a matrix
Returns:
X + Y

plus

public static org.apache.commons.math.linear.RealMatrix plus(org.apache.commons.math.linear.RealMatrix A,
                                                             double v)
Array addition between a matrix and a scalar.

Parameters:
A - a matrix
v - a scalar
Returns:
A + v

plus

public static org.apache.commons.math.linear.RealMatrix plus(double v,
                                                             org.apache.commons.math.linear.RealMatrix A)
Array addition between a scalar and a matrix.

Parameters:
v - a scalar
A - a matrix
Returns:
v + A

plus

public static double plus(double a,
                          double b)
Addition between two scalars a and b.

Parameters:
a - a scalar
b - a scalar
Returns:
a + b

minus

public static org.apache.commons.math.linear.RealMatrix minus(org.apache.commons.math.linear.RealMatrix X,
                                                              org.apache.commons.math.linear.RealMatrix Y)
Array subtraction between two matrices.

Parameters:
X - a matrix
Y - a matrix
Returns:
X - Y

minus

public static org.apache.commons.math.linear.RealMatrix minus(org.apache.commons.math.linear.RealMatrix A,
                                                              double v)
Array subtraction between a matrix and a scalar.

Parameters:
A - a matrix
v - a scalar
Returns:
A - v

minus

public static org.apache.commons.math.linear.RealMatrix minus(double v,
                                                              org.apache.commons.math.linear.RealMatrix A)
Array subtraction between a scalar and a matrix.

Parameters:
v - a scalar
A - a matrix
Returns:
v - A

minus

public static double minus(double a,
                           double b)
Subtraction between two scalars a and b.

Parameters:
a - a scalar
b - a scalar
Returns:
a - b

uplus

public static org.apache.commons.math.linear.RealMatrix uplus(org.apache.commons.math.linear.RealMatrix A)
Unary plus.

Parameters:
A - a matrix
Returns:
+A

uminus

public static org.apache.commons.math.linear.RealMatrix uminus(org.apache.commons.math.linear.RealMatrix A)
Unary minus.

Parameters:
A - a matrix
Returns:
-A

innerProduct

public static double innerProduct(org.apache.commons.math.linear.RealMatrix X,
                                  org.apache.commons.math.linear.RealMatrix Y)
Compute the inner product between two matrices (vectors could be viewed as column matrices).

Parameters:
X - a matrix
Y - a matrix
Returns:
inner product of X and Y or trace(X'Y)

subplus

public static org.apache.commons.math.linear.RealMatrix subplus(org.apache.commons.math.linear.RealMatrix A)
Get the nonnegative part of a matrix A.

Parameters:
A - a matrix
Returns:
a matrix which is the nonnegative part of a matrix A

trace

public static double trace(org.apache.commons.math.linear.RealMatrix A)
Calculate the trace of a matrix A.

Parameters:
A - a matrix
Returns:
trace(A)

dotMultiply

public static org.apache.commons.math.linear.RealMatrix dotMultiply(org.apache.commons.math.linear.RealMatrix X,
                                                                    org.apache.commons.math.linear.RealMatrix Y)
Calculate element by element multiplication of two matrices.

Parameters:
X - a matrix
Y - a matrix
Returns:
X .* Y

dotDivide

public static org.apache.commons.math.linear.RealMatrix dotDivide(org.apache.commons.math.linear.RealMatrix X,
                                                                  org.apache.commons.math.linear.RealMatrix Y)
Calculate element by element division of two matrices.

Parameters:
X - a matrix
Y - a matrix
Returns:
X ./ Y

dotDivide

public static org.apache.commons.math.linear.RealMatrix dotDivide(double v,
                                                                  org.apache.commons.math.linear.RealMatrix X)
Calculate element by element division between a scalar and a matrix.

Parameters:
v - a real number to be divided by all entries of a matrix
X - a matrix
Returns:
v ./ X

power

public static org.apache.commons.math.linear.RealMatrix power(org.apache.commons.math.linear.RealMatrix X,
                                                              double v)
Compute element-wise exponentiation of a matrix.

Parameters:
X - a matrix
v - exponent
Returns:
X .^ v

power

public static org.apache.commons.math.linear.RealMatrix power(double v,
                                                              org.apache.commons.math.linear.RealMatrix X)
Compute element-wise exponentiation of a matrix.

Parameters:
X - a matrix
v - exponent
Returns:
v .^ X

power

public static org.apache.commons.math.linear.RealMatrix power(org.apache.commons.math.linear.RealMatrix X,
                                                              org.apache.commons.math.linear.RealMatrix Y)
Array power. Z = X .^ Y denotes element-by-element powers. X and Y must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X .^ Y

ldivide

public static org.apache.commons.math.linear.RealMatrix ldivide(double v,
                                                                org.apache.commons.math.linear.RealMatrix X)
Left array division.

Parameters:
v - a scalar
X - a matrix
Returns:
v .\ X

ldivide

public static org.apache.commons.math.linear.RealMatrix ldivide(org.apache.commons.math.linear.RealMatrix X,
                                                                double v)
Left array division.

Parameters:
X - a matrix
v - a scalar
Returns:
X .\ v == v ./ X

ldivide

public static org.apache.commons.math.linear.RealMatrix ldivide(org.apache.commons.math.linear.RealMatrix A,
                                                                org.apache.commons.math.linear.RealMatrix B)
Left array division.

Parameters:
A - a matrix
B - a matrix
Returns:
A .\ B

rdivide

public static org.apache.commons.math.linear.RealMatrix rdivide(double v,
                                                                org.apache.commons.math.linear.RealMatrix X)
Right array division.

Parameters:
v - a scalar
X - a matrix
Returns:
v ./ X

rdivide

public static org.apache.commons.math.linear.RealMatrix rdivide(org.apache.commons.math.linear.RealMatrix X,
                                                                double v)
Right array division.

Parameters:
X - a matrix
v - a scalar
Returns:
X ./ v

rdivide

public static org.apache.commons.math.linear.RealMatrix rdivide(org.apache.commons.math.linear.RealMatrix A,
                                                                org.apache.commons.math.linear.RealMatrix B)
Right array division.

Parameters:
A - a matrix
B - a matrix
Returns:
A ./ B

scalarDivide

public static org.apache.commons.math.linear.RealMatrix scalarDivide(double v,
                                                                     org.apache.commons.math.linear.RealMatrix X)
Calculate element by element division between a scalar and a matrix.

Parameters:
v - a real number to be divided by all entries of a matrix
X - a matrix
Returns:
v ./ X

ebeDivide

public static org.apache.commons.math.linear.RealMatrix ebeDivide(org.apache.commons.math.linear.RealMatrix X,
                                                                  org.apache.commons.math.linear.RealMatrix Y)
Get the element-wise division of two matrix.

Parameters:
X - a matrix
Y - a matrix
Returns:
X ./ Y

ebeMultiply

public static org.apache.commons.math.linear.RealMatrix ebeMultiply(org.apache.commons.math.linear.RealMatrix X,
                                                                    org.apache.commons.math.linear.RealMatrix Y)
Get the element-wise multiplication of two matrix.

Parameters:
X - a matrix
Y - a matrix
Returns:
X .* Y

norm

public static double norm(org.apache.commons.math.linear.RealMatrix A,
                          java.lang.String type)
Calculate the Frobenius norm of a matrix A.

Parameters:
A - a matrix
type - can only be "fro"
Returns:
||A||_F

norm

public static double norm(org.apache.commons.math.linear.RealMatrix A,
                          int type)
Compute the norm of a matrix or a vector.

Parameters:
A - a matrix
type - 1, 2
Returns:
||A||_{type}

norm

public static double norm(org.apache.commons.math.linear.RealMatrix A,
                          double type)
Compute the induced vector norm of a matrix or a vector.

Parameters:
A - a matrix or a vector
type - 1, 2, or, inf for a matrix or a positive real number for a vector
Returns:
||A||_{type}

norm

public static double norm(org.apache.commons.math.linear.RealMatrix A)
Calculate the induced 2-norm of a matrix A or 2-norm of a vector.

Parameters:
A - a matrix or a vector
Returns:
||A||_2

sigmoid

public static org.apache.commons.math.linear.RealMatrix sigmoid(org.apache.commons.math.linear.RealMatrix A)
Calculate the sigmoid of a matrix A by rows. Specifically, supposing that the input activation matrix is [a11, a12; a21, a22], the output value is

[exp(a11) / exp(a11) + exp(a12), exp(a12) / exp(a11) + exp(a12);
exp(a21) / exp(a21) + exp(a22), exp(a22) / exp(a21) + exp(a22)].

Parameters:
A - a real matrix
Returns:
sigmoid(A)

rand

public static org.apache.commons.math.linear.RealMatrix rand(int nRow,
                                                             int nCol)
Generate an nRow-by-nCol matrix containing pseudo-random values drawn from the standard uniform distribution on the open interval (0,1).

Parameters:
nRow - number of rows
nCol - number of columns
Returns:
rand(nRow, nCol)

rand

public static org.apache.commons.math.linear.RealMatrix rand(int n)
Generate an n-by-n matrix containing pseudo-random values drawn from the standard uniform distribution on the open interval (0,1).

Parameters:
n - number of rows or columns
Returns:
rand(n, n)

randn

public static org.apache.commons.math.linear.RealMatrix randn(int nRow,
                                                              int nCol)
Generate an nRow-by-nCol matrix containing pseudo-random values drawn from the standard normal distribution.

Parameters:
nRow - number of rows
nCol - number of columns
Returns:
randn(nRow, nCol)

mean

public static org.apache.commons.math.linear.RealMatrix mean(org.apache.commons.math.linear.RealMatrix X)
Average or mean value of array. If A is a vector, mean(A) returns the mean value of A. If A is a matrix, mean(A) treats the columns of A as vectors, returning a row vector of mean values.

Parameters:
X - a real matrix
Returns:
mean(A)

mean

public static org.apache.commons.math.linear.RealMatrix mean(org.apache.commons.math.linear.RealMatrix X,
                                                             int dim)
M = mean(A, dim) returns the mean values for elements along the dimension of A specified by scalar dim. For matrices, mean(A, 2) is a column matrix containing the mean value of each row.

Parameters:
X - a real matrix
dim - dimension order
Returns:
mean(A, dim)

mvnrnd

public static org.apache.commons.math.linear.RealMatrix mvnrnd(org.apache.commons.math.linear.RealMatrix MU,
                                                               org.apache.commons.math.linear.RealMatrix SIGMA,
                                                               int cases)
Generate random samples chosen from the multivariate Gaussian distribution with mean MU and covariance SIGMA.

Parameters:
MU - 1 x d mean vector
SIGMA - covariance matrix
cases - number of d dimensional random samples
Returns:
cases-by-d sample matrix subject to the multivariate Gaussian distribution N(MU, SIGMA)

mvnrnd

public static org.apache.commons.math.linear.RealMatrix mvnrnd(double[] MU,
                                                               double[][] SIGMA,
                                                               int cases)
Generate random samples chosen from the multivariate Gaussian distribution with mean MU and covariance SIGMA.

Parameters:
MU - a 1D double array holding the mean vector
SIGMA - a 2D double array holding the covariance matrix
cases - number of d dimensional random samples
Returns:
cases-by-d sample matrix subject to the multivariate Gaussian distribution N(MU, SIGMA)

mvnrnd

public static org.apache.commons.math.linear.RealMatrix mvnrnd(double[] MU,
                                                               double[] SIGMA,
                                                               int cases)
Generate random samples chosen from the multivariate Gaussian distribution with mean MU and a diagonal covariance SIGMA.

Parameters:
MU - a 1D double array holding the mean vector
SIGMA - a 1D double array holding the diagonal elements of the covariance matrix
cases - number of d dimensional random samples
Returns:
cases-by-d sample matrix subject to the multivariate Gaussian distribution N(MU, SIGMA)

randn

public static org.apache.commons.math.linear.RealMatrix randn(int n)
Generate an n-by-n matrix containing pseudo-random values drawn from the standard normal distribution.

Parameters:
n - number of rows or columns
Returns:
randn(n, n)

repmat

public static org.apache.commons.math.linear.RealMatrix repmat(org.apache.commons.math.linear.RealMatrix A,
                                                               int M,
                                                               int N)
Replicate and tile an array.

Parameters:
A - a matrix
M - number of rows to replicate
N - number of columns to replicate
Returns:
repmat(A, M, N)

repmat

public static org.apache.commons.math.linear.RealMatrix repmat(org.apache.commons.math.linear.RealMatrix A,
                                                               int[] size)
Replicate and tile an array.

Parameters:
A - a matrix
size - a int[2] vector [M N]
Returns:
repmat(A, size)

log

public static org.apache.commons.math.linear.RealMatrix log(org.apache.commons.math.linear.RealMatrix A)
Calculate the element-wise logarithm of a matrix.

Parameters:
A - a matrix
Returns:
log(A)

exp

public static org.apache.commons.math.linear.RealMatrix exp(org.apache.commons.math.linear.RealMatrix A)
Calculate the element-wise exponential of a matrix

Parameters:
A - a matrix
Returns:
exp(A)

linspace

public static org.apache.commons.math.linear.RealMatrix linspace(double begin,
                                                                 double end,
                                                                 int n)
Generates a linearly spaced vector.

Parameters:
begin - starting point
end - ending point
n - number of points generated
Returns:
a row matrix containing n points between begin and end

colon

public static org.apache.commons.math.linear.RealMatrix colon(double begin,
                                                              double d,
                                                              double end)
Generates a linearly spaced vector with distance of D between two consecutive numbers. colon(J, D, K) is the same as [J, J+D, ..., J+m*D] where m = fix((K-J)/D).

Parameters:
begin - starting point
d - distance between two consecutive numbers
end - ending point
Returns:
a linearly spaced row matrix equally spaced by d

colon

public static org.apache.commons.math.linear.RealMatrix colon(double begin,
                                                              double end)
Same as colon(begin, 1, end).

Parameters:
begin - starting point
end - ending point
Returns:
a linearly spaced row matrix equally spaced by 1

colon

public static int[] colon(int begin,
                          int d,
                          int end)
Generates a linearly spaced integer array with distance of D between two consecutive numbers. colon(J, D, K) is the same as [J, J+D, ..., J+m*D] where m = fix((K-J)/D).

Parameters:
begin - starting point (inclusive)
d - distance between two consecutive numbers
end - ending point (inclusive if possible)
Returns:
indices array for the syntax begin:d:end

colon

public static int[] colon(int begin,
                          int end)
Same as colon(begin, 1, end).

Parameters:
begin - starting point (inclusive)
end - ending point (inclusive)
Returns:
indices array for the syntax begin:end

isnan

public static org.apache.commons.math.linear.RealMatrix isnan(org.apache.commons.math.linear.RealMatrix A)
Returns an array that contains 1's where the elements of X are NaN's and 0's where they are not.

Parameters:
A - a matrix
Returns:
a 0-1 matrix: isnan(A)

isinf

public static org.apache.commons.math.linear.RealMatrix isinf(org.apache.commons.math.linear.RealMatrix A)
returns an array that contains 1's where the elements of X are +Inf or -Inf and 0's where they are not.

Parameters:
A - a matrix
Returns:
a 0-1 matrix: isinf(A)

lt

public static org.apache.commons.math.linear.RealMatrix lt(org.apache.commons.math.linear.RealMatrix X,
                                                           org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. A and B must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X < Y or lt(X, Y)

lt

public static org.apache.commons.math.linear.RealMatrix lt(org.apache.commons.math.linear.RealMatrix X,
                                                           double x)
Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
X - a matrix
x - a real scalar
Returns:
X < x or lt(X, x)

lt

public static org.apache.commons.math.linear.RealMatrix lt(double x,
                                                           org.apache.commons.math.linear.RealMatrix X)
Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
x - a real scalar
X - a matrix
Returns:
x < X or lt(x, X)

gt

public static org.apache.commons.math.linear.RealMatrix gt(org.apache.commons.math.linear.RealMatrix X,
                                                           org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. A and B must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X > Y or gt(X, Y)

gt

public static org.apache.commons.math.linear.RealMatrix gt(org.apache.commons.math.linear.RealMatrix X,
                                                           double x)
Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
X - a matrix
x - a real scalar
Returns:
X > x or gt(X, x)

gt

public static org.apache.commons.math.linear.RealMatrix gt(double x,
                                                           org.apache.commons.math.linear.RealMatrix X)
Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
x - a real scalar
X - a matrix
Returns:
x > X or gt(x, X)

le

public static org.apache.commons.math.linear.RealMatrix le(org.apache.commons.math.linear.RealMatrix X,
                                                           org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. X and Y must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X <= Y or le(X, Y)

le

public static org.apache.commons.math.linear.RealMatrix le(org.apache.commons.math.linear.RealMatrix X,
                                                           double x)
Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
X - a matrix
x - a real scalar
Returns:
X <= x or le(X, x)

le

public static org.apache.commons.math.linear.RealMatrix le(double x,
                                                           org.apache.commons.math.linear.RealMatrix X)
Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
x - a real scalar
X - a matrix
Returns:
x <= X or le(x, X)

ge

public static org.apache.commons.math.linear.RealMatrix ge(org.apache.commons.math.linear.RealMatrix X,
                                                           org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. X and Y must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X >= Y or ge(X, Y)

ge

public static org.apache.commons.math.linear.RealMatrix ge(org.apache.commons.math.linear.RealMatrix X,
                                                           double x)
Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
X - a matrix
x - a real scalar
Returns:
X >= x or ge(X, x)

ge

public static org.apache.commons.math.linear.RealMatrix ge(double x,
                                                           org.apache.commons.math.linear.RealMatrix X)
Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
x - a real scalar
X - a matrix
Returns:
x >= X or ge(x, X)

eq

public static org.apache.commons.math.linear.RealMatrix eq(org.apache.commons.math.linear.RealMatrix X,
                                                           org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. X and Y must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X == Y or eq(X, Y)

eq

public static org.apache.commons.math.linear.RealMatrix eq(org.apache.commons.math.linear.RealMatrix X,
                                                           double x)
Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
X - a matrix
x - a real scalar
Returns:
X == x or eq(X, x)

eq

public static org.apache.commons.math.linear.RealMatrix eq(double x,
                                                           org.apache.commons.math.linear.RealMatrix X)
Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
x - a real scalar
X - a matrix
Returns:
x == X or eq(x, X)

ne

public static org.apache.commons.math.linear.RealMatrix ne(org.apache.commons.math.linear.RealMatrix X,
                                                           org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. X and Y must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X ~= Y or ne(X, Y)

ne

public static org.apache.commons.math.linear.RealMatrix ne(org.apache.commons.math.linear.RealMatrix X,
                                                           double x)
Do element by element comparisons between X and x and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
X - a matrix
x - a real scalar
Returns:
X ~= x or ne(X, x)

ne

public static org.apache.commons.math.linear.RealMatrix ne(double x,
                                                           org.apache.commons.math.linear.RealMatrix X)
Do element by element comparisons between x and X and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not.

Parameters:
x - a real scalar
X - a matrix
Returns:
x ~= X or ne(x, X)

not

public static org.apache.commons.math.linear.RealMatrix not(org.apache.commons.math.linear.RealMatrix X)
Performs a logical NOT of input array X, and returns an array containing elements set to either 1 (TRUE) or 0 (FALSE). An element of the output array is set to 1 if X contains a zero value element at that same array location. Otherwise, that element is set to 0.

Parameters:
X - a matrix
Returns:
~X or not(X)

and

public static org.apache.commons.math.linear.RealMatrix and(org.apache.commons.math.linear.RealMatrix X,
                                                            org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. X and Y must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X & Y or and(X, Y)

or

public static org.apache.commons.math.linear.RealMatrix or(org.apache.commons.math.linear.RealMatrix X,
                                                           org.apache.commons.math.linear.RealMatrix Y)
Do element by element comparisons between X and Y and returns a matrix of the same size with elements set to 1 where the relation is true and elements set to 0 where it is not. X and Y must have the same dimensions.

Parameters:
X - a matrix
Y - a matrix
Returns:
X | Y or or(X, Y)

logicalIndexing

public static org.apache.commons.math.linear.RealMatrix logicalIndexing(org.apache.commons.math.linear.RealMatrix A,
                                                                        org.apache.commons.math.linear.RealMatrix B)
Logical indexing A by B for the syntax A(B). A logical matrix provides a different type of array indexing in MATLAB. While most indices are numeric, indicating a certain row or column number, logical indices are positional. That is, it is the position of each 1 in the logical matrix that determines which array element is being referred to.

Parameters:
A - a real matrix
B - a logical matrix with elements being either 1 or 0
Returns:
A(B)

linearIndexing

public static int[] linearIndexing(int[] V,
                                   int[] indices)
Linear indexing V by an index array.

Parameters:
V - an int array
indices - an int array of selected indices
Returns:
V(indices)

linearIndexing

public static double[] linearIndexing(double[] V,
                                      int[] indices)
Linear indexing V by an index array.

Parameters:
V - an double array
indices - an int array of selected indices
Returns:
V(indices)

linearIndexing

public static org.apache.commons.math.linear.RealMatrix linearIndexing(org.apache.commons.math.linear.RealMatrix A,
                                                                       int[] indices)
Linear indexing A by an index array.

Parameters:
A - a real matrix
indices - an int array of selected indices
Returns:
V(indices)

linearIndexingAssignment

public static void linearIndexingAssignment(org.apache.commons.math.linear.RealMatrix A,
                                            int[] idx,
                                            org.apache.commons.math.linear.RealMatrix V)
Matrix assignment by linear indexing for the syntax A(B) = V.

Parameters:
A - a matrix to be assigned
idx - a linear index vector
V - a column matrix to assign A(idx)

linearIndexingAssignment

public static void linearIndexingAssignment(org.apache.commons.math.linear.RealMatrix A,
                                            int[] idx,
                                            double v)
Matrix assignment by linear indexing for the syntax A(B) = v.

Parameters:
A - a matrix to be assigned
idx - a linear index vector
v - a real scalar to assign A(idx)

logicalIndexingAssignment

public static void logicalIndexingAssignment(org.apache.commons.math.linear.RealMatrix A,
                                             org.apache.commons.math.linear.RealMatrix B,
                                             org.apache.commons.math.linear.RealMatrix V)
Matrix assignment by logical indexing for the syntax A(B) = V.

Parameters:
A - a matrix to be assigned
B - a logical matrix where position of each 1 determines which array element is being assigned
V - a column matrix to assign A(B)

logicalIndexingAssignment

public static void logicalIndexingAssignment(org.apache.commons.math.linear.RealMatrix A,
                                             org.apache.commons.math.linear.RealMatrix B,
                                             double v)
Matrix assignment by logical indexing for the syntax A(B) = v.

Parameters:
A - a matrix to be assigned
B - a logical matrix where position of each 1 determines which array element is being assigned
v - a real scalar to assign A(B)

abs

public static org.apache.commons.math.linear.RealMatrix abs(org.apache.commons.math.linear.RealMatrix A)
Calculate element-wise absolute value of the elements of matrix.

Parameters:
A - a matrix
Returns:
abs(A)

sign

public static org.apache.commons.math.linear.RealMatrix sign(org.apache.commons.math.linear.RealMatrix A)
Signum function.

For each element of X, SIGN(X) returns 1 if the element is greater than zero, 0 if it equals zero and -1 if it is less than zero.

Parameters:
A - a real matrix
Returns:
sign(A)

fix

public static int fix(double x)
Round towards zero.

Parameters:
x - a real number
Returns:
fix(x)

fix

public static org.apache.commons.math.linear.RealMatrix fix(org.apache.commons.math.linear.RealMatrix A)
Round elements of a matrix A towards zero to.

Parameters:
A - a matrix
Returns:
fix(A)

floor

public static org.apache.commons.math.linear.RealMatrix floor(org.apache.commons.math.linear.RealMatrix A)
Round towards minus infinity of elements of a matrix A.

Parameters:
A - a matrix
Returns:
floor(A)

ceil

public static org.apache.commons.math.linear.RealMatrix ceil(org.apache.commons.math.linear.RealMatrix A)
Round elements of a matrix A towards plus infinity.

Parameters:
A - a matrix
Returns:
ceil(A)

round

public static org.apache.commons.math.linear.RealMatrix round(org.apache.commons.math.linear.RealMatrix A)
Round elements of a matrix A towards nearest integer.

Parameters:
A - a matrix
Returns:
round(A)

sqrt

public static org.apache.commons.math.linear.RealMatrix sqrt(org.apache.commons.math.linear.RealMatrix A)
Calculate square root for all elements of a matrix A.

Parameters:
A - a matrix
Returns:
sqrt(A)

diag

public static org.apache.commons.math.linear.RealMatrix diag(org.apache.commons.math.linear.RealVector V)
Generate a diagonal matrix with its elements of a vector V on its main diagonal.

Parameters:
V - a vector
Returns:
diag(V)

diag

public static org.apache.commons.math.linear.RealMatrix diag(double[] V)
Generate a diagonal matrix with its elements of a 1D double array on its main diagonal.

Parameters:
V - a 1D double array holding the diagonal elements
Returns:
diag(V)

diag

public static org.apache.commons.math.linear.RealMatrix diag(org.apache.commons.math.linear.RealMatrix A)
If A is a 1-row or 1-column matrix, then diag(A) is a sparse diagonal matrix with elements of A as its main diagonal, else diag(A) is a column matrix holding A's diagonal elements.

Parameters:
A - a matrix
Returns:
diag(A)

ones

public static org.apache.commons.math.linear.RealMatrix ones(int nRow,
                                                             int nCol)
Generate an all one matrix with nRow rows and nCol columns.

Parameters:
nRow - number of rows
nCol - number of columns
Returns:
ones(nRow, nCol)

ones

public static org.apache.commons.math.linear.RealMatrix ones(int[] size)
Generate an all one matrix with its size specified by a two dimensional integer array.

Parameters:
size - a two dimensional integer array
Returns:
an all one matrix with its shape specified by size

ones

public static org.apache.commons.math.linear.RealMatrix ones(int n)
Generate an n by n all one matrix.

Parameters:
n - number of rows and columns
Returns:
ones(n)

zeros

public static org.apache.commons.math.linear.RealMatrix zeros(int nRow,
                                                              int nCol)
Generate nRow by nCol all zero matrix.

Parameters:
nRow - number of rows
nCol - number of columns
Returns:
zeros(nRow, nCol)

zeros

public static org.apache.commons.math.linear.RealMatrix zeros(int[] size)
Generate an all zero matrix with its size specified by a two dimensional integer array.

Parameters:
size - a two dimensional integer array
Returns:
an all zero matrix with its shape specified by size

zeros

public static org.apache.commons.math.linear.RealMatrix zeros(int n)
Generate an n by n all zero matrix.

Parameters:
n - number of rows and columns
Returns:
ones(n)

size

public static int[] size(org.apache.commons.math.linear.RealMatrix A)
Get a two dimensional integer array for size of a matrix A.

Parameters:
A - a matrix
Returns:
size(A)

size

public static int size(org.apache.commons.math.linear.RealMatrix A,
                       int dim)
Get the dimensionality on dim-th dimension for a matrix A.

Parameters:
A - a matrix
dim - dimension order
Returns:
size(A, dim)

vec

public static org.apache.commons.math.linear.RealMatrix vec(org.apache.commons.math.linear.RealMatrix A)
Vectorize a matrix A.

Parameters:
A - a matrix
Returns:
Vectorization of a matrix A

vertcat

public static org.apache.commons.math.linear.RealMatrix vertcat(org.apache.commons.math.linear.RealMatrix... As)
Concatenate matrices vertically. All matrices in the argument list must have the same number of columns.

Parameters:
As - matrices to be concatenated vertically
Returns:
[A1; A2; ...]

horzcat

public static org.apache.commons.math.linear.RealMatrix horzcat(org.apache.commons.math.linear.RealMatrix... As)
Concatenate matrices horizontally. All matrices in the argument list must have the same number of rows.

Parameters:
As - matrices to be concatenated horizontally
Returns:
[A1 A2 ...]

cat

public static org.apache.commons.math.linear.RealMatrix cat(int dim,
                                                            org.apache.commons.math.linear.RealMatrix... As)
Concatenate matrices along specified dimension.

Parameters:
dim - specified dimension, can only be either 1 or 2 currently
As - matrices to be concatenated
Returns:
a concatenation of all the matrices in the argument list

kron

public static org.apache.commons.math.linear.RealMatrix kron(org.apache.commons.math.linear.RealMatrix A,
                                                             org.apache.commons.math.linear.RealMatrix B)
Calculate the Kronecker tensor product of A and B

Parameters:
A - a matrix
B - a matrix
Returns:
Kronecker product of A and B

reshape

public static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealMatrix A,
                                                                int M,
                                                                int N)
Reshape a matrix to a new shape specified number of rows and columns.

Parameters:
A - a matrix
M - number of rows of the new shape
N - number of columns of the new shape
Returns:
a new M-by-N matrix whose elements are taken columnwise from A

reshape

public static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealMatrix A,
                                                                int[] size)
Reshape a matrix to a new shape specified by a two dimensional integer array.

Parameters:
A - a matrix
size - a two dimensional integer array describing a new shape
Returns:
a new matrix with a shape specified by size

reshape

public static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealVector V,
                                                                int M,
                                                                int N)
Reshape a vector to a new shape specified number of rows and columns.

Parameters:
V - a vector
M - number of rows of the new shape
N - number of columns of the new shape
Returns:
a new M-by-N matrix whose elements are taken from V

reshape

public static org.apache.commons.math.linear.RealMatrix reshape(org.apache.commons.math.linear.RealVector V,
                                                                int[] size)
Reshape a vector to a matrix with a shape specified by a two dimensional integer array.

Parameters:
V - a vector
size - a two dimensional integer array describing a new shape
Returns:
a new matrix with a shape specified by size

sort

public static SortResult sort(org.apache.commons.math.linear.RealMatrix A,
                              int dim,
                              java.lang.String order)
Sort elements of a matrix A on a direction in a specified order. A will not be modified.

Parameters:
A - a matrix to be sorted
dim - sorting direction, 1 for column-wise, 2 for row-wise
order - sorting order, either "ascend" or "descend"
Returns:
a SortResult data structure which has two instance data members:
B: sorted values as a RealMatrix data structure
IX: indices of sorted values in the original matrix

sort

public static SortResult sort(org.apache.commons.math.linear.RealMatrix A,
                              int dim)
Sort elements of a matrix A on a direction in a increasing order. A will not be modified.

Parameters:
A - a matrix to be sorted
dim - sorting direction, 1 for column-wise, 2 for row-wise
Returns:
a SortResult data structure which has two instance data members:
B: sorted values as a RealMatrix data structure
IX: indices of sorted values in the original matrix

sort

public static int[] sort(org.apache.commons.math.linear.RealVector V,
                         java.lang.String order)
Sort elements of a real vector V in place in a specified order.

Parameters:
V - a real vector to be sorted
order - sorting order, either "ascend" or "descend"
Returns:
1D array of indices for sorted values in the original vector

sort2

public static org.apache.commons.math.linear.RealMatrix sort2(org.apache.commons.math.linear.RealMatrix A,
                                                              int dim)
Sort elements of a matrix A on a direction in an increasing order.

Parameters:
A - a matrix, A will be sorted in place
dim - sorting direction, 1 for column-wise, 2 for row-wise
Returns:
index matrix, indices start from 0

sort2

public static org.apache.commons.math.linear.RealMatrix sort2(org.apache.commons.math.linear.RealMatrix A)
Sort elements of a matrix A column-wisely in an increasing order.

Parameters:
A - a matrix, A will be sorted in place
Returns:
index matrix, indices start from 0

sort2

public static org.apache.commons.math.linear.RealMatrix sort2(org.apache.commons.math.linear.RealMatrix A,
                                                              int dim,
                                                              java.lang.String order)
Sort elements of a matrix A on a direction in a specified order.

Parameters:
A - a matrix, A will be sorted in place
dim - sorting direction, 1 for column-wise, 2 for row-wise
order - sorting order, either "ascend" or "descend"
Returns:
index matrix, indices start from 0

sort3

@Deprecated
public static org.apache.commons.math.linear.RealMatrix sort3(org.apache.commons.math.linear.RealMatrix A,
                                                                         int dim,
                                                                         java.lang.String order)
Deprecated. 


sum

public static org.apache.commons.math.linear.RealMatrix sum(org.apache.commons.math.linear.RealMatrix A)
Calculate the sum of a row matrix A or its column-wise sum.

Parameters:
A - a matrix
Returns:
sum(A)

sumAll

public static double sumAll(org.apache.commons.math.linear.RealMatrix A)
Compute the sum of all elements of a matrix.

Parameters:
A - a matrix
Returns:
sum(sum(A))

sum

public static org.apache.commons.math.linear.RealMatrix sum(org.apache.commons.math.linear.RealMatrix A,
                                                            int dim)
Calculate the sum of elements of A on a dimension.

Parameters:
A - a real matrix
dim - 1: column-wise; 2: row-wise
Returns:
sum(A, dim)

sum

public static double sum(org.apache.commons.math.linear.RealVector V)
Compute the sum of all elements of a vector.

Parameters:
V - a vector
Returns:
sum_i V_i

max

public static org.apache.commons.math.linear.RealMatrix max(org.apache.commons.math.linear.RealMatrix A)
Calculate the maximum of a row matrix A or its column-wise maximum.

Parameters:
A - a matrix
Returns:
max(A)

max

public static org.apache.commons.math.linear.RealMatrix max(org.apache.commons.math.linear.RealMatrix A,
                                                            double c)
Calculate maximum between elements of A and a real number and return as a matrix with the same shape of A.

Parameters:
A - a matrix
c - a real number
Returns:
max(A, c)

max

public static org.apache.commons.math.linear.RealMatrix max(double c,
                                                            org.apache.commons.math.linear.RealMatrix A)
Calculate maximum between elements of A and a real number and return as a matrix with the same shape of A.

Parameters:
c - a real number
A - a matrix
Returns:
max(c, A)

max

public static org.apache.commons.math.linear.RealMatrix max(org.apache.commons.math.linear.RealMatrix X,
                                                            org.apache.commons.math.linear.RealMatrix Y)
Calculate element-wise maximum between two matrices X and Y.

Parameters:
X - a real matrix
Y - a real matrix
Returns:
max(X, Y)

max

public static java.util.TreeMap<java.lang.String,org.apache.commons.math.linear.RealMatrix> max(org.apache.commons.math.linear.RealMatrix A,
                                                                                                int dim)
Calculate the maximal value and its row or column index of a matrix A. The row and column indices start from 0.

Parameters:
A - a matrix
dim - dimension order
Returns:
A TreeMap
 "val": maximal values
 "idx": indices of the maximal values in A
         

max1

@Deprecated
public static java.util.ArrayList<org.apache.commons.math.linear.RealMatrix> max1(org.apache.commons.math.linear.RealMatrix A,
                                                                                             int dim)
Deprecated. 


max2

@Deprecated
public static java.util.ArrayList<org.apache.commons.math.linear.RealVector> max2(org.apache.commons.math.linear.RealMatrix A,
                                                                                             int dim)
Deprecated. 


max

public static double[] max(org.apache.commons.math.linear.RealVector V)
Get the maximal value and its index in V.

Parameters:
V - a vector
Returns:
a two dimensional double array int[2] res, res[0] is the maximum, and res[1] is the index

min

public static org.apache.commons.math.linear.RealMatrix min(org.apache.commons.math.linear.RealMatrix A)
Calculate the minimum of a row matrix A or its column-wise minimum.

Parameters:
A - a matrix
Returns:
min(A)

min

public static org.apache.commons.math.linear.RealMatrix min(org.apache.commons.math.linear.RealMatrix A,
                                                            double c)
Calculate minimum between elements of A and a real number and return as a matrix with the same shape of A.

Parameters:
A - a matrix
c - a real number
Returns:
min(A, c)

min

public static org.apache.commons.math.linear.RealMatrix min(double c,
                                                            org.apache.commons.math.linear.RealMatrix A)
Calculate minimum between elements of A and a real number and return as a matrix with the same shape of A.

Parameters:
c - a real number
A - a matrix
Returns:
min(c, A)

min

public static org.apache.commons.math.linear.RealMatrix min(org.apache.commons.math.linear.RealMatrix X,
                                                            org.apache.commons.math.linear.RealMatrix Y)
Calculate element-wise minimum between two matrices X and Y.

Parameters:
X - a real matrix
Y - a real matrix
Returns:
min(X, Y)

min

public static java.util.TreeMap<java.lang.String,org.apache.commons.math.linear.RealMatrix> min(org.apache.commons.math.linear.RealMatrix A,
                                                                                                int dim)
Calculate the minimal value and its row and column index of a matrix A. The row and column indices start from 0.

Parameters:
A - a matrix
dim - dimension order
Returns:
A TreeMap
 "val": minimal values
 "idx": indices of the minimal values in A
         

min1

@Deprecated
public static java.util.ArrayList<org.apache.commons.math.linear.RealMatrix> min1(org.apache.commons.math.linear.RealMatrix A,
                                                                                             int dim)
Deprecated. 


min2

@Deprecated
public static java.util.ArrayList<org.apache.commons.math.linear.RealVector> min2(org.apache.commons.math.linear.RealMatrix A,
                                                                                             int dim)
Deprecated. 


min

public static double[] min(org.apache.commons.math.linear.RealVector V)
Get the minimal value and its index in V.

Parameters:
V - a vector
Returns:
a two dimensional double array int[2] res, res[0] is the minimum, and res[1] is the index

eye

public static org.apache.commons.math.linear.RealMatrix eye(int n)
Construct an n-by-n sparse identity matrix.

Parameters:
n - number of rows and columns
Returns:
an n-by-n sparse identity matrix

eye

public static org.apache.commons.math.linear.RealMatrix eye(int m,
                                                            int n)
Construct an m-by-n sparse identity matrix.

Parameters:
m - number of rows
n - number of columns
Returns:
an m-by-n sparse identity matrix

eye

public static org.apache.commons.math.linear.RealMatrix eye(int... size)
Generate a sparse identity matrix with its size specified by a two dimensional integer array.

Parameters:
size - a two dimensional integer array
Returns:
a sparse identity matrix with its shape specified by size

getTFIDF

public static org.apache.commons.math.linear.RealMatrix getTFIDF(org.apache.commons.math.linear.RealMatrix docTermCountMatrix)
Calculate TFIDF of a doc-term-count matrix, each column is a data sample.

Parameters:
docTermCountMatrix - a matrix, each column is a data sample
Returns:
TFIDF of docTermCountMatrix

normalizeByColumns

public static org.apache.commons.math.linear.RealMatrix normalizeByColumns(org.apache.commons.math.linear.RealMatrix A)
Normalize A by columns.

Parameters:
A - a matrix
Returns:
a column-wise normalized matrix

normalizeByRows

public static org.apache.commons.math.linear.RealMatrix normalizeByRows(org.apache.commons.math.linear.RealMatrix A)
Normalize A by rows.

Parameters:
A - a matrix
Returns:
a row-wise normalized matrix

mldivide

public static org.apache.commons.math.linear.RealMatrix mldivide(org.apache.commons.math.linear.RealMatrix A,
                                                                 org.apache.commons.math.linear.RealMatrix B)
Calculate the left division of the form A \ B. A \ B is the matrix division of A into B, which is roughly the same as INV(A)*B , except it is computed in a different way. For implementation, we actually solve the system of linear equations A * X = B.

Parameters:
A - divisor
B - dividend
Returns:
A \ B

mrdivide

public static org.apache.commons.math.linear.RealMatrix mrdivide(org.apache.commons.math.linear.RealMatrix A,
                                                                 org.apache.commons.math.linear.RealMatrix B)
Calculate the right division of B into A, i.e., A / B. For implementation, we actually solve the system of linear equations X * B = A.

Note: X = A / B <=> X * B = A <=> B' * X' = A' <=> X' = B' \ A' <=> X = (B' \ A')'

Parameters:
A - dividend
B - divisor
Returns:
A / B

inverse

public static org.apache.commons.math.linear.RealMatrix inverse(org.apache.commons.math.linear.RealMatrix A)
Compute the inverse (or pseudo-inverse) of the decomposed matrix A.

Parameters:
A - a matrix
Returns:
A^{-1}

setSubMatrix

public static void setSubMatrix(org.apache.commons.math.linear.RealMatrix A,
                                int[] selectedRows,
                                int[] selectedColumns,
                                org.apache.commons.math.linear.RealMatrix B)
Set submatrix of A with selected rows and selected columns by elements of B. B should have the same shape to the submatrix of A to be set. It is equivalent to the syntax A(selectedRows, selectedColumns) = B.

Parameters:
A - a matrix whose submatrix is to be set
selectedRows - int[] holding indices of selected rows
selectedColumns - int[] holding indices of selected columns
B - a matrix to set the submatrix of A

getRows

public static org.apache.commons.math.linear.RealMatrix getRows(org.apache.commons.math.linear.RealMatrix A,
                                                                int startRow,
                                                                int endRow)
Get the subMatrix containing the elements of the specified rows. Rows are indicated counting from 0.

Parameters:
A - a real matrix
startRow - initial row index (inclusive)
endRow - final row index (inclusive)
Returns:
the subMatrix of A containing the data of the specified rows

getRows

public static org.apache.commons.math.linear.RealMatrix getRows(org.apache.commons.math.linear.RealMatrix A,
                                                                int... selectedRows)
Get the subMatrix containing the elements of the specified rows. Rows are indicated counting from 0.

Parameters:
A - a real matrix
selectedRows - indices of selected rows
Returns:
the subMatrix of A containing the data of the specified rows

getColumns

public static org.apache.commons.math.linear.RealMatrix getColumns(org.apache.commons.math.linear.RealMatrix A,
                                                                   int startColumn,
                                                                   int endColumn)
Get the subMatrix containing the elements of the specified columns. Columns are indicated counting from 0.

Parameters:
A - a real matrix
startColumn - initial column index (inclusive)
endColumn - final column index (inclusive)
Returns:
the subMatrix of A containing the data of the specified rows

getColumns

public static org.apache.commons.math.linear.RealMatrix getColumns(org.apache.commons.math.linear.RealMatrix A,
                                                                   int... selectedColumns)
Get the subMatrix containing the elements of the specified columns. Columns are indicated counting from 0.

Parameters:
A - a real matrix
selectedColumns - indices of selected columns
Returns:
the subMatrix of A containing the data of the specified columns

setMatrix

public static void setMatrix(org.apache.commons.math.linear.RealMatrix X,
                             org.apache.commons.math.linear.RealMatrix Y)
Set all the elements of X to be those of Y, this is particularly useful when we want to change elements of the object referred by X rather than the reference X itself.

Parameters:
X - a matrix to be set
Y - a matrix to set X

sparse

public static org.apache.commons.math.linear.RealMatrix sparse(org.apache.commons.math.linear.RealMatrix D)
Convert a dense matrix into a sparse matrix.

Parameters:
D - a dense matrix
Returns:
a sparse matrix

full

public static org.apache.commons.math.linear.RealMatrix full(org.apache.commons.math.linear.RealMatrix S)
Convert a sparse matrix into a dense matrix.

Parameters:
S - a sparse matrix
Returns:
a dense matrix

double1DArray2Int1DArray

public static int[] double1DArray2Int1DArray(double[] x)
convert a double[] to an int[].

Parameters:
x - a double[]
Returns:
an int[]

double2DArray2Int2DArray

public static int[][] double2DArray2Int2DArray(double[][] X)
convert a double[][] to an int[][].

Parameters:
X - a double[][]
Returns:
an int[][]

disp

public static void disp(org.apache.commons.math.linear.RealMatrix M)
Display a matrix.

Parameters:
M - a matrix

disp

public static void disp(org.apache.commons.math.linear.RealMatrix M,
                        int p)
Display a matrix with a specified precision.

Parameters:
M - a matrix
p - number of digits after decimal point with rounding

disp

public static void disp(java.lang.String str)
Display a string.

Parameters:
str - a string to display

display

public static void display(org.apache.commons.math.linear.RealMatrix M)
Display a matrix.

Parameters:
M - a matrix

display

public static void display(org.apache.commons.math.linear.RealMatrix M,
                           int p)
Display a matrix with a specified precision.

Parameters:
M - a matrix
p - number of digits after decimal point with rounding

display

public static void display(int[][] M)
Display an integer 2D array.

Parameters:
M - an integer 2D array

display

public static void display(double[][] M)
Display a real valued 2D array.

Parameters:
M - a real valued 2D array

display

public static void display(double[][] M,
                           int p)
Display a real valued 2D array with a specified precision.

Parameters:
M - a real valued 2D array
p - number of digits after decimal point with rounding

display

public static void display(double v)
Display a double scalar.

Parameters:
v - a double scalar

display

public static void display(java.lang.String s)
Display a string.

Parameters:
s - a string

display

public static void display(org.apache.commons.math.linear.RealVector V)
Display a vector.

Parameters:
V - a vector

display

public static void display(double[] V)
Display a 1D double array.

Parameters:
V - a 1D double array

display

public static void display(double[] V,
                           int p)
Display a 1D double array with a specified precision.

Parameters:
V - a 1D double array
p - number of digits after decimal point with rounding

display

public static void display(int[] V)
Display a 1D integer array.

Parameters:
V - a 1D integer array

printMatrix

public static void printMatrix(org.apache.commons.math.linear.RealMatrix M)
Print a matrix.

Parameters:
M - a matrix

printMatrix

public static void printMatrix(org.apache.commons.math.linear.RealMatrix M,
                               int p)
Print a matrix with a specified precision.

Parameters:
M - a matrix
p - number of digits after decimal point with rounding

printSparseMatrix

private static void printSparseMatrix(org.apache.commons.math.linear.RealMatrix M)
Print a sparse matrix.

Parameters:
M - a sparse matrix

printVector

public static void printVector(org.apache.commons.math.linear.RealVector V)
Print a vector.

Parameters:
V - a vector

printVector

public static void printVector(org.apache.commons.math.linear.RealVector V,
                               int p)
Print a vector with a specified precision.

Parameters:
V - a vector
p - number of digits after decimal point with rounding

fprintf

public static void fprintf(java.lang.String format,
                           java.lang.Object... os)
Write a formatted string to the standard output (the screen).

Parameters:
format - a string in single quotation marks that describes the format of the output fields
os - argument list applying the format to

sprintf

public static java.lang.String sprintf(java.lang.String format,
                                       java.lang.Object... os)
Format variables into a string.

Parameters:
format - a string in single quotation marks that describes the format of the output fields
os - argument list applying the format to
Returns:
a formatted string

l2NormByRows

public static org.apache.commons.math.linear.RealMatrix l2NormByRows(org.apache.commons.math.linear.RealMatrix A)
Calculate the l_2 norm of a vector or row vectors of a matrix.

Parameters:
A - a vector or a matrix
Returns:
the l_2 norm of a vecor or row vectors of a matrix