Documentation of 'org.jquantlib.math.matrixutilities.Matrix' Java class
Matrix
org.jquantlib.math.matrixutilities

Class Matrix

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    Identity


    public class Matrix
    extends Cells<Address.MatrixAddress>
    implements java.lang.Cloneable
    Bidimensional matrix operations

    Performance 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 op(int row, int col) which is responsible for returning the physical address of the desired tuple , given a certain access method.

    The mentioned access method is provided by a concrete implementation of 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 and alike) from an existing Matrix without any need of copying the underlying data. Certain operations benefit a lot from such approach, like transpose() which presents 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 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.

    Assignment operations

       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
     

    Algebraic products

       opr method     this    right    result
       --- ---------- ------- -------- ------
       +   add        Matrix  Matrix   Matrix
       -   sub        Matrix  Matrix   Matrix
       -   negative   Matrix           this
       *   mul        Matrix  scalar   Matrix
       /   div        Matrix  scalar   Matrix
     

    Vectorial products

       method         this    right    result
       -------------- ------- -------- ------
       mul            Matrix  Array    Array
       mul            Matrix  Matrix   Matrix
     

    Decompositions

       method         this    right    result
       -------------- ------- -------- ------
       lu             Matrix           LUDecomposition
       qr             Matrix           QRDecomposition
       cholensky      Matrix           CholeskyDecomposition
       svd            Matrix           SingularValueDecomposition
       eigenvalue     Matrix           EigenvalueDecomposition
     

    Element iterators

       method         this    right    result
       ------------   ------- -------- ------
       rowIterator    Matrix           RowIterator
       columnIterator Matrix           ColumnIterator
     

    Miscellaneous

       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
     

    (1): clone()
    (2): Unary + is equivalent to: array.clone()
    (3): Unary ? is equivalent to: array.clone().mulAssign(-1)

    • Constructor Detail

      • Matrix

        public Matrix()
        Default constructor

        Builds a Matrix with dimensions 1x1

      • Matrix

        public Matrix(java.util.Set<Address.Flags> flags)
        Default constructor

        Builds a Matrix with dimensions 1x1

        Parameters:
        flags - is a Set<Address.Flags>
        See Also:
        Address.Flags
      • Matrix

        public Matrix(int rows,
                      int cols)
        Builds a Matrix of rows by cols
        Parameters:
        rows - is the number of rows
        cols - is the number of columns
        Throws:
        java.lang.IllegalArgumentException - if parameters are less than zero
      • Matrix

        public Matrix(int rows,
                      int cols,
                      java.util.Set<Address.Flags> flags)
        Builds a Matrix of rows by cols
        Parameters:
        rows - is the number of rows
        cols - is the number of columns
        flags - is a Set<Address.Flags>
        Throws:
        java.lang.IllegalArgumentException - if parameters are less than zero
        See Also:
        Address.Flags
      • Matrix

        public Matrix(double[][] data)
        Creates a Matrix given a double[][] array
        Parameters:
        data -
      • Matrix

        public Matrix(double[][] data,
                      java.util.Set<Address.Flags> flags)
        Creates a Matrix given a double[][] array
        Parameters:
        data -
      • Matrix

        public Matrix(Matrix m)
        copy constructor
        Parameters:
        $ -
    • Method Detail

      • _

        @Deprecated
        public int _(int row,
                                 int col)
        Deprecated. 
        This is a convenience method intended to return the physical address of an element.

        The use of this method is highly discouraged

        Parameters:
        index - is a logical address of an element
        Returns:
        the physical address to an element
        See Also:
        Cells.$
      • get

        public double get(int row,
                          int col)
        Retrieves an element of this Matrix which identified by (row, col)
        Parameters:
        row - coordinate
        col - coordinate
        Returns:
        the contents of a given cell
      • set

        public void set(int row,
                        int col,
                        double value)
        Stores a value into an element of this Matrix which is identified by (row, col)
        Parameters:
        row - coordinate
        col - coordinate
      • addAssign

        public Matrix addAssign(Matrix another)
        Returns the result of an addition of this Matrix and another Matrix
        Parameters:
        another -
        Returns:
        this
      • subAssign

        public Matrix subAssign(Matrix another)
        Returns the result of a subtraction of this Matrix and another Matrix
        Parameters:
        another -
        Returns:
        this
      • mulAssign

        public Matrix mulAssign(double scalar)
        Returns the result of a multiplication of this Matrix by a scalar
        Parameters:
        scalar -
        Returns:
        this
      • divAssign

        public Matrix divAssign(double scalar)
        Returns the result of a division of this Matrix by a scalar
        Parameters:
        scalar -
        Returns:
        this
      • add

        public Matrix add(Matrix another)
        Returns the result of addition of this Matrix and another Matrix
        Parameters:
        another -
        Returns:
        a new instance
      • sub

        public Matrix sub(Matrix another)
        Returns the result of a subtraction of this Matrix and another Matrix
        Parameters:
        another -
        Returns:
        a new instance
      • negative

        public Matrix negative()
        Returns the negative of this Matrix
        Returns:
        this
      • mul

        public Matrix mul(double scalar)
        Returns the result of a multiplication of this Matrix by a scalar
        Parameters:
        scalar -
        Returns:
        a new instance
      • div

        public Matrix div(double scalar)
        Returns the result of a division of this Matrix by a scalar
        Parameters:
        scalar -
        Returns:
        a new instance
      • mul

        public Array mul(Array array)
        Returns an Array which represents the multiplication of this Matrix by an Array
        Parameters:
        array - is the input Array which participates in the operation
        Returns:
        a new Array which contains the result
      • mul

        public Matrix mul(Matrix another)
        Returns a Matrix which represents the multiplication of this Matrix and another Matrix
        Parameters:
        another -
        Returns:
        a new Matrix which contains the result
      • lu

        public LUDecomposition lu()
        LU Decomposition
        Parameters:
        moreGreeks - is a rectangular Matrix
        Returns:
        Structure to access L, U and piv.
      • svd

        public SVD svd()
        Singular Value Decomposition
        Returns:
        SingularValueDecomposition
        See Also:
        SVD
      • transpose

        public Matrix transpose()
        Returns the transpose of this Matrix
        Returns:
        a new instance which contains the result of this operation
      • diagonal

        public Array diagonal()
        Returns a diagonal from this Matrix, if it is square
        Returns:
        a new instance which contains the result of this operation
      • determinant

        public double determinant()
        Determinant
        Returns:
        determinant of matrix
        Throws:
        java.lang.IllegalArgumentException - Matrix must be square
      • inverse

        public Matrix inverse()
        Returns an inverse Matrix from this Matrix
        Returns:
        a new instance which contains the result of this operation
      • rangeRow

        public Array rangeRow(int row)
      • rangeRow

        public Array rangeRow(int row,
                              int col0)
      • rangeRow

        public Array rangeRow(int row,
                              int col0,
                              int col1)
      • rangeCol

        public Array rangeCol(int col)
      • rangeCol

        public Array rangeCol(int col,
                              int row0)
      • rangeCol

        public Array rangeCol(int col,
                              int row0,
                              int row1)
      • range

        public Matrix range(int row0,
                            int row1,
                            int col0,
                            int col1)
      • range

        public Matrix range(int[] ridx,
                            int col0,
                            int col1)
      • range

        public Matrix range(int row0,
                            int row1,
                            int[] cidx)
      • range

        public Matrix range(int[] ridx,
                            int[] cidx)
      • constRangeRow

        public Array constRangeRow(int row)
      • constRangeRow

        public Array constRangeRow(int row,
                                   int col0)
      • constRangeRow

        public Array constRangeRow(int row,
                                   int col0,
                                   int col1)
      • constRangeCol

        public Array constRangeCol(int col)
      • constRangeCol

        public Array constRangeCol(int col,
                                   int row0)
      • constRangeCol

        public Array constRangeCol(int col,
                                   int row0,
                                   int row1)
      • constRange

        public Matrix constRange(int row0,
                                 int row1,
                                 int col0,
                                 int col1)
      • constRange

        public Matrix constRange(int[] ridx,
                                 int col0,
                                 int col1)
      • constRange

        public Matrix constRange(int row0,
                                 int row1,
                                 int[] cidx)
      • constRange

        public Matrix constRange(int[] ridx,
                                 int[] cidx)
      • toFortran

        public Matrix toFortran()
      • toJava

        public Matrix toJava()
      • fill

        public Matrix fill(double scalar)
      • fillRow

        public void fillRow(int row,
                            Array array)
        Overwrites contents of a certain row
        Parameters:
        row - is the requested row to be overwritten
        array - contains the elements to be copied
      • fillCol

        public void fillCol(int col,
                            Array array)
        Overwrites contents of a certain column
        Parameters:
        col - is the requested column to be overwritten
        array - contains the elements to be copied
      • equals

        public boolean equals(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • offset

        public int offset()

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.