Matrix Utilities Library

The matrix utilities return information on various attributes of vector space mapping and related matrix tensors.

The URI for the matrix utilities is <http://cambridgesemantics.com/anzograph/matrices#>. For readability, the syntax for each function below includes the prefix matrices:, defined as PREFIX matrices: <http://cambridgesemantics.com/anzograph/matrices#>.

Matrix Information

  • dump_tensor: Displays the Armadillo header and the first few elements of the matrix or vector as a string.
  • dump_vec: Returns the string representation of a row or column vector.
  • get_cols: Returns the number of columns present in a tensor.
  • get_diag: Extracts a diagonal from a matrix or sparse matrix.
  • get_elem: Accesses one or more elements that are stored in a tensor.
  • get_max_val: Retrieves the maximum value from a tensor.
  • get_min_val: Retrieves the minimum value from a tensor.
  • get_nonzero: Returns the number of non-zero elements that are present in a sparse matrix.
  • get_order: Returns the tensor order.
  • get_rows: Returns the number of rows present in a tensor.
  • get_shape: Formats the shape of a tensor as a string.
  • get_slices: Returns the number of slices present in a tensor.
  • get_subvec: Extracts a range of elements from a row or column vector.
  • get_total_elem: Returns the total number of elements that are present in a tensor.

dump_tensor

This function displays the Armadillo header and the first few elements of the matrix or vector as a string.

Syntax

matrices:dump_tensor(b [, type ] [, isRowWise ]) 
Parameter Type Description
b http://anzograph.com/matrices#tensor A tensor of matrix/row vector/column vector.
type int Optional argument that specifies the type of tensor: 0=row vector, 1=column vector, 2=matrix. Default is 2.
isRowWise Boolean Optional argument that indicates whether the display matrix is column- or row- wise: false=column-wise, true=row-wise. Default is true.

Returns

Type Description
string Row- or column- wise string representation of the vector or matrix.

dump_vec

This function returns the string representation of a row or column vector.

Syntax

matrices:dump_vec(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The row or column vector to convert to a string.

Returns

Type Description
string The string representation of the row or column vector.

get_cols

This function returns the number of columns present in a tensor.

Syntax

matrices:get_cols(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor to evaluate.

Returns

Type Description
long The number of columns.

get_diag

This function extracts a diagonal from a matrix or sparse matrix.

Syntax

matrices:get_diag(b [, k ])
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix or sparse matrix.
k long Optional diagonal number. By default, the main diagonal is accessed (k=0). For k>0 , the kth super-diagonal is accessed (top right corner). For k<0, the kth sub-diagonal is accessed (bottom left corner).

Returns

Type Description
http://anzograph.com/matrices#tensor The tensor representation of the diagonal as a column vector.

get_elem

This function accesses one or more elements that are stored in a tensor.

Syntax

matrices:get_elem(b, i [, j ] [, k ])
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor.
i long The element stored in the ith row.
j long Optional argument that lists the element stored in the jth column.
k long Optional argument that lists the element stored in the kth slice.

Returns

Type Description
double The element value.

get_max_val

This function retrieves the maximum value from a tensor.

Syntax

matrices:getmax_val(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor from which to return the maximum value.

Returns

Type Description
double The maximum value in the tensor.

get_min_val

This function retrieves the minimum value from a tensor.

Syntax

matrices:getmin_val(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor from which to return the minimum value.

Returns

Type Description
double The minimum value from the tensor.

get_nonzero

This function gets the number of non-zero elements that are present in a sparse matrix.

Syntax

matrices:get_nonzero(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The sparse matrix.

Returns

Type Description
long The number of non-zero elements.

get_order

This function returns the tensor order.

Syntax

matrices:get_order(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor to evaluate.

Returns

Type Description
long The tensor order.

get_rows

This function returns the number of rows present in a tensor.

Syntax

matrices:get_rows(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor for which to return the number of rows.

Returns

Type Description
long The number of rows.

get_shape

This function formats the shape of a tensor as a string.

Syntax

matrices:get_shape(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor to format.

Returns

Type Description
string The shape of the tensor.

get_slices

This function gets the number of slices present in a tensor.

Syntax

matrices:get_slices(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor for which to return the number of slices.

Returns

Type Description
long The number of slices.

get_subvec

This function extracts a range of elements from a row or column vector.

Syntax

matrices:get_subvec(b, i, j)
Parameter Type Description
b http://anzograph.com/matrices#tensor The row or column vector.
i long The start index.
j long The end index.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a row or column vector.

get_total_elem

This function returns the total number of elements that are present in a tensor.

Syntax

matrices:get_total_elem(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The tensor for which to return the total number of elements.

Returns

Type Description
long The total number of elements.

Matrix Properties

  • has_nan: Evaluates whether a matrix is not a number (NaN).
  • is_colvec: Evaluates whether the given matrix is a column vector.
  • is_diag_mat: Evaluates whether a matrix is diagonal.
  • is_hermitian: Evaluates whether the matrix is hermitian (self-adjoint).
  • is_rowvec: Evaluates whether the given matrix is a row vector.
  • is_sorted: Evaluates whether a vector or matrix is sorted.
  • is_square: Evaluates whether a matrix is square.
  • is_symmetric: Evaluates whether a matrix is symmetrical.
  • is_tri_mat_lower: Evaluates whether a matrix is lower triangular.
  • is_tri_mat_upper: Evaluates whether a matrix is upper triangular.
  • is_vec: Evaluates whether the given matrix is a row or column vector.

has_nan

This function evaluates whether a matrix is not a number (NaN).

Syntax

matrices:has_nan(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean Returns true if at least one of the elements is NaN and false if all elements are numbers.

is_colvec

This function evaluates whether the given matrix is a column vector.

Syntax

matrices:is_colvec(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean True if the matrix can be interpreted as a column vector. False if the matrix does not have exactly one column.

is_diag_mat

This function evaluates whether a matrix is diagonal, i.e., all elements outside of the main diagonal are zero.

Syntax

matrices:is_diag_mat(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean Returns true if the matrix is diagonal and false if it is not.

is_hermitian

This function evaluates whether a matrix is hermitian (self-adjoint).

Syntax

matrices:is_hermitian(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean Returns true if the matrix is hermitian and false if it is not.

is_rowvec

This function evaluates whether the given matrix is a row vector.

Syntax

matrices:is_rowvec(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean True if the matrix can be interpreted as a row vector. False if the matrix does not have exactly one row.

is_sorted

This function evaluates whether a vector or matrix is sorted.

Syntax

matrices:is_sorted(b [, t ] [, d ])
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.
t boolean Optional argument that specifies the sort dimension for the matrix. Set to true if elements are sorted row-wise and false if they are sorted column-wise. Default is false.
d int Optional argument that specifies the sort direction for the matrix. Allowed arguments are:
  • 0: ascend (default). Elements are ascending; consecutive elements can be equal.
  • 1: descend. Elements are descending; consecutive elements can be equal.
  • 2: strictascend. Elements are strictly ascending; consecutive elements cannot be equal.
  • 3: strictdescend. Elements are strictly descending; consecutive elements cannot be equal.

Returns

Type Description
boolean True if the elements are sorted. False if they are not.

is_square

This function evaluates whether a matrix is square, i.e., the number of rows is equal to the number of columns.

Syntax

matrices:is_square(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean Returns true if the matrix is square and false if it is not.

is_symmetric

This function evaluates whether a matrix is symmetrical.

Syntax

matrices:is_symmetric(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean Returns true if the matrix is symmetrical and false if it is not.

is_tri_mat_lower

This function evaluates whether a matrix is lower triangular, i.e., the matrix is square sized and all elements above the main diagonal are zero.

Syntax

matrices:is_tri_mat_lower(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean Returns true if the matrix is lower triangular and false if it is not.

is_tri_mat_upper

This function evaluates whether a matrix is upper triangular, i.e., the matrix is square sized and all elements below the main diagonal are zero.

Syntax

matrices:is_tri_mat_upper(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean Returns true if the matrix is upper triangular and false if it is not.

is_vec

This function evaluates whether the given matrix is a row or column vector.

Syntax

matrices:is_vec(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.

Returns

Type Description
boolean True if the matrix can be interpreted as a column or row vector. False if the matrix does not have exactly one column or one row.

Matrix and Vector Construction

  • gramian: Creates a Gramian matrix that is commonly used to compute linear independence.
  • make_matrix: Creates a matrix of doubles with the given dimensions and values.
  • make_tensor_from_string: Constructs a tensor from the given dimensions in a string.
  • make_vec: Constructs a row vector with the given index and value to be stored in the index.
  • string_from_vector: Formats a row vector as a plain string.
  • vector_from_string: Returns a vector from a string representation of a vector.

gramian

The Gramian matrix linear algebra aggregate creates a Gramian matrix commonly used to compute linear independence.

Syntax

matrices:gramian(x1, x2, ..., xn)
Parameter Type Description
x1–xn double The feature column datasets.

Returns

Type Description
http://anzograph.com/matrices#tensor The Gramian matrix.

make_matrix

This function creates a matrix of doubles with the given dimensions and values.

Syntax

matrices:make_matrix(m, n [, v1, v2, ..., vn ])
Parameter Type Description
m int The number of rows for the new matrix.
n int The number of columns for the new matrix.
v1–vn double Optional arguments that specify the row-wise matrix elements to include. Default value is 0 for all elements.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation for m x n matrix of doubles.

make_tensor_from_string

This function constructs a tensor from the given dimensions in a string.

Syntax

matrices:make_tensor_from_string(s [, n ])
Parameter Type Description
s string The string that contains the row-wise elements for constructing the tensor.
n int Optional argument that specifies the number of columns to include in the tensor. The default value is 0, which constructs a row vector. A value of 1 constructs a column vector. A value that is greater than 1 constructs a matrix with the specified number of columns.

Returns

Type Description
http://anzograph.com/matrices#tensor A tensor of doubles.

make_vec

This aggregate constructs a row vector with the given index and value to be stored in the index.

Syntax

matrices:make_vec(n, v)
Parameter Type Description
n int The index into the vector.
v double The value to be stored in the vector at the nth index.

Returns

Type Description
http://anzograph.com/matrices#tensor A row vector.

string_from_vector

This function formats a row vector as a plain string.

Syntax

matrices:string_from_vector(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The row vector to format.

Returns

Type Description
string The row vector.

vector_from_string

This function returns a vector from a string representation of a vector.

Syntax

matrices:vector_from_string(s)
Parameter Type Description
s string The string representation of a vector.

Returns

Type Description
http://anzograph.com/matrices#tensor The vector as a tensor.

Submatrix and Subvector Extraction

  • subvec_head: Extracts starting elements from a row or column vector.
  • subvec_tail: Extracts tailing elements from a row or column vector.
  • subview_col: Extracts a column from a matrix or sparse matrix.
  • subview_cols: Extracts a range of columns from a matrix or sparse matrix.
  • subview_head_cols: Extracts starting columns from a matrix or sparse matrix.
  • subview_head_rows: Extracts starting rows from a matrix or sparse matrix.
  • subview_mat: Extracts a submatrix from a matrix or sparse matrix.
  • subview_row: Extracts a row from a matrix or sparse matrix.
  • subview_rows: Extracts a range of rows from a matrix or sparse matrix.
  • subview_tail_cols: Extracts tailing columns from a matrix or sparse matrix.
  • subview_tail_rows: Extracts tailing rows from a matrix or sparse matrix.

subvec_head

This function extracts starting elements from a row or column vector.

Syntax

matrices:subvec_head(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor A row or column vector.
n long The number of elements to extract from the beginning of the vector.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a row or column vector with elements from 0 to n-1.

subvec_tail

This function extracts tailing elements from a row or column vector.

Syntax

matrices:subvec_tail(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor A row or column vector.
n long The number of elements to extract from the end of the vector.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a row or column vector with n elements from the tail.

subview_col

This function extracts a column from a matrix or sparse matrix.

Syntax

matrices:subview_col(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor A matrix or sparse matrix.
n long The column index.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a column vector.

subview_cols

This function extracts a range of columns from a matrix or sparse matrix.

Syntax

matrices:subview_cols(b, c1, ..., cn)
Parameter Type Description
b http://anzograph.com/matrices#tensor A matrix or sparse matrix.
c1–n long The start column index to the end column index.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of the matrix with columns from c1 to cn.

subview_head_cols

This function extracts starting columns from a matrix or sparse matrix.

Syntax

matrices:subview_head_cols(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to extract starting columns from.
n long The number of columns to extract from the beginning of the matrix.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a matrix with columns from 0 to n-1.

subview_head_rows

This function extracts starting rows from a matrix or sparse matrix.

Syntax

matrices:subview_head_rows(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to extract starting rows from.
n long The number of rows to extract from the beginning of the matrix

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a matrix with rows from 0 to n-1.

subview_mat

This function extracts a submatrix from a matrix or sparse matrix.

Syntax

matrices:subview_mat(b, r1, ..., rn, c1, ..., cn)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to extract a submatrix from.
r1–n long The start row index to the end row
index.
c1–n long The start column index to the end column index.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a matrix of size [1+(rn-r1)] x [1+(cn-c1)].

subview_row

This function extracts a row from a matrix or sparse matrix.

Syntax

matrices:subview_row(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to extract the row from.
n long The row index.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a row vector.

subview_rows

This function extracts a range of rows from a matrix or sparse matrix.

Syntax

matrices:subview_rows(b, r1, ..., rn)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to extract the rows from.
r1–rn long The start row index to the end row
index.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of the matrix with rows from r1 to rn.

subview_tail_cols

This function extracts tailing columns from a matrix or sparse matrix.

Syntax

matrices:subview_tail_cols(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to extract trailing columns from.
n long The number of columns to extract from the end of the matrix.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a matrix with n columns from the tail.

subview_tail_rows

This function extracts tailing rows from a matrix or sparse matrix.

Syntax

matrices:subview_tail_rows(b, n)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to extract tailing rows from.
n long The number of rows to extract from the end of the matrix.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a matrix with n rows from the tail.

Correlation and Similarity

  • cancor: Calculates the overall correlation between two sets of variables.
  • cosine_similarity: Calculates the cosine similarity between two row vectors.
  • covariance: Provides a measure of the strength of the correlation between two or more sets of random variables.

cancor

The Canonical correlation aggregate calculates the canonical correlation between two sets of variables.

Syntax

matrices:cancor(lc, m, x1, x2, ..., xn, y1, y2, ..., yn)
Parameter Type Description
lc int The number of linear combinations for the first canonical correlation.
m int The number of columns in the first set.
x1–xn double The feature columns from the first dataset.
y1–yn double The feature columns from the second dataset.

Returns

Type Description
string Canonical correlation.
string Square of the canonical correlation.
string Canonical coefficient.

cosine_similarity

This function calculates the cosine similarity between two row vectors.

The cosine_similarity function is not compatible with column or matrix vectors. The input must be row vectors.

Syntax

matrices:cosine_similarity(m, n)
Parameter Type Description
m http://anzograph.com/matrices#tensor A row vector.
n http://anzograph.com/matrices#tensor The row vector to compare to the vector in argument m.

Returns

Type Description
double Results range from -1 to 1: -1 is perfectly dissimilar and 1 is perfectly similar.

covariance

The Covariance aggregate provides a measure of the strength of the correlation between two or more sets of random variables (or variates).

Syntax

matrices:covariance(x1, x2, ..., xn) 
Parameter Type Description
x1–xn double Feature columns from the dataset.

Returns

Type Description
http://anzograph.com/matrices#tensor The covariance matrix.

Distance and Vector Flattening

euclidean_distance

This function returns the euclidean distance between two vectors.

Syntax

matrices:euclidean_distance(b, c)
Parameter Type Description
b http://anzograph.com/matrices#tensor The first vector in the calculation.
c http://anzograph.com/matrices#tensor The vector to calculate the distance from vector b.

Returns

Type Description
double The euclidean distance between the input vectors.

flatten_as_col

This function returns a flattened version of a matrix as a column vector.

Syntax

matrices:flatten_as_col(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to flatten.

Returns

Type Description
http://anzograph.com/matrices#tensor The tensor representation of the matrix as a column vector.

flatten_as_row

This function returns a flattened version of a matrix as a row vector.

Syntax

matrices:flatten_as_row(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to flatten.

Returns

Type Description
http://anzograph.com/matrices#tensor The tensor representation of the matrix as a row vector.

Dimensionality Reduction

Linear Discriminant Analysis (LDA)

Linear discriminant analysis functions apply linear discriminant analysis (LDA) to create combined eigenvalues and vectors that characterize or separate two or more classes of objects or events. The following functions are available for LDA operations:

lda::create

This aggregate applies LDA to create combined eigenvalues and eigenvectors.

Syntax

matrices:lda::create(y, x1, x2, ..., xn)
Parameter Type Description
y double

The class of the feature tuple.

x1–xn double The feature column datasets.

Returns

Type Description
http://anzograph.com/matrices#lda_result The combined eigenvalues, eigenvectors, class mean, count, and class map.

lda::get_eigvec

Given LDA data, this function returns LDA's eigenvectors as a matrix.

Syntax

matrices:lda::get_eigvec(lda_data) 
Parameter Type Description
lda_data http://anzograph.com/matrices#lda_result Linear discriminant analysis data.

Returns

Type Description
http://anzograph.com/matrices#tensor Eigenvectors as a matrix.

lda::get_eigval

Given LDA data, this function gets LDA's eigenvalues as a column vector.

Syntax

matrices:lda::get_eigval(lda_data)
Parameter Type Description
lda_data http://anzograph.com/matrices#lda_result Linear discriminant analysis data.

Returns

Type Description
http://anzograph.com/matrices#tensor Eigenvalues in descending order as a column vector.

lda::get_raw_eigval

Given LDA data, this function gets LDA's unsorted eigenvalues.

Syntax

matrices:lda::get_raw_eigval(lda_data) 
Parameter Type Description
lda_data http://anzograph.com/matrices#lda_result LDA data.

Returns

Type Description
http://anzograph.com/matrices#tensor Eigenvalues in unsorted order as a column vector.

lda::predict

This function predicts the class for the samples using LDA as the classifier.

Syntax

matrices:lda::predict(lda_data, p1, p2, ..., pn)
Parameter Type Description
lda_data http://anzograph.com/matrices#lda_result LDA data.
p1–pn double The data sample that contains the class to predict.

Returns

Type Description
string The class name to which data tuple belongs.

lda::transform

This function applies LDA to transform samples onto the new subspace.

Syntax

matrices:lda::transform(lda_data, d, x1, x2, ..., xn)
Parameter Type Description
lda_data http://anzograph.com/matrices#lda_result Linear discriminant analysis data.
d int The number of eigenvectors to consider from the start.
x1–xn double The feature column datasets.

Returns

Type Description
double The original data transformed into the tuple of lower dimensional space.

Principal Component Analysis (PCA)

Applies Principal component analysis (PCA) to create combined eigenvalues and vectors that highlight patterns in a dataset, making it easier to explore and visualize data. The following functions are available for PCA operations:

pca::create

This aggregate applies PCA to create combined eigenvalues and eigenvectors.

Syntax

matrices:pca::create(x1, x2, ..., xn)
Parameter Type Description
x1–xn double The feature column datasets.

Returns

Type Description
http://anzograph.com/matrices#feature_result PCA data containing eigenvalues and eigenvectors.

pca::get_eigval

This function retrieves PCA's eigenvalues as a column vector from PCA data.

Syntax

matrices:pca::get_eigval(pca_data)
Parameter Type Description
pca_data http://anzograph.com/matrices#feature_result Principal Component Analysis data.

Returns

Type Description
http://anzograph.com/matrices#tensor Eigenvalues in descending order as column vectors.

pca::get_eigvec

This function retrieves PCA's eigenvectors as a matrix from the PCA data.

Syntax

matrices:pca::get_eigvec(pca_data)
Parameter Type Description
pca_data http://anzograph.com/matrices#feature_result Principal Component Analysis data.

Returns

Type Description
http://anzograph.com/matrices#tensor Eigenvectors as a matrix.

pca::get_raw_eigval

This function gets the PCA's unsorted eigenvalues from the PCA data.

Syntax

matrices:pca::get_raw_eigval(pca_data)
Parameter Type Description
pca_data http://anzograph.com/matrices#feature_result Principal Component Analysis data.

Returns

Type Description
http://anzograph.com/matrices#tensor Eigenvalues in unsorted order as column vectors.

Singular Value Decomposition (SVD)

The Singular value decomposition (SVD) matrix factorization method creates combined singular values and right singular vectors.

The following functions are available for SVD operations:

svd::create

This aggregate applies SVD to create combined singular values and right singular vectors.

Syntax

matrices:svd::create(x1, x2, ..., xn) 
Parameter Type Description
x1–xn double The feature column datasets.

Returns

Type Description
http://anzograph.com/matrices#feature_result SVD data containing singular values and right singular vectors.

svd::get_sigval

This function gets SVD's singular values as a column vector from the SVD data.

Syntax

matrices:svd::get_sigval(svd_data)
Parameter Type Description
svd_data http://anzograph.com/matrices#feature_result SVD data.

Returns

Type Description
http://anzograph.com/matrices#tensor Singular values in descending order as a column vector.

svd::get_sigvec

This function gets SVD's singular vector as a matrix from the SVD data.

Syntax

matrices:svd::get_sigvec(svd_data)
Parameter Type Description
svd_data http://anzograph.com/matrices#feature_result SVD data.

Returns

Type Description
http://anzograph.com/matrices#tensor Right singular vectors as a matrix.

transform

This function applies PCA or SVD (depending on the input) to transform the samples onto the new subspace.

Syntax

matrices:transform(data, d, x1, x2, ..., xn) 
Parameter Type Description
data http://anzograph.com/matrices#feature_result PCA or SVD data.
d int The number of eigenvectors to consider from the end.
x1–xn double Feature column datasets.

Returns

Type Description
double Sample data transformed into the tuple of lower dimensional space.

Mathematical Operations

  • sigmoid: Returns the logistic sigmoid calculation of a vector.
  • vdiff: Returns the difference between two vectors.
  • vsum: Returns the sum of two vectors.

sigmoid

This function returns the logistic sigmoid calculation of a vector.

Syntax

matrices:sigmoid(b)
Parameter Type Description
b http://anzograph.com/matrices#tensor The vector to evaluate.

Returns

Type Description
http://anzograph.com/matrices#tensor The logistic sigmoid of the vector.

vdiff

This function returns the difference between two vectors.

Syntax

matrices:vdiff(b, c)
Parameter Type Description
b http://anzograph.com/matrices#tensor The first vector in the calculation.
c http://anzograph.com/matrices#tensor The vector to subtract from vector b.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of the difference between the input vectors.

vsum

This function returns the sum of two vectors.

Syntax

matrices:vsum(b, c)
Parameter Type Description
b http://anzograph.com/matrices#tensor The first vector in the calculation.
c http://anzograph.com/matrices#tensor The vector to add to vector b.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of the sum of the input vectors.

Relational Condition Evaluation

  • mat_all: Evaluates whether all elements in a matrix are non-zero or satisfy the specified relational condition.
  • mat_any: Evaluates whether any elements in a matrix are non-zero or satisfy the specified relational condition.
  • vec_all: Evaluates whether all elements in a row or column vector are non-zero or satisfy the specified relational condition.
  • vec_any: Evaluates whether any elements in a row or column vector are non-zero or satisfy the specified relational condition.

mat_all

This function evaluates whether all elements in a matrix are non-zero or satisfy the specified relational condition.

Syntax

matrices:mat_all(b [, d ] [, c ] [, val ])
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.
d boolean Optional argument that indicates whether to check rows or columns. Set to true for rows or false for columns. Default is false.
c int Optional argument that specifies the relational condition to test:
  • 0 (default): not equal
  • 1: greater than
  • 2: less than
  • 3: equal
  • 4: greater than or equal to
  • 5: less than or equal to
val double Optional argument that specifies the value to apply the condition (c) to. Default is 0.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a row vector with each element as 0 or 1, indicating whether the corresponding row or column has all non-zero elements.

mat_any

This function evaluates whether any elements in a matrix are non-zero or satisfy the specified relational condition.

Syntax

matrices:mat_any(b [, d ] [, c ] [, val ])
Parameter Type Description
b http://anzograph.com/matrices#tensor The matrix to evaluate.
d boolean Optional argument that indicates whether to check rows or columns. Set to true for rows or false for columns. Default is false.
c int Optional argument that specifies the relational condition to test:
  • 0 (default): not equal
  • 1: greater than
  • 2: less than
  • 3: equal
  • 4: greater than or equal to
  • 5: less than or equal to
val double Optional argument that specifies the value to apply the condition (c) to. Default is 0.

Returns

Type Description
http://anzograph.com/matrices#tensor Tensor representation of a row vector with each element as 0 or 1, indicating whether the corresponding row or column has any non-zero elements.

vec_all

This function evaluates whether all elements in a row or column vector are non-zero or satisfy the specified relational condition.

Syntax

matrices:vec_all(b [, c ] [, val ])
Parameter Type Description
b http://anzograph.com/matrices#tensor The vector to evaluate.
c int Optional argument that specifies the relational condition to test:
  • 0 (default): not equal
  • 1: greater than
  • 2: less than
  • 3: equal
  • 4: greater than or equal to
  • 5: less than or equal to
val double Optional argument that specifies the value to apply the condition (c) to. Default is 0.

Returns

Type Description
boolean Returns true if all elements are non-zero or satisfy the condition and false if not.

vec_any

This function evaluates whether any elements in a row or column vector are non-zero or satisfy the specified relational condition.

Syntax

matrices:vec_any(b [, c ] [, val ])
Parameter Type Description
b http://anzograph.com/matrices#tensor The vector to evaluate.
c int Optional argument that specifies the relational condition to test:
  • 0 (default): not equal
  • 1: greater than
  • 2: less than
  • 3: equal
  • 4: greater than or equal to
  • 5: less than or equal to
val double Optional argument that specifies the value to apply the condition (c) to. Default is 0.

Returns

Type Description
boolean Returns true if any elements are non-zero or satisfy the condition and false if not.