Libraries.Compute.Matrix Documentation

This class is a two dimensional matrix of number variables.

Example Code

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 1.1)
output matrix:ToText()
end
end
``````

Inherits from: Libraries.Language.Object

Actions Documentation

This method is used to add a value to all the elements in a Matrix. Attribute Parameter value The value to be added to the matrix elements. Attribute Returns A new matrix after the operation is performed.

• number value

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
output matrix:ToText()
end
end
``````

This method is used to add all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix to add to the current matrix. Attribute Returns A new matrix after the operation is performed.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(2, 3, 2.0)
output matrix:ToText()
end
end
``````

Calculate(Libraries.Compute.MatrixTransform.MatrixCalculation calculate)

This is a blueprint method for creating a Matrix Calculation class.

Return

number: A new matrix after the operation is performed.

Example

``````use Libraries.Compute.MatrixTransform.MatrixTransform
use Libraries.Compute.Matrix

action Calculate(Matrix matrix) returns Matrix
Matrix newMatrix
newMatrix:SetSize(matrix)
row = 0
repeat matrix:GetRows() times
col = 0
repeat matrix:GetColumns() times
newMatrix:Set(row, col, matrix:Get(row, col) + 3)                    col = col + 1
end
row = row + 1
end
return newMatrix
end
end
``````

CenterByColumn()

This action centers the matrix by column and returns a new matrix. Subtracts the column mean from each value in the column. Attribute Returns a Matrix.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 7)
Matrix newMatrix = matrix:CenterByColumn()
end
end
``````

CenterByRow()

This action centers the matrix by row and returns a new matrix. Subtracts the row mean from each value in the row. Attribute Returns a Matrix.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 7)
Matrix newMatrix = matrix:CenterByRow()
end
end
``````

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

``````Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
``````

This method converts the Matrix to a dataframe with columns labelled by a given text array. The size of the column header array must be equal to the number of matrix columns. Attribute Returns A dataframe with the column headers.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main

Matrix matrix
matrix:Fill(2, 3, 10.0)
output frame:ToText()
end
end
``````

Copy()

This method returns a copy of a Matrix. Attribute Returns A new copied matrix.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2 = matrix:Copy()
output matrix2:ToText()
end
end
``````

Divide(number value)

This method is used to divide all the elements in a Matrix by a value. Attribute Parameter value The value to divide the matrix elements by. Attribute Returns A new matrix after the operation is performed.

• number value

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
matrix = matrix:Divide(2.0)
output matrix:ToText()
end
end
``````

DivideElements(Libraries.Compute.Matrix matrix)

This method is used to divide all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix of values to divide by the current matrix values. Attribute Returns A new matrix after the operation is performed.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(2, 3, 2.0)
matrix = matrix:DivideElements(matrix2)
output matrix:ToText()
end
end
``````

DoubleCenter()

This action double centers the matrix and returns a new matrix. This is useful in cases like estimating a population covariance matrix using a sample covariance matrix. Attribute Returns a Matrix.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 7)
Matrix newMatrix = matrix:DoubleCenter()
end
end
``````

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

``````use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
``````

Fill(number fillValue)

This method fills the matrix with the specified value. Attribute Parameter fillValue The value to place in each element in the matrix. Attribute Returns A new matrix after the operation is performed.

Parameters

• number fillValue

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0)
matrix = matrix:Fill(1.1)
output matrix:ToText()
end
end
``````

Fill(integer rows, integer columns, number value)

This method fills a matrix with a specified number of rows and columns with the same value. Attribute Parameter rows The number of rows for the matrix. Attribute Parameter columns The number of columns for the matrix. Attribute Parameter value The value to place in each element in the matrix. Attribute Returns A new matrix after the operation is performed.

Parameters

• integer rows
• integer columns
• number value

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2 = matrix:Copy()
output matrix2:ToText()
end
end
``````

FillByColumn(integer columns, Libraries.Compute.Matrix matrix)

This method fills a matrix from the values of a single column matrix for a specified number of columns. Attribute Parameter columns The number of columns to fill. Attribute Parameter matrix The set of values for each column.

Parameters

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
Matrix matrix2
matrix2:Fill(1, 3, 1.1)
matrix:FillByColumn(3, matrix2)
output matrix:ToText()
end
end
``````

FillByColumn(integer columns, Libraries.Containers.Array<number> array)

This method fills a matrix from the values in an array of numbers for a specified number of columns. Attribute Parameter columns The number of columns to fill. Attribute Parameter array The set of values for each column.

Parameters

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
Array<number> array
matrix:FillByColumn(3, array)
output matrix:ToText()
end
end
``````

FillByRow(integer rows, Libraries.Containers.Array<number> array)

This method fills a matrix from the values in an array of numbers for a specified number of rows. Attribute Parameter rows The number of rows to fill. Attribute Parameter array The set of values for each row.

Parameters

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
Array<number> array
matrix:FillByRow(3, array)
output matrix:ToText()
end
end
``````

FillByRow(integer rows, Libraries.Compute.Matrix matrix)

This method fills a matrix from the values of a single row matrix for a specified number of rows. Attribute Parameter rows The number of rows to fill. Attribute Parameter matrix The set of values for each row.

Parameters

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
Matrix matrix2
matrix2:Fill(1, 3, 1.1)
matrix:FillByRow(3, matrix2)
output matrix:ToText()
end
end
``````

FlipHorizontal()

This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix = matrix:FlipHorizontal()
output matrix:ToText()
end
end
``````

FlipVertical()

This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.

Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetRow(0, 1.1)
matrix:SetRow(1, 2.1)
matrix:SetRow(2, 3.1)
matrix = matrix:FlipVertical()
output matrix:ToText()
end
end
``````

Get(integer row, integer column)

This method is used to get the value in a specified location in the matrix.

Parameters

• integer row: The row number of the item.
• integer column: The column number of the item.

Return

number: The value of the item in the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 1.1)
output matrix:Get(1, 1)
end
end
``````

GetColumn(integer column)

This method is used to get a column of a Matrix returned as a new matrix.

Parameters

• integer column: The column number of the matrix to return.

Return

Libraries.Compute.Matrix: A matrix containing only the specified column.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Matrix col1 = matrix:GetColumn(0)
output col1:ToText()
end
end
``````

GetColumnArray(integer column)

This method is used to get a column of a Matrix returned as an array of numbers.

Parameters

• integer column: The column number of the matrix to return.

Return

Libraries.Containers.Array: An array containing only the specified row.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Array<number> col1 = matrix:GetColumnArray(0)
output col1:GetSize()
end
end
``````

GetColumnMajorArray()

This method is used to get a list of all the elements in a Matrix ordered by column returned as an array of numbers.

Return

Libraries.Containers.Array: An array containing all the elements in matrix in order by column.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Array<number> col1 = matrix:GetColumnMajorArray()
output col1:GetSize()
end
end
``````

GetColumnVector(integer column)

This method is used to get a column of a Matrix returned as an vector of numbers.

Parameters

• integer column: The column number of the matrix to return.

Return

Libraries.Compute.Vector: An vector containing only the specified column.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Vector col1 = matrix:GetColumnVector(0)
output col1:GetSize()
end
end
``````

GetColumns()

This method is used to get the number of columns in a matrix.

Return

integer: The number of columns in the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:SetSize(2, 3)
output matrix:GetColumns()
end
end
``````

GetDeterminant()

This method returns the determinant of a square matrix. The determinant is the product of the eigenvalues. Attribute Returns determinant of the matrix

Return

number:

Example

``````
use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:GetDeterminant()
end
end
``````

GetDiagonal()

This method returns the diagonal of a square matrix Attribute Returns Matrix of the diagonal values.

Return

Example

``````
use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:GetDiagonal():ToText()
end
end
``````

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

``````Object o
integer hash = o:GetHashCode()
``````

GetMaximum()

This method returns the value of the maximum element in a Matrix Attribute Returns The value of the largest element in the matrix.

Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMaximum()
end
end
``````

GetMean()

This method returns the mean (average) of all the elements in a Matrix Attribute Returns The mean of all the elements in the matrix.

Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMean()
end
end
``````

GetMedian()

This method returns the median (middle value) of all the elements in a Matrix Attribute Returns The median of all the elements in the matrix.

Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMedian()
end
end
``````

GetMinimum()

This method returns the value of the minimum element in a Matrix Attribute Returns The value of the smallest element in the matrix.

Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMinimum()
end
end
``````

GetModes()

This method returns an array of all the modes (most common value) of a Matrix Attribute Returns An array of the modes of all the elements in the matrix.

Return

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
Array<number> modes = matrix:GetModes()
output modes:Get(0)
end
end
``````