sparse-linear-algebra-0.2.9.2: Numerical computation in native Haskell

Copyright (c) Marco Zocca 2017 GPL-style (see the file LICENSE) zocca marco gmail experimental portable None Haskell2010

Numeric.LinearAlgebra.Class

Description

Typeclasses for linear algebra and related concepts

Synopsis

Matrix and vector elements (optionally Complex)

class (Eq e, Fractional e, Floating e, Num (EltMag e), Ord (EltMag e)) => Elt e where Source #

Minimal complete definition

mag

Associated Types

type EltMag e :: * Source #

Methods

conj :: e -> e Source #

Complex conjugate, or identity function if its input is real-valued

mag :: e -> EltMag e Source #

Magnitude

Instances

 Source # Associated Typestype EltMag Double :: * Source # Methods Source # Associated Typestype EltMag Float :: * Source # Methods RealFloat e => Elt (Complex e) Source # Associated Typestype EltMag (Complex e) :: * Source # Methodsconj :: Complex e -> Complex e Source #mag :: Complex e -> EltMag (Complex e) Source #

Vector space

(.*) :: VectorSpace v => Scalar v -> v -> v Source #

Scale a vector

(./) :: (VectorSpace v, Fractional (Scalar v)) => v -> Scalar v -> v Source #

Scale a vector by the reciprocal of a number (e.g. for normalization)

cvx :: (VectorSpace e, Num (Scalar e)) => Scalar e -> e -> e -> e Source #

Convex combination of two vectors (NB: 0 <= a <= 1).

Hilbert space (inner product)

dot :: InnerSpace v => v -> v -> Scalar v Source #

Inner product

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 #

Minimal complete definition

Associated Types

type Magnitude v :: * Source #

type RealScalar v :: * Source #

Methods

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)

Instances

 Source # Associated Typestype Magnitude Double :: * Source #type RealScalar Double :: * Source # Methods Source # Associated Typestype Magnitude (Complex Double) :: * Source #type RealScalar (Complex Double) :: * Source # Methods Source # Associated Typestype Magnitude (SpVector Double) :: * Source #type RealScalar (SpVector Double) :: * Source # Methods Source # Associated Typestype Magnitude (SpVector (Complex Double)) :: * Source #type RealScalar (SpVector (Complex Double)) :: * Source # Methods

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)

dotLp :: (Set t, Foldable t, Floating a) => a -> t a -> t a -> a Source #

Lp inner product (p > 0)

reciprocal :: (Functor f, Fractional b) => f b -> f b Source #

Reciprocal

scale :: (Num b, Functor f) => b -> f b -> f b Source #

Scale

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

Minimal complete definition

Associated Types

type MatrixNorm m :: * Source #

Methods

(##) :: m -> m -> m Source #

Matrix-matrix product

(##^) :: m -> m -> m Source #

A B^T

(#^#) :: m -> m -> m Source #

A^T B

transpose :: m -> m Source #

Matrix transpose

normFrobenius :: m -> MatrixNorm m Source #

Frobenius norm

Instances

 Source # Associated Typestype MatrixNorm (SpMatrix Double) :: * Source # Methods Source # Associated Typestype MatrixNorm (SpMatrix (Complex Double)) :: * Source # Methods

Linear vector space

class (VectorSpace v, MatrixRing (MatrixType v)) => LinearVectorSpace v where Source #

Minimal complete definition

Associated Types

type MatrixType v :: * Source #

Methods

(#>) :: MatrixType v -> v -> v Source #

Matrix-vector action

(<#) :: v -> MatrixType v -> v Source #

Dual matrix-vector action

Linear systems

class LinearVectorSpace v => LinearSystem v where Source #

Minimal complete definition

(<\>)

Methods

(<\>) :: (MonadIO m, MonadThrow m) => MatrixType v -> v -> m v Source #

Solve a linear system

FiniteDim : finite-dimensional objects

class Functor f => FiniteDim f where Source #

Minimal complete definition

dim

Associated Types

type FDSize f :: * Source #

Methods

dim :: f a -> FDSize f Source #

Dimension (i.e. Int for SpVector, (Int, Int) for SpMatrix)

Instances

 Source # SpVectors form a vector space because they can be multiplied by a scalarSpVectors are finite-dimensional vectors Associated Typestype FDSize (SpVector :: * -> *) :: * Source # Methods Source # SpMatrixes are maps between finite-dimensional spaces Associated Typestype FDSize (SpMatrix :: * -> *) :: * Source # Methods

class FiniteDim' f where Source #

Minimal complete definition

dim'

Associated Types

type FDSize' f :: * Source #

Methods

dim' :: f -> FDSize' f Source #

HasData : accessing inner data (do not export)

class HasData f a where Source #

Minimal complete definition

Associated Types

type HDData f a :: * Source #

Methods

nnz :: f a -> Int Source #

Number of nonzeros

dat :: f a -> HDData f a Source #

Instances

 Source # Associated Typestype HDData (SpVector :: * -> *) a :: * Source # Methodsnnz :: SpVector a -> Int Source # Source # Associated Typestype HDData (SpMatrix :: * -> *) a :: * Source # Methodsnnz :: SpMatrix a -> Int Source #

class HasData' f where Source #

Minimal complete definition

Associated Types

type HDD f :: * Source #

Methods

nnz' :: f -> Int Source #

dat' :: f -> HDD f Source #

Sparse : sparse datastructures

class (FiniteDim f, HasData f a) => Sparse f a where Source #

Minimal complete definition

spy

Methods

spy :: Fractional b => f a -> b Source #

Sparsity (fraction of nonzero elements)

Instances

 Source # Methodsspy :: Fractional b => SpVector a -> b Source # Source # Methodsspy :: Fractional b => SpMatrix a -> b Source #

class (FiniteDim' f, HasData' f) => Sparse' f where Source #

Minimal complete definition

spy'

Methods

spy' :: Fractional b => f -> b Source #

Set : types that behave as sets

class Functor f => Set f where Source #

Minimal complete definition

Methods

liftU2 :: (a -> a -> a) -> f a -> f a -> f a Source #

Union binary lift : apply function on _union_ of two "sets"

liftI2 :: (a -> a -> b) -> f a -> f a -> f b Source #

Intersection binary lift : apply function on _intersection_ of two "sets"

Instances

 Source # MethodsliftU2 :: (a -> a -> a) -> SpVector a -> SpVector a -> SpVector a Source #liftI2 :: (a -> a -> b) -> SpVector a -> SpVector a -> SpVector b Source # Source # MethodsliftU2 :: (a -> a -> a) -> SpMatrix a -> SpMatrix a -> SpMatrix a Source #liftI2 :: (a -> a -> b) -> SpMatrix a -> SpMatrix a -> SpMatrix b Source #

SpContainer : sparse container datastructures. Insertion, lookup, toList, lookup with 0 default

class Sparse c a => SpContainer c a where Source #

Minimal complete definition

Associated Types

type ScIx c :: * Source #

Methods

scInsert :: ScIx c -> a -> c a -> c a Source #

scLookup :: c a -> ScIx c -> Maybe a Source #

scToList :: c a -> [(ScIx c, a)] Source #

(@@) :: c a -> ScIx c -> a Source #

Instances

 Source # SpVectors are sparse containers too, i.e. any specific component may be missing (so it is assumed to be 0) Associated Typestype ScIx (SpVector :: * -> *) :: * Source # MethodsscInsert :: ScIx SpVector -> a -> SpVector a -> SpVector a Source #scToList :: SpVector a -> [(ScIx SpVector, a)] Source #(@@) :: SpVector a -> ScIx SpVector -> a Source # Source # SpMatrixes are sparse containers too, i.e. any specific component may be missing (so it is assumed to be 0) Associated Typestype ScIx (SpMatrix :: * -> *) :: * Source # MethodsscInsert :: ScIx SpMatrix -> a -> SpMatrix a -> SpMatrix a Source #scToList :: SpMatrix a -> [(ScIx SpMatrix, a)] Source #(@@) :: SpMatrix a -> ScIx SpMatrix -> a Source #

class SpContainer' c where Source #

Minimal complete definition

Associated Types

type ScIx' c :: * Source #

Methods

scInsert' :: ScIx' c -> a -> c -> c Source #

scLookup' :: c -> ScIx' c -> Maybe a Source #

scToList' :: c -> [a] Source #

SparseVector

class SpContainer v e => SparseVector v e where Source #

Minimal complete definition

Associated Types

type SpvIx v :: * Source #

Methods

svFromList :: Int -> [(SpvIx v, e)] -> v e Source #

svFromListDense :: Int -> [e] -> v e Source #

svConcat :: Foldable t => t (v e) -> v e Source #

SparseMatrix

class SpContainer m e => SparseMatrix m e where Source #

Minimal complete definition

Methods

smFromVector :: LexOrd -> (Int, Int) -> Vector (IxRow, IxCol, e) -> m e Source #

smTranspose :: m e -> m e Source #

encodeIx :: m e -> LexOrd -> (IxRow, IxCol) -> LexIx Source #

decodeIx :: m e -> LexOrd -> LexIx -> (IxRow, IxCol) Source #

Utilities

toC :: Num a => a -> Complex a Source #

Lift a real number onto the complex plane