Matrix2D
2D matrix operations
Operations
- Add
- AverageColumn
- AverageRow
- Concatenate
- Divide
- DotProduct
- DotSigmoid
- EuclideanDistance
- GetColumn
- GetRow
- HadamardDivide
- HadamardProduct
- Identity
- Inverse
- LeakyReLU
- Multiple
- Random
- RandomNormal
- ReLU
- Sigmoid
- Softmax
- Solve
- Split
- Subtract
- SumColumn
- SumRow
- Tanh
- ToBool
- ToFloat
- ToInt
- Transpose
Add # native
Adds a constant to a matrix
function : native : Add(c:Float, m:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| c | Float | constant |
| m | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Add # native
Adds a constant to a matrix
function : native : Add(m:Float[,], c:Float) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m | Float | matrix |
| c | Float | constant |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Add # native
Adds two matrices
function : native : Add(m1:Float[,], m2:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m1 | Float | left matrix |
| m2 | Float | right matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
AverageColumn # native
Average of the given column
function : native : AverageColumn(c:Int, matrix:Float[,]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| c | Int | column index |
| matrix | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | average of the column |
AverageRow # native
Average of the given row
function : native : AverageRow(r:Int, matrix:Float[,]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| r | Int | row index |
| matrix | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | average of the row |
Concatenate # function
Concatenates two matrix
function : Concatenate(a:Float[,], b:Float[,], is_row:Bool) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| a | Float | left matrix |
| b | Float | right matrix |
| is_row | Bool | true concatenate by rows, false for columns |
Return
| Type | Description |
|---|---|
| Float | concatenated matrix |
Divide # native
Divides a constant by a matrix
function : native : Divide(c:Float, m:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| c | Float | constant |
| m | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Divide # native
Divides a constant by a matrix
function : native : Divide(m:Float[,], c:Float) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m | Float | matrix |
| c | Float | constant |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
DotProduct # native
Calculates the dot product.
function : native : DotProduct(m1:Float[,], m2:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m1 | Float | left matrix |
| m2 | Float | right matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
DotSigmoid # native
Calculates the Dot Product applying while applying the Sigmoid function to all elements
function : native : DotSigmoid(a:Float[,], b:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| a | Float | matrix |
| b | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
EuclideanDistance # native
Calculates the Euclidean Distance between the two vectors
function : native : EuclideanDistance(m1:Float[,]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| m1 | Float | data matrix |
Return
| Type | Description |
|---|---|
| Float | Euclidean Distance between the two vectors |
Example
# Two 3D points: [1,4], [2,5], [3,6] paired as columns
points := [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]];
dist := Matrix2D->EuclideanDistance(points);
"Distance: {$dist}"->PrintLine();GetColumn # native
Get the column from a matrix
function : native : GetColumn(c:Int, matrix:Float[,]) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| c | Int | column index |
| matrix | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | column from matrix |
GetRow # native
Get the row from a matrix
function : native : GetRow(r:Int, matrix:Float[,]) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| r | Int | row index |
| matrix | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | row from matrix |
HadamardDivide # native
Divides two matrices using the Hadamard rule
function : native : HadamardDivide(m1:Float[,], m2:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m1 | Float | left matrix |
| m2 | Float | right matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
HadamardProduct # native
Multiplies two matrices using the Hadamard rule
function : native : HadamardProduct(m1:Float[,], m2:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m1 | Float | left matrix |
| m2 | Float | right matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Identity # native
Creates an identity a matrix
function : native : Identity(s:Int) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| s | Int | size of matrix |
Return
| Type | Description |
|---|---|
| Float | row from matrix |
Inverse # native
Inverse of matrix
function : native : Inverse(a:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| a | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | inverted matrix |
LeakyReLU # native
Leaky ReLU activation function
function : native : LeakyReLU(x:Float, alpha:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | input value |
| alpha | Float | slope for negative values (default 0.01) |
Return
| Type | Description |
|---|---|
| Float | Leaky ReLU value |
LeakyReLU # native
Applies the Leaky ReLU function to all elements
function : native : LeakyReLU(b:Float[,], alpha:Float) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| b | Float | matrix |
| alpha | Float | slope for negative values |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Multiple # native
Multiplies a constant by a matrix
function : native : Multiple(c:Float, m:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| c | Float | constant |
| m | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Multiple # native
Multiplies a constant by a matrix
function : native : Multiple(m:Float[,], c:Float) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m | Float | matrix |
| c | Float | constant |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Random # function
Generates a random 2D array of values from 0.0 to 1.0
function : Random(rows:Int, cols:Int) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| rows | Int | rows |
| cols | Int | columns |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
RandomNormal # function
Generates a random normal distribution of values
function : RandomNormal(mean:Float, variance:Float, rows:Int, cols:Int) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| mean | Float | center of values |
| variance | Float | variance in values |
| rows | Int | rows |
| cols | Int | columns |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
RandomNormal # function
Generates a random normal value
function : RandomNormal(mean:Float, variance:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| mean | Float | center of values |
| variance | Float | variance in values |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
ReLU # native
ReLU (Rectified Linear Unit) activation function
function : native : ReLU(x:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | input value |
Return
| Type | Description |
|---|---|
| Float | ReLU value (max(0, x)) |
Example
"ReLU(-1.5)={$Matrix2D->ReLU(-1.5)}"->PrintLine();
"ReLU(3.2)={$Matrix2D->ReLU(3.2)}"->PrintLine();ReLU # native
Applies the ReLU function to all elements
function : native : ReLU(b:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| b | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Sigmoid # native
Sigmoid 'S' function
function : native : Sigmoid(x:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | input value |
Return
| Type | Description |
|---|---|
| Float | Sigmoid value |
Example
val := Matrix2D->Sigmoid(2.0);
"Sigmoid(2.0)={$val}"->PrintLine();Sigmoid # native
Applies the Sigmoid function to all elements
function : native : Sigmoid(b:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| b | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Softmax # native
Softmax activation function for classification
function : native : Softmax(b:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| b | Float | matrix (single row or column vector) |
Return
| Type | Description |
|---|---|
| Float | normalized probability distribution |
Example
logits := [[1.0], [2.0], [3.0]];
probs := Matrix2D->Softmax(logits);
each(i : probs->Size()[0]) {
probs[i,0]->PrintLine();
};Solve # native
Solves a unit of equations
function : native : Solve(m1:Float[,], m2:Float[,]) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| m1 | Float | data matrix |
| m2 | Float | result matrix |
Return
| Type | Description |
|---|---|
| Float | least squares |
Example
A := [[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]];
b := [[1.0], [2.0], [3.0]];
coeffs := Matrix2D->Solve(A, b);
each(c in coeffs) {
c->PrintLine();
};Split # native
Splits a matrix
function : native : Split(b:Float[,], offset:Int, count:Int, is_row:Bool) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| b | Float | matrix |
| offset | Int | offset index |
| count | Int | number of rows to split |
| is_row | Bool | true for row split, false for column |
Return
| Type | Description |
|---|---|
| Float | copied matrix |
Subtract # native
Subtracts a constant from a matrix
function : native : Subtract(c:Float, m:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| c | Float | constant |
| m | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Subtract # native
Adds a constant to a matrix
function : native : Subtract(m:Float[,], c:Float) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m | Float | matrix |
| c | Float | constant |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
Subtract # native
Subtracts two matrices
function : native : Subtract(m1:Float[,], m2:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| m1 | Float | left matrix |
| m2 | Float | right matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
SumColumn # native
Sum of the given column
function : native : SumColumn(c:Int, matrix:Float[,]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| c | Int | column index |
| matrix | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | sum of the column |
SumRow # native
Sum of the given row
function : native : SumRow(r:Int, matrix:Float[,]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| r | Int | row index |
| matrix | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | sum of the row |
Tanh # native
Tanh (Hyperbolic Tangent) activation function
function : native : Tanh(x:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | input value |
Return
| Type | Description |
|---|---|
| Float | Tanh value |
Example
"Tanh(0.5)={$Matrix2D->Tanh(0.5)}"->PrintLine();Tanh # native
Applies the Tanh function to all elements
function : native : Tanh(b:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| b | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | updated matrix |
ToBool # function
Parsers a boolean value
function : ToBool(m:Float[,]) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| m | Float | matrix |
Return
| Type | Description |
|---|---|
| Bool | boolean value |
ToFloat # function
Parsers a decimal value
function : ToFloat(m:Float[,]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| m | Float | matrix |
Return
| Type | Description |
|---|---|
| Float | decimal value |