edu.northwestern.at.utils.math.matrix
Interface Matrix

All Superinterfaces:
java.io.Serializable
All Known Implementing Classes:
AbstractMatrix, DenseMatrix, SparseMatrix

public interface Matrix
extends java.io.Serializable

Two-dimensional matrix interface class for doubles.

Matrix elements are assumed to be doubles, but this class imposes no specific structure as to how the doubles are stored. Only operations to get and set elements in the matrix are defined here. All other matrix operations are handled by methods in other classes which take Matrix types as arguments.


Method Summary
 int columns()
          Get number of columns in the matrix.
 double[][] get()
          Get all elements as a two-dimensional double array.
 double get(int row, int column)
          Gets value of element at given row and column.
 Matrix getColumn(int column)
          Get entire column as a matrix.
 double[] getColumnData(int column)
          Get entire column as an array of doubles.
 Matrix getColumns(int[] columns)
          Extract columns.
 Matrix getColumns(int firstColumn, int lastColumn)
          Extract columns.
 Matrix getCopy()
          Get all elements as a new matrix.
 Matrix getRow(int row)
          Get entire row as a matrix.
 double[] getRowData(int row)
          Get entire row as an array of doubles .
 Matrix getRows(int[] rows)
          Extract rows.
 Matrix getRows(int firstRow, int lastRow)
          Extract rows.
 Matrix getSubMatrix(int[] rows, int[] columns)
          Extract a submatrix.
 Matrix getSubMatrix(int[] rows, int firstColumn, int lastColumn)
          Extract a submatrix.
 Matrix getSubMatrix(int firstRow, int lastRow, int[] columns)
          Extract a submatrix.
 Matrix getSubMatrix(int firstRow, int firstColumn, int lastRow, int lastColumn)
          Extract a submatrix.
 int rows()
          Get number of rows in the matrix.
 void set(double[][] values)
          Set all elements of a matrix from a double array.
 void set(int row, int column, double value)
          Set an element at the given position to a new value.
 void set(Matrix matrix)
          Set all elements from another matrix.
 void setColumn(int column, Matrix columnMatrix)
          Set entire column of values from a column matrix.
 void setColumnData(int column, double[] columnData)
          Set entire column from an array of doubles .
 void setColumnData(int column, int[] columnData)
          Set entire column from an array of ints .
 void setRow(int row, Matrix rowMatrix)
          Set entire row of values from a row matrix.
 void setRowData(int row, double[] rowData)
          Set entire row from an array of doubles .
 java.lang.String toString()
          Return the matrix as a displayable string.
 

Method Detail

rows

int rows()
Get number of rows in the matrix.

Returns:
Number of rows in the matrix.

columns

int columns()
Get number of columns in the matrix.

Returns:
Number of columns in the matrix.

get

double get(int row,
           int column)
Gets value of element at given row and column.

Parameters:
row - Row in which the element occurs.
column - Column in which the element occurs.
Returns:
The value at the given position.

set

void set(int row,
         int column,
         double value)
Set an element at the given position to a new value.

Parameters:
row - Row in which the element occurs.
column - Column in which the element occurs.
value - The new value to be set.

getCopy

Matrix getCopy()
Get all elements as a new matrix.

Returns:
Copy of all elements as another matrix.

Essentially creates a deep clone of the current matrix.


set

void set(Matrix matrix)
Set all elements from another matrix.

Parameters:
matrix - Matrix whose value to copy to this matrix.
Throws:
MatrixMismatchedSizeException - If the source matrix and this one don't have the same number of rows and columns.

get

double[][] get()
Get all elements as a two-dimensional double array.

Returns:
Copy of all elements as a two-dimensional double array.

set

void set(double[][] values)
Set all elements of a matrix from a double array.

Parameters:
values - The double[][] from which values should be set.

getRow

Matrix getRow(int row)
Get entire row as a matrix.

Parameters:
row - Row to retrieve.
Returns:
Matrix containing row.

getRowData

double[] getRowData(int row)
Get entire row as an array of doubles .

Parameters:
row - Row to retrieve.
Returns:
Array of doubles containing row data.

setRow

void setRow(int row,
            Matrix rowMatrix)
Set entire row of values from a row matrix.

Parameters:
row - Row to set.
rowMatrix - Matrix containing row data.

setRowData

void setRowData(int row,
                double[] rowData)
Set entire row from an array of doubles .

Parameters:
row - Row to set.
rowData - Array of doubles containing row data.

getColumn

Matrix getColumn(int column)
Get entire column as a matrix.

Parameters:
column - Column to retrieve.
Returns:
Matrix containing column.

getColumnData

double[] getColumnData(int column)
Get entire column as an array of doubles.

Parameters:
column - Column to retrieve.
Returns:
Array of doubles containing column data.

setColumn

void setColumn(int column,
               Matrix columnMatrix)
Set entire column of values from a column matrix.

Parameters:
column - Column to set.
columnMatrix - Matrix containing column data.

setColumnData

void setColumnData(int column,
                   double[] columnData)
Set entire column from an array of doubles .

Parameters:
column - Column to set.
columnData - Array of doubles containing column data.

setColumnData

void setColumnData(int column,
                   int[] columnData)
Set entire column from an array of ints .

Parameters:
column - Column to set.
columnData - Array of ints containing column data.

getSubMatrix

Matrix getSubMatrix(int firstRow,
                    int firstColumn,
                    int lastRow,
                    int lastColumn)
Extract a submatrix.

Parameters:
firstRow - First row index.
firstColumn - First column index.
lastRow - Last row index.
lastColumn - Last column index.
Returns:
Matrix containing rows firstRow through lastRow and columns firstColumn through lastColumn .
Throws:
MatrixMismatchedSizeException - If requested matrix indices are bad.

getSubMatrix

Matrix getSubMatrix(int[] rows,
                    int[] columns)
Extract a submatrix.

Parameters:
rows - Array of row indices.
columns - Array of column indices.
Returns:
Matrix containing rows and columns defined by indices.
Throws:
MatrixMismatchedSizeException - If requested matrix indices are bad.

getSubMatrix

Matrix getSubMatrix(int firstRow,
                    int lastRow,
                    int[] columns)
Extract a submatrix.

Parameters:
firstRow - First row index.
lastRow - Last row index
columns - Array of column indices.
Returns:
Matrix defined by specified row and column indices.
Throws:
MismatchedSizeException - If requested matrix indices are bad.

getSubMatrix

Matrix getSubMatrix(int[] rows,
                    int firstColumn,
                    int lastColumn)
Extract a submatrix.

Parameters:
rows - Array of row indices.
firstColumn - First column index.
lastColumn - Last column index.
Returns:
Matrix defined by specified row and column indices.
Throws:
MismatchedSizeException - If requested matrix indices are bad.

getColumns

Matrix getColumns(int firstColumn,
                  int lastColumn)
Extract columns.

Parameters:
firstColumn - First column index.
lastColumn - Last column index.
Returns:
Matrix containing all rows for specified column range.
Throws:
MismatchedSizeException - If requested matrix indices are bad.

getColumns

Matrix getColumns(int[] columns)
Extract columns.

Parameters:
columns - Indices of columns to extract.
Returns:
Matrix containing all rows for specified column indices.
Throws:
MismatchedSizeException - If requested matrix indices are bad.

getRows

Matrix getRows(int firstRow,
               int lastRow)
Extract rows.

Parameters:
firstRow - First row index.
lastRow - Last row index.
Returns:
Matrix containing all columns for specified row range.
Throws:
MismatchedSizeException - If requested matrix indices are bad.

getRows

Matrix getRows(int[] rows)
Extract rows.

Parameters:
rows - Indices of rows to extract.
Returns:
Matrix containing all columns for specified row indices.
Throws:
MismatchedSizeException - If requested matrix indices are bad.

toString

java.lang.String toString()
Return the matrix as a displayable string.

Overrides:
toString in class java.lang.Object
Returns:
The matrix as a string.