Skip to content

Matrix API Reference

flavianv edited this page Aug 9, 2012 · 45 revisions

Matrix library functions can be divided into three types:

In addition, matrix library contains

Value operations work over individual values in a matrix, usually transforming them in some way.

# mat.mapValues( mapping function ): Matrix

Maps the values of the matrix to new values using a function

// The new matrix contains the squares of the elements from the original matrix
val squaredMatrix = matrix.mapValues{ value : Int => value * value }

# mat.filterValues( filter function ) : Matrix

Keep only the values of the matrix that set the function to true

// The new matrix contains only the positive non-zero elements from the matrix
val filteredMatrix = matrix.filterValues{ _ > 0 }

# mat.binarizeAs[NewValT] : Matrix

Sets all of the non-zero values of the matrix to the one element of the type

// The new matrix contains ones as integers for all non-zero values from the matri
val binMatrix = matrix.binarizeAs[Int]

# mat.getRow( rowNumber ) : RowVector

Returns the row indexed with the specified value from the original matrix

// Returns the 3-rd row from the matrix
val row = matrix.getRow(3)
// Returns the row from the matrix that is indexed with “France”
val row = matrix.getRow(“France”)

# matrix.reduceRowVectors{ reduce function } : RowVector

Reduces all row vectors into a single row vector using a associative pairwise aggregation function

// Returns the row vector of all column-wise products of the matrix
// matrix = 1 1 1
//         2 2 1
//         3 0 1
// rowProd = 6 0 1
val rowProd = matrix.reduceRowVectors { (x,y) => x * y }

# matrix.sumRowVectors : RowVector

Reduces all row vectors into the sum row vector

// Returns the row vector of all column-wise sums of the matrix
val rowSum = matrix.sumRowVectors

# matrix.mapRows{ mapping function } : Matrix

Maps all row vectors into new row vector using a function over the list of non-zero elements in the original rows

// Returns the row vector of all column-wise sums of the matrix
val rowSum = matrix.mapRows{ fn }
def fn( list : List[(Int,Double)]) : List[(Int,Double)]  

# matrix.topRowElems( numberOfElements ) : Matrix

Returns the matrix containing only the top K elements in each row

// Returns the matrix with top 10 elements
val topkMatrix = matrix.topRowElems(10)

# matrix.rowL1Normalize : Matrix

Returns the matrix containing the L1 row-normalized elements of the original matrix

// Returns the adjacency matrix of the follow graph normalized by outdegree
// matrix = 1 0 1
//          1 1 1
//          1 0 0
// matrixL1Norm = 0.5 0 0.5
//                0.33 0.33 0.33
//                1 0 0
val matrixL1Norm = matrix.rowL1Normalize

# matrix.rowL2Normalize : Matrix

Returns the matrix containing the L2 row-normalized elements of the original matrix

// Returns the adjacency matrix of the follow graph normalized by outdegree
val matrixL2Norm = matrix.rowL2Normalize

# matrix.rowMeanCentering : Matrix

Returns the matrix containing the row-mean centered elements of the original matrix

// Substracts all of the row-wise means from all the elements
val matrixCentered = matrix.rowMeanCentering

# matrix.rowSizeAveStdev : Matrix

Computes the row size, ave and stdev and returns a k x 3 matrix containing the stats

// Computes the row stats
val matrixRowStats = matrix.rowSizeAveStdev
def rowColValSymbols : List[Symbol] = List(rowSym, colSym, valSym)

Contents

Getting help

Documentation

Matrix API

Third Party Modules

Videos

How-tos

Tutorials

Articles

Other

Clone this wiki locally