| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Numeric.LinAlg
Description
This module provides an interface for specifying immutable linear algebra computations.
This is done with the Matr typeclass.
- data Dim
- class Solve n dim | dim -> n where
- class Product a b where
- class (Floating k, Scale k arr) => Matr k arr where
- fromVect :: Vect n k -> arr (V n) k
- toVect :: arr (V n) k -> Vect n k
- fromVects :: Vect m (Vect n k) -> arr (M m n) k
- toVects :: arr (M m n) k -> Vect m (Vect n k)
- toRows :: arr (M m n) k -> Vect m (arr (V n) k)
- toColumns :: arr (M m n) k -> Vect n (arr (V m) k)
- fromRows :: Vect m (arr (V n) k) -> arr (M m n) k
- fromColumns :: Vect n (arr (V m) k) -> arr (M m n) k
- asColMat :: arr (V n) k -> arr (M n 1) k
- asColVec :: arr (M n 1) k -> arr (V n) k
- fromDiag :: arr (V n) k -> arr (M n n) k
- takeDiag :: arr (M n n) k -> arr (V n) k
- dim :: arr (M m n) k -> (SNat m, SNat n)
- rows :: arr (M m n) k -> SNat m
- cols :: arr (M m n) k -> SNat n
- len :: arr (V n) k -> SNat n
- trans :: arr (M m n) k -> arr (M n m) k
- ident :: SNat n -> arr (M n n) k
- outer :: arr (V m) k -> arr (V n) k -> arr (M m n) k
- (>.<) :: arr (V n) k -> arr (V n) k -> k
- mXm :: arr (M m n) k -> arr (M n p) k -> arr (M m p) k
- elementwiseprod :: arr (M m n) k -> arr (M m n) k -> arr (M m n) k
- inv :: arr (M n n) k -> arr (M n n) k
- invL :: arr (M n n) k -> arr (M n n) k
- invU :: arr (M n n) k -> arr (M n n) k
- chol :: arr (M n n) k -> arr (M n n) k
- cholInv :: arr (M n n) k -> arr (M n n) k
- cholLnDet :: arr (M n n) k -> k
- trsymprod :: arr (M n n) k -> arr (M n n) k -> k
- constant :: k -> SNat n -> arr (V n) k
- linearSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
- ltriSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
- utriSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
- posdefSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
- cholSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
- square :: Matr k arr => arr (M m n) k -> Maybe (m :~: n)
- showMat :: (Show k, Matr k arr) => arr (M m n) k -> String
- toLists :: Matr k arr => arr (M m n) k -> [[k]]
- class Scale k arr where
- (.*) :: k -> arr dim k -> arr dim k
Documentation
class Solve n dim | dim -> n where
Infix, overloaded versions of functions for solving linear equations
class Product a b where
class (Floating k, Scale k arr) => Matr k arr where
An instance of means
that Matr k v mv k is a vector type and m k is a matrix type over the field k.
Minimal complete definition
fromVect, toVect, fromVects, toVects, toRows, fromRows, fromColumns, asColMat, fromDiag, takeDiag, dim, len, trans, ident, outer, (>.<), mXm, elementwiseprod, chol, trsymprod, constant, linearSolve
Methods
fromVect :: Vect n k -> arr (V n) k
Convert a list of elements to a vector.
toVect :: arr (V n) k -> Vect n k
Convert a vector to a list of its elements.
fromVects :: Vect m (Vect n k) -> arr (M m n) k
Convert a row-major list of lists of elements (which should all have the same length) to a matrix containing those elements.
toVects :: arr (M m n) k -> Vect m (Vect n k)
Convert a matrix to a list of its rows, each given as a list of elements.
toRows :: arr (M m n) k -> Vect m (arr (V n) k)
Convert a matrix to a list of its rows.
toColumns :: arr (M m n) k -> Vect n (arr (V m) k)
Convert a matrix to a list of its columns.
fromRows :: Vect m (arr (V n) k) -> arr (M m n) k
Convert a list of vectors to a matrix having those vectors as rows.
fromColumns :: Vect n (arr (V m) k) -> arr (M m n) k
Convert a list of vectors to a matrix having those vectors as columns.
asColMat :: arr (V n) k -> arr (M n 1) k
Regard a vector as a matrix with a single column.
asColVec :: arr (M n 1) k -> arr (V n) k
Convert a matrix which has only one column to a vector. This function may have undefined behavior if the input matrix has more than one column.
fromDiag :: arr (V n) k -> arr (M n n) k
Produce a diagonal matrix with the given vector along its diagonal (and zeros elsewhere).
takeDiag :: arr (M n n) k -> arr (V n) k
Return a vector of elements along the diagonal of the matrix. Does not necessarily fail if the matrix is not square.
dim :: arr (M m n) k -> (SNat m, SNat n)
Dimension of a matrix (rows, columns).
rows :: arr (M m n) k -> SNat m
The number of rows in a matrix.
cols :: arr (M m n) k -> SNat n
The number of columns in a matrix.
The length of a vector.
trans :: arr (M m n) k -> arr (M n m) k
Transpose a matrix.
ident :: SNat n -> arr (M n n) k
Construct the identity matrix of a given dimension.
outer :: arr (V m) k -> arr (V n) k -> arr (M m n) k
Compute the outer product of two vectors.
(>.<) :: arr (V n) k -> arr (V n) k -> k infixl 7
Compute the dot product (i.e., inner product) of two vectors.
mXm :: arr (M m n) k -> arr (M n p) k -> arr (M m p) k
elementwiseprod :: arr (M m n) k -> arr (M m n) k -> arr (M m n) k
Compute the elementwise product (i.e., Hadamard product) of two matrices.
inv :: arr (M n n) k -> arr (M n n) k
General matrix inverse.
invL :: arr (M n n) k -> arr (M n n) k
Inverse of a lower-triangular matrix.
invU :: arr (M n n) k -> arr (M n n) k
Inverse of an upper-triangular matrix.
chol :: arr (M n n) k -> arr (M n n) k
Cholesky decomposition of a positive-definite symmetric matrix. Returns lower triangular matrix of the decomposition. May not necessarily zero out the upper portion of the matrix.
cholInv :: arr (M n n) k -> arr (M n n) k
Invert a positive-definite symmetric system using a precomputed
Cholesky decomposition. That is, if l == and
chol a b == , then cholInv l b is the inverse of a .
cholLnDet :: arr (M n n) k -> k
Compute the log-determinant of a positive-definite symmetric matrix
using its precomputed Cholesky decomposition. That is, if
l == and chol a d == , then cholLnDet l d is the
log-determinant of a .
trsymprod :: arr (M n n) k -> arr (M n n) k -> k
If matrices a and b are symmetric, then trsymprod a b is
the trace of a . Note that in this case, the trace of
>< b a is just the sum of the elements in the element-wise
product of >< b a and b .
constant :: k -> SNat n -> arr (V n) k
Create a vector of a given length whose elements all have the same value.
linearSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
Solve a general system. If there is some x such that
m , then >< x == b x == 'linearSolve m b' .
ltriSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
Solve a lower-triangular system. If l is a lower-triangular
matrix, then x == means that ltriSolve l b l .>< x == b
utriSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
Solve a upper-triangular system. If u is a upper-triangular
matrix, then x == means that utriSolve u b u .>< x == b
posdefSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k
Solve a positive-definite symmetric system. That is, if a is a
positive-definite symmetric matrix and x == , then
posdefSolve a b a .>< x == b
cholSolve :: arr (M n n) k -> arr (M n p) k -> arr (M n p) k