Copyright | (c) Marco Zocca 2017 |
---|---|
License | GPL-style (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)
- Vector space
- Hilbert space (inner product)
- 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
- (.*) :: VectorSpace v => Scalar v -> v -> v
- (./) :: (VectorSpace v, Fractional (Scalar v)) => v -> Scalar v -> v
- cvx :: (VectorSpace e, Num (Scalar e)) => Scalar e -> e -> e -> e
- dot :: InnerSpace v => v -> v -> Scalar 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 Functor f => FiniteDim f where
- class FiniteDim' f where
- class HasData f a where
- class HasData' f where
- class (FiniteDim f, HasData f a) => Sparse f a where
- class (FiniteDim' f, HasData' f) => Sparse' f where
- class Functor f => Set f where
- class Sparse c a => SpContainer c a where
- class SpContainer' c where
- class SpContainer v e => SparseVector v e where
- class SpContainer m e => SparseMatrix m e 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
Vector space
(.*) :: VectorSpace v => Scalar v -> v -> v #
Scale a vector
(./) :: (VectorSpace v, Fractional (Scalar v)) => v -> Scalar v -> v #
Scale a vector by the reciprocal of a number (e.g. for normalization)
cvx :: (VectorSpace e, Num (Scalar e)) => Scalar e -> e -> e -> e #
Convex combination of two vectors (NB: 0 <= a
<= 1).
Hilbert space (inner product)
dot :: InnerSpace v => v -> v -> Scalar v #
Inner product
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
(<\>) :: (MonadIO m, MonadThrow m) => MatrixType v -> v -> m v #
Solve a linear system; uses GMRES internally as default method
FiniteDim : finite-dimensional objects
class FiniteDim' f where #
Minimal complete definition
HasData : accessing inner data (do not export)
Sparse : sparse datastructures
class (FiniteDim' f, HasData' f) => Sparse' f where #
Minimal complete definition
Methods
spy' :: Fractional b => f -> b #
Set : types that behave as sets
SpContainer : sparse container datastructures. Insertion, lookup, toList, lookup with 0 default
class Sparse c a => SpContainer c a where #
Methods
scInsert :: ScIx c -> a -> c a -> c a #
scLookup :: c a -> ScIx c -> Maybe a #
Instances
Elt a => SpContainer SpVector a # |
|
Num a => SpContainer SpMatrix a # |
|
class SpContainer' c where #
SparseVector
class SpContainer v e => SparseVector v e where #
Minimal complete definition
SparseMatrix
class SpContainer m e => SparseMatrix m e where #
Minimal complete definition