Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## prea.data.structure
Class DenseMatrix

    java.lang.Object
      prea.data.structure.DenseMatrix

    public class DenseMatrix

extends java.lang.Object

This class implements dense matrix. Note that we use UJMP package (http://www.ujmp.org) to implement this class.

Since:
  2012. 4. 20
Version:
  1.1
Author:
  Joonseok Lee

Field Summary
`private int` | `M` The number of rows.
`private org.ujmp.core.Matrix` | `map` The UJMP matrix to store data.
`private int` | `N` The number of columns.

Constructor Summary
`DenseMatrix(int m, int n)` Construct an empty dense matrix, with a given size.
`DenseMatrix(org.ujmp.core.Matrix m)` Construct an empty dense matrix, with data copied from UJMP matrix.

Method Summary
`DenseMatrix` | `add(double alpha)` Scalar addition.
`double` | `average()` Average of every element.
`DenseMatrix` | `cholesky()` Calculate Cholesky decomposition of the matrix.
`DenseMatrix` | `covariance()` Generate a covariance matrix of the current matrix.
`DenseVector` | `diagonal()` Return items in the diagonal in vector form.
`DenseMatrix` | `exp(double alpha)` Exponential of a given constant.
`DenseVector` | `getCol(int index)` Return a copy of a given column.
`DenseVector` | `getColRef(int index)` Return a reference of a given column.
`org.ujmp.core.Matrix` | `getMatrix()` Get an UJMP matrix.
`DenseVector` | `getRow(int index)` Return a copy of a given row.
`DenseVector` | `getRowRef(int index)` Return a reference of a given row.
`double` | `getValue(int i, int j)` Retrieve a stored value from the given index.
`DenseMatrix` | `inverse()` Calculate inverse matrix.
`int` | `itemCount()` Actual number of items in the matrix.
`int[]` | `length()` Capacity of this matrix.
`static DenseMatrix` | `makeIdentity(int n)` Generate an identity matrix with the given size.
`DenseMatrix` | `partInverse(int[] indexList)` Inverse of matrix only with indices in indexList.
`DenseMatrix` | `partMinus(DenseMatrix B, int[] indexList)` Matrix subtraction (A = A - B) only with indices in indexList.
`DenseMatrix` | `partPlus(DenseMatrix B, int[] indexList)` Matrix summation (A = A + B) only with indices in indexList.
`DenseMatrix` | `partScale(double alpha, int[] indexList)` Scalar Multiplication only with indices in indexList.
`DenseVector` | `partTimes(DenseVector x, int[] indexList)` Matrix-vector product (b = Ax) only with indices in indexList.
`DenseMatrix` | `plus(DenseMatrix B)` Matrix-matrix sum (C = A + B)
`DenseMatrix` | `scale(double alpha)` Scalar multiplication (aX).
`void` | `selfAdd(double alpha)` Scalar addition on the matrix itself.
`void` | `selfScale(double alpha)` Scalar multiplication (aX) on the matrix itself.
`void` | `setValue(int i, int j, double value)` Set a new value at the given index.
`double` | `stdev()` Standard Deviation of every element.
`double` | `sum()` Sum of every element.
`DenseMatrix` | `times(DenseMatrix B)` Matrix-matrix product (C = AB)
`DenseVector` | `times(DenseVector x)` Matrix-vector product (b = Ax)
`DenseMatrix` | `toDenseSubset(int[] indexList)` Condense the matrix only with given indices.
`DenseMatrix` | `toDenseSubset(int[] rowList, int[] colList)` Condense the matrix only with given indices, both rows and columns separately.
`SparseMatrix` | `toSparseMatrix()` Convert the matrix into sparse matrix.
`java.lang.String` | `toString()` Convert the matrix to a printable string.
`DenseMatrix` | `transpose()` The transpose of the matrix.
`double` | `variance()` Variance of every element.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### M

    private int M

  The number of rows.

### N

    private int N

  The number of columns.

### map

    private org.ujmp.core.Matrix map

  The UJMP matrix to store data.

Constructor Detail

### DenseMatrix

    public DenseMatrix(int m,
                       int n)

  Construct an empty dense matrix, with a given size.

  Parameters:
    `m` - The number of rows.
    `n` - The number of columns.

### DenseMatrix

    public DenseMatrix(org.ujmp.core.Matrix m)

  Construct an empty dense matrix, with data copied from UJMP matrix.

  Parameters:
    `m` - An UJMP matrix.

Method Detail

### getMatrix

    public org.ujmp.core.Matrix getMatrix()

  Get an UJMP matrix.

  Returns:
    UJMP matrix.

### setValue

    public void setValue(int i,
                         int j,
                         double value)

  Set a new value at the given index.

  Parameters:
    `i` - The row index to store new value.
    `j` - The column index to store new value.
    `value` - The value to store.

### getValue

    public double getValue(int i,
                           int j)

  Retrieve a stored value from the given index.

  Parameters:
    `i` - The row index to retrieve.
    `j` - The column index to retrieve.
  Returns:
    The value stored at the given index.

### getRowRef

    public DenseVector getRowRef(int index)

  Return a reference of a given row. Make sure to use this method only for read-only purpose.

  Parameters:
    `index` - The row index to retrieve.
  Returns:
    A reference to the designated row.

### getRow

    public DenseVector getRow(int index)

  Return a copy of a given row. Use this if you do not want to affect to original data.

  Parameters:
    `index` - The row index to retrieve.
  Returns:
    A reference to the designated row.

### getColRef

    public DenseVector getColRef(int index)

  Return a reference of a given column. Make sure to use this method only for read-only purpose.

  Parameters:
    `index` - The column index to retrieve.
  Returns:
    A reference to the designated column.

### getCol

    public DenseVector getCol(int index)

  Return a copy of a given column. Use this if you do not want to affect to original data.

  Parameters:
    `index` - The column index to retrieve.
  Returns:
    A reference to the designated column.

### toSparseMatrix

    public SparseMatrix toSparseMatrix()

  Convert the matrix into sparse matrix.

  Returns:
    The converted sparse matrix.

### toDenseSubset

    public DenseMatrix toDenseSubset(int[] indexList)

  Condense the matrix only with given indices.

  Parameters:
    `indexList` - The list of indices.
  Returns:
    The converted matrix, only with given indices.

### toDenseSubset

    public DenseMatrix toDenseSubset(int[] rowList,
                                     int[] colList)

  Condense the matrix only with given indices, both rows and columns separately.

  Parameters:
    `rowList` - The list of row indices.
    `colList` - The list of column indices.
  Returns:
    The converted matrix, only with given indices.

### length

    public int[] length()

  Capacity of this matrix.

  Returns:
    An array containing the length of this matrix. Index 0 contains row count, while index 1 column count.

### itemCount

    public int itemCount()

  Actual number of items in the matrix.

  Returns:
    The number of items in the matrix.

### diagonal

    public DenseVector diagonal()

  Return items in the diagonal in vector form.

  Returns:
    Diagonal vector from the matrix.

### sum

    public double sum()

  Sum of every element. It ignores non-existing values.

  Returns:
    The sum value.

### average

    public double average()

  Average of every element. It ignores non-existing values.

  Returns:
    The average value.

### variance

    public double variance()

  Variance of every element. It ignores non-existing values.

  Returns:
    The variance value.

### stdev

    public double stdev()

  Standard Deviation of every element. It ignores non-existing values.

  Returns:
    The standard deviation value.

### scale

    public DenseMatrix scale(double alpha)

  Scalar multiplication (aX).

  Parameters:
    `alpha` - The scalar value to be multiplied to this matrix.
  Returns:
    The resulting matrix after scaling.

### selfScale

    public void selfScale(double alpha)

  Scalar multiplication (aX) on the matrix itself. This is used for minimizing memory usage.

  Parameters:
    `alpha` - The scalar value to be multiplied to this matrix.

### add

    public DenseMatrix add(double alpha)

  Scalar addition.

  Parameters:
    `alpha` - The scalar value to be added to this matrix.
  Returns:
    The resulting matrix after addition.

### selfAdd

    public void selfAdd(double alpha)

  Scalar addition on the matrix itself.

  Parameters:
    `alpha` - The scalar value to be added to this matrix.

### exp

    public DenseMatrix exp(double alpha)

  Exponential of a given constant.

  Parameters:
    `alpha` - The exponent.
  Returns:
    The resulting exponential matrix.

### transpose

    public DenseMatrix transpose()

  The transpose of the matrix. This is simply implemented by interchanging row and column each other.

  Returns:
    The transpose of the matrix.

### times

    public DenseVector times(DenseVector x)

  Matrix-vector product (b = Ax)

  Parameters:
    `x` - The vector to be multiplied to this matrix.
  Returns:
    The resulting vector after multiplication.
  Throws:
    `java.lang.RuntimeException` - when dimensions disagree

### times

    public DenseMatrix times(DenseMatrix B)

  Matrix-matrix product (C = AB)

  Parameters:
    `B` - The matrix to be multiplied to this matrix.
  Returns:
    The resulting matrix after multiplication.
  Throws:
    `java.lang.RuntimeException` - when dimensions disagree

### plus

    public DenseMatrix plus(DenseMatrix B)

  Matrix-matrix sum (C = A + B)

  Parameters:
    `B` - The matrix to be added to this matrix.
  Returns:
    The resulting matrix after summation.
  Throws:
    `java.lang.RuntimeException` - when dimensions disagree

### makeIdentity

    public static DenseMatrix makeIdentity(int n)

  Generate an identity matrix with the given size.

  Parameters:
    `n` - The size of requested identity matrix.
  Returns:
    An identity matrix with the size of n by n.

### inverse

    public DenseMatrix inverse()

  Calculate inverse matrix.

  Returns:
    The inverse of current matrix.
  Throws:
    `java.lang.RuntimeException` - when dimensions disagree.

### cholesky

    public DenseMatrix cholesky()

  Calculate Cholesky decomposition of the matrix.

  Returns:
    The Cholesky decomposition result.
  Throws:
    `java.lang.RuntimeException` - when matrix is not square.

### covariance

    public DenseMatrix covariance()

  Generate a covariance matrix of the current matrix.

  Returns:
    The covariance matrix of the current matrix.

### partScale

    public DenseMatrix partScale(double alpha,
                                 int[] indexList)

  Scalar Multiplication only with indices in indexList.

  Parameters:
    `alpha` - The scalar to be multiplied to this matrix.
    `indexList` - The list of indices to be applied summation.
  Returns:
    The resulting matrix after scaling.

### partPlus

    public DenseMatrix partPlus(DenseMatrix B,
                                int[] indexList)

  Matrix summation (A = A + B) only with indices in indexList.

  Parameters:
    `B` - The matrix to be added to this matrix.
    `indexList` - The list of indices to be applied summation.
  Returns:
    The resulting matrix after summation.
  Throws:
    `java.lang.RuntimeException` - when dimensions disagree.

### partMinus

    public DenseMatrix partMinus(DenseMatrix B,
                                 int[] indexList)

  Matrix subtraction (A = A - B) only with indices in indexList.

  Parameters:
    `B` - The matrix to be subtracted from this matrix.
    `indexList` - The list of indices to be applied subtraction.
  Returns:
    The resulting matrix after subtraction.
  Throws:
    `java.lang.RuntimeException` - when dimensions disagree.

### partTimes

    public DenseVector partTimes(DenseVector x,
                                 int[] indexList)

  Matrix-vector product (b = Ax) only with indices in indexList.

  Parameters:
    `x` - The vector to be multiplied to this matrix.
    `indexList` - The list of indices to be applied multiplication.
  Returns:
    The resulting vector after multiplication.

### partInverse

    public DenseMatrix partInverse(int[] indexList)

  Inverse of matrix only with indices in indexList.

  Parameters:
    `indexList` - The list of indices to be applied multiplication.
  Returns:
    The resulting inverse matrix.
  Throws:
    `java.lang.RuntimeException` - when dimensions disagree.

### toString

    public java.lang.String toString()

  Convert the matrix to a printable string.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    The resulted string."

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD