## org.apache.mahout.math Interface Matrix

All Superinterfaces:
Cloneable, Iterable<MatrixSlice>, VectorIterable
All Known Implementing Classes:
AbstractMatrix, DenseMatrix, MatrixView, SparseColumnMatrix, SparseMatrix, SparseRowMatrix, VectorList

public interface Matrix
extends Cloneable, VectorIterable

The basic interface including numerous convenience functions

Method Summary
double aggregate(DoubleDoubleFunction combiner, DoubleFunction mapper)
Collects the results of a function applied to each element of a matrix and then aggregated.
Vector aggregateColumns(VectorFunction f)
Collects the results of a function applied to each column of a matrix.
Vector aggregateRows(VectorFunction f)
Collects the results of a function applied to each row of a matrix.
String asFormatString()

Matrix assign(double value)
Assign the value to all elements of the receiver
Matrix assign(double[][] values)
Assign the values to the receiver
Matrix assign(DoubleFunction function)
Apply the function to each element of the receiver
Matrix assign(Matrix other)
Assign the other vector values to the receiver
Matrix assign(Matrix other, DoubleDoubleFunction function)
Apply the function to each element of the receiver and the corresponding element of the other argument
Matrix assignColumn(int column, Vector other)
Assign the other vector values to the column of the receiver
Matrix assignRow(int row, Vector other)
Assign the other vector values to the row of the receiver
Matrix clone()
Return a copy of the recipient
int columnSize()

double determinant()
Returns matrix determinator using Laplace theorem
Matrix divide(double x)
Return a new matrix containing the values of the recipient divided by the argument
double get(int row, int column)
Return the value at the given indexes
double get(String rowLabel, String columnLabel)
Return the value at the given labels
Vector getColumn(int column)
Return the column at the given index
Map<String,Integer> getColumnLabelBindings()
Return a map of the current column label bindings of the receiver
int[] getNumNondefaultElements()
Return the number of values in the recipient
double getQuick(int row, int column)
Return the value at the given indexes, without checking bounds
Vector getRow(int row)
Return the row at the given index
Map<String,Integer> getRowLabelBindings()
Return a map of the current row label bindings of the receiver
Matrix like()
Return an empty matrix of the same underlying class as the receiver
Matrix like(int rows, int columns)
Returns an empty matrix of the same underlying class as the receiver and of the specified size.
Matrix minus(Matrix x)
Return a new matrix containing the element by element difference of the recipient and the argument
Matrix plus(double x)
Return a new matrix containing the sum of each value of the recipient and the argument
Matrix plus(Matrix x)
Return a new matrix containing the element by element sum of the recipient and the argument
int rowSize()

void set(int row, double[] data)

void set(int row, int column, double value)
Set the value at the given index
void set(String rowLabel, double[] rowData)
Sets the row values at the given row label
void set(String rowLabel, int row, double[] rowData)
Sets the row values at the given row index and updates the row labels
void set(String rowLabel, String columnLabel, double value)
Set the value at the given index
void set(String rowLabel, String columnLabel, int row, int column, double value)
Set the value at the given index, updating the row and column label bindings
void setColumnLabelBindings(Map<String,Integer> bindings)
Sets a map of column label bindings in the receiver
void setQuick(int row, int column, double value)
Set the value at the given index, without checking bounds
void setRowLabelBindings(Map<String,Integer> bindings)
Sets a map of row label bindings in the receiver
int[] size()
Return the cardinality of the recipient (the maximum number of values)
Matrix times(double x)
Return a new matrix containing the product of each value of the recipient and the argument
Matrix times(Matrix x)
Return a new matrix containing the product of the recipient and the argument
Matrix transpose()
Return a new matrix that is the transpose of the receiver
Vector viewColumn(int column)

Matrix viewPart(int[] offset, int[] size)
Return a new matrix containing the subset of the recipient
Matrix viewPart(int rowOffset, int rowsRequested, int columnOffset, int columnsRequested)
Return a new matrix containing the subset of the recipient
Vector viewRow(int row)

double zSum()
Return the sum of all the elements of the receiver

Methods inherited from interface org.apache.mahout.math.VectorIterable
iterateAll, numCols, numRows, numSlices, times, timesSquared

Methods inherited from interface java.lang.Iterable
iterator

Method Detail

### asFormatString

String asFormatString()
Returns:
a formatted String suitable for output

### assign

Matrix assign(double value)
Assign the value to all elements of the receiver

Parameters:
value - a double value
Returns:

### assign

Matrix assign(double[][] values)
Assign the values to the receiver

Parameters:
values - a double[] of values
Returns:
Throws:
CardinalityException - if the cardinalities differ

### assign

Matrix assign(Matrix other)
Assign the other vector values to the receiver

Parameters:
other - a Matrix
Returns:
Throws:
CardinalityException - if the cardinalities differ

### assign

Matrix assign(DoubleFunction function)
Apply the function to each element of the receiver

Parameters:
function - a DoubleFunction to apply
Returns:

### assign

Matrix assign(Matrix other,
DoubleDoubleFunction function)
Apply the function to each element of the receiver and the corresponding element of the other argument

Parameters:
other - a Matrix containing the second arguments to the function
function - a DoubleDoubleFunction to apply
Returns:
Throws:
CardinalityException - if the cardinalities differ

### assignColumn

Matrix assignColumn(int column,
Vector other)
Assign the other vector values to the column of the receiver

Parameters:
column - the int row to assign
other - a Vector
Returns:
Throws:
CardinalityException - if the cardinalities differ

### assignRow

Matrix assignRow(int row,
Vector other)
Assign the other vector values to the row of the receiver

Parameters:
row - the int row to assign
other - a Vector
Returns:
Throws:
CardinalityException - if the cardinalities differ

### aggregateRows

Vector aggregateRows(VectorFunction f)
Collects the results of a function applied to each row of a matrix.

Parameters:
f - The function to be applied to each row.
Returns:
The vector of results.

### aggregateColumns

Vector aggregateColumns(VectorFunction f)
Collects the results of a function applied to each column of a matrix.

Parameters:
f - The function to be applied to each column.
Returns:
The vector of results.

### aggregate

double aggregate(DoubleDoubleFunction combiner,
DoubleFunction mapper)
Collects the results of a function applied to each element of a matrix and then aggregated.

Parameters:
combiner - A function that combines the results of the mapper.
mapper - A function to apply to each element.
Returns:
The result.

### size

int[] size()
Return the cardinality of the recipient (the maximum number of values)

Returns:
an int[2]

### columnSize

int columnSize()
Returns:
The number of rows in the matrix.

### rowSize

int rowSize()
Returns:
Returns the number of rows in the matrix.

### clone

Matrix clone()
Return a copy of the recipient

Returns:
a new Matrix

### determinant

double determinant()
Returns matrix determinator using Laplace theorem

Returns:
a matrix determinator

### divide

Matrix divide(double x)
Return a new matrix containing the values of the recipient divided by the argument

Parameters:
x - a double value
Returns:
a new Matrix

### get

double get(int row,
int column)
Return the value at the given indexes

Parameters:
row - an int row index
column - an int column index
Returns:
the double at the index
Throws:
IndexException - if the index is out of bounds

### getColumn

Vector getColumn(int column)
Return the column at the given index

Parameters:
column - an int column index
Returns:
a Vector at the index
Throws:
IndexException - if the index is out of bounds

### getRow

Vector getRow(int row)
Return the row at the given index

Parameters:
row - an int row index
Returns:
a Vector at the index
Throws:
IndexException - if the index is out of bounds

### getQuick

double getQuick(int row,
int column)
Return the value at the given indexes, without checking bounds

Parameters:
row - an int row index
column - an int column index
Returns:
the double at the index

### like

Matrix like()
Return an empty matrix of the same underlying class as the receiver

Returns:
a Matrix

### like

Matrix like(int rows,
int columns)
Returns an empty matrix of the same underlying class as the receiver and of the specified size.

Parameters:
rows - the int number of rows
columns - the int number of columns

### minus

Matrix minus(Matrix x)
Return a new matrix containing the element by element difference of the recipient and the argument

Parameters:
x - a Matrix
Returns:
a new Matrix
Throws:
CardinalityException - if the cardinalities differ

### plus

Matrix plus(double x)
Return a new matrix containing the sum of each value of the recipient and the argument

Parameters:
x - a double
Returns:
a new Matrix

### plus

Matrix plus(Matrix x)
Return a new matrix containing the element by element sum of the recipient and the argument

Parameters:
x - a Matrix
Returns:
a new Matrix
Throws:
CardinalityException - if the cardinalities differ

### set

void set(int row,
int column,
double value)
Set the value at the given index

Parameters:
row - an int row index into the receiver
column - an int column index into the receiver
value - a double value to set
Throws:
IndexException - if the index is out of bounds

### set

void set(int row,
double[] data)

### setQuick

void setQuick(int row,
int column,
double value)
Set the value at the given index, without checking bounds

Parameters:
row - an int row index into the receiver
column - an int column index into the receiver
value - a double value to set

### getNumNondefaultElements

int[] getNumNondefaultElements()
Return the number of values in the recipient

Returns:
an int[2] containing [row, column] count

### times

Matrix times(double x)
Return a new matrix containing the product of each value of the recipient and the argument

Parameters:
x - a double argument
Returns:
a new Matrix

### times

Matrix times(Matrix x)
Return a new matrix containing the product of the recipient and the argument

Parameters:
x - a Matrix argument
Returns:
a new Matrix
Throws:
CardinalityException - if the cardinalities are incompatible

### transpose

Matrix transpose()
Return a new matrix that is the transpose of the receiver

Returns:
the transpose

### viewPart

Matrix viewPart(int[] offset,
int[] size)
Return a new matrix containing the subset of the recipient

Parameters:
offset - an int[2] offset into the receiver
size - the int[2] size of the desired result
Returns:
a new Matrix that is a view of the original
Throws:
CardinalityException - if the length is greater than the cardinality of the receiver
IndexException - if the offset is negative or the offset+length is outside of the receiver

### viewPart

Matrix viewPart(int rowOffset,
int rowsRequested,
int columnOffset,
int columnsRequested)
Return a new matrix containing the subset of the recipient

Parameters:
rowOffset - The first row of the view
rowsRequested - The number of rows in the view
columnOffset - The first column in the view
columnsRequested - The number of columns in the view
Returns:
a new Matrix that is a view of the original
Throws:
CardinalityException - if the length is greater than the cardinality of the receiver
IndexException - if the offset is negative or the offset+length is outside of the receiver

### zSum

double zSum()
Return the sum of all the elements of the receiver

Returns:
a double

### getColumnLabelBindings

Map<String,Integer> getColumnLabelBindings()
Return a map of the current column label bindings of the receiver

Returns:
a Map

### getRowLabelBindings

Map<String,Integer> getRowLabelBindings()
Return a map of the current row label bindings of the receiver

Returns:
a Map

### setColumnLabelBindings

void setColumnLabelBindings(Map<String,Integer> bindings)
Sets a map of column label bindings in the receiver

Parameters:
bindings - a Map of label bindings

### setRowLabelBindings

void setRowLabelBindings(Map<String,Integer> bindings)
Sets a map of row label bindings in the receiver

Parameters:
bindings - a Map of label bindings

### get

double get(String rowLabel,
String columnLabel)
Return the value at the given labels

Parameters:
rowLabel - a String row label
columnLabel - a String column label
Returns:
the double at the index
Throws:
IndexException - if the index is out of bounds

### set

void set(String rowLabel,
String columnLabel,
double value)
Set the value at the given index

Parameters:
rowLabel - a String row label
columnLabel - a String column label
value - a double value to set
Throws:
IndexException - if the index is out of bounds

### set

void set(String rowLabel,
String columnLabel,
int row,
int column,
double value)
Set the value at the given index, updating the row and column label bindings

Parameters:
rowLabel - a String row label
columnLabel - a String column label
row - an int row index
column - an int column index
value - a double value

### set

void set(String rowLabel,
double[] rowData)
Sets the row values at the given row label

Parameters:
rowLabel - a String row label
rowData - a double[] array of row data

### set

void set(String rowLabel,
int row,
double[] rowData)
Sets the row values at the given row index and updates the row labels

Parameters:
rowLabel - the String row label
row - an int the row index
rowData - a double[] array of row data

### viewRow

Vector viewRow(int row)

### viewColumn

Vector viewColumn(int column)