hmatrix-backprop-0.1.2.3: hmatrix operations lifted for backprop

Copyright(c) Justin Le 2018
LicenseBSD3
Maintainerjustin@jle.im
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Numeric.LinearAlgebra.Static.Backprop

Contents

Description

A wrapper over Numeric.LinearAlgebra.Static (type-safe vector and matrix operations based on blas/lapack) that allows its operations to work with backprop. Also provides orphan instances of Backprop for types in Numeric.LinearAlgebra.Static.

In short, these functions are "lifted" to work with BVars.

Using evalBP will run the original operation:

evalBP :: (forall s. Reifies s W. BVar s a -> BVar s b) -> a -> b

But using gradBP or backprop will give you the gradient:

gradBP :: (forall s. Reifies s W. BVar s a -> BVar s b) -> a -> a

These can act as a drop-in replacement to the API of Numeric.LinearAlgebra.Static. Just change your imports, and your functions are automatically backpropagatable. Useful types are all re-exported.

Also contains sumElements BVar operation.

Formulas for gradients come from the following papers:

Some functions are notably unlifted:

Synopsis

Vector

data R (n :: Nat) :: Nat -> * #

Instances

Domain R L 

Methods

mul :: (KnownNat m, KnownNat k, KnownNat n) => L m k -> L k n -> L m n #

app :: (KnownNat m, KnownNat n) => L m n -> R n -> R m #

dot :: KnownNat n => R n -> R n -> #

cross :: R 3 -> R 3 -> R 3 #

diagR :: (KnownNat m, KnownNat n, KnownNat k) => -> R k -> L m n #

dvmap :: KnownNat n => ( -> ) -> R n -> R n #

dmmap :: (KnownNat m, KnownNat n) => ( -> ) -> L n m -> L n m #

outer :: (KnownNat m, KnownNat n) => R n -> R m -> L n m #

zipWithVector :: KnownNat n => ( -> -> ) -> R n -> R n -> R n #

det :: KnownNat n => L n n -> #

invlndet :: KnownNat n => L n n -> (L n n, (, )) #

expm :: KnownNat n => L n n -> L n n #

sqrtm :: KnownNat n => L n n -> L n n #

inv :: KnownNat n => L n n -> L n n #

KnownNat n => Sized (R n) Vector 

Methods

konst :: -> R n #

unwrap :: R n -> Vector #

fromList :: [] -> R n #

extract :: R n -> Vector #

create :: Vector -> Maybe (R n) #

size :: R n -> IndexOf Vector #

Floating (R n) 

Methods

pi :: R n #

exp :: R n -> R n #

log :: R n -> R n #

sqrt :: R n -> R n #

(**) :: R n -> R n -> R n #

logBase :: R n -> R n -> R n #

sin :: R n -> R n #

cos :: R n -> R n #

tan :: R n -> R n #

asin :: R n -> R n #

acos :: R n -> R n #

atan :: R n -> R n #

sinh :: R n -> R n #

cosh :: R n -> R n #

tanh :: R n -> R n #

asinh :: R n -> R n #

acosh :: R n -> R n #

atanh :: R n -> R n #

log1p :: R n -> R n #

expm1 :: R n -> R n #

log1pexp :: R n -> R n #

log1mexp :: R n -> R n #

Fractional (R n) 

Methods

(/) :: R n -> R n -> R n #

recip :: R n -> R n #

fromRational :: Rational -> R n #

Num (R n) 

Methods

(+) :: R n -> R n -> R n #

(-) :: R n -> R n -> R n #

(*) :: R n -> R n -> R n #

negate :: R n -> R n #

abs :: R n -> R n #

signum :: R n -> R n #

fromInteger :: Integer -> R n #

KnownNat n => Show (R n) 

Methods

showsPrec :: Int -> R n -> ShowS #

show :: R n -> String #

showList :: [R n] -> ShowS #

Generic (R n) 

Associated Types

type Rep (R n) :: * -> * #

Methods

from :: R n -> Rep (R n) x #

to :: Rep (R n) x -> R n #

KnownNat n => Binary (R n) 

Methods

put :: R n -> Put #

get :: Get (R n) #

putList :: [R n] -> Put #

NFData (R n) 

Methods

rnf :: R n -> () #

KnownNat n => Disp (R n) 

Methods

disp :: Int -> R n -> IO () #

Additive (R n) 

Methods

add :: R n -> R n -> R n #

KnownNat n => Eigen (Sym n) (R n) (L n n) 

Methods

eigensystem :: Sym n -> (R n, L n n) #

eigenvalues :: Sym n -> R n #

KnownNat n => Diag (L n n) (R n) 

Methods

takeDiag :: L n n -> R n #

type Rep (R n) 
type Rep (R n) = D1 * (MetaData "R" "Internal.Static" "hmatrix-0.19.0.0-8Mr31CRhnp43mXA6dLNmAt" True) (C1 * (MetaCons "R" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * (Dim n (Vector )))))

type = Double #

vec2 :: Reifies s W => BVar s -> BVar s -> BVar s (R 2) Source #

vec3 :: Reifies s W => BVar s -> BVar s -> BVar s -> BVar s (R 3) Source #

vec4 :: Reifies s W => BVar s -> BVar s -> BVar s -> BVar s -> BVar s (R 4) Source #

(&) :: (KnownNat n, 1 <= n, KnownNat (n + 1), Reifies s W) => BVar s (R n) -> BVar s -> BVar s (R (n + 1)) infixl 4 Source #

(#) :: (KnownNat n, KnownNat m, Reifies s W) => BVar s (R n) -> BVar s (R m) -> BVar s (R (n + m)) infixl 4 Source #

split :: forall p n s. (KnownNat p, KnownNat n, p <= n, Reifies s W) => BVar s (R n) -> (BVar s (R p), BVar s (R (n - p))) Source #

headTail :: (Reifies s W, KnownNat n, 1 <= n) => BVar s (R n) -> (BVar s , BVar s (R (n - 1))) Source #

vector :: forall n s. Reifies s W => Vector n (BVar s ) -> BVar s (R n) Source #

Potentially extremely bad for anything but short lists!!!

linspace :: forall n s. (KnownNat n, Reifies s W) => BVar s -> BVar s -> BVar s (R n) Source #

range :: KnownNat n => R n #

dim :: KnownNat n => R n #

Matrix

data L (m :: Nat) (n :: Nat) :: Nat -> Nat -> * #

Instances

Domain R L 

Methods

mul :: (KnownNat m, KnownNat k, KnownNat n) => L m k -> L k n -> L m n #

app :: (KnownNat m, KnownNat n) => L m n -> R n -> R m #

dot :: KnownNat n => R n -> R n -> #

cross :: R 3 -> R 3 -> R 3 #

diagR :: (KnownNat m, KnownNat n, KnownNat k) => -> R k -> L m n #

dvmap :: KnownNat n => ( -> ) -> R n -> R n #

dmmap :: (KnownNat m, KnownNat n) => ( -> ) -> L n m -> L n m #

outer :: (KnownNat m, KnownNat n) => R n -> R m -> L n m #

zipWithVector :: KnownNat n => ( -> -> ) -> R n -> R n -> R n #

det :: KnownNat n => L n n -> #

invlndet :: KnownNat n => L n n -> (L n n, (, )) #

expm :: KnownNat n => L n n -> L n n #

sqrtm :: KnownNat n => L n n -> L n n #

inv :: KnownNat n => L n n -> L n n #

(KnownNat m, KnownNat n) => Sized (L m n) Matrix 

Methods

konst :: -> L m n #

unwrap :: L m n -> Matrix #

fromList :: [] -> L m n #

extract :: L m n -> Matrix #

create :: Matrix -> Maybe (L m n) #

size :: L m n -> IndexOf Matrix #

KnownNat n => Eigen (Sq n) (C n) (M n n) 

Methods

eigensystem :: Sq n -> (C n, M n n) #

eigenvalues :: Sq n -> C n #

KnownNat n => Eigen (Sym n) (R n) (L n n) 

Methods

eigensystem :: Sym n -> (R n, L n n) #

eigenvalues :: Sym n -> R n #

(KnownNat n, KnownNat m) => Floating (L n m) 

Methods

pi :: L n m #

exp :: L n m -> L n m #

log :: L n m -> L n m #

sqrt :: L n m -> L n m #

(**) :: L n m -> L n m -> L n m #

logBase :: L n m -> L n m -> L n m #

sin :: L n m -> L n m #

cos :: L n m -> L n m #

tan :: L n m -> L n m #

asin :: L n m -> L n m #

acos :: L n m -> L n m #

atan :: L n m -> L n m #

sinh :: L n m -> L n m #

cosh :: L n m -> L n m #

tanh :: L n m -> L n m #

asinh :: L n m -> L n m #

acosh :: L n m -> L n m #

atanh :: L n m -> L n m #

log1p :: L n m -> L n m #

expm1 :: L n m -> L n m #

log1pexp :: L n m -> L n m #

log1mexp :: L n m -> L n m #

(KnownNat n, KnownNat m) => Fractional (L n m) 

Methods

(/) :: L n m -> L n m -> L n m #

recip :: L n m -> L n m #

fromRational :: Rational -> L n m #

(KnownNat n, KnownNat m) => Num (L n m) 

Methods

(+) :: L n m -> L n m -> L n m #

(-) :: L n m -> L n m -> L n m #

(*) :: L n m -> L n m -> L n m #

negate :: L n m -> L n m #

abs :: L n m -> L n m #

signum :: L n m -> L n m #

fromInteger :: Integer -> L n m #

(KnownNat m, KnownNat n) => Show (L m n) 

Methods

showsPrec :: Int -> L m n -> ShowS #

show :: L m n -> String #

showList :: [L m n] -> ShowS #

Generic (L m n) 

Associated Types

type Rep (L m n) :: * -> * #

Methods

from :: L m n -> Rep (L m n) x #

to :: Rep (L m n) x -> L m n #

(KnownNat n, KnownNat m) => Binary (L m n) 

Methods

put :: L m n -> Put #

get :: Get (L m n) #

putList :: [L m n] -> Put #

NFData (L n m) 

Methods

rnf :: L n m -> () #

(KnownNat m, KnownNat n) => Disp (L m n) 

Methods

disp :: Int -> L m n -> IO () #

(KnownNat m, KnownNat n) => Additive (L m n) 

Methods

add :: L m n -> L m n -> L m n #

KnownNat n => Diag (L n n) (R n) 

Methods

takeDiag :: L n n -> R n #

(KnownNat n, KnownNat m) => Transposable (L m n) (L n m) 

Methods

tr :: L m n -> L n m #

tr' :: L m n -> L n m #

type Rep (L m n) 
type Rep (L m n) = D1 * (MetaData "L" "Internal.Static" "hmatrix-0.19.0.0-8Mr31CRhnp43mXA6dLNmAt" True) (C1 * (MetaCons "L" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * (Dim m (Dim n (Matrix ))))))

type Sq (n :: Nat) = L n n #

row :: Reifies s W => BVar s (R n) -> BVar s (L 1 n) Source #

col :: (KnownNat n, Reifies s W) => BVar s (R n) -> BVar s (L n 1) Source #

(|||) :: (KnownNat c, KnownNat r1, KnownNat (r1 + r2), Reifies s W) => BVar s (L c r1) -> BVar s (L c r2) -> BVar s (L c (r1 + r2)) infixl 3 Source #

(===) :: (KnownNat c, KnownNat r1, KnownNat (r1 + r2), Reifies s W) => BVar s (L r1 c) -> BVar s (L r2 c) -> BVar s (L (r1 + r2) c) infixl 2 Source #

splitRows :: forall p m n s. (KnownNat p, KnownNat m, KnownNat n, p <= m, Reifies s W) => BVar s (L m n) -> (BVar s (L p n), BVar s (L (m - p) n)) Source #

splitCols :: forall p m n s. (KnownNat p, KnownNat m, KnownNat n, KnownNat (n - p), p <= n, Reifies s W) => BVar s (L m n) -> (BVar s (L m p), BVar s (L m (n - p))) Source #

unrow :: (KnownNat n, Reifies s W) => BVar s (L 1 n) -> BVar s (R n) Source #

uncol :: (KnownNat n, Reifies s W) => BVar s (L n 1) -> BVar s (R n) Source #

tr :: (Transposable m mt, Transposable mt m, Backprop m, Reifies s W) => BVar s m -> BVar s mt Source #

eye :: KnownNat n => Sq n #

diag :: (KnownNat n, Reifies s W) => BVar s (R n) -> BVar s (Sq n) Source #

matrix :: forall m n s. (KnownNat m, KnownNat n, Reifies s W) => [BVar s ] -> BVar s (L m n) Source #

Potentially extremely bad for anything but short lists!!!

Complex

data C (n :: Nat) :: Nat -> * #

Instances

Domain C M 

Methods

mul :: (KnownNat m, KnownNat k, KnownNat n) => M m k -> M k n -> M m n #

app :: (KnownNat m, KnownNat n) => M m n -> C n -> C m #

dot :: KnownNat n => C n -> C n -> #

cross :: C 3 -> C 3 -> C 3 #

diagR :: (KnownNat m, KnownNat n, KnownNat k) => -> C k -> M m n #

dvmap :: KnownNat n => ( -> ) -> C n -> C n #

dmmap :: (KnownNat m, KnownNat n) => ( -> ) -> M n m -> M n m #

outer :: (KnownNat m, KnownNat n) => C n -> C m -> M n m #

zipWithVector :: KnownNat n => ( -> -> ) -> C n -> C n -> C n #

det :: KnownNat n => M n n -> #

invlndet :: KnownNat n => M n n -> (M n n, (, )) #

expm :: KnownNat n => M n n -> M n n #

sqrtm :: KnownNat n => M n n -> M n n #

inv :: KnownNat n => M n n -> M n n #

KnownNat n => Sized (C n) Vector 

Methods

konst :: -> C n #

unwrap :: C n -> Vector #

fromList :: [] -> C n #

extract :: C n -> Vector #

create :: Vector -> Maybe (C n) #

size :: C n -> IndexOf Vector #

Floating (C n) 

Methods

pi :: C n #

exp :: C n -> C n #

log :: C n -> C n #

sqrt :: C n -> C n #

(**) :: C n -> C n -> C n #

logBase :: C n -> C n -> C n #

sin :: C n -> C n #

cos :: C n -> C n #

tan :: C n -> C n #

asin :: C n -> C n #

acos :: C n -> C n #

atan :: C n -> C n #

sinh :: C n -> C n #

cosh :: C n -> C n #

tanh :: C n -> C n #

asinh :: C n -> C n #

acosh :: C n -> C n #

atanh :: C n -> C n #

log1p :: C n -> C n #

expm1 :: C n -> C n #

log1pexp :: C n -> C n #

log1mexp :: C n -> C n #

Fractional (C n) 

Methods

(/) :: C n -> C n -> C n #

recip :: C n -> C n #

fromRational :: Rational -> C n #

Num (C n) 

Methods

(+) :: C n -> C n -> C n #

(-) :: C n -> C n -> C n #

(*) :: C n -> C n -> C n #

negate :: C n -> C n #

abs :: C n -> C n #

signum :: C n -> C n #

fromInteger :: Integer -> C n #

KnownNat n => Show (C n) 

Methods

showsPrec :: Int -> C n -> ShowS #

show :: C n -> String #

showList :: [C n] -> ShowS #

Generic (C n) 

Associated Types

type Rep (C n) :: * -> * #

Methods

from :: C n -> Rep (C n) x #

to :: Rep (C n) x -> C n #

NFData (C n) 

Methods

rnf :: C n -> () #

KnownNat n => Disp (C n) 

Methods

disp :: Int -> C n -> IO () #

Additive (C n) 

Methods

add :: C n -> C n -> C n #

KnownNat n => Eigen (Sq n) (C n) (M n n) 

Methods

eigensystem :: Sq n -> (C n, M n n) #

eigenvalues :: Sq n -> C n #

KnownNat n => Diag (M n n) (C n) 

Methods

takeDiag :: M n n -> C n #

type Rep (C n) 
type Rep (C n) = D1 * (MetaData "C" "Internal.Static" "hmatrix-0.19.0.0-8Mr31CRhnp43mXA6dLNmAt" True) (C1 * (MetaCons "C" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * (Dim n (Vector )))))

data M (m :: Nat) (n :: Nat) :: Nat -> Nat -> * #

Instances

Domain C M 

Methods

mul :: (KnownNat m, KnownNat k, KnownNat n) => M m k -> M k n -> M m n #

app :: (KnownNat m, KnownNat n) => M m n -> C n -> C m #

dot :: KnownNat n => C n -> C n -> #

cross :: C 3 -> C 3 -> C 3 #

diagR :: (KnownNat m, KnownNat n, KnownNat k) => -> C k -> M m n #

dvmap :: KnownNat n => ( -> ) -> C n -> C n #

dmmap :: (KnownNat m, KnownNat n) => ( -> ) -> M n m -> M n m #

outer :: (KnownNat m, KnownNat n) => C n -> C m -> M n m #

zipWithVector :: KnownNat n => ( -> -> ) -> C n -> C n -> C n #

det :: KnownNat n => M n n -> #

invlndet :: KnownNat n => M n n -> (M n n, (, )) #

expm :: KnownNat n => M n n -> M n n #

sqrtm :: KnownNat n => M n n -> M n n #

inv :: KnownNat n => M n n -> M n n #

(KnownNat m, KnownNat n) => Sized (M m n) Matrix 

Methods

konst :: -> M m n #

unwrap :: M m n -> Matrix #

fromList :: [] -> M m n #

extract :: M m n -> Matrix #

create :: Matrix -> Maybe (M m n) #

size :: M m n -> IndexOf Matrix #

KnownNat n => Eigen (Sq n) (C n) (M n n) 

Methods

eigensystem :: Sq n -> (C n, M n n) #

eigenvalues :: Sq n -> C n #

(KnownNat n, KnownNat m) => Floating (M n m) 

Methods

pi :: M n m #

exp :: M n m -> M n m #

log :: M n m -> M n m #

sqrt :: M n m -> M n m #

(**) :: M n m -> M n m -> M n m #

logBase :: M n m -> M n m -> M n m #

sin :: M n m -> M n m #

cos :: M n m -> M n m #

tan :: M n m -> M n m #

asin :: M n m -> M n m #

acos :: M n m -> M n m #

atan :: M n m -> M n m #

sinh :: M n m -> M n m #

cosh :: M n m -> M n m #

tanh :: M n m -> M n m #

asinh :: M n m -> M n m #

acosh :: M n m -> M n m #

atanh :: M n m -> M n m #

log1p :: M n m -> M n m #

expm1 :: M n m -> M n m #

log1pexp :: M n m -> M n m #

log1mexp :: M n m -> M n m #

(KnownNat n, KnownNat m) => Fractional (M n m) 

Methods

(/) :: M n m -> M n m -> M n m #

recip :: M n m -> M n m #

fromRational :: Rational -> M n m #

(KnownNat n, KnownNat m) => Num (M n m) 

Methods

(+) :: M n m -> M n m -> M n m #

(-) :: M n m -> M n m -> M n m #

(*) :: M n m -> M n m -> M n m #

negate :: M n m -> M n m #

abs :: M n m -> M n m #

signum :: M n m -> M n m #

fromInteger :: Integer -> M n m #

(KnownNat m, KnownNat n) => Show (M m n) 

Methods

showsPrec :: Int -> M m n -> ShowS #

show :: M m n -> String #

showList :: [M m n] -> ShowS #

Generic (M m n) 

Associated Types

type Rep (M m n) :: * -> * #

Methods

from :: M m n -> Rep (M m n) x #

to :: Rep (M m n) x -> M m n #

NFData (M n m) 

Methods

rnf :: M n m -> () #

(KnownNat m, KnownNat n) => Disp (M m n) 

Methods

disp :: Int -> M m n -> IO () #

(KnownNat m, KnownNat n) => Additive (M m n) 

Methods

add :: M m n -> M m n -> M m n #

KnownNat n => Diag (M n n) (C n) 

Methods

takeDiag :: M n n -> C n #

(KnownNat n, KnownNat m) => Transposable (M m n) (M n m) 

Methods

tr :: M m n -> M n m #

tr' :: M m n -> M n m #

type Rep (M m n) 
type Rep (M m n) = D1 * (MetaData "M" "Internal.Static" "hmatrix-0.19.0.0-8Mr31CRhnp43mXA6dLNmAt" True) (C1 * (MetaCons "M" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * (Dim m (Dim n (Matrix ))))))

𝑖 :: Sized s c => s #

Products

(<>) :: (KnownNat m, KnownNat k, KnownNat n, Reifies s W) => BVar s (L m k) -> BVar s (L k n) -> BVar s (L m n) infixr 8 Source #

Matrix product

(#>) :: (KnownNat m, KnownNat n, Reifies s W) => BVar s (L m n) -> BVar s (R n) -> BVar s (R m) infixr 8 Source #

Matrix-vector product

(<.>) :: (KnownNat n, Reifies s W) => BVar s (R n) -> BVar s (R n) -> BVar s infixr 8 Source #

Dot product

Factorizations

svd :: forall m n s. (KnownNat m, KnownNat n, Reifies s W) => BVar s (L m n) -> BVar s (R n) Source #

Can only get the singular values, for now. Let me know if you find an algorithm that can compute the gradients based on differentials for the other matricies!

svd_ :: forall m n s. (KnownNat m, KnownNat n, Reifies s W) => BVar s (L m n) -> (BVar s (L m m), BVar s (R n), BVar s (L n n)) Source #

Version of svd that returns the full SVD, but if you attempt to find the gradient, it will fail at runtime if you ever use U or V.

class Eigen m l v | m -> l, m -> v #

Minimal complete definition

eigensystem, eigenvalues

Instances

KnownNat n => Eigen (Sq n) (C n) (M n n) 

Methods

eigensystem :: Sq n -> (C n, M n n) #

eigenvalues :: Sq n -> C n #

KnownNat n => Eigen (Sym n) (R n) (L n n) 

Methods

eigensystem :: Sym n -> (R n, L n n) #

eigenvalues :: Sym n -> R n #

eigensystem :: forall n s. (KnownNat n, Reifies s W) => BVar s (Sym n) -> (BVar s (R n), BVar s (L n n)) Source #

NOTE The gradient is not necessarily symmetric! The gradient is not meant to be retireved directly; insteadl, eigenvalues is meant to be used as a part of a larger computation, and the gradient as an intermediate step.

eigenvalues :: forall n s. (KnownNat n, Reifies s W) => BVar s (Sym n) -> BVar s (R n) Source #

NOTE The gradient is not necessarily symmetric! The gradient is not meant to be retireved directly; insteadl, eigenvalues is meant to be used as a part of a larger computation, and the gradient as an intermediate step.

chol :: forall n s. (KnownNat n, Reifies s W) => BVar s (Sym n) -> BVar s (Sq n) Source #

Algorithm from https://arxiv.org/abs/1602.07527

The paper also suggests a potential imperative algorithm that might help. Need to benchmark to see what is best.

NOTE The gradient is not necessarily symmetric! The gradient is not meant to be retireved directly; insteadl, eigenvalues is meant to be used as a part of a larger computation, and the gradient as an intermediate step.

Norms

class Normed a #

p-norm for vectors, operator norm for matrices

Minimal complete definition

norm_0, norm_1, norm_2, norm_Inf

Instances

Normed (Matrix R) 

Methods

norm_0 :: Matrix R -> R #

norm_1 :: Matrix R -> R #

norm_2 :: Matrix R -> R #

norm_Inf :: Matrix R -> R #

Normed (Matrix C) 

Methods

norm_0 :: Matrix C -> R #

norm_1 :: Matrix C -> R #

norm_2 :: Matrix C -> R #

norm_Inf :: Matrix C -> R #

Normed (Vector Float) 
Normed (Vector (Complex Float)) 
KnownNat m => Normed (Vector (Mod m I)) 

Methods

norm_0 :: Vector (Mod m I) -> R #

norm_1 :: Vector (Mod m I) -> R #

norm_2 :: Vector (Mod m I) -> R #

norm_Inf :: Vector (Mod m I) -> R #

KnownNat m => Normed (Vector (Mod m Z)) 

Methods

norm_0 :: Vector (Mod m Z) -> R #

norm_1 :: Vector (Mod m Z) -> R #

norm_2 :: Vector (Mod m Z) -> R #

norm_Inf :: Vector (Mod m Z) -> R #

Normed (Vector I) 

Methods

norm_0 :: Vector I -> R #

norm_1 :: Vector I -> R #

norm_2 :: Vector I -> R #

norm_Inf :: Vector I -> R #

Normed (Vector Z) 

Methods

norm_0 :: Vector Z -> R #

norm_1 :: Vector Z -> R #

norm_2 :: Vector Z -> R #

norm_Inf :: Vector Z -> R #

Normed (Vector R) 

Methods

norm_0 :: Vector R -> R #

norm_1 :: Vector R -> R #

norm_2 :: Vector R -> R #

norm_Inf :: Vector R -> R #

Normed (Vector C) 

Methods

norm_0 :: Vector C -> R #

norm_1 :: Vector C -> R #

norm_2 :: Vector C -> R #

norm_Inf :: Vector C -> R #

norm_0 :: (Normed a, Backprop a, Reifies s W) => BVar s a -> BVar s Source #

Number of non-zero items

norm_1V :: (KnownNat n, Reifies s W) => BVar s (R n) -> BVar s Source #

Sum of absolute values

norm_1M :: (KnownNat n, KnownNat m, Reifies s W) => BVar s (L n m) -> BVar s Source #

Maximum norm_1 of columns

norm_2V :: (KnownNat n, Reifies s W) => BVar s (R n) -> BVar s Source #

Square root of sum of squares

Be aware that gradient diverges when the norm is zero

norm_2M :: (KnownNat n, KnownNat m, Reifies s W) => BVar s (L n m) -> BVar s Source #

Maximum singular value

norm_InfV :: (KnownNat n, Reifies s W) => BVar s (R n) -> BVar s Source #

Maximum absolute value

norm_InfM :: (KnownNat n, KnownNat m, Reifies s W) => BVar s (L n m) -> BVar s Source #

Maximum norm_1 of rows

Misc

mean :: (KnownNat n, 1 <= n, Reifies s W) => BVar s (R n) -> BVar s Source #

meanCov :: forall m n s. (KnownNat n, KnownNat m, 1 <= m, Reifies s W) => BVar s (L m n) -> (BVar s (R n), BVar s (Sym n)) Source #

Mean and covariance. If you know you only want to use one or the other, use meanL or cov.

meanL :: forall m n s. (KnownNat n, KnownNat m, 1 <= m, Reifies s W) => BVar s (L m n) -> BVar s (R n) Source #

meanCov, but if you know you won't use the covariance.

cov :: forall m n s. (KnownNat n, KnownNat m, 1 <= m, Reifies s W) => BVar s (L m n) -> BVar s (Sym n) Source #

cov, but if you know you won't use the covariance.

class Disp t where #

Minimal complete definition

disp

Methods

disp :: Int -> t -> IO () #

Instances

KnownNat n => Disp (Sym n) 

Methods

disp :: Int -> Sym n -> IO () #

KnownNat n => Disp (Her n) 

Methods

disp :: Int -> Her n -> IO () #

KnownNat n => Disp (R n) 

Methods

disp :: Int -> R n -> IO () #

KnownNat n => Disp (C n) 

Methods

disp :: Int -> C n -> IO () #

(KnownNat m, KnownNat n) => Disp (L m n) 

Methods

disp :: Int -> L m n -> IO () #

(KnownNat m, KnownNat n) => Disp (M m n) 

Methods

disp :: Int -> M m n -> IO () #

Domain

class Domain field (vec :: Nat -> *) (mat :: Nat -> Nat -> *) | mat -> vec field, vec -> mat field, field -> mat vec #

Minimal complete definition

mul, app, dot, cross, diagR, dvmap, dmmap, outer, zipWithVector, det, invlndet, expm, sqrtm, inv

Instances

Domain R L 

Methods

mul :: (KnownNat m, KnownNat k, KnownNat n) => L m k -> L k n -> L m n #

app :: (KnownNat m, KnownNat n) => L m n -> R n -> R m #

dot :: KnownNat n => R n -> R n -> #

cross :: R 3 -> R 3 -> R 3 #

diagR :: (KnownNat m, KnownNat n, KnownNat k) => -> R k -> L m n #

dvmap :: KnownNat n => ( -> ) -> R n -> R n #

dmmap :: (KnownNat m, KnownNat n) => ( -> ) -> L n m -> L n m #

outer :: (KnownNat m, KnownNat n) => R n -> R m -> L n m #

zipWithVector :: KnownNat n => ( -> -> ) -> R n -> R n -> R n #

det :: KnownNat n => L n n -> #

invlndet :: KnownNat n => L n n -> (L n n, (, )) #

expm :: KnownNat n => L n n -> L n n #

sqrtm :: KnownNat n => L n n -> L n n #

inv :: KnownNat n => L n n -> L n n #

Domain C M 

Methods

mul :: (KnownNat m, KnownNat k, KnownNat n) => M m k -> M k n -> M m n #

app :: (KnownNat m, KnownNat n) => M m n -> C n -> C m #

dot :: KnownNat n => C n -> C n -> #

cross :: C 3 -> C 3 -> C 3 #

diagR :: (KnownNat m, KnownNat n, KnownNat k) => -> C k -> M m n #

dvmap :: KnownNat n => ( -> ) -> C n -> C n #

dmmap :: (KnownNat m, KnownNat n) => ( -> ) -> M n m -> M n m #

outer :: (KnownNat m, KnownNat n) => C n -> C m -> M n m #

zipWithVector :: KnownNat n => ( -> -> ) -> C n -> C n -> C n #

det :: KnownNat n => M n n -> #

invlndet :: KnownNat n => M n n -> (M n n, (, )) #

expm :: KnownNat n => M n n -> M n n #

sqrtm :: KnownNat n => M n n -> M n n #

inv :: KnownNat n => M n n -> M n n #

mul :: (KnownNat m, KnownNat k, KnownNat n, Domain field vec mat, Backprop (mat m k), Backprop (mat k n), Transposable (mat m k) (mat k m), Transposable (mat k n) (mat n k), Reifies s W) => BVar s (mat m k) -> BVar s (mat k n) -> BVar s (mat m n) Source #

app :: (KnownNat m, KnownNat n, Domain field vec mat, Transposable (mat m n) (mat n m), Backprop (mat m n), Backprop (vec n), Reifies s W) => BVar s (mat m n) -> BVar s (vec n) -> BVar s (vec m) Source #

dot :: (KnownNat n, Domain field vec mat, Sized field (vec n) d, Num (vec n), Backprop (vec n), Reifies s W) => BVar s (vec n) -> BVar s (vec n) -> BVar s field Source #

cross :: (Domain field vec mat, Reifies s W, Backprop (vec 3)) => BVar s (vec 3) -> BVar s (vec 3) -> BVar s (vec 3) Source #

diagR Source #

Arguments

:: (Domain field vec mat, Num (vec k), Num (mat m n), KnownNat m, KnownNat n, KnownNat k, Container Vector field, Sized field (mat m n) Matrix, Sized field (vec k) Vector, Backprop field, Backprop (vec k), Reifies s W) 
=> BVar s field

default value

-> BVar s (vec k)

diagonal

-> BVar s (mat m n) 

Create matrix with diagonal, and fill with default entries

vmap :: (KnownNat n, Reifies s W) => (BVar s -> BVar s ) -> BVar s (R n) -> BVar s (R n) Source #

Note: if possible, use the potentially much more performant vmap'.

vmap' :: (Num (vec n), Storable field, Sized field (vec n) Vector, Backprop (vec n), Backprop field, Reifies s W) => (forall s'. Reifies s' W => BVar s' field -> BVar s' field) -> BVar s (vec n) -> BVar s (vec n) Source #

vmap, but potentially more performant. Only usable if the mapped function does not depend on any external BVars.

dvmap :: (KnownNat n, Domain field vec mat, Num (vec n), Backprop (vec n), Backprop field, Reifies s W) => (forall s'. Reifies s' W => BVar s' field -> BVar s' field) -> BVar s (vec n) -> BVar s (vec n) Source #

Note: Potentially less performant than vmap'.

mmap :: (KnownNat n, KnownNat m, Reifies s W) => (BVar s -> BVar s ) -> BVar s (L n m) -> BVar s (L n m) Source #

Note: if possible, use the potentially much more performant mmap'.

mmap' :: forall n m mat field s. (KnownNat m, Num (mat n m), Backprop (mat n m), Backprop field, Sized field (mat n m) Matrix, Element field, Reifies s W) => (forall s'. Reifies s' W => BVar s' field -> BVar s' field) -> BVar s (mat n m) -> BVar s (mat n m) Source #

mmap, but potentially more performant. Only usable if the mapped function does not depend on any external BVars.

dmmap :: (KnownNat n, KnownNat m, Domain field vec mat, Num (mat n m), Backprop (mat n m), Backprop field, Reifies s W) => (forall s'. Reifies s' W => BVar s' field -> BVar s' field) -> BVar s (mat n m) -> BVar s (mat n m) Source #

Note: Potentially less performant than mmap'.

outer :: (KnownNat m, KnownNat n, Domain field vec mat, Transposable (mat n m) (mat m n), Backprop (vec n), Backprop (vec m), Reifies s W) => BVar s (vec n) -> BVar s (vec m) -> BVar s (mat n m) Source #

zipWithVector :: (KnownNat n, Reifies s W) => (BVar s -> BVar s -> BVar s ) -> BVar s (R n) -> BVar s (R n) -> BVar s (R n) Source #

Note: if possible, use the potentially much more performant zipWithVector'.

zipWithVector' :: (Num (vec n), Backprop (vec n), Storable field, Backprop field, Sized field (vec n) Vector, Reifies s W) => (forall s'. Reifies s' W => BVar s' field -> BVar s' field -> BVar s' field) -> BVar s (vec n) -> BVar s (vec n) -> BVar s (vec n) Source #

dzipWithVector :: (KnownNat n, Domain field vec mat, Num (vec n), Backprop (vec n), Backprop field, Reifies s W) => (forall s'. Reifies s' W => BVar s' field -> BVar s' field -> BVar s' field) -> BVar s (vec n) -> BVar s (vec n) -> BVar s (vec n) Source #

A version of zipWithVector' that is potentially less performant but is based on zipWithVector from Domain.

det :: (KnownNat n, Num (mat n n), Backprop (mat n n), Domain field vec mat, Sized field (mat n n) d, Transposable (mat n n) (mat n n), Reifies s W) => BVar s (mat n n) -> BVar s field Source #

invlndet :: forall n mat field vec d s. (KnownNat n, Num (mat n n), Domain field vec mat, Sized field (mat n n) d, Transposable (mat n n) (mat n n), Backprop field, Backprop (mat n n), Reifies s W) => BVar s (mat n n) -> (BVar s (mat n n), (BVar s field, BVar s field)) Source #

The inverse and the natural log of the determinant together. If you know you don't need the inverse, it is best to use lndet.

lndet :: forall n mat field vec d s. (KnownNat n, Num (mat n n), Backprop (mat n n), Domain field vec mat, Sized field (mat n n) d, Transposable (mat n n) (mat n n), Reifies s W) => BVar s (mat n n) -> BVar s field Source #

The natural log of the determinant.

inv :: (KnownNat n, Num (mat n n), Backprop (mat n n), Domain field vec mat, Transposable (mat n n) (mat n n), Reifies s W) => BVar s (mat n n) -> BVar s (mat n n) Source #

Conversions

toRows :: forall m n s. (KnownNat m, KnownNat n, Reifies s W) => BVar s (L m n) -> Vector m (BVar s (R n)) Source #

toColumns :: forall m n s. (KnownNat m, KnownNat n, Reifies s W) => BVar s (L m n) -> Vector n (BVar s (R m)) Source #

fromRows :: forall m n s. (KnownNat m, Reifies s W) => Vector m (BVar s (R n)) -> BVar s (L m n) Source #

fromColumns :: forall m n s. (KnownNat n, Reifies s W) => Vector n (BVar s (R m)) -> BVar s (L m n) Source #

Misc Operations

konst :: forall t s d q. (Sized t s d, Container d t, Backprop t, Reifies q W) => BVar q t -> BVar q s Source #

sumElements :: forall t s d q. (Sized t s d, Container d t, Backprop s, Reifies q W) => BVar q s -> BVar q t Source #

extractV :: forall t s q. (Sized t s Vector, Konst t Int Vector, Container Vector t, Backprop s, Reifies q W) => BVar q s -> BVar q (Vector t) Source #

If there are extra items in the total derivative, they are dropped. If there are missing items, they are treated as zero.

extractM :: forall t s q. (Sized t s Matrix, Backprop s, Konst t (Int, Int) Matrix, Container Matrix t, Num (Matrix t), Reifies q W) => BVar q s -> BVar q (Matrix t) Source #

If there are extra items in the total derivative, they are dropped. If there are missing items, they are treated as zero.

create :: (Sized t s d, Backprop s, Num (d t), Backprop (d t), Reifies q W) => BVar q (d t) -> Maybe (BVar q s) Source #

class Diag m d | m -> d #

Minimal complete definition

takeDiag

Instances

KnownNat n => Diag (L n n) (R n) 

Methods

takeDiag :: L n n -> R n #

KnownNat n => Diag (M n n) (C n) 

Methods

takeDiag :: M n n -> C n #

takeDiag :: (KnownNat n, Diag (mat n n) (vec n), Domain field vec mat, Num field, Backprop (mat n n), Reifies s W) => BVar s (mat n n) -> BVar s (vec n) Source #

data Sym (n :: Nat) :: Nat -> * #

Instances

KnownNat n => Floating (Sym n) 

Methods

pi :: Sym n #

exp :: Sym n -> Sym n #

log :: Sym n -> Sym n #

sqrt :: Sym n -> Sym n #

(**) :: Sym n -> Sym n -> Sym n #

logBase :: Sym n -> Sym n -> Sym n #

sin :: Sym n -> Sym n #

cos :: Sym n -> Sym n #

tan :: Sym n -> Sym n #

asin :: Sym n -> Sym n #

acos :: Sym n -> Sym n #

atan :: Sym n -> Sym n #

sinh :: Sym n -> Sym n #

cosh :: Sym n -> Sym n #

tanh :: Sym n -> Sym n #

asinh :: Sym n -> Sym n #

acosh :: Sym n -> Sym n #

atanh :: Sym n -> Sym n #

log1p :: Sym n -> Sym n #

expm1 :: Sym n -> Sym n #

log1pexp :: Sym n -> Sym n #

log1mexp :: Sym n -> Sym n #

KnownNat n => Fractional (Sym n) 

Methods

(/) :: Sym n -> Sym n -> Sym n #

recip :: Sym n -> Sym n #

fromRational :: Rational -> Sym n #

KnownNat n => Num (Sym n) 

Methods

(+) :: Sym n -> Sym n -> Sym n #

(-) :: Sym n -> Sym n -> Sym n #

(*) :: Sym n -> Sym n -> Sym n #

negate :: Sym n -> Sym n #

abs :: Sym n -> Sym n #

signum :: Sym n -> Sym n #

fromInteger :: Integer -> Sym n #

KnownNat n => Show (Sym n) 

Methods

showsPrec :: Int -> Sym n -> ShowS #

show :: Sym n -> String #

showList :: [Sym n] -> ShowS #

KnownNat n => Disp (Sym n) 

Methods

disp :: Int -> Sym n -> IO () #

KnownNat n => Additive (Sym n) 

Methods

add :: Sym n -> Sym n -> Sym n #

KnownNat n => Transposable (Sym n) (Sym n) 

Methods

tr :: Sym n -> Sym n #

tr' :: Sym n -> Sym n #

KnownNat n => Eigen (Sym n) (R n) (L n n) 

Methods

eigensystem :: Sym n -> (R n, L n n) #

eigenvalues :: Sym n -> R n #

sym :: (KnownNat n, Reifies s W) => BVar s (Sq n) -> BVar s (Sym n) Source #

\[ \frac{1}{2} (M + M^T) \]

mTm :: (KnownNat m, KnownNat n, Reifies s W) => BVar s (L m n) -> BVar s (Sym n) Source #

\[ M^T M \]

unSym :: (KnownNat n, Reifies s W) => BVar s (Sym n) -> BVar s (Sq n) Source #

Warning: the gradient is going necessarily symmetric, and so is not meant to be used directly. Rather, it is meant to be used in the middle (or at the end) of a longer computation.

(<·>) :: (KnownNat n, Reifies s W) => BVar s (R n) -> BVar s (R n) -> BVar s infixr 8 Source #

Unicode synonym for <.>>

Backprop types re-exported

Re-exported for convenience.

Since: 0.1.1.0

data BVar s a :: Type -> * -> * #

A BVar s a is a value of type a that can be "backpropagated".

Functions referring to BVars are tracked by the library and can be automatically differentiated to get their gradients and results.

For simple numeric values, you can use its Num, Fractional, and Floating instances to manipulate them as if they were the numbers they represent.

If a contains items, the items can be accessed and extracted using lenses. A Lens' b a can be used to access an a inside a b, using ^^. (viewVar):

(^.)  ::        a -> Lens' a b ->        b
(^^.) :: BVar s a -> Lens' a b -> BVar s b

There is also ^^? (previewVar), to use a Prism' or Traversal' to extract a target that may or may not be present (which can implement pattern matching), ^^.. (toListOfVar) to use a Traversal' to extract all targets inside a BVar, and .~~ (setVar) to set and update values inside a BVar.

If you have control over your data type definitions, you can also use splitBV and joinBV to manipulate data types by easily extracting fields out of a BVar of data types and creating BVars of data types out of BVars of their fields. See Numeric.Backprop for a tutorial on this use pattern.

For more complex operations, libraries can provide functions on BVars using liftOp and related functions. This is how you can create primitive functions that users can use to manipulate your library's values. See https://backprop.jle.im/08-equipping-your-library.html for a detailed guide.

For example, the hmatrix library has a matrix-vector multiplication function, #> :: L m n -> R n -> L m.

A library could instead provide a function #> :: BVar (L m n) -> BVar (R n) -> BVar (R m), which the user can then use to manipulate their BVars of L m ns and R ns, etc.

See Numeric.Backprop and documentation for liftOp for more information.

Instances

BVGroup s ([] *) (K1 * i a) (K1 * i (BVar s a)) 

Methods

gsplitBV :: Rec * AddFunc [*] -> Rec * ZeroFunc [*] -> BVar s (K1 * i a ()) -> K1 * i (BVar s a) ()

gjoinBV :: Rec * AddFunc [*] -> Rec * ZeroFunc [*] -> K1 * i (BVar s a) () -> BVar s (K1 * i a ())

Eq a => Eq (BVar s a)

Compares the values inside the BVar.

Since: 0.1.5.0

Methods

(==) :: BVar s a -> BVar s a -> Bool #

(/=) :: BVar s a -> BVar s a -> Bool #

(Floating a, Reifies Type s W) => Floating (BVar s a) 

Methods

pi :: BVar s a #

exp :: BVar s a -> BVar s a #

log :: BVar s a -> BVar s a #

sqrt :: BVar s a -> BVar s a #

(**) :: BVar s a -> BVar s a -> BVar s a #

logBase :: BVar s a -> BVar s a -> BVar s a #

sin :: BVar s a -> BVar s a #

cos :: BVar s a -> BVar s a #

tan :: BVar s a -> BVar s a #

asin :: BVar s a -> BVar s a #

acos :: BVar s a -> BVar s a #

atan :: BVar s a -> BVar s a #

sinh :: BVar s a -> BVar s a #

cosh :: BVar s a -> BVar s a #

tanh :: BVar s a -> BVar s a #

asinh :: BVar s a -> BVar s a #

acosh :: BVar s a -> BVar s a #

atanh :: BVar s a -> BVar s a #

log1p :: BVar s a -> BVar s a #

expm1 :: BVar s a -> BVar s a #

log1pexp :: BVar s a -> BVar s a #

log1mexp :: BVar s a -> BVar s a #

(Fractional a, Reifies Type s W) => Fractional (BVar s a) 

Methods

(/) :: BVar s a -> BVar s a -> BVar s a #

recip :: BVar s a -> BVar s a #

fromRational :: Rational -> BVar s a #

(Num a, Reifies Type s W) => Num (BVar s a) 

Methods

(+) :: BVar s a -> BVar s a -> BVar s a #

(-) :: BVar s a -> BVar s a -> BVar s a #

(*) :: BVar s a -> BVar s a -> BVar s a #

negate :: BVar s a -> BVar s a #

abs :: BVar s a -> BVar s a #

signum :: BVar s a -> BVar s a #

fromInteger :: Integer -> BVar s a #

Ord a => Ord (BVar s a)

Compares the values inside the BVar.

Since: 0.1.5.0

Methods

compare :: BVar s a -> BVar s a -> Ordering #

(<) :: BVar s a -> BVar s a -> Bool #

(<=) :: BVar s a -> BVar s a -> Bool #

(>) :: BVar s a -> BVar s a -> Bool #

(>=) :: BVar s a -> BVar s a -> Bool #

max :: BVar s a -> BVar s a -> BVar s a #

min :: BVar s a -> BVar s a -> BVar s a #

(Backprop a, Reifies Type s W) => Backprop (BVar s a)

Since: 0.2.2.0

Methods

zero :: BVar s a -> BVar s a #

add :: BVar s a -> BVar s a -> BVar s a #

one :: BVar s a -> BVar s a #

NFData a => NFData (BVar s a)

This will force the value inside, as well.

Methods

rnf :: BVar s a -> () #

class Backprop a #

Class of values that can be backpropagated in general.

For instances of Num, these methods can be given by zeroNum, addNum, and oneNum. There are also generic options given in Numeric.Backprop.Class for functors, IsList instances, and Generic instances.

instance Backprop Double where
    zero = zeroNum
    add = addNum
    one = oneNum

If you leave the body of an instance declaration blank, GHC Generics will be used to derive instances if the type has a single constructor and each field is an instance of Backprop.

To ensure that backpropagation works in a sound way, should obey the laws:

identity

Also implies preservation of information, making zipWith (+) an illegal implementation for lists and vectors.

This is only expected to be true up to potential "extra zeroes" in x and y in the result.

commutativity
associativity
idempotence
unital

Note that not all values in the backpropagation process needs all of these methods: Only the "final result" needs one, for example. These are all grouped under one typeclass for convenience in defining instances, and also to talk about sensible laws. For fine-grained control, use the "explicit" versions of library functions (for example, in Numeric.Backprop.Explicit) instead of Backprop based ones.

This typeclass replaces the reliance on Num of the previous API (v0.1). Num is strictly more powerful than Backprop, and is a stronger constraint on types than is necessary for proper backpropagating. In particular, fromInteger is a problem for many types, preventing useful backpropagation for lists, variable-length vectors (like Data.Vector) and variable-size matrices from linear algebra libraries like hmatrix and accelerate.

Since: 0.2.0.0

Instances

Backprop Double 

Methods

zero :: Double -> Double #

add :: Double -> Double -> Double #

one :: Double -> Double #

Backprop Float 

Methods

zero :: Float -> Float #

add :: Float -> Float -> Float #

one :: Float -> Float #

Backprop Int 

Methods

zero :: Int -> Int #

add :: Int -> Int -> Int #

one :: Int -> Int #

Backprop Integer 
Backprop Natural

Since: 0.2.1.0

Backprop Word

Since: 0.2.2.0

Methods

zero :: Word -> Word #

add :: Word -> Word -> Word #

one :: Word -> Word #

Backprop Word8

Since: 0.2.2.0

Methods

zero :: Word8 -> Word8 #

add :: Word8 -> Word8 -> Word8 #

one :: Word8 -> Word8 #

Backprop Word16

Since: 0.2.2.0

Methods

zero :: Word16 -> Word16 #

add :: Word16 -> Word16 -> Word16 #

one :: Word16 -> Word16 #

Backprop Word32

Since: 0.2.2.0

Methods

zero :: Word32 -> Word32 #

add :: Word32 -> Word32 -> Word32 #

one :: Word32 -> Word32 #

Backprop Word64

Since: 0.2.2.0

Methods

zero :: Word64 -> Word64 #

add :: Word64 -> Word64 -> Word64 #

one :: Word64 -> Word64 #

Backprop ()

add is strict, but zero and one are lazy in their arguments.

Methods

zero :: () -> () #

add :: () -> () -> () #

one :: () -> () #

Backprop Void 

Methods

zero :: Void -> Void #

add :: Void -> Void -> Void #

one :: Void -> Void #

Backprop Expr

Since: 0.2.4.0

Methods

zero :: Expr -> Expr #

add :: Expr -> Expr -> Expr #

one :: Expr -> Expr #

Backprop a => Backprop [a]

add assumes the shorter list has trailing zeroes, and the result has the length of the longest input.

Methods

zero :: [a] -> [a] #

add :: [a] -> [a] -> [a] #

one :: [a] -> [a] #

Backprop a => Backprop (Maybe a)

Nothing is treated the same as Just 0. However, zero, add, and one preserve Nothing if all inputs are also Nothing.

Methods

zero :: Maybe a -> Maybe a #

add :: Maybe a -> Maybe a -> Maybe a #

one :: Maybe a -> Maybe a #

Integral a => Backprop (Ratio a) 

Methods

zero :: Ratio a -> Ratio a #

add :: Ratio a -> Ratio a -> Ratio a #

one :: Ratio a -> Ratio a #

Num a => Backprop (NumBP a) 

Methods

zero :: NumBP a -> NumBP a #

add :: NumBP a -> NumBP a -> NumBP a #

one :: NumBP a -> NumBP a #

RealFloat a => Backprop (Complex a) 

Methods

zero :: Complex a -> Complex a #

add :: Complex a -> Complex a -> Complex a #

one :: Complex a -> Complex a #

Backprop a => Backprop (First a)

Since: 0.2.2.0

Methods

zero :: First a -> First a #

add :: First a -> First a -> First a #

one :: First a -> First a #

Backprop a => Backprop (Last a)

Since: 0.2.2.0

Methods

zero :: Last a -> Last a #

add :: Last a -> Last a -> Last a #

one :: Last a -> Last a #

Backprop a => Backprop (Option a)

Since: 0.2.2.0

Methods

zero :: Option a -> Option a #

add :: Option a -> Option a -> Option a #

one :: Option a -> Option a #

Backprop a => Backprop (NonEmpty a)

add assumes the shorter list has trailing zeroes, and the result has the length of the longest input.

Methods

zero :: NonEmpty a -> NonEmpty a #

add :: NonEmpty a -> NonEmpty a -> NonEmpty a #

one :: NonEmpty a -> NonEmpty a #

Backprop a => Backprop (Identity a) 

Methods

zero :: Identity a -> Identity a #

add :: Identity a -> Identity a -> Identity a #

one :: Identity a -> Identity a #

Backprop a => Backprop (Dual a)

Since: 0.2.2.0

Methods

zero :: Dual a -> Dual a #

add :: Dual a -> Dual a -> Dual a #

one :: Dual a -> Dual a #

Backprop a => Backprop (Sum a)

Since: 0.2.2.0

Methods

zero :: Sum a -> Sum a #

add :: Sum a -> Sum a -> Sum a #

one :: Sum a -> Sum a #

Backprop a => Backprop (Product a)

Since: 0.2.2.0

Methods

zero :: Product a -> Product a #

add :: Product a -> Product a -> Product a #

one :: Product a -> Product a #

Backprop a => Backprop (First a)

Since: 0.2.2.0

Methods

zero :: First a -> First a #

add :: First a -> First a -> First a #

one :: First a -> First a #

Backprop a => Backprop (Last a)

Since: 0.2.2.0

Methods

zero :: Last a -> Last a #

add :: Last a -> Last a -> Last a #

one :: Last a -> Last a #

Backprop a => Backprop (IntMap a)

zero and one replace all current values, and add merges keys from both maps, adding in the case of double-occurrences.

Methods

zero :: IntMap a -> IntMap a #

add :: IntMap a -> IntMap a -> IntMap a #

one :: IntMap a -> IntMap a #

Backprop a => Backprop (Seq a)

add assumes the shorter sequence has trailing zeroes, and the result has the length of the longest input.

Methods

zero :: Seq a -> Seq a #

add :: Seq a -> Seq a -> Seq a #

one :: Seq a -> Seq a #

(Storable a, Backprop a) => Backprop (Vector a) 

Methods

zero :: Vector a -> Vector a #

add :: Vector a -> Vector a -> Vector a #

one :: Vector a -> Vector a #

(Unbox a, Backprop a) => Backprop (Vector a) 

Methods

zero :: Vector a -> Vector a #

add :: Vector a -> Vector a -> Vector a #

one :: Vector a -> Vector a #

(Prim a, Backprop a) => Backprop (Vector a) 

Methods

zero :: Vector a -> Vector a #

add :: Vector a -> Vector a -> Vector a #

one :: Vector a -> Vector a #

Backprop a => Backprop (Vector a) 

Methods

zero :: Vector a -> Vector a #

add :: Vector a -> Vector a -> Vector a #

one :: Vector a -> Vector a #

Backprop a => Backprop (r -> a)

add adds together results; zero and one act on results.

Since: 0.2.2.0

Methods

zero :: (r -> a) -> r -> a #

add :: (r -> a) -> (r -> a) -> r -> a #

one :: (r -> a) -> r -> a #

Backprop (V1 * p)

Since: 0.2.2.0

Methods

zero :: V1 * p -> V1 * p #

add :: V1 * p -> V1 * p -> V1 * p #

one :: V1 * p -> V1 * p #

Backprop (U1 * p)

Since: 0.2.2.0

Methods

zero :: U1 * p -> U1 * p #

add :: U1 * p -> U1 * p -> U1 * p #

one :: U1 * p -> U1 * p #

(Backprop a, Backprop b) => Backprop (a, b)

add is strict

Methods

zero :: (a, b) -> (a, b) #

add :: (a, b) -> (a, b) -> (a, b) #

one :: (a, b) -> (a, b) #

(Backprop a, Reifies Type s W) => Backprop (BVar s a)

Since: 0.2.2.0

Methods

zero :: BVar s a -> BVar s a #

add :: BVar s a -> BVar s a -> BVar s a #

one :: BVar s a -> BVar s a #

(Vector v a, Num a) => Backprop (NumVec v a) 

Methods

zero :: NumVec v a -> NumVec v a #

add :: NumVec v a -> NumVec v a -> NumVec v a #

one :: NumVec v a -> NumVec v a #

(Applicative f, Backprop a) => Backprop (ABP f a) 

Methods

zero :: ABP f a -> ABP f a #

add :: ABP f a -> ABP f a -> ABP f a #

one :: ABP f a -> ABP f a #

(Backprop a, Backprop b) => Backprop (Arg a b)

Since: 0.2.2.0

Methods

zero :: Arg a b -> Arg a b #

add :: Arg a b -> Arg a b -> Arg a b #

one :: Arg a b -> Arg a b #

Backprop (Proxy * a) 

Methods

zero :: Proxy * a -> Proxy * a #

add :: Proxy * a -> Proxy * a -> Proxy * a #

one :: Proxy * a -> Proxy * a #

(Backprop a, Ord k) => Backprop (Map k a)

zero and one replace all current values, and add merges keys from both maps, adding in the case of double-occurrences.

Methods

zero :: Map k a -> Map k a #

add :: Map k a -> Map k a -> Map k a #

one :: Map k a -> Map k a #

(Backprop a, Backprop b, Backprop c) => Backprop (a, b, c)

add is strict

Methods

zero :: (a, b, c) -> (a, b, c) #

add :: (a, b, c) -> (a, b, c) -> (a, b, c) #

one :: (a, b, c) -> (a, b, c) #

(Backprop a, Applicative m) => Backprop (Kleisli m r a)

Since: 0.2.2.0

Methods

zero :: Kleisli m r a -> Kleisli m r a #

add :: Kleisli m r a -> Kleisli m r a -> Kleisli m r a #

one :: Kleisli m r a -> Kleisli m r a #

Backprop w => Backprop (Const * w a)

Since: 0.2.2.0

Methods

zero :: Const * w a -> Const * w a #

add :: Const * w a -> Const * w a -> Const * w a #

one :: Const * w a -> Const * w a #

Backprop a => Backprop (K1 * i a p)

Since: 0.2.2.0

Methods

zero :: K1 * i a p -> K1 * i a p #

add :: K1 * i a p -> K1 * i a p -> K1 * i a p #

one :: K1 * i a p -> K1 * i a p #

(Backprop (f p), Backprop (g p)) => Backprop ((:*:) * f g p)

Since: 0.2.2.0

Methods

zero :: (* :*: f) g p -> (* :*: f) g p #

add :: (* :*: f) g p -> (* :*: f) g p -> (* :*: f) g p #

one :: (* :*: f) g p -> (* :*: f) g p #

(Backprop a, Backprop b, Backprop c, Backprop d) => Backprop (a, b, c, d)

add is strict

Methods

zero :: (a, b, c, d) -> (a, b, c, d) #

add :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) #

one :: (a, b, c, d) -> (a, b, c, d) #

(Backprop (f a), Backprop (g a)) => Backprop (Product * f g a)

Since: 0.2.2.0

Methods

zero :: Product * f g a -> Product * f g a #

add :: Product * f g a -> Product * f g a -> Product * f g a #

one :: Product * f g a -> Product * f g a #

Backprop (f p) => Backprop (M1 * i c f p)

Since: 0.2.2.0

Methods

zero :: M1 * i c f p -> M1 * i c f p #

add :: M1 * i c f p -> M1 * i c f p -> M1 * i c f p #

one :: M1 * i c f p -> M1 * i c f p #

(Backprop a, Backprop b, Backprop c, Backprop d, Backprop e) => Backprop (a, b, c, d, e)

add is strict

Methods

zero :: (a, b, c, d, e) -> (a, b, c, d, e) #

add :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) #

one :: (a, b, c, d, e) -> (a, b, c, d, e) #

Backprop (f (g a)) => Backprop (Compose * * f g a)

Since: 0.2.2.0

Methods

zero :: Compose * * f g a -> Compose * * f g a #

add :: Compose * * f g a -> Compose * * f g a -> Compose * * f g a #

one :: Compose * * f g a -> Compose * * f g a #

class Reifies k (s :: k) a | s -> a #

Minimal complete definition

reflect

Instances

KnownNat n => Reifies Nat n Integer 

Methods

reflect :: proxy Integer -> a #

KnownSymbol n => Reifies Symbol n String 

Methods

reflect :: proxy String -> a #

Reifies * Z Int 

Methods

reflect :: proxy Int -> a #

Reifies * n Int => Reifies * (D n) Int 

Methods

reflect :: proxy Int -> a #

Reifies * n Int => Reifies * (SD n) Int 

Methods

reflect :: proxy Int -> a #

Reifies * n Int => Reifies * (PD n) Int 

Methods

reflect :: proxy Int -> a #

(B * b0, B * b1, B * b2, B * b3, B * b4, B * b5, B * b6, B * b7, (~) * w0 (W b0 b1 b2 b3), (~) * w1 (W b4 b5 b6 b7)) => Reifies * (Stable w0 w1 a) a 

Methods

reflect :: proxy a -> a #

data W :: * #

An ephemeral Wengert Tape in the environment. Used internally to track of the computational graph of variables.

For the end user, one can just imagine Reifies s W as a required constraint on s that allows backpropagation to work.

Orphan instances

KnownNat n => Backprop (Sym n) Source # 

Methods

zero :: Sym n -> Sym n #

add :: Sym n -> Sym n -> Sym n #

one :: Sym n -> Sym n #

Backprop (R n) Source # 

Methods

zero :: R n -> R n #

add :: R n -> R n -> R n #

one :: R n -> R n #

Backprop (C n) Source # 

Methods

zero :: C n -> C n #

add :: C n -> C n -> C n #

one :: C n -> C n #

(KnownNat n, KnownNat m) => Backprop (L n m) Source # 

Methods

zero :: L n m -> L n m #

add :: L n m -> L n m -> L n m #

one :: L n m -> L n m #

(KnownNat n, KnownNat m) => Backprop (M n m) Source # 

Methods

zero :: M n m -> M n m #

add :: M n m -> M n m -> M n m #

one :: M n m -> M n m #