Android Programming Press on the image to return to the main documentation page.

EJML

Written by Andrew Graham

This library is based on EJML - efficient-java-matrix-library.
A fast and easy to use dense matrix linear algebra library written in Java.
http://code.google.com/p/efficient-java-matrix-library/

Not all the functionality of EJML is exposed to Basic4android
This library exposes SimpleMatrix which is an interface that provides an easy to use
object oriented way of doing linear algebra.
SimpleMatrix

Simplified ways to use popular matrix decompositions are provided.
These decompositions should meet most people needs.
SVD : Computes the singular value decomposition of 'this' matrix.
EIG : Computes the eigen value decomposition of 'this' matrix.

EJML and therefore also this library is licensed under the GNU Lesser General Public License.
http://www.gnu.org/licenses/lgpl.html
Copies of both the General Public License and Lesser General Public License are in the provided archive.

Copyright 2013 Anywhere Software

List of types:

SimpleEVD
SimpleMatrix
SimpleSVD

SimpleEVD

This object holds the Eigendecomposition of a matrix.
Eigenvalues and eigenvectors have the following property: A*v=λ*v
where A is a square matrix and v is an eigenvector associated with the eigenvalue λ.

In general, both eigenvalues and eigenvectors can be complex numbers.
For symmetric matrices the eigenvalues and eigenvectors are always real numbers.
EJML does not support complex matrices but it does have minimal support for complex numbers.
As a result complex eigenvalues are found, but only the real eigenvectors are computed.

Events:

None

Members:


  GetEigenvalue (index As Int) As Double()

  GetEigenVector (index As Int) As SimpleMatrix

  IndexMax As Int [read only]

  IndexMin As Int [read only]

  NumberOfEigenvalues As Int [read only]

  Quality As Double

Members description:

GetEigenvalue (index As Int) As Double()
Returns an eigenvalue as a complex number, a Double(2) where 0 is the real component and 1 the imaginary.

For symmetric matrices the returned eigenvalue will always be a real number,
which means the imaginary component will be equal to zero.

NOTE: The order of the eigenvalues is dependent upon the decomposition algorithm used.
This means that they may or may not be ordered by magnitude.
GetEigenVector (index As Int) As SimpleMatrix
Used to retrieve real valued eigenvectors.
If an eigenvector is associated with a complex eigenvalue then null is returned instead.
IndexMax As Int [read only]
Returns the index of the eigenvalue which has the largest magnitude.
IndexMin As Int [read only]
Returns the index of the eigenvalue which has the smallest magnitude.
NumberOfEigenvalues As Int [read only]
Returns the number of eigenvalues/eigenvectors. This is the matrix's dimension.
Quality As Double
Computes the quality of the computed decomposition.
A value close to or less than 1e-15 is considered to be within machine precision.

This function must be called before the original matrix has been modified
or else it will produce meaningless results.

SimpleMatrix

SimpleMatrix is an interface that provides an easy to use object oriented way of doing linear algebra.
It is a wrapper around the operation interface in EJML and was originally inspired by Jama.
When using SimpleMatrix memory management is automatically handled and it allows commands to be chained
together as many of the operations return the SimpleMatrix itself.

For example A.Transpose().Mult(B).Scale(12).Invert. Such expressions are evaluated left to right.

The typical method in SimpleMatrix takes at least one SimpleMatrix as an input and returns a SimpleMatrix.
None of the input matrices are modified during function calls, a new matrix is always returned.

The names of the methods in this library are as far as possible the names in the original EJML libray.

The EJML documentation should be studied for more information on SimpleMatrix.
SimpleMatrix

Events:

None

Members:


  Combine (insertRow As Int, insertCol As Int, B As SimpleMatrix) As SimpleMatrix

  ConditionP2 As Double

  Copy As SimpleMatrix

  Data() As Double

  Determinant As Double

  Divide (val As Double) As SimpleMatrix

  Dot (V As SimpleMatrix) As Double

  EIG As SimpleEVD

  ElementMaxAbs As Double

  ElementMult (B As SimpleMatrix) As SimpleMatrix

  ElementSum As Double

  END As Int

  ExtractDiag As SimpleMatrix

  ExtractMatrix (y0 As Int, y1 As Int, x0 As Int, x1 As Int) As SimpleMatrix

  ExtractVector (extractRow As Boolean, element As Int) As SimpleMatrix

  GetElement (row As Int, col As Int) As Double

  GetElement1D (index As Int) As Double

  GetIndex (row As Int, col As Int) As Int

  GetNumElements As Int

  HasUncountable As Boolean

  Initialize (numRows As Int, numCols As Int)

  Initialize2 (double2Darray(,) As Double)

  Initialize3 (simplematrix As SimpleMatrix)

  Initialize4 (width As Int)

  Initialize5 (values() As Double)

  Initialize6 (numRows As Int, numCols As Int, minValue As Double, maxValue As Double)

  InsertIntoThis (insertRow As Int, insertCol As Int, B As SimpleMatrix)

  Invert As SimpleMatrix

  IsIdentical (B As SimpleMatrix, tol As Double) As Boolean

  IsInBounds (row As Int, col As Int) As Boolean

  IsVector As Boolean

  Kron (B As SimpleMatrix) As SimpleMatrix

  LoadBinary (pathandfileName As String) As SimpleMatrix

  LoadCSV (pathandfileName As String) As SimpleMatrix

  Minus (B As SimpleMatrix) As SimpleMatrix

  Mult (B As SimpleMatrix) As SimpleMatrix

  Negative As SimpleMatrix

  NormF As Double

  NumCols As Int

  NumRows As Int

  Plus (B As SimpleMatrix) As SimpleMatrix

  PlusScaled (beta As Double, B As SimpleMatrix) As SimpleMatrix

  PseudoInverse (pathandfileName As String) As SimpleMatrix

  Reshape (numRows As Int, numCols As Int)

  SaveToFileBinary (pathandfileName As String)

  SaveToFileCSV (pathandfileName As String)

  Scale (val As Double) As SimpleMatrix

  SetColumn (column As Int, offset As Int, values() As Double)

  SetDouble (val As Double)

  SetElement (row As Int, col As Int, value As Double)

  SetElement1D (index As Int, value As Double)

  SetMatrix (A As SimpleMatrix)

  SetRow (row As Int, offset As Int, values() As Double)

  Solve (B As SimpleMatrix) As SimpleMatrix

  SVD (iscompact As Boolean) As SimpleSVD

  ToString As String

  Trace As Double

  Transpose As SimpleMatrix

  Version As Double [read only]

  Zero

Members description:

Combine (insertRow As Int, insertCol As Int, B As SimpleMatrix) As SimpleMatrix
Creates a new matrix that is a combination of this matrix and matrix B.
B is written into A at the specified location if needed the size of A is increased by growing it.
A is grown by padding the new area with zeros.
While useful when adding data to a matrix which will be solved for it is also much less efficient than
predeclaring a matrix and inserting data into it.
If insertRow or insertCol is set to SimpleMatrix.END then it will be combined at the last row or column respectively.
ConditionP2 As Double
The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b.
A value near one indicates that it is a well conditioned matrix.
Copy As SimpleMatrix
Creates and returns a matrix which is idential to this one.
Data() As Double
Gets or sets a reference to the underlying Double array of data for the matrix.
Determinant As Double
Computes and returns the determinant of the matri.x
Divide (val As Double) As SimpleMatrix
Returns a new matrix, the result of dividing each element of 'this' by 'val': Bi,j = Ai,j/val
Dot (V As SimpleMatrix) As Double
Computes the dot product (a.k.a. inner product) between this vector and vector 'V'.
EIG As SimpleEVD
Computes the Eigendecomposition of a matrix.
Eigenvalues and eigenvectors have the following property: A*v=λ*v
where A is a square matrix and v is an eigenvector associated with the eigenvalue λ.

In general, both eigenvalues and eigenvectors can be complex numbers.
For symmetric matrices the eigenvalues and eigenvectors are always real numbers.
EJML does not support complex matrices but it does have minimal support for complex numbers.
As a result complex eigenvalues are found, but only the real eigenvectors are computed.

Returns a SimpleEVD for assignment to a SimpleEVD variable.
ElementMaxAbs As Double
Returns the maximum absolute value of all the elements in this matrix.
This is equivalent the the infinite p-norm of the matrix.
ElementMult (B As SimpleMatrix) As SimpleMatrix
Returns a matrix which is the result of an element by element multiplication of 'this' and 'B'
Ci,j = Ai,j*Bi,j
ElementSum As Double
Returns the sum of all the elements in the matrix.
END As Int
Constant for defining the last row or column of a SimpleMatrix.
ExtractDiag As SimpleMatrix
Extracts the diagonal from this matrix and returns the values inside a column vector.
ExtractMatrix (y0 As Int, y1 As Int, x0 As Int, x1 As Int) As SimpleMatrix
Extracts the diagonal from this matrix and returns the values inside a column vector.
ExtractVector (extractRow As Boolean, element As Int) As SimpleMatrix
Extracts a row or column from this matrix.
The returned vector will either be a row or column vector depending on the input type.
extractRow - If true a row will be extracted.
element - The row or column the vector is contained in.
GetElement (row As Int, col As Int) As Double
Returns the value of the specified matrix element.
Performs a bounds check to make sure the requested element is part of the matrix.
GetElement1D (index As Int) As Double
GetIndex (row As Int, col As Int) As Int
GetNumElements As Int
Returns the number of elements in this matrix
which is equal to the number of rows times the number of columns.
HasUncountable As Boolean
Checks to see if any of the elements in this matrix are either NaN or infinite.
Returns True if an element is NaN or infinite, False otherwise.
Initialize (numRows As Int, numCols As Int)
Creates a new matrix that is initially set to zero with the specified dimensions.
Initialize2 (double2Darray(,) As Double)
Creates a matrix with the values and shape defined by the 2D array 'data'.
It is assumed that 'data' has a row-major formatting: data[ row ][ column ]
Initialize3 (simplematrix As SimpleMatrix)
Creats a new copy of a SimpleMatrix which is identical to the original.
Note that
Dim NewMatrix As SimpleMatrix
NewMatrix.Initialize3(OldMatrix)


is identical to

Dim NewMatrix As SimpleMatrix
NewMatrix = OldMatrix.Copy
Initialize4 (width As Int)
Creates a new identity matrix with the specified size
Initialize5 (values() As Double)
Creates a matrix where all but the diagonal elements are zero.
The values of the diagonal elements are specified by the parameter 'values'.
Initialize6 (numRows As Int, numCols As Int, minValue As Double, maxValue As Double)
Creates a new SimpleMatrix with random elements drawn from a uniform distribution from minValue to maxValue.
InsertIntoThis (insertRow As Int, insertCol As Int, B As SimpleMatrix)
Copy matrix B into this matrix at location (insertRow, insertCol).
This method is one of the few that changes this matrix rather returning a new one.
Invert As SimpleMatrix
Returns the inverse of this matrix: B = A^-1
If the matrix could not be inverted then SingularMatrixException is thrown.
Even if no exception is thrown the matrix could still be singular or nearly singular.
IsIdentical (B As SimpleMatrix, tol As Double) As Boolean
Returns true if matrix 'B' is the same as this matrix within the specified tolerance.
IsInBounds (row As Int, col As Int) As Boolean
Returns true if the specified matrix element is a valid element inside this matrix.
IsVector As Boolean
Returns true if this matrix is a vector.
Kron (B As SimpleMatrix) As SimpleMatrix
Returns the computed Kronecker product between this matrix and the provided B matrix:
C = kron(A,B)
LoadBinary (pathandfileName As String) As SimpleMatrix
Returns a new matrix loaded from a serialized binary file.
LoadCSV (pathandfileName As String) As SimpleMatrix
Returns a new matrix loaded from a CSV file.
Minus (B As SimpleMatrix) As SimpleMatrix
Returns a matrix which is the result of matrix subtraction: C = A - B
where C is the returned matrix, A is this matrix, and B is the passed in matrix.
Mult (B As SimpleMatrix) As SimpleMatrix
Returns a matrix which is the result of matrix multiplication: C = A * B
where C is the returned matrix, A is this matrix, and B is the passed in matrix.
Negative As SimpleMatrix
Returns a new matrix whose elements are the negative of 'this' matrix's elements
NormF As Double
Computes the Frobenius normal of the matrix: normF = Sqrt{ ∑i=1:m ∑j=1:n { aij2} }
NumCols As Int
Returns the number of columns in this matrix.
NumRows As Int
Returns the number of rows in this matrix.
Plus (B As SimpleMatrix) As SimpleMatrix
Returns a new matrix, the result of matrix addition: C = A + B
where C is the returned matrix, A is this matrix, and B is the passed in matrix.
PlusScaled (beta As Double, B As SimpleMatrix) As SimpleMatrix
Returns a new matrix, the result of matrix addition and scaling: C = A + beta*B
where C is the returned matrix, Z is this matrix, and B is the passed in matrix.
PseudoInverse (pathandfileName As String) As SimpleMatrix
Computes the Moore-Penrose pseudo-inverse matrix of this and returns a new matrix.
Reshape (numRows As Int, numCols As Int)
Reshapes the matrix to the specified number of rows and columns.
If the total number of elements is <= number of elements it had before the data is saved.
Otherwise a new internal array is declared and the old data lost.
This method is one of the few that changes this matrix rather returning a new one.
SaveToFileBinary (pathandfileName As String)
Saves this matrix to a file as a serialized binary object.
SaveToFileCSV (pathandfileName As String)
Saves this matrix to a file in a CSV format.
For the file format see MatrixIO in the original EJML documentation.
Scale (val As Double) As SimpleMatrix
Returns a new matrix, the result of scaling each element by 'val': Bi,j = val*Ai,j
SetColumn (column As Int, offset As Int, values() As Double)
Assigns consecutive elements inside a column to the provided array.
A(offset:(offset + values.length),column) = values
SetDouble (val As Double)
Sets all the elements in this matrix equal to the specified value.
SetElement (row As Int, col As Int, value As Double)
Assigns the pscified element in the Matrix to the specified value
SetElement1D (index As Int, value As Double)
SetMatrix (A As SimpleMatrix)
Sets the elements in this matrix to be equal to the elements in the passed in matrix.
Both matrix must have the same dimension.
SetRow (row As Int, offset As Int, values() As Double)
Assigns consecutive elements inside a row to the provided array.
A(offset:(offset + values.length),row) = values
Solve (B As SimpleMatrix) As SimpleMatrix
Solves for X in the following equation: x = A^-1 * B
where 'A' is this matrix and 'B' is an n by p matrix.

If the system could not be solved then a SingularMatrixException is thrown.
Even if no exception is thrown 'A' could still be singular or nearly singular.
SVD (iscompact As Boolean) As SimpleSVD
Computes the Singular Value Decomposition (SVD) of this matrix, which is defined as A = U * W * V^T
where A is m by n, and U and V are orthogonal matrices, and W is a diagonal matrix.
The eigenvalues are ordered from largest to smallest.

Returns a SimpleSVD for assignment to a SimpleSVD variable.

If compact is True then compact matrices will be returned from the SVD.
See the help for SimpleSVD for a definition of compact matrices.
ToString As String
Converts the array into a string format for display purposes.
Trace As Double
Computes and returns the trace of the matrix.
Transpose As SimpleMatrix
Returns a new matrix which is the transpose of this matrix
Version As Double [read only]
Returns the version of the library.
Zero
Sets all the elements in this matrix equal to zero.

SimpleSVD

This object holds the Singular Value Decomposition (SVD) of a matrix, which is defined as A = U * W * V^T
where A is m by n, and U and V are orthogonal matrices, and W is a diagonal matrix.

The dimension of U,W,V depends if it is a compact SVD or not.
If not compact then U is m by m, *W is m by n, V is n by n.
If compact then let s be the number of singular values, U is m by s, W is s by s, and V is n by s.

Events:

None

Members:


  GetSingleValue (index As Int) As Double

  GetSingularValues (index As Int) As Double()

  GetU As SimpleMatrix

  GetV As SimpleMatrix

  GetW As SimpleMatrix

  IsCompact As Boolean

  Nullity As Int

  NullSpace As SimpleMatrix

  NumberOfSingularValues As Int

  NumCols As Int

  NumRows As Int

  Rank As Int

Members description:

GetSingleValue (index As Int) As Double
Returns the specified singular value.
GetSingularValues (index As Int) As Double()
Returns all the singular values as a Double array.
GetU As SimpleMatrix
Returns the orthogonal 'U' m x m matrix as a SimpleMatrix
GetV As SimpleMatrix
Returns the orthogonal 'V' n x n matrix as a SimpleMatrix
GetW As SimpleMatrix
Returns a diagonal matrix with the singular values along the diagonal as a SimpleMatrix.
The singular values are ordered from largest to smallest.
IsCompact As Boolean
If true then compact matrices are returned.
Nullity As Int
Returns the nullity of the decomposed matrix.
NullSpace As SimpleMatrix
Returns the computed null space of the decomposed matrix as a SimpleMatrix.
The null space is a set of non-zero vectors that when multiplied by the original matrix return zero.
The null space is found by extracting the columns in V that are associated singular values less than or equal to the threshold.
In some situations a non-compact SVD is required.
NumberOfSingularValues As Int
Returns the number of singular values in the decomposed matrix.
NumCols As Int
Returns the number of columns in the decomposed matrix.
NumRows As Int
Returns the number of rows in the decomposed matrix.
Rank As Int
Returns the rank of the decomposed matrix.
Top