💣 Machine learning which might blow up in your face 💣

added the sinusoid activation function layer

+43 -3
+1
grenade.cabal
··· 81 81 Grenade.Layers.Pooling 82 82 Grenade.Layers.Relu 83 83 Grenade.Layers.Reshape 84 + Grenade.Layers.Sinusoid 84 85 Grenade.Layers.Softmax 85 86 Grenade.Layers.Tanh 86 87 Grenade.Layers.Trivial
+39
src/Grenade/Layers/Sinusoid.hs
··· 1 + {-# LANGUAGE DataKinds #-} 2 + {-# LANGUAGE FlexibleInstances #-} 3 + {-# LANGUAGE MultiParamTypeClasses #-} 4 + {-# LANGUAGE TypeFamilies #-} 5 + {-# LANGUAGE TypeOperators #-} 6 + {-| 7 + Module : Grenade.Layers.Tanh 8 + Description : Sinusoid nonlinear layer 9 + Copyright : (c) Manuel Schneckenreither, 2018 10 + License : BSD2 11 + Stability : experimental 12 + -} 13 + module Grenade.Layers.Sinusoid ( 14 + Sinusoid (..) 15 + ) where 16 + 17 + import Data.Serialize 18 + import Data.Singletons 19 + 20 + import Grenade.Core 21 + 22 + -- | A Sinusoid layer. 23 + -- A layer which can act between any shape of the same dimension, performing a sin function. 24 + data Sinusoid = Sinusoid 25 + deriving Show 26 + 27 + instance UpdateLayer Sinusoid where 28 + type Gradient Sinusoid = () 29 + runUpdate _ _ _ = Sinusoid 30 + createRandom = return Sinusoid 31 + 32 + instance Serialize Sinusoid where 33 + put _ = return () 34 + get = return Sinusoid 35 + 36 + instance (a ~ b, SingI a) => Layer Sinusoid a b where 37 + type Tape Sinusoid a b = S a 38 + runForwards _ a = (a, sin a) 39 + runBackwards _ a g = ((), cos a * g)
+3 -3
src/Grenade/Layers/Tanh.hs
··· 1 1 {-# LANGUAGE DataKinds #-} 2 - {-# LANGUAGE TypeOperators #-} 3 - {-# LANGUAGE TypeFamilies #-} 4 2 {-# LANGUAGE FlexibleInstances #-} 5 3 {-# LANGUAGE MultiParamTypeClasses #-} 4 + {-# LANGUAGE TypeFamilies #-} 5 + {-# LANGUAGE TypeOperators #-} 6 6 {-| 7 7 Module : Grenade.Layers.Tanh 8 8 Description : Hyperbolic tangent nonlinear layer ··· 20 20 import Grenade.Core 21 21 22 22 -- | A Tanh layer. 23 - -- A layer which can act between any shape of the same dimension, perfoming a tanh function. 23 + -- A layer which can act between any shape of the same dimension, performing a tanh function. 24 24 data Tanh = Tanh 25 25 deriving Show 26 26