Provides tools for working with various matrix types, including fixed-size (2x2, 3x3, 4x4), Java double[][]
arrays, and Apache Commons Math RealMatrix
.
It offers efficient mathematical operations for linear algebra, geometric transformations, and data manipulation, unifying different representations under a common protocol approach where appropriate.
Provides tools for working with various matrix types, including fixed-size (2x2, 3x3, 4x4), Java `double[][]` arrays, and Apache Commons Math `RealMatrix`. It offers efficient mathematical operations for linear algebra, geometric transformations, and data manipulation, unifying different representations under a common protocol approach where appropriate.
(acos vector)
Applies acos to matrix elements.
Applies acos to matrix elements.
(acosh vector)
Applies acosh to matrix elements.
Applies acosh to matrix elements.
(acot vector)
Applies acot to matrix elements.
Applies acot to matrix elements.
(acoth vector)
Applies acoth to matrix elements.
Applies acoth to matrix elements.
(acsc vector)
Applies acsc to matrix elements.
Applies acsc to matrix elements.
(acsch vector)
Applies acsch to matrix elements.
Applies acsch to matrix elements.
(adds A s)
Adds scalar to all matrix elements
Adds scalar to all matrix elements
(array2d->mat2x2 arrs)
Creates 2x2 matrix from 2d double array.
Creates 2x2 matrix from 2d double array.
(array2d->mat3x3 arrs)
Creates 3x3 matrix from 2d double array.
Creates 3x3 matrix from 2d double array.
(array2d->mat4x4 arrs)
Creates 4x4 matrix from 2d double array.
Creates 4x4 matrix from 2d double array.
(array2d->RealMatrix arrs)
Creates RealMatrix matrix from 2d double array.
Creates RealMatrix matrix from 2d double array.
(asec vector)
Applies asec to matrix elements.
Applies asec to matrix elements.
(asech vector)
Applies asech to matrix elements.
Applies asech to matrix elements.
(asin vector)
Applies asin to matrix elements.
Applies asin to matrix elements.
(asinh vector)
Applies asinh to matrix elements.
Applies asinh to matrix elements.
(atan vector)
Applies atan to matrix elements.
Applies atan to matrix elements.
(atanh vector)
Applies atanh to matrix elements.
Applies atanh to matrix elements.
(bind-cols mats)
(bind-cols m & r)
Creates matrix from columns of given matrices.
Creates matrix from columns of given matrices.
(bind-rows mats)
(bind-rows m & r)
Creates matrix from rows of given matrices.
Creates matrix from rows of given matrices.
(block-diagonal mats)
(block-diagonal m & r)
Creates block diagonal matrix (RealMatrix) from a sequence of square matrices.
Creates block diagonal matrix (RealMatrix) from a sequence of square matrices.
(cbrt vector)
Applies cbrt to matrix elements.
Applies cbrt to matrix elements.
(ceil vector)
Applies ceil to matrix elements.
Applies ceil to matrix elements.
(cholesky A)
(cholesky A upper?)
Calculates L (lower by default) triangular for where L * L^T = A.
Checks only for symmetry, can return NaNs when A is not positive-definite.
Calculates L (lower by default) triangular for where L * L^T = A. Checks only for symmetry, can return NaNs when A is not positive-definite.
(cholesky-decomposition mat)
(cholesky-decomposition mat symmetry_threshold positivity_threshold)
Performs Cholesky decomposition.
Decomposition of real symmetric positive-definite matrix. A = L x LT
Solver minimizes using least squares method.
Components, access with decomposition-component
function:
:L
, :LT
- matrices:det
- determinant.Can be used as input for solve
, inverse
and singular?
functions.
Performs Cholesky decomposition. Decomposition of real symmetric positive-definite matrix. A = L x LT Solver minimizes using least squares method. Components, access with `decomposition-component` function: * `:L`, `:LT` - matrices * `:det` - determinant. Can be used as input for `solve`, `inverse` and `singular?` functions.
(cols->mat real-matrix-cols)
(cols->mat [a00 a10] [a01 a11])
(cols->mat [a00 a10 a20] [a01 a11 a21] [a02 a12 a22])
(cols->mat [a00 a10 a20 a30]
[a01 a11 a21 a31]
[a02 a12 a22 a32]
[a03 a13 a23 a33])
Creates nxn matrix from nd vectors (columns).
Creates nxn matrix from nd vectors (columns).
(cols->mat2x2 [a00 a10] [a01 a11])
Create 2x2 matrix from 2d vectors (columns).
Create 2x2 matrix from 2d vectors (columns).
(cols->mat3x3 [a00 a10 a20] [a01 a11 a21] [a02 a12 a22])
Creates 3x3 matrix from 3d vectors (columns).
Creates 3x3 matrix from 3d vectors (columns).
(cols->mat4x4 [a00 a10 a20 a30]
[a01 a11 a21 a31]
[a02 a12 a22 a32]
[a03 a13 a23 a33])
Creates 4x4 matrix from 4d vectors (columns).
Creates 4x4 matrix from 4d vectors (columns).
(cols->RealMatrix cols)
Returns Apache Commons Math Array2DRowMatrix from sequence of columns
Returns Apache Commons Math Array2DRowMatrix from sequence of columns
(condition A)
(condition A norm-type)
Condition number calculated for L2 norm by default (see norm
for other norm types).
Cond(A) = norm(A) * norm(inv(A))
Condition number calculated for L2 norm by default (see [[norm]] for other norm types). Cond(A) = norm(A) * norm(inv(A))
(cos vector)
Applies cos to matrix elements.
Applies cos to matrix elements.
(cosh vector)
Applies cosh to matrix elements.
Applies cosh to matrix elements.
(cot vector)
Applies cot to matrix elements.
Applies cot to matrix elements.
(coth vector)
Applies coth to matrix elements.
Applies coth to matrix elements.
(csc vector)
Applies csc to matrix elements.
Applies csc to matrix elements.
(csch vector)
Applies csch to matrix elements.
Applies csch to matrix elements.
(decomposition-component decomposition-matrix component-name)
Returns value of the component of matrix decomposition
Returns value of the component of matrix decomposition
(degrees vector)
Applies degrees to matrix elements.
Applies degrees to matrix elements.
(demean A)
(demean A rows?)
Subracts mean from columns (or rows)
Subracts mean from columns (or rows)
(det A)
Returns determinant of the matrix.
Returns determinant of the matrix.
(diag A)
Returns diagonal of the matrix as a vector.
Returns diagonal of the matrix as a vector.
(diag->mat2x2 d)
(diag->mat2x2 d1 d2)
Creates 2x2 diagonal matrix.
Creates 2x2 diagonal matrix.
(diag->mat3x3 d)
(diag->mat3x3 d1 d2 d3)
Creates 3x3 diagonal matrix.
Creates 3x3 diagonal matrix.
(diag->mat4x4 d)
(diag->mat4x4 d1 d2 d3 d4)
Creates 4x4 diagonal matrix.
Creates 4x4 diagonal matrix.
(diagonal v)
(diagonal a11 a22)
(diagonal a11 a22 a33)
(diagonal a11 a22 a33 a44)
Creates diagonal matrix.
Creates diagonal matrix.
(differences m)
(differences m diffs)
(differences m diffs lag)
Apply lagged differences on matrix columns, always returns RealMatrix.
Apply lagged differences on matrix columns, always returns RealMatrix.
(eigen-decomposition mat)
Performs Eigen decomposition.
A = V x D x VT, D contains eigenvalues (diagonal: real values, subdiagonal: imaginary), V - eigenvectors.
Solver is exact.
Components, access with decomposition-component
function:
:D
, :V
, :VT
, :sqrt
- matrices.:det
- determinant:real-eigenvalues
, imag-eigenvalues
- eigenvalues:eigenvectors
- sequence of eigenvectors:complex?
- are eigenvalues complex?Can be used as input for solve
, inverse
and singular?
functions.
Performs Eigen decomposition. A = V x D x VT, D contains eigenvalues (diagonal: real values, subdiagonal: imaginary), V - eigenvectors. Solver is exact. Components, access with `decomposition-component` function: * `:D`, `:V`, `:VT`, `:sqrt` - matrices. * `:det` - determinant * `:real-eigenvalues`, `imag-eigenvalues` - eigenvalues * `:eigenvectors` - sequence of eigenvectors * `:complex?` - are eigenvalues complex? Can be used as input for `solve`, `inverse` and `singular?` functions.
(eigenvalues A)
Returns complex eigenvalues for given matrix as a sequence
Returns complex eigenvalues for given matrix as a sequence
(eigenvalues-matrix A)
Returns eigenvalues for given matrix as a diagonal or block diagonal matrix
Returns eigenvalues for given matrix as a diagonal or block diagonal matrix
(eigenvectors A)
(eigenvectors A normalize?)
Returns eigenvectors as a matrix (columns). Vectors can be normalized.
Returns eigenvectors as a matrix (columns). Vectors can be normalized.
(emulm A B)
Multiplies two matrices element-wise, Hadamard product, C=AoB
Multiplies two matrices element-wise, Hadamard product, C=AoB
(entry A row col)
Returns entry at given row and column
Returns entry at given row and column
(exp vector)
Applies exp to matrix elements.
Applies exp to matrix elements.
(expm1 vector)
Applies expm1 to matrix elements.
Applies expm1 to matrix elements.
(eye size)
(eye size real-matrix?)
Creates identity matrix for given size.
Creates identity matrix for given size.
(floor vector)
Applies floor to matrix elements.
Applies floor to matrix elements.
(fmap A f)
Applies a function f
to each matrix element.
Applies a function `f` to each matrix element.
(frac vector)
Applies frac to matrix elements.
Applies frac to matrix elements.
(inverse m)
Matrix inversion.
Returns nil
if inversion doesn't exist.
Matrix inversion. Returns `nil` if inversion doesn't exist.
(kronecker mat1 mat2)
Returns Kronecker product of two matrices.
Returns Kronecker product of two matrices.
(log vector)
Applies log to matrix elements.
Applies log to matrix elements.
(log10 vector)
Applies log10 to matrix elements.
Applies log10 to matrix elements.
(log1mexp vector)
Applies log1mexp to matrix elements.
Applies log1mexp to matrix elements.
(log1p vector)
Applies log1p to matrix elements.
Applies log1p to matrix elements.
(log1pexp vector)
Applies log1pexp to matrix elements.
Applies log1pexp to matrix elements.
(log1pmx vector)
Applies log1pmx to matrix elements.
Applies log1pmx to matrix elements.
(log1psq vector)
Applies log1psq to matrix elements.
Applies log1psq to matrix elements.
(log2 vector)
Applies log2 to matrix elements.
Applies log2 to matrix elements.
(logexpm1 vector)
Applies logexpm1 to matrix elements.
Applies logexpm1 to matrix elements.
(logit vector)
Applies logit to matrix elements.
Applies logit to matrix elements.
(logmxp1 vector)
Applies logmxp1 to matrix elements.
Applies logmxp1 to matrix elements.
(lu-decomposition mat)
(lu-decomposition mat threshold)
Performs QR decomposition.
A = inv(P) x L x U, L is lower triangular, U is upper triangular.
Solver is exact.
Components, access with decomposition-component
function:
:L
, :U
, :P
(permutation) - matrices.:det
- determinant:pivot
- pivot permutation vectorCan be used as input for solve
, inverse
and singular?
functions.
Performs QR decomposition. A = inv(P) x L x U, L is lower triangular, U is upper triangular. Solver is exact. Components, access with `decomposition-component` function: * `:L`, `:U`, `:P` (permutation) - matrices. * `:det` - determinant * `:pivot` - pivot permutation vector Can be used as input for `solve`, `inverse` and `singular?` functions.
(map-cols f A)
Operate on columns, f should return a column
Operate on columns, f should return a column
(map-rows f A)
Operate on rows, f should return a row
Operate on rows, f should return a row
(mat real-matrix-rows)
(mat a00 a01 a10 a11)
(mat a00 a01 a02 a10 a11 a12 a20 a21 a22)
(mat a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 a30 a31 a32 a33)
Creates mat2x2, mat3x3 or mat4x4 or RealMatrix from rows
Creates mat2x2, mat3x3 or mat4x4 or RealMatrix from rows
(mat->array A)
Returns flat double array of entries (row order)
Returns flat double array of entries (row order)
(mat->array2d A)
Returns doubles of doubles
Returns doubles of doubles
(mat->float-array A)
Returns flat float array of entries (row order)
Returns flat float array of entries (row order)
(mat->float-array2d A)
Returns doubles of doubles
Returns doubles of doubles
(mat->RealMatrix A)
Returns Apache Commons Math Array2DRowMatrix from a 2x2, 3x3 or 4x4 matrix
Returns Apache Commons Math Array2DRowMatrix from a 2x2, 3x3 or 4x4 matrix
(mat->seq A)
Returns flat sequence of entries (row order)
Returns flat sequence of entries (row order)
(mat2x2 v)
(mat2x2 d1 d2)
(mat2x2 a00 a01 a10 a11)
Creates 2x2 matrix.
Arity:
Creates 2x2 matrix. Arity: * 1 - fills matrix with given value * 2 - creates diagonal matrix * 4 - creates row ordered matrix
(mat3x3 v)
(mat3x3 d1 d2 d3)
(mat3x3 a00 a01 a02 a10 a11 a12 a20 a21 a22)
Creates 3x3 matrix.
Arity:
Creates 3x3 matrix. Arity: * 1 - fills matrix with given value * 3 - creates diagonal matrix * 9 - creates row ordered matrix
(mat4x4 v)
(mat4x4 d1 d2 d3 d4)
(mat4x4 a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 a30 a31 a32 a33)
Creates 4x4 matrix.
Arity:
Creates 4x4 matrix. Arity: * 1 - fills matrix with given value * 4 - creates diagonal matrix * 16 - creates row ordered matrix
(mulm A B)
(mulm A transposeA? B transposeB?)
Multiplies two matrices, C=AxB.
Optionally you can apply transposition of matrices.
Multiplies two matrices, C=AxB. Optionally you can apply transposition of matrices.
(mulmt A B)
Multiplies with transposed matrix, C=AxB^T
Multiplies with transposed matrix, C=AxB^T
(muls A s)
Multplies matrix by a scalar, C=sA
Multplies matrix by a scalar, C=sA
(mulv A v)
Multplies matrix by a vector, x=Av
Multplies matrix by a vector, x=Av
(negate A)
Negates all matrix elements, C=-A
Negates all matrix elements, C=-A
(norm A)
(norm A norm-type)
Calculates norm of the matrix for given type, default: 1 (maximum absolute column sum).
All norm types are:
Calculates norm of the matrix for given type, default: 1 (maximum absolute column sum). All norm types are: * 1 - maximum absolute column sum * :inf - maximum absolute row sum * 2 - spectral norm, maximum singular value * :max - maximum absolute value * :frobenius - Frobenius norm * [p,q] - generalized L_pq norm, [2,2] - Frobenius norm, [p,p] - entrywise p-norm * [p] - Shatten p-norm, [1] - nuclear/trace norm
(normalize A)
(normalize A rows?)
Normalizes columns (or rows)
Normalizes columns (or rows)
(outer v1 v2)
Outer project for two vectors.
Outer project for two vectors.
(pow m exponent)
Applies power to a vector elements.
Applies power to a vector elements.
(pow10 vector)
Applies pow10 to matrix elements.
Applies pow10 to matrix elements.
(qr-decomposition mat)
(qr-decomposition mat threshold)
Performs QR decomposition.
A = Q x R, Q is orthogonal (QT x Q = I), R is upper triangular.
Solver minimizes using least squares method.
Components, access with decomposition-component
function:
:H
(Hauseholder reflecors), :Q
, :QT
, :R
- matrices.Can be used as input for solve
, inverse
and singular?
functions.
Performs QR decomposition. A = Q x R, Q is orthogonal (QT x Q = I), R is upper triangular. Solver minimizes using least squares method. Components, access with `decomposition-component` function: * `:H` (Hauseholder reflecors), `:Q`, `:QT`, `:R` - matrices. Can be used as input for `solve`, `inverse` and `singular?` functions.
(radians vector)
Applies radians to matrix elements.
Applies radians to matrix elements.
(real-matrix rows)
Creates Apache Commons Math Array2DRowMatrix from sequence of rows
Creates Apache Commons Math Array2DRowMatrix from sequence of rows
(rint vector)
Applies rint to matrix elements.
Applies rint to matrix elements.
(rotation-matrix-2d theta)
Creates rotation matrix for a plane
Creates rotation matrix for a plane
(rotation-matrix-3d [x y z])
(rotation-matrix-3d x y z)
Creates rotation matrix for a 3d space. Tait–Bryan angles z-y′-x″
Creates rotation matrix for a 3d space. Tait–Bryan angles z-y′-x″
(rotation-matrix-3d-x a)
Creates rotation matrix for a 3d space, x-axis, right hand rule.
Creates rotation matrix for a 3d space, x-axis, right hand rule.
(rotation-matrix-3d-y a)
Creates rotation matrix for a 3d space, y-axis, right hand rule.
Creates rotation matrix for a 3d space, y-axis, right hand rule.
(rotation-matrix-3d-z a)
Creates rotation matrix for a 3d space, z-axis, right hand rule.
Creates rotation matrix for a 3d space, z-axis, right hand rule.
(rotation-matrix-axis-3d angle axis)
Creates 3d rotation matrix for axis ratation.
Creates 3d rotation matrix for axis ratation.
(round vector)
Applies round to matrix elements.
Applies round to matrix elements.
(rows->mat real-matrix-rows)
(rows->mat [a00 a01] [a10 a11])
(rows->mat [a00 a01 a02] [a10 a11 a12] [a20 a21 a22])
(rows->mat [a00 a01 a02 a03]
[a10 a11 a12 a13]
[a20 a21 a22 a23]
[a30 a31 a32 a33])
Creates nxn matrix from nd vectors (rows).
Creates nxn matrix from nd vectors (rows).
(rows->mat2x2 [a00 a01] [a10 a11])
Creates 2x2 matrix from 2d vectors (rows).
Creates 2x2 matrix from 2d vectors (rows).
(rows->mat3x3 [a00 a01 a02] [a10 a11 a12] [a20 a21 a22])
Creates 3x3 matrix from 3d vectors (rows).
Creates 3x3 matrix from 3d vectors (rows).
(rows->mat4x4 [a00 a01 a02 a03]
[a10 a11 a12 a13]
[a20 a21 a22 a23]
[a30 a31 a32 a33])
Creates 4x4 matrix from 4d vectors (rows).
Creates 4x4 matrix from 4d vectors (rows).
(rows->RealMatrix rows)
Returns Apache Commons Math Array2DRowMatrix from sequence of rows
Returns Apache Commons Math Array2DRowMatrix from sequence of rows
(rrqr-decomposition mat)
(rrqr-decomposition mat threshold)
Performs Rank-Revealing QR decomposition.
A = Q x R x inv(P), Q is orthogonal (QT x Q = I), R is upper triangular.
Solver minimizes using least squares method.
Components, access with decomposition-component
function:
:H
(Hauseholder reflecors), :Q
, :QT
, :R
, :P
(permutation) - matrices:rank-fn
- calculates numerical matrix rank, accepts threshold for rank computation (default: 0.0).Can be used as input for solve
, inverse
and singular?
functions.
Performs Rank-Revealing QR decomposition. A = Q x R x inv(P), Q is orthogonal (QT x Q = I), R is upper triangular. Solver minimizes using least squares method. Components, access with `decomposition-component` function: * `:H` (Hauseholder reflecors), `:Q`, `:QT`, `:R`, `:P` (permutation) - matrices * `:rank-fn` - calculates numerical matrix rank, accepts threshold for rank computation (default: 0.0). Can be used as input for `solve`, `inverse` and `singular?` functions.
(safe-sqrt vector)
Applies safe-sqrt to matrix elements.
Applies safe-sqrt to matrix elements.
(scale-cols A)
(scale-cols A scale)
Multiplies cols by a value (default: 1/(sqrt(sum(x^2)/(n-1)))) or a result of the function
Multiplies cols by a value (default: 1/(sqrt(sum(x^2)/(n-1)))) or a result of the function
(scale-rows A)
(scale-rows A scale)
Multiplies rows by a value (default: 1/(sqrt(sum(x^2)/(n-1)))) or a result of the function
Multiplies rows by a value (default: 1/(sqrt(sum(x^2)/(n-1)))) or a result of the function
(sec vector)
Applies sec to matrix elements.
Applies sec to matrix elements.
(sech vector)
Applies sech to matrix elements.
Applies sech to matrix elements.
(sfrac vector)
Applies sfrac to matrix elements.
Applies sfrac to matrix elements.
(sgn vector)
Applies sgn to matrix elements.
Applies sgn to matrix elements.
(shift-cols A)
(shift-cols A shift)
Shifts columns by a value or a result of the function (negative of mean by default)
Shifts columns by a value or a result of the function (negative of mean by default)
(shift-rows A)
(shift-rows A shift)
Shifts rows by a value or a result of the function (nagetive of mean by default)
Shifts rows by a value or a result of the function (nagetive of mean by default)
(sigmoid vector)
Applies sigmoid to matrix elements.
Applies sigmoid to matrix elements.
(signum vector)
Applies signum to matrix elements.
Applies signum to matrix elements.
(sin vector)
Applies sin to matrix elements.
Applies sin to matrix elements.
(sinc vector)
Applies sinc to matrix elements.
Applies sinc to matrix elements.
(singular-values A)
Returuns singular values of the matrix as sqrt of eigenvalues of A^T * A matrix.
Returuns singular values of the matrix as sqrt of eigenvalues of A^T * A matrix.
(singular? mat)
Returns singularity of the matrix
Returns singularity of the matrix
(sinh vector)
Applies sinh to matrix elements.
Applies sinh to matrix elements.
(solve A b)
Solve linear equation Ax=b, if decomposition is provided, decomposition is used.
Some decompositions solve using least squares method.
Solve linear equation Ax=b, if decomposition is provided, decomposition is used. Some decompositions solve using least squares method.
(sqrt vector)
Applies sqrt to matrix elements.
Applies sqrt to matrix elements.
(standardize A)
(standardize A rows?)
Normalizes columns (or rows) to have mean = 0 and stddev = 1
Normalizes columns (or rows) to have mean = 0 and stddev = 1
(sv-decomposition mat)
Performs Singular Value Decomposition (SVD).
A = U x S x VT
Solver minimizes using least squares method.
Components, access with decomposition-component
function:
:S
, :U
, :UT
, :V
:VT
- matrices:singular-values
- vector of singular values:info
:condition-number
:inv-condition-number
:norm
- L2 norm:rank
- effective numerical rankcoviariance-fn
- convariance function, returns covariance V x J x VT, where J is inverse of squares of singular values. When min-sv
argument is provided, ignores singular values lower than its value.Can be used as input for solve
, inverse
and singular?
functions.
Performs Singular Value Decomposition (SVD). A = U x S x VT Solver minimizes using least squares method. Components, access with `decomposition-component` function: * `:S`, `:U`, `:UT`, `:V` `:VT` - matrices * `:singular-values` - vector of singular values * `:info` - `:condition-number` - `:inv-condition-number` - `:norm` - L2 norm - `:rank` - effective numerical rank * `coviariance-fn` - convariance function, returns covariance V x J x VT, where J is inverse of squares of singular values. When `min-sv` argument is provided, ignores singular values lower than its value. Can be used as input for `solve`, `inverse` and `singular?` functions.
(symmetric? A)
(symmetric? A tolerance)
Checks if matrix is symmetric
Checks if matrix is symmetric
(tan vector)
Applies tan to matrix elements.
Applies tan to matrix elements.
(tanh vector)
Applies tanh to matrix elements.
Applies tanh to matrix elements.
(tmulm A B)
Transposes and multiplies, C=A^TxB
Transposes and multiplies, C=A^TxB
(tmulmt A B)
Transposes both and multiplies, C=A^TxB^T
Transposes both and multiplies, C=A^TxB^T
(trace A)
Returns trace of the matrix (sum of diagonal elements)
Returns trace of the matrix (sum of diagonal elements)
(trunc vector)
Applies trunc to matrix elements.
Applies trunc to matrix elements.
(vtmul A v)
Multiplies transposed vector by matrix, C=v^T A
Multiplies transposed vector by matrix, C=v^T A
(xlogx vector)
Applies xlogx to matrix elements.
Applies xlogx to matrix elements.
(zero size)
(zero size real-matrix?)
(zero rows cols real-matrix?)
Creates zero matrix for given size.
Creates zero matrix for given size.
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |