Copyright | (c) Marco Zocca 2017 |
---|---|
License | GPL-3 (see the file LICENSE) |
Maintainer | zocca marco gmail |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
- Matrix and vector elements (optionally Complex)
- Additive group
- Vector space
v
. - Normed vector spaces
- Matrix ring
- Linear vector space
- FiniteDim : finite-dimensional objects
- HasData : accessing inner data (do not export)
- Sparse : sparse datastructures
- Set : types that behave as sets
- SpContainer : sparse container datastructures. Insertion, lookup, toList, lookup with 0 default
- SparseVector
- SparseMatrix
- SparseMatVec
- Utilities
Typeclasses for linear algebra and related concepts
- class (Eq e, Fractional e, Floating e, Num (EltMag e), Ord (EltMag e)) => Elt e where
- class AdditiveGroup v where
- class (AdditiveGroup v, Num (Scalar v)) => VectorSpace v where
- class VectorSpace v => InnerSpace v where
- dot :: InnerSpace v => v -> v -> Scalar v
- (./) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v
- (*.) :: (VectorSpace v, s ~ Scalar v) => v -> s -> v
- cvx :: VectorSpace v => Scalar v -> v -> v -> v
- hilbertDistSq :: InnerSpace v => v -> v -> Scalar v
- class (InnerSpace v, Num (RealScalar v), Eq (RealScalar v), Epsilon (Magnitude v), Show (Magnitude v), Ord (Magnitude v)) => Normed v where
- type Magnitude v :: *
- type RealScalar v :: *
- normInftyR :: (Foldable t, Ord a) => t a -> a
- normInftyC :: (Foldable t, RealFloat a, Functor t) => t (Complex a) -> a
- dotLp :: (Set t, Foldable t, Floating a) => a -> t a -> t a -> a
- reciprocal :: (Functor f, Fractional b) => f b -> f b
- scale :: (Num b, Functor f) => b -> f b -> f b
- class (AdditiveGroup m, Epsilon (MatrixNorm m)) => MatrixRing m where
- type MatrixNorm m :: *
- class VectorSpace v => LinearVectorSpace v where
- type MatrixType v :: *
- type V v = (LinearVectorSpace v, Normed v)
- class LinearVectorSpace v => LinearSystem v where
- class FiniteDim f where
- type FDSize f
- class HasData f where
- type HDData f
- class (FiniteDim f, HasData f) => Sparse f where
- class Functor f => Set f where
- class Sparse c => SpContainer c where
- class SpContainer v => SparseVector v where
- class SpContainer m => SparseMatrix m where
- toC :: Num a => a -> Complex a
Matrix and vector elements (optionally Complex)
class (Eq e, Fractional e, Floating e, Num (EltMag e), Ord (EltMag e)) => Elt e where Source #
Complex conjugate, or identity function if its input is real-valued
Magnitude
Additive group
class AdditiveGroup v where Source #
The zero element: identity for '(^+^)'
(^+^) :: v -> v -> v infixl 6 Source #
Add vectors
Additive inverse
(^-^) :: v -> v -> v infixl 6 Source #
Group subtraction
AdditiveGroup Double Source # | |
AdditiveGroup Float Source # | Instances for builtin types |
AdditiveGroup (Complex Double) Source # | |
AdditiveGroup (Complex Float) Source # | |
AdditiveGroup a => AdditiveGroup (SpVector a) Source # | |
AdditiveGroup a => AdditiveGroup (SpMatrix a) Source # |
|
Vector space v
.
class (AdditiveGroup v, Num (Scalar v)) => VectorSpace v where Source #
VectorSpace Double Source # | |
VectorSpace Float Source # | |
VectorSpace (Complex Double) Source # | |
VectorSpace (Complex Float) Source # | |
VectorSpace a => VectorSpace (SpVector a) Source # | |
VectorSpace a => VectorSpace (SpMatrix a) Source # | |
class VectorSpace v => InnerSpace v where Source #
Adds inner (dot) products.
InnerSpace Double Source # | |
InnerSpace Float Source # | |
InnerSpace (Complex Double) Source # | |
InnerSpace (Complex Float) Source # | |
InnerSpace a => InnerSpace (SpVector a) Source # | |
dot :: InnerSpace v => v -> v -> Scalar v Source #
Inner product
(./) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v infixr 7 Source #
Scale a vector by the reciprocal of a number (e.g. for normalization)
(*.) :: (VectorSpace v, s ~ Scalar v) => v -> s -> v infixl 7 Source #
Vector multiplied by scalar
cvx :: VectorSpace v => Scalar v -> v -> v -> v Source #
Convex combination of two vectors (NB: 0 <= a
<= 1).
Hilbert-space distance function
hilbertDistSq :: InnerSpace v => v -> v -> Scalar v Source #
`hilbertDistSq x y = || x - y ||^2` computes the squared L2 distance between two vectors
Normed vector spaces
class (InnerSpace v, Num (RealScalar v), Eq (RealScalar v), Epsilon (Magnitude v), Show (Magnitude v), Ord (Magnitude v)) => Normed v where Source #
norm1 :: v -> Magnitude v Source #
L1 norm
norm2Sq :: v -> Magnitude v Source #
Euclidean (L2) norm squared
normP :: RealScalar v -> v -> Magnitude v Source #
Lp norm (p > 0)
normalize :: RealScalar v -> v -> v Source #
Normalize w.r.t. Lp norm
normalize2 :: v -> v Source #
Normalize w.r.t. L2 norm
normalize2' :: Floating (Scalar v) => v -> v Source #
Normalize w.r.t. norm2' instead of norm2
norm2 :: Floating (Magnitude v) => v -> Magnitude v Source #
Euclidean (L2) norm
norm2' :: Floating (Scalar v) => v -> Scalar v Source #
Euclidean (L2) norm; returns a Complex (norm :+ 0) for Complex-valued vectors
norm :: Floating (Magnitude v) => RealScalar v -> v -> Magnitude v Source #
Lp norm (p > 0)
normInftyR :: (Foldable t, Ord a) => t a -> a Source #
Infinity-norm (Real)
normInftyC :: (Foldable t, RealFloat a, Functor t) => t (Complex a) -> a Source #
Infinity-norm (Complex)
reciprocal :: (Functor f, Fractional b) => f b -> f b Source #
Reciprocal
Matrix ring
class (AdditiveGroup m, Epsilon (MatrixNorm m)) => MatrixRing m where Source #
A matrix ring is any collection of matrices over some ring R that form a ring under matrix addition and matrix multiplication
type MatrixNorm m :: * Source #
Matrix-matrix product
Matrix times matrix transpose (A B^T)
Matrix transpose times matrix (A^T B)
Matrix transpose (Hermitian conjugate in the Complex case)
normFrobenius :: m -> MatrixNorm m Source #
Frobenius norm
Linear vector space
class VectorSpace v => LinearVectorSpace v where Source #
type MatrixType v :: * Source #
(#>) :: MatrixType v -> v -> v Source #
Matrix-vector action
(<#) :: v -> MatrixType v -> v Source #
Dual matrix-vector action
LinearVectorSpace + Normed
type V v = (LinearVectorSpace v, Normed v) Source #
Linear systems
class LinearVectorSpace v => LinearSystem v where Source #
:: (MonadIO m, MonadThrow m) | |
=> MatrixType v | System matrix |
-> v | Right-hand side |
-> m v | Result |
Solve a linear system; uses GMRES internally as default method
FiniteDim : finite-dimensional objects
HasData : accessing inner data (do not export)
Sparse : sparse datastructures
class (FiniteDim f, HasData f) => Sparse f where Source #
spy :: Fractional b => f -> b Source #
Sparsity (fraction of nonzero elements)
Set : types that behave as sets
SpContainer : sparse container datastructures. Insertion, lookup, toList, lookup with 0 default
class Sparse c => SpContainer c where Source #
SparseVector
class SpContainer v => SparseVector v where Source #
SparseMatrix
class SpContainer m => SparseMatrix m where Source #