neural-0.3.0.0: Neural Networks in native Haskell

Copyright(c) Lars Brünjes, 2016
LicenseMIT
Maintainerbrunjlar@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010
Extensions
  • MonoLocalBinds
  • TypeFamilies
  • DataKinds
  • DeriveFunctor
  • DeriveTraversable
  • DeriveFoldable
  • KindSignatures
  • GeneralizedNewtypeDeriving
  • TypeOperators
  • ExplicitNamespaces

Data.Utils.Matrix

Description

This module defines fixed-size matrices and some basic typeclass instances and operations for them.

Synopsis

Documentation

newtype Matrix m n a Source #

Matrix m n a is the type of matrices with m rows, n columns and entries of type a.

Constructors

Matrix (Vector m (Vector n a)) 

Instances

Functor (Matrix m n) Source # 

Methods

fmap :: (a -> b) -> Matrix m n a -> Matrix m n b #

(<$) :: a -> Matrix m n b -> Matrix m n a #

(KnownNat m, KnownNat n) => Applicative (Matrix m n) Source # 

Methods

pure :: a -> Matrix m n a #

(<*>) :: Matrix m n (a -> b) -> Matrix m n a -> Matrix m n b #

(*>) :: Matrix m n a -> Matrix m n b -> Matrix m n b #

(<*) :: Matrix m n a -> Matrix m n b -> Matrix m n a #

Foldable (Matrix m n) Source # 

Methods

fold :: Monoid m => Matrix m n m -> m #

foldMap :: Monoid m => (a -> m) -> Matrix m n a -> m #

foldr :: (a -> b -> b) -> b -> Matrix m n a -> b #

foldr' :: (a -> b -> b) -> b -> Matrix m n a -> b #

foldl :: (b -> a -> b) -> b -> Matrix m n a -> b #

foldl' :: (b -> a -> b) -> b -> Matrix m n a -> b #

foldr1 :: (a -> a -> a) -> Matrix m n a -> a #

foldl1 :: (a -> a -> a) -> Matrix m n a -> a #

toList :: Matrix m n a -> [a] #

null :: Matrix m n a -> Bool #

length :: Matrix m n a -> Int #

elem :: Eq a => a -> Matrix m n a -> Bool #

maximum :: Ord a => Matrix m n a -> a #

minimum :: Ord a => Matrix m n a -> a #

sum :: Num a => Matrix m n a -> a #

product :: Num a => Matrix m n a -> a #

Traversable (Matrix m n) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Matrix m n a -> f (Matrix m n b) #

sequenceA :: Applicative f => Matrix m n (f a) -> f (Matrix m n a) #

mapM :: Monad m => (a -> m b) -> Matrix m n a -> m (Matrix m n b) #

sequence :: Monad m => Matrix m n (m a) -> m (Matrix m n a) #

Eq a => Eq (Matrix m n a) Source # 

Methods

(==) :: Matrix m n a -> Matrix m n a -> Bool #

(/=) :: Matrix m n a -> Matrix m n a -> Bool #

Show a => Show (Matrix m n a) Source # 

Methods

showsPrec :: Int -> Matrix m n a -> ShowS #

show :: Matrix m n a -> String #

showList :: [Matrix m n a] -> ShowS #

NFData a => NFData (Matrix m n a) Source # 

Methods

rnf :: Matrix m n a -> () #

(<%%>) :: Num a => Matrix m n a -> Vector n a -> Vector m a Source #

Multiplication of a matrix by a (column-)vector.

>>> :set -XDataKinds
>>> (pure 1 :: Matrix 1 2 Int) <%%> cons 1 (cons 2 nil)
[3]

row :: Matrix m n a -> Int -> Maybe (Vector n a) Source #

Gives the matrix row with the specified index (starting at zero) if the index is valid, otherwise Nothing.

>>> :set -XDataKinds
>>> row (pure 42 :: Matrix 2 4 Int) 0
Just [42,42,42,42]
>>> row (pure 42 :: Matrix 2 4 Int) 2
Nothing

column :: Matrix m n a -> Int -> Maybe (Vector m a) Source #

Gives the matrix column with the specified index (starting at zero) if the index is valid, otherwise Nothing.

>>> :set -XDataKinds
>>> column (pure 42 :: Matrix 2 4 Int) 3
Just [42,42]
>>> column (pure 42 :: Matrix 2 4 Int) 4
Nothing

mgenerate :: (KnownNat m, KnownNat n) => ((Int, Int) -> a) -> Matrix m n a Source #

Generates a matrix by applying the given function to each index (row, column).

>>> :set -XDataKinds
>>> mgenerate id :: Matrix 3 2 (Int, Int)
Matrix [[(0,0),(0,1)],[(1,0),(1,1)],[(2,0),(2,1)]]

(!!?) :: Matrix m n a -> (Int, Int) -> Maybe a Source #

Gives the matrix element with the specified index (row, column) if the index is valid, otherwise Nothing.

>>> :set -XDataKinds
>>> let m = mgenerate (uncurry (+)) :: Matrix 2 3 Int
>>> m !!? (0,0)
Just 0
>>> m !!? (1, 2)
Just 3
>>> m !!? (5, 7)
Nothing

(!!!) :: Matrix m n a -> (Int, Int) -> a Source #

Gives the matrix element with the specified index (row, column) if the index is valid, otherwise throws an exception.

>>> :set -XDataKinds
>>> let m = mgenerate (uncurry (+)) :: Matrix 2 3 Int
>>> m !!! (0,0)
0
>>> m !!! (1, 2)
3

transpose :: (KnownNat m, KnownNat n) => Matrix m n a -> Matrix n m a Source #

Transposes a matrix.

>>> transpose (Matrix $ cons (cons 'a' nil) (cons (cons 'b' nil) nil))
Matrix ["ab"]