| 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
Synopsis
- 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 #
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
| AdditiveGroup Double # | |
| AdditiveGroup Float # | Instances for builtin types |
| AdditiveGroup (Complex Double) # | |
| AdditiveGroup (Complex Float) # | |
| AdditiveGroup a => AdditiveGroup (SpVector a) # | |
| AdditiveGroup a => AdditiveGroup (SpMatrix a) # |
|
Vector space v.
class (AdditiveGroup v, Num (Scalar v)) => VectorSpace v where #
Minimal complete definition
Instances
| VectorSpace Double # | |
| VectorSpace Float # | |
| VectorSpace (Complex Double) # | |
| VectorSpace (Complex Float) # | |
| VectorSpace a => VectorSpace (SpVector a) # | |
| VectorSpace a => VectorSpace (SpMatrix a) # | |
class VectorSpace v => InnerSpace v where #
Adds inner (dot) products.
Minimal complete definition
Instances
| InnerSpace Double # | |
| InnerSpace Float # | |
| InnerSpace (Complex Double) # | |
| InnerSpace (Complex Float) # | |
| InnerSpace a => InnerSpace (SpVector a) # | |
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)
Instances
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
| MatrixRing (SpMatrix Double) # | |
Defined in Data.Sparse.SpMatrix Associated Types type MatrixNorm (SpMatrix Double) :: * # Methods (##) :: SpMatrix Double -> SpMatrix Double -> SpMatrix Double # (##^) :: SpMatrix Double -> SpMatrix Double -> SpMatrix Double # (#^#) :: SpMatrix Double -> SpMatrix Double -> SpMatrix Double # transpose :: SpMatrix Double -> SpMatrix Double # normFrobenius :: SpMatrix Double -> MatrixNorm (SpMatrix Double) # | |
| MatrixRing (SpMatrix (Complex Double)) # | |
Defined in Data.Sparse.SpMatrix Methods (##) :: SpMatrix (Complex Double) -> SpMatrix (Complex Double) -> SpMatrix (Complex Double) # (##^) :: SpMatrix (Complex Double) -> SpMatrix (Complex Double) -> SpMatrix (Complex Double) # (#^#) :: SpMatrix (Complex Double) -> SpMatrix (Complex Double) -> SpMatrix (Complex Double) # transpose :: SpMatrix (Complex Double) -> SpMatrix (Complex Double) # normFrobenius :: SpMatrix (Complex Double) -> MatrixNorm (SpMatrix (Complex Double)) # | |
Linear vector space
class VectorSpace 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
Instances
| (InnerSpace t, Scalar t ~ t) => LinearVectorSpace (SpVector t) # | |
Defined in Data.Sparse.Common Associated Types type MatrixType (SpVector t) :: * # | |
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
Instances
| LinearSystem (SpVector Double) # | <> uses the GMRES method as default |
Defined in Numeric.LinearAlgebra.Sparse | |
FiniteDim : finite-dimensional objects
Minimal complete definition
HasData : accessing inner data (do not export)
Sparse : sparse datastructures
class (FiniteDim f, HasData f) => Sparse f where #
Minimal complete definition
Instances
| Sparse (SpVector a) # | |
Defined in Data.Sparse.SpVector Methods spy :: Fractional b => SpVector a -> b # | |
| Sparse (SpMatrix a) # | |
Defined in Data.Sparse.SpMatrix Methods spy :: Fractional b => SpMatrix a -> b # | |
Set : types that behave as sets
class Functor f => Set f where #
Methods
liftU2 :: (a -> a -> a) -> f a -> f a -> f a #
Union binary lift : apply function on _union_ of two "sets"
liftI2 :: (a -> a -> b) -> f a -> f a -> f b #
Intersection binary lift : apply function on _intersection_ of two "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) # |
|
Defined in Data.Sparse.SpVector | |
| Num a => SpContainer (SpMatrix a) # |
|
Defined in Data.Sparse.SpMatrix | |
SparseVector
class SpContainer v => SparseVector v where #
Minimal complete definition
SparseMatrix
class SpContainer m => SparseMatrix m where #
Minimal complete definition