ch.akuhn.matrix

Class Matrix

• Constructor Summary

Constructors
Constructor and Description
`Matrix()`
• Method Summary

All Methods
Modifier and Type Method and Description
`double` ```add(int row, int column, double value)```
Add to the value at the given row/column
`double[][]` `asArray()`
Get the matrix data as a 2D dense array
`double[]` `asColumnMajorArray()`
Get in col-major format
`Vector` `column(int column)`
Get the given column as a vector
`abstract int` `columnCount()`
Get the number of columns
`Iterable<Vector>` `columns()`
Get an `Iterable` over the columns
`static Matrix` ```dense(int n, int m)```
Create a zeroed dense matrix
`double` `density()`
Get the density
`int` `elementCount()`
`static Matrix` ```from(int n, int m, double... values)```
Build a matrix from the given values (row-major)
`abstract double` ```get(int row, int column)```
`int[]` `getHistogram()`
`static int` `indexOf(Vector vec)`
Get the index of the given vector
`boolean` `isSquare()`
`double` `max()`
`double` `mean()`
`double` `min()`
`Vector` `mult(Vector x)`
Returns `y = Ax`.
`Matrix` `newInstance()`
`abstract Matrix` ```newInstance(int rows, int cols)```
`abstract double` ```put(int row, int column, double value)```
Set the value at the given row/column
`Vector` `row(int row)`
Get the given row as a vector
`abstract int` `rowCount()`
`Iterable<Vector>` `rows()`
Get an `Iterable` over the rows
`double[]` `rowwiseMean()`
`static SparseMatrix` ```sparse(int n, int m)```
Create a sparse matrix
`void` `storeSparseOn(Appendable appendable)`
I/O
`void` `storeSparseOn(String fname)`
Write to file
`String` `toString()`
`Vector` `transposeMultiply(Vector x)`
Returns `y = (A^T)x`.
`Vector` `transposeNonTransposeMultiply(Vector x)`
Returns `y = (A^T)Ax`.
`double[][]` `unwrap()`
`abstract int` `used()`
• Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• Constructor Detail

• Matrix

`public Matrix()`
• Method Detail

```public double add(int row,
int column,
double value)```
Add to the value at the given row/column
Parameters:
`row` -
`column` -
`value` -
Returns:
the new value
• columnCount

`public abstract int columnCount()`
Get the number of columns
Returns:
the number of columns
• density

`public double density()`
Get the density
Returns:
the density
• elementCount

`public int elementCount()`
Returns:
the number of elements
• get

```public abstract double get(int row,
int column)```
Parameters:
`row` -
`column` -
Returns:
the value at the given row and column
• put

```public abstract double put(int row,
int column,
double value)```
Set the value at the given row/column
Parameters:
`row` -
`column` -
`value` -
Returns:
the value being set
• rowCount

`public abstract int rowCount()`
Returns:
the number of rows
• used

`public abstract int used()`
Returns:
the number of non-zero elements
• storeSparseOn

```public void storeSparseOn(Appendable appendable)
throws IOException```
I/O
Parameters:
`appendable` -
Throws:
`IOException`
"http://tedlab.mit.edu/~dr/svdlibc/SVD_F_ST.html"
• storeSparseOn

```public void storeSparseOn(String fname)
throws IOException```
Write to file
Parameters:
`fname` - filename
Throws:
`IOException`
• row

`public Vector row(int row)`
Get the given row as a vector
Parameters:
`row` -
Returns:
the row
• column

`public Vector column(int column)`
Get the given column as a vector
Parameters:
`column` -
Returns:
the column
• asArray

`public double[][] asArray()`
Get the matrix data as a 2D dense array
Returns:
the array representation
• indexOf

`public static int indexOf(Vector vec)`
Get the index of the given vector
Parameters:
`vec` -
Returns:
the index
• mult

`public Vector mult(Vector x)`
Returns `y = Ax`.
Parameters:
`x` -
Returns:
the result
• transposeMultiply

`public Vector transposeMultiply(Vector x)`
Returns `y = (A^T)x`.
Parameters:
`x` -
Returns:
the result
• transposeNonTransposeMultiply

`public Vector transposeNonTransposeMultiply(Vector x)`
Returns `y = (A^T)Ax`.

Useful for doing singular decomposition using ARPACK's dsaupd routine.

Parameters:
`x` -
Returns:
the result
• from

```public static Matrix from(int n,
int m,
double... values)```
Build a matrix from the given values (row-major)
Parameters:
`n` -
`m` -
`values` -
Returns:
the matrix
• dense

```public static Matrix dense(int n,
int m)```
Create a zeroed dense matrix
Parameters:
`n` -
`m` -
Returns:
the matrix
• isSquare

`public boolean isSquare()`
Returns:
true of matrix is square; false otherwise
• asColumnMajorArray

`public double[] asColumnMajorArray()`
Get in col-major format
Returns:
the data in column major format
• sparse

```public static SparseMatrix sparse(int n,
int m)```
Create a sparse matrix
Parameters:
`n` -
`m` -
Returns:
new sparse matrix
• max

`public double max()`
Returns:
max value in matrix
• min

`public double min()`
Returns:
min value in matrix
• mean

`public double mean()`
Returns:
mean value of matrix
• unwrap

`public double[][] unwrap()`
Returns:
unwrapped matrix
• rowwiseMean

`public double[] rowwiseMean()`
Returns:
mean of each row
• getHistogram

`public int[] getHistogram()`
Returns:
the histogram
• newInstance

`public Matrix newInstance()`
Returns:
an empty instance of this matrix type
• newInstance

```public abstract Matrix newInstance(int rows,
int cols)```
Parameters:
`rows` -
`cols` -
Returns:
an empty instance of this matrix type
• toString

`public String toString()`
Overrides:
`toString` in class `Object`