The Java Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the Matrix Class involve real matrices. Complex matrices may be handled in a future version.
Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the Matrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:
double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}}; Matrix A = new Matrix(vals); Matrix b = Matrix.random(3,1); Matrix x = A.solve(b); Matrix r = A.times(x).minus(b); double rnorm = r.normInf();
The Java Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the Matrix Class involve real matrices. Complex matrices may be handled in a future version.
Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the Matrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:
double[][] vals = { { 1., 2., 3 }, { 4., 5., 6. }, { 7., 8., 10. } }; Matrix A = new Matrix(vals); Matrix b = Matrix.random(3, 1); Matrix x = A.solve(b); Matrix r = A.times(x).minus(b); double rnorm = r.normInf();
The following features are supported:
@author Adrian Kuhn
The Java Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the Matrix Class involve real matrices. Complex matrices may be handled in a future version.
Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the Matrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:
double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}}; Matrix A = new Matrix(vals); Matrix b = Matrix.random(3,1); Matrix x = A.solve(b); Matrix r = A.times(x).minus(b); double rnorm = r.normInf();
double
s in a rectangular 2D array, and it is used alongside Vector
in numerical computations. Implementing classes decides on the actual storage. Use numRows
and numColumns
to get the basic size of a matrix. get(int,int)
gets an element, and there are corresponding set(int,int,double)
and add(int,int,double)
methods as well. Note that matrix indices are zero-based (typical for Java and C). This means that the row-indices range from 0 to numRows-1
, likewise for the columns. It is legal to have numRows
or numColumns
equal zero.
Other basic operations are zero
which zeros all the entries of the matrix, which can be cheaper than either zeroing the matrix manually, or creating a new matrix, and the operation copy
which creates a deep copy of the matrix. This copy has separate storage, but starts with the same contents as the current matrix.
The matrix interface extends Iterable
, and the iterator returns a MatrixEntry
which contains current index and entry value. Note that the iterator may skip non-zero entries. Using an iterator, many simple and efficient algorithms can be created. The iterator also permits changing values in the matrix, however only non-zero entries can be changed.
A large selection of basic linear algebra operations are available. To ensure high efficiency, little or no internal memory allocation is done, and the user is required to supply the output arguments.
The operations available include:
A very simple matrix class, that is actually nothing more then a POJO object.
@author Pieter De GraefA very simple matrix definition. Used for transformations on geometries, HTML objects or vector objects.
@author Pieter De Graef @since 1.0.0Performance of multidimensional arrays is a big concern in Java. This is because multidimensional arrays are stored as arrays of arrays, spanning this concept to as many depths as necessary. In C++, a multidimensional array is stored internally as a unidimensional array where depths are stacked together one after another. A very simple calculation is needed in order to map multiple dimensional indexes to an unidimensional index.
This class provides a C/C++ like approach of internal unidimensional array backing a conceptual bidimensional matrix. This mapping is provided by method The mentioned access method is provided by a concrete implementation of {@link Address} which is passed to constructors.Doing so, it is possible to access the same underlying unidimensional data storage in various different ways, which allows us obtain another Matrix (see method {@link Matrix#range(int,int,int,int) and alike}) from an existing Matrix without any need of copying the underlying data. Certain operations benefit a lot from such approach, like {@link Matrix#transpose()} whichpresents constant execution time. The price we have to pay for such flexibility and benefits is that an access method is necessary, which means that a the bytecode may potentially need a dereference to a class which contain the concrete implementation of method Assignment operations Algebraic products Vectorial products Decompositions Element iterators Miscellaneous (1): clone()
@note This class is not thread-safe
@author Richard Gomes
op(int row, int col)
which is responsible for returning the physical address of the desired tuple op(int row, int col)
. In order to keep this cost at minimum, implementation of access method keep indexes at hand whenever possible, in order to being able to calculate the actual unidimensional index as fast as possible. This additional dereference impacts performance more or less in the same ways dereference impacts performance when a bidimensional array (double[][]
) is employed. Contrary to the bidimensional implementation, our implementation can potentially benefit from bytecode inlining, which means that calculation of the unidimensional index can be performed potentially faster than calculation of address location when a bidimensional array (double[][]
) is used as underlying storage. opr method this right result --- ---------- ------- -------- ------ = assign Matrix Matrix (1) += addAssign Matrix Matrix this -= subAssign Matrix Matrix this *= mulAssign Matrix scalar this /= divAssign Matrix scalar this
opr method this right result --- ---------- ------- -------- ------ + add Matrix Matrix Matrix - sub Matrix Matrix Matrix - negative Matrix this * mul Matrix scalar Matrix / div Matrix scalar Matrix
method this right result -------------- ------- -------- ------ mul Matrix Array Array mul Matrix Matrix Matrix
method this right result -------------- ------- -------- ------ lu Matrix LUDecomposition qr Matrix QRDecomposition cholensky Matrix CholeskyDecomposition svd Matrix SingularValueDecomposition eigenvalue Matrix EigenvalueDecomposition
method this right result ------------ ------- -------- ------ rowIterator Matrix RowIterator columnIterator Matrix ColumnIterator
method this right result -------------- ------- -------- ------ transpose Matrix Matrix diagonal Matrix Array determinant Matrix double inverse Matrix Matrix solve Matrix Matrix swap Matrix Matrix this range Matrix Matrix Matrix
(2): Unary + is equivalent to: array.clone()
(3): Unary ? is equivalent to: array.clone().mulAssign(-1)
Matrix
defines and maintains a 4x4 matrix in row major order. This matrix is intended for use in a translation and rotational capacity. It provides convenience methods for creating the matrix from a multitude of sources. Matrices are stored assuming column vectors on the right, with the translation in the rightmost column. Element numbering is row,column, so m03 is the zeroth row, third column, which is the "x" translation part. This means that the implicit storage order is column major. However, the get() and set() functions on float arrays default to row major order! Copyright (c) JMonkeyEngine
@author Mark Powell
@author Joshua Slack
@author C.Ruff
weka.core.matrix
- only for backwards compatibility.
@author Gabi Schmidberger (gabi@cs.waikato.ac.nz)
@author Yong Wang (yongwang@cs.waikato.ac.nz)
@author Eibe Frank (eibe@cs.waikato.ac.nz)
@author Len Trigg (eibe@cs.waikato.ac.nz)
@author Fracpete (fracpete at waikato dot ac dot nz)
@version $Revision: 1.25 $
@deprecated Use weka.core.matrix.Matrix
instead - only forbackwards compatibility.
@author
tag.
@author The Mathworks and NIST
@author Fracpete (fracpete at waikato dot ac dot nz)
@version $Revision: 1.8 $
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|