From 8aee2ad09267a5f7e99944508d8100558383339e Mon Sep 17 00:00:00 2001 From: Manuel Schneckenreither Date: Fri, 26 Jan 2018 10:52:41 +0100 Subject: [PATCH 1/2] added the sinusoid activation function layer --- grenade.cabal | 1 + src/Grenade/Layers/Sinusoid.hs | 39 ++++++++++++++++++++++++++++++++++ src/Grenade/Layers/Tanh.hs | 6 +++--- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/Grenade/Layers/Sinusoid.hs 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..7523990 --- /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.Tanh +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 From b5e1243f240b4c0ac266c0ddfb6362599a0be178 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 26 Jan 2018 20:20:37 +0100 Subject: [PATCH 2/2] Update Sinusoid.hs --- src/Grenade/Layers/Sinusoid.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grenade/Layers/Sinusoid.hs b/src/Grenade/Layers/Sinusoid.hs index 7523990..cc68dd0 100644 --- a/src/Grenade/Layers/Sinusoid.hs +++ b/src/Grenade/Layers/Sinusoid.hs @@ -4,7 +4,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-| -Module : Grenade.Layers.Tanh +Module : Grenade.Layers.Sinusoid Description : Sinusoid nonlinear layer Copyright : (c) Manuel Schneckenreither, 2018 License : BSD2