Documentation
¶
Index ¶
- func CallOut1(fun func(a tensor.Tensor, out *tensor.Float64) error, a tensor.Tensor) *tensor.Float64
- func CallOut2(fun func(a, b tensor.Tensor, out *tensor.Float64) error, a, b tensor.Tensor) *tensor.Float64
- func CopyFromDense(to tensor.Values, dm *mat.Dense)
- func Det(a tensor.Tensor) *tensor.Float64
- func Diagonal(tsr tensor.Tensor, offset ...int) *tensor.Indexed
- func DiagonalIndices(size int, offset_cols ...int) *tensor.Int
- func DiagonalN(size int, offset_cols ...int) int
- func Eig(a tensor.Tensor) (vecs, vals *tensor.Float64)
- func EigOut(a tensor.Tensor, vecs, vals *tensor.Float64) error
- func EigSym(a tensor.Tensor) (vecs, vals *tensor.Float64)
- func EigSymOut(a tensor.Tensor, vecs, vals *tensor.Float64) error
- func Identity(size int, offset_cols ...int) *tensor.Float64
- func Inverse(a tensor.Tensor) *tensor.Float64
- func InverseOut(a tensor.Tensor, out *tensor.Float64) error
- func LogDet(a tensor.Tensor) *tensor.Float64
- func Mul(a, b tensor.Tensor) *tensor.Float64
- func MulOut(a, b tensor.Tensor, out *tensor.Float64) error
- func NewDense(tsr *tensor.Float64) (*mat.Dense, error)
- func ProjectOnMatrixColumn(mtx, vec, colindex tensor.Tensor) tensor.Values
- func ProjectOnMatrixColumnOut(mtx, vec, colindex tensor.Tensor, out tensor.Values) error
- func SVD(a tensor.Tensor) (vecs, vals *tensor.Float64)
- func SVDOut(a tensor.Tensor, vecs, vals *tensor.Float64) error
- func SVDValues(a tensor.Tensor) *tensor.Float64
- func SVDValuesOut(a tensor.Tensor, vals *tensor.Float64) error
- func StringCheck(tsr tensor.Tensor) error
- func Trace(tsr tensor.Tensor, offset ...int) tensor.Values
- func Tri(size int, offset_cols ...int) *tensor.Float64
- func TriL(tsr tensor.Tensor, offset ...int) tensor.Tensor
- func TriLIndicies(size int, offset_cols ...int) *tensor.Int
- func TriLNum(size int, offset_cols ...int) int
- func TriLView(tsr tensor.Tensor, offset ...int) *tensor.Indexed
- func TriU(tsr tensor.Tensor, offset ...int) tensor.Tensor
- func TriUIndicies(size int, offset_cols ...int) *tensor.Int
- func TriUNum(size int, offset_cols ...int) int
- func TriUView(tsr tensor.Tensor, offset ...int) *tensor.Indexed
- func TriUpper(size int, offset_cols ...int) *tensor.Float64
- type Matrix
- type Symmetric
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallOut1 ¶
func CallOut1(fun func(a tensor.Tensor, out *tensor.Float64) error, a tensor.Tensor) *tensor.Float64
CallOut1 calls an Out function with 1 input arg. All matrix functions require *tensor.Float64 outputs.
func CallOut2 ¶
func CallOut2(fun func(a, b tensor.Tensor, out *tensor.Float64) error, a, b tensor.Tensor) *tensor.Float64
CallOut2 calls an Out function with 2 input args. All matrix functions require *tensor.Float64 outputs.
func CopyFromDense ¶
CopyFromDense copies a gonum mat.Dense matrix into given Tensor using standard Float64 interface
func Det ¶
Det returns the determinant of the given tensor. For a 2D matrix [[a, b], [c, d]] it this is ad - bc. See also LogDet for a version that is more numerically stable for large matricies.
func Diagonal ¶
Diagonal returns an [Indexed] view of the given tensor for the diagonal values, as a 1D list. An error is logged if the tensor is not 2D. Use the optional offset parameter to get values above (positive) or below (negative) the diagonal.
func DiagonalIndices ¶
DiagonalIndices returns a list of indices for the diagonal elements of a 2D matrix of given row and column size. The result is a 2D list of indices, where the outer (row) dimension is the number of indices, and the inner dimension is 2 for the r, c coords.
- If one additional parameter is passed, it is the offset, to set values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix (first size parameter = number of rows).
func DiagonalN ¶
DiagonalN returns the number of elements in the along the diagonal of a 2D matrix of given row and column size.
- If one additional parameter is passed, it is the offset, to include values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix (first size parameter = number of rows).
func Eig ¶
Eig performs the eigen decomposition of the given square matrix, which is not symmetric. See EigSym for a symmetric square matrix. In this non-symmetric case, the results are typically complex valued, so the outputs are complex tensors. TODO: need complex support! The vectors are same size as the input. Each vector is a column in this 2D square matrix, ordered *lowest* to *highest* across the columns, i.e., maximum vector is the last column. The values are the size of one row, ordered *lowest* to *highest*. If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func EigOut ¶
EigOut performs the eigen decomposition of the given square matrix, which is not symmetric. See EigSym for a symmetric square matrix. In this non-symmetric case, the results are typically complex valued, so the outputs are complex tensors. TODO: need complex support! The vectors are same size as the input. Each vector is a column in this 2D square matrix, ordered *lowest* to *highest* across the columns, i.e., maximum vector is the last column. The values are the size of one row, ordered *lowest* to *highest*. If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func EigSym ¶
EigSym performs the eigen decomposition of the given symmetric square matrix, which produces real-valued results. When input is the [metric.CovarianceMatrix], this is known as Principal Components Analysis (PCA). The vectors are same size as the input. Each vector is a column in this 2D square matrix, ordered *lowest* to *highest* across the columns, i.e., maximum vector is the last column. The values are the size of one row, ordered *lowest* to *highest*. Note that Eig produces results in the *opposite* order of SVD (which is much faster). If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func EigSymOut ¶
EigSymOut performs the eigen decomposition of the given symmetric square matrix, which produces real-valued results. When input is the [metric.CovarianceMatrix], this is known as Principal Components Analysis (PCA). The vectors are same size as the input. Each vector is a column in this 2D square matrix, ordered *lowest* to *highest* across the columns, i.e., maximum vector is the last column. The values are the size of one row, ordered *lowest* to *highest*. Note that Eig produces results in the *opposite* order of SVD (which is much faster). If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func Identity ¶
Identity returns a new 2D Float64 tensor with 1s along the diagonal and 0s elsewhere, with the given row and column size.
- If one additional parameter is passed, it is the offset, to set values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix (first size parameter = number of rows).
func Inverse ¶
Inverse performs matrix inversion of a square matrix, logging an error for non-invertable cases. See InverseOut for a version that returns an error. If the input tensor is > 2D, it is treated as a list of 2D matricies which are each inverted.
func InverseOut ¶
InverseOut performs matrix inversion of a square matrix, returning an error for non-invertable cases. If the input tensor is > 2D, it is treated as a list of 2D matricies which are each inverted.
func LogDet ¶
LogDet returns the determinant of the given tensor, as the log and sign of the value, which is more numerically stable. The return is a 1D vector of length 2, with the first value being the log, and the second the sign.
func Mul ¶
Mul performs matrix multiplication, using the following rules based on the shapes of the relevant tensors. If the tensor shapes are not suitable, an error is logged (see MulOut for a version returning the error). N > 2 dimensional cases use parallel threading where beneficial.
- If both arguments are 2-D they are multiplied like conventional matrices.
- If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly.
- If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed.
- If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed.
func MulOut ¶
MulOut performs matrix multiplication, into the given output tensor, using the following rules based on the shapes of the relevant tensors. If the tensor shapes are not suitable, a [gonum] mat.ErrShape error is returned. N > 2 dimensional cases use parallel threading where beneficial.
- If both arguments are 2-D they are multiplied like conventional matrices. The result has shape a.Rows, b.Columns.
- If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly. Both cannot be > 2 dimensional, unless their outer dimension size is 1 or the same.
- If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed.
- If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed.
func NewDense ¶
NewDense returns given tensor.Float64 as a [gonum] mat.Dense Matrix, on which many of the matrix operations are defined. It functions similar to the tensor.Values type, as the output of matrix operations. The Dense type serves as a view onto the tensor's data, so operations directly modify it.
func ProjectOnMatrixColumn ¶
ProjectOnMatrixColumn is a convenience function for projecting given vector of values along a specific column (2nd dimension) of the given 2D matrix, specified by the scalar colindex, putting results into out. If the vec is more than 1 dimensional, then it is treated as rows x cells, and each row of cells is projected through the matrix column, producing a 1D output with the number of rows. Otherwise a single number is produced. This is typically done with results from SVD or EigSym (PCA).
func ProjectOnMatrixColumnOut ¶
ProjectOnMatrixColumnOut is a convenience function for projecting given vector of values along a specific column (2nd dimension) of the given 2D matrix, specified by the scalar colindex, putting results into out. If the vec is more than 1 dimensional, then it is treated as rows x cells, and each row of cells is projected through the matrix column, producing a 1D output with the number of rows. Otherwise a single number is produced. This is typically done with results from SVD or EigSym (PCA).
func SVD ¶
SVD performs the singular value decomposition of the given symmetric square matrix, which produces real-valued results, and is generally much faster than EigSym, while producing the same results. The vectors are same size as the input. Each vector is a column in this 2D square matrix, ordered *highest* to *lowest* across the columns, i.e., maximum vector is the first column. The values are the size of one row ordered in alignment with the vectors. Note that SVD produces results in the *opposite* order of EigSym. If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func SVDOut ¶
SVDOut performs the singular value decomposition of the given symmetric square matrix, which produces real-valued results, and is generally much faster than EigSym, while producing the same results. The vectors are same size as the input. Each vector is a column in this 2D square matrix, ordered *highest* to *lowest* across the columns, i.e., maximum vector is the first column. The values are the size of one row ordered in alignment with the vectors. Note that SVD produces results in the *opposite* order of EigSym. If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func SVDValues ¶
SVDValues performs the singular value decomposition of the given symmetric square matrix, which produces real-valued results, and is generally much faster than EigSym, while producing the same results. This version only generates eigenvalues, not vectors: see SVD. The values are the size of one row ordered highest to lowest, which is the opposite of EigSym. If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func SVDValuesOut ¶
SVDValuesOut performs the singular value decomposition of the given symmetric square matrix, which produces real-valued results, and is generally much faster than EigSym, while producing the same results. This version only generates eigenvalues, not vectors: see SVDOut. The values are the size of one row ordered highest to lowest, which is the opposite of EigSym. If the input tensor is > 2D, it is treated as a list of 2D matricies, and parallel threading is used where beneficial.
func StringCheck ¶
func Trace ¶
Trace returns the sum of the Diagonal elements of the given tensor, as a tensor scalar. An error is logged if the tensor is not 2D. Use the optional offset parameter to get values above (positive) or below (negative) the diagonal.
func Tri ¶
Tri returns a new 2D Float64 tensor with 1s along the diagonal and below it, and 0s elsewhere (i.e., a filled lower triangle).
- If one additional parameter is passed, it is the offset, to include values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix (first size parameter = number of rows).
func TriL ¶
TriL returns a copy of the given tensor containing the lower triangular region of values (including the diagonal), with the lower triangular region zeroed. An error is logged if the tensor is not 2D. Use the optional offset parameter to include values above (positive) or below (negative) the diagonal.
func TriLIndicies ¶
TriLIndicies returns the list of r, c indexes for the lower triangular portion of a square matrix of size n, including the diagonal. The result is a 2D list of indices, where the outer (row) dimension is the number of indices, and the inner dimension is 2 for the r, c coords.
- If one additional parameter is passed, it is the offset, to include values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix.
func TriLNum ¶
TriLNum returns the number of elements in the lower triangular region of a 2D matrix of given row and column size, where the triangle includes the elements along the diagonal.
- If one additional parameter is passed, it is the offset, to include values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix (first size parameter = number of rows).
func TriLView ¶
TriLView returns an [Indexed] view of the given tensor for the lower triangular region of values, as a 1D list. An error is logged if the tensor is not 2D. Use the optional offset parameter to get values above (positive) or below (negative) the diagonal.
func TriU ¶
TriU returns a copy of the given tensor containing the upper triangular region of values (including the diagonal), with the lower triangular region zeroed. An error is logged if the tensor is not 2D. Use the optional offset parameter to include values above (positive) or below (negative) the diagonal.
func TriUIndicies ¶
TriUIndicies returns the list of r, c indexes for the upper triangular portion of a square matrix of size n, including the diagonal. If one additional parameter is passed, it is the offset, to include values above (positive) or below (negative) the diagonal. If a second additional parameter is passed, it is the number of columns for a non-square matrix. The result is a 2D list of indices, where the outer (row) dimension is the number of indices, and the inner dimension is 2 for the r, c coords.
func TriUNum ¶
TriUNum returns the number of elements in the upper triangular region of a 2D matrix of given row and column size, where the triangle includes the elements along the diagonal.
- If one additional parameter is passed, it is the offset, to include values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix (first size parameter = number of rows).
func TriUView ¶
TriUView returns an [Indexed] view of the given tensor for the upper triangular region of values, as a 1D list. An error is logged if the tensor is not 2D. Use the optional offset parameter to get values above (positive) or below (negative) the diagonal.
func TriUpper ¶
TriUpper returns a new 2D Float64 tensor with 1s along the diagonal and above it, and 0s elsewhere (i.e., a filled upper triangle).
- If one additional parameter is passed, it is the offset, to include values above (positive) or below (negative) the diagonal.
- If a second additional parameter is passed, it is the number of columns for a non-square matrix (first size parameter = number of rows).
Types ¶
type Matrix ¶
Matrix provides a view of the given tensor.Tensor as a [gonum] mat.Matrix interface type.
func NewMatrix ¶
NewMatrix returns given tensor.Tensor as a [gonum] mat.Matrix. It returns an error if the tensor is not 2D.
func (*Matrix) At ¶
At is the gonum/mat.Matrix interface method for returning 2D matrix element at given row, column index. Assumes Row-major ordering.
type Symmetric ¶
type Symmetric struct {
Matrix
}
Symmetric provides a view of the given tensor.Tensor as a [gonum] mat.Symmetric matrix interface type.
func NewSymmetric ¶
NewSymmetric returns given tensor.Tensor as a [gonum] mat.Symmetric matrix. It returns an error if the tensor is not 2D or not symmetric.
func (*Symmetric) SymmetricDim ¶
SymmetricDim is the gonum/mat.Matrix interface method for returning the dimensionality of a symmetric 2D Matrix.