backprop-learn-0.1.0.0: Combinators and useful tools for ANNs using the backprop library

Safe HaskellNone
LanguageHaskell2010

Backprop.Learn.Model.Function

Contents

Synopsis

Statistics

meanModel :: (Backprop (t a), Foldable t, Functor t, Fractional a, Reifies s W) => BVar s (t a) -> BVar s a Source #

varModel :: (Backprop (t a), Foldable t, Functor t, Fractional a, Reifies s W) => BVar s (t a) -> BVar s a Source #

stdevModel :: (Backprop (t a), Foldable t, Functor t, Floating a, Reifies s W) => BVar s (t a) -> BVar s a Source #

rangeModel :: (Backprop (t a), Foldable t, Functor t, Ord a, Num a, Reifies s W) => BVar s (t a) -> BVar s a Source #

Activation functions

step :: (Ord a, Num a) => a -> a Source #

Binary step / heaviside step

To use with vectors (R), use vmap'.

\[ \begin{cases} 0 & \text{for } x < 0 \\ 1 & \text{for } x \ge 0 \end{cases} \]

logistic :: Floating a => a -> a Source #

Logistic function

\[ \sigma(x) = \frac{1}{1 + e^{-x}} \]

softsign :: Fractional a => a -> a Source #

Softsign activation function

\[ \frac{x}{1 + \lvert x \rvert} \]

reLU :: (Num a, Ord a) => a -> a Source #

Rectified linear unit.

To use with vectors (R), use vmap'.

\[ \max(0,x) \]

reLU = preLU 0

softPlus :: Floating a => a -> a Source #

SoftPlus

\[ \ln(1 + e^x) \]

bentIdentity :: Floating a => a -> a Source #

Bent identity

\[ \frac{\sqrt{x^2 + 1} - 1}{2} + x \]

siLU :: Floating a => a -> a Source #

Sigmoid-weighted linear unit. Multiply logistic by its input.

\[ x \sigma(x) \]

softExponential Source #

Arguments

:: (Floating a, Ord a) 
=> a

α

-> a

x

-> a 

SoftExponential

To use with vectors (R), use vmap'.

\[ \begin{cases} - \frac{\ln(1 - \alpha (x + \alpha))}{\alpha} & \text{for } \alpha < 0 \\ x & \text{for } \alpha = 0 \\ \frac{e^{\alpha x} - 1}{\alpha} + \alpha & \text{for } \alpha > 0 \end{cases} \]

sinc :: (Floating a, Eq a) => a -> a Source #

Sinc

\[ \begin{cases} 1 & \text{for } x = 0 \\ \frac{\sin(x)}{x} & \text{for } x \ne 0 \end{cases} \]

gaussian :: Floating a => a -> a Source #

Gaussian

\[ e^{-x^2} \]

tanh :: Floating a => a -> a #

atan :: Floating a => a -> a #

sin :: Floating a => a -> a #

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

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) #

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

Parameterized

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

Usable with functions like *, isru, etc. to turn them into a form usable with PFP:

liftUniform (*)  :: BVar s Double -> BVar s (R n) -> BVar s (R n)
liftUniform isru :: BVar s Double -> BVar s (R n) -> BVar s (R n)

Basically turns a parmaeterized function on individual elements of into one that shares the same parameter across all elements of the vector.

isru Source #

Arguments

:: Floating a 
=> a

α (scaling parameter)

-> a

x

-> a 

Inverse square root unit

\[ \frac{x}{\sqrt{1 + \alpha x^2}} \]

See liftUniform to make this compatible with PFP.

You can also just use this after partially applying it, to fix the parameter (and not have it trained).

preLU Source #

Arguments

:: (Num a, Ord a) 
=> a

α (scaling parameter)

-> a

x

-> a 

Parametric rectified linear unit

To use with vectors (R), use vmap'.

If scaling parameter is a fixed (and not learned) parameter, this is typically called a leaky recitified linear unit (typically with α = 0.01).

To use as a learned parameter:

vmap . preLU :: BVar s Double -> BVar s (R n) -> BVar s (R n)

This can be give directly to PFP.

To fix the paramater ("leaky"), just partially apply a parameter:

preLU 0.01           :: BVar s (R n) -> BVar s (R n)
preLU (realToFrac α) :: BVar s (R n) -> BVar s (R n)

See also rreLU.

\[ \begin{cases} \alpha x & \text{for } x < 0 \\ x & \text{for } x \ge 0 \end{cases} \]

sreLU Source #

Arguments

:: (Num a, Ord a) 
=> a
t_l
-> a
a_l
-> a
t_r
-> a
a_l
-> a
x
-> a 

S-shaped rectified linear activiation unit

See sreLUPFP for an uncurried and uniformly lifted version usable with PFP.

\[ \begin{cases} t_l + a_l (x - t_l) & \text{for } x \le t_l \\ x & \text{for } t_l < x < t_r \\ t_r + a_r (x - t_r) & \text{for } x \ge t_r \end{cases} \]

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

An uncurried and uniformly lifted version of sreLU directly usable with PFP.

eLU Source #

Arguments

:: (Floating a, Ord a) 
=> a

α (scaling parameter)

-> a

x

-> a 

Exponential linear unit

To use with vectors (R), use vmap'.

To use as a learned parameter:

vmap . eLU :: BVar s Double -> BVar s (R n) -> BVar s (R n)

This can be give directly to PFP.

To fix the paramater, just partially apply a parameter:

vmap' (eLU 0.01) :: BVar s (R n) -> BVar s (R n)

\[ \begin{cases} \alpha (e^x - 1) & \text{for } x < 0 \\ x & \text{for } x \ge 0 \end{cases} \]

isrLU Source #

Arguments

:: (Floating a, Ord a) 
=> a

α

-> a

x

-> a 

Inverse square root linear unit

To use with vectors (R), use vmap'.

\[ \begin{cases} \frac{x}{1 + \alpha x^2} & \text{for } x < 0 \\ x & \text{for } x \ge 0 \end{cases} \]

apl Source #

Arguments

:: (KnownNat n, KnownNat m, Reifies s W) 
=> BVar s (L n m)

a

-> BVar s (L n m)

b

-> BVar s (R m)

x

-> BVar s (R m) 

Adaptive piecewise linear activation unit

See aplPFP for an uncurried version usable with PFP.

\[ \max(0, x_i) + \sum_j^M a_i^j \max(0, -x_i + b_i^j) \]

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

apl uncurried, to be directly usable with PFP.

Mixing

softMax :: (KnownNat i, Reifies s W) => BVar s (R i) -> BVar s (R i) Source #

Softmax normalizer

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

Maximum of vector.

Compare to norm_InfV, which gives the maximum absolute value.

kSparse Source #

Arguments

:: (Reifies s W, KnownNat n) 
=> Int

number of items to keep

-> BVar s (R n) 
-> BVar s (R n) 

Keep only the top k values, and zero out all of the rest.

Useful for postcomposing in between layers (with a logistic function before) to encourage the number of "activated" neurons is kept to be around k. Used in k-Sprase autoencoders (see KAutoencoder).

http://www.ericlwilkinson.com/blog/2014/11/19/deep-learning-sparse-autoencoders