| 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 |
Numeric.LinearAlgebra.Class
Contents
- 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
Description
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, AdditiveGroup (Scalar 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, MatrixRing (MatrixType 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 #
Minimal complete definition
Methods
Complex conjugate, or identity function if its input is real-valued
Magnitude
Additive group
class AdditiveGroup v where #
Methods
The zero element: identity for '(^+^)'
(^+^) :: v -> v -> v infixl 6 #
Add vectors
Additive inverse
(^-^) :: v -> v -> v infixl 6 #
Group subtraction
Instances
| Num a => AdditiveGroup (SpMatrix a) # |
|
Vector space v.
class (AdditiveGroup v, Num (Scalar v)) => VectorSpace v where #
Minimal complete definition
class (VectorSpace v, AdditiveGroup (Scalar v)) => InnerSpace v where #
Adds inner (dot) products.
Minimal complete definition
dot :: InnerSpace v => v -> v -> Scalar v #
Inner product
(./) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v infixr 7 #
Scale a vector by the reciprocal of a number (e.g. for normalization)
(*.) :: (VectorSpace v, s ~ Scalar v) => v -> s -> v infixl 7 #
Vector multiplied by scalar
cvx :: VectorSpace v => Scalar v -> v -> v -> v #
Convex combination of two vectors (NB: 0 <= a <= 1).
Hilbert-space distance function
hilbertDistSq :: InnerSpace v => v -> v -> Scalar v #
`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 #
Minimal complete definition
Methods
L1 norm
Euclidean (L2) norm squared
normP :: RealScalar v -> v -> Magnitude v #
Lp norm (p > 0)
normalize :: RealScalar v -> v -> v #
Normalize w.r.t. Lp norm
normalize2 :: v -> v #
Normalize w.r.t. L2 norm
normalize2' :: Floating (Scalar v) => v -> v #
Normalize w.r.t. norm2' instead of norm2
norm2 :: Floating (Magnitude v) => v -> Magnitude v #
Euclidean (L2) norm
norm2' :: Floating (Scalar v) => v -> Scalar v #
Euclidean (L2) norm; returns a Complex (norm :+ 0) for Complex-valued vectors
norm :: Floating (Magnitude v) => RealScalar v -> v -> Magnitude v #
Lp norm (p > 0)
normInftyR :: (Foldable t, Ord a) => t a -> a #
Infinity-norm (Real)
reciprocal :: (Functor f, Fractional b) => f b -> f b #
Reciprocal
Matrix ring
class (AdditiveGroup m, Epsilon (MatrixNorm m)) => MatrixRing m where #
A matrix ring is any collection of matrices over some ring R that form a ring under matrix addition and matrix multiplication
Minimal complete definition
Associated Types
type MatrixNorm m :: * #
Methods
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 #
Frobenius norm
Instances
Linear vector space
class (VectorSpace v, MatrixRing (MatrixType v)) => LinearVectorSpace v where #
Associated Types
type MatrixType v :: * #
Methods
(#>) :: MatrixType v -> v -> v #
Matrix-vector action
(<#) :: v -> MatrixType v -> v #
Dual matrix-vector action
LinearVectorSpace + Normed
type V v = (LinearVectorSpace v, Normed v) #
Linear systems
class LinearVectorSpace v => LinearSystem v where #
Minimal complete definition
Methods
Arguments
| :: (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
Minimal complete definition
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
class Sparse c => SpContainer c where #
Methods
scInsert :: ScIx c -> ScElem c -> c -> c #
scLookup :: c -> ScIx c -> Maybe (ScElem c) #
Instances
| Elt a => SpContainer (SpVector a) # |
|
| Num a => SpContainer (SpMatrix a) # |
|
SparseVector
class SpContainer v => SparseVector v where #
Minimal complete definition
SparseMatrix
class SpContainer m => SparseMatrix m where #
Minimal complete definition