diff --git a/grenade.cabal b/grenade.cabal index 930d2e0..9f79f02 100644 --- a/grenade.cabal +++ b/grenade.cabal @@ -81,6 +81,7 @@ library Grenade.Layers.Pooling Grenade.Layers.Relu Grenade.Layers.Reshape + Grenade.Layers.Sinusoid Grenade.Layers.Softmax Grenade.Layers.Tanh Grenade.Layers.Trivial diff --git a/src/Grenade/Layers/Sinusoid.hs b/src/Grenade/Layers/Sinusoid.hs new file mode 100644 index 0000000..cc68dd0 --- /dev/null +++ b/src/Grenade/Layers/Sinusoid.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} +{-| +Module : Grenade.Layers.Sinusoid +Description : Sinusoid nonlinear layer +Copyright : (c) Manuel Schneckenreither, 2018 +License : BSD2 +Stability : experimental +-} +module Grenade.Layers.Sinusoid ( + Sinusoid (..) + ) where + +import Data.Serialize +import Data.Singletons + +import Grenade.Core + +-- | A Sinusoid layer. +-- A layer which can act between any shape of the same dimension, performing a sin function. +data Sinusoid = Sinusoid + deriving Show + +instance UpdateLayer Sinusoid where + type Gradient Sinusoid = () + runUpdate _ _ _ = Sinusoid + createRandom = return Sinusoid + +instance Serialize Sinusoid where + put _ = return () + get = return Sinusoid + +instance (a ~ b, SingI a) => Layer Sinusoid a b where + type Tape Sinusoid a b = S a + runForwards _ a = (a, sin a) + runBackwards _ a g = ((), cos a * g) diff --git a/src/Grenade/Layers/Tanh.hs b/src/Grenade/Layers/Tanh.hs index b298f43..fafbe3d 100644 --- a/src/Grenade/Layers/Tanh.hs +++ b/src/Grenade/Layers/Tanh.hs @@ -1,8 +1,8 @@ {-# LANGUAGE DataKinds #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} {-| Module : Grenade.Layers.Tanh Description : Hyperbolic tangent nonlinear layer @@ -20,7 +20,7 @@ import Data.Singletons import Grenade.Core -- | A Tanh layer. --- A layer which can act between any shape of the same dimension, perfoming a tanh function. +-- A layer which can act between any shape of the same dimension, performing a tanh function. data Tanh = Tanh deriving Show