on master help sign in
Remove Show constraint on UpdateLayer
commitd82a121797238c93220c27615cc318e89f7d41eb authorHuw Campbell <huw.campbell@ambiata.com> dateTue 24 Jan 2017, 13:47 (10 years ago) parent148c777
8 files changed+25−16
mafia+1−1 main/mnist.hs+2−2 src/Grenade.hs+4−3 src/Grenade/Core/Network.hs+5−3 src/Grenade/Core/Runner.hs+3−1 src/Grenade/Layers/Flatten.hs+1−1 src/Grenade/Recurrent/Core/Network.hs+6−5 src/Grenade/Recurrent/Core/Runner.hs+3
mafia+1−1
@@ -120,4 +120,4 @@ case "$MODE" in
120120upgrade) shift; run_upgrade "$@" ;;
121121*) exec_mafia "$@"
122122esac
123−# Version: 3044e63eb472fb9e16926d4ab2ca9dd9e255829c
123+# Version: 360716306a06db842ec022a7b9f161d2208483f0
main/mnist.hs+2−2
@@ -33,8 +33,8 @@ import Grenade.Utils.OneHot
3333
3434-- With the mnist data from Kaggle normalised to doubles between 0 and 1, learning rate of 0.01 and 15 iterations,
3535-- this network should get down to about a 1.3% error rate.
36−type MNIST = Network '[ Convolution 1 10 5 5 1 1, Pooling 2 2 2 2, Relu, Convolution 10 16 5 5 1 1, Pooling 2 2 2 2, FlattenLayer, Relu, FullyConnected 256 80, Logit, FullyConnected 80 10, Logit]
37− '[ 'D2 28 28, 'D3 24 24 10, 'D3 12 12 10, 'D3 12 12 10, 'D3 8 8 16, 'D3 4 4 16, 'D1 256, 'D1 256, 'D1 80, 'D1 80, 'D1 10, 'D1 10]
36+type MNIST = Network '[ Convolution 1 10 5 5 1 1, Pooling 2 2 2 2, Relu, Convolution 10 16 5 5 1 1, Pooling 2 2 2 2, Relu, FlattenLayer, FullyConnected 256 80, Logit, FullyConnected 80 10, Logit]
37+ '[ 'D2 28 28, 'D3 24 24 10, 'D3 12 12 10, 'D3 12 12 10, 'D3 8 8 16, 'D3 4 4 16, 'D3 4 4 16, 'D1 256, 'D1 80, 'D1 80, 'D1 10, 'D1 10]
3838
3939randomMnist :: MonadRandom m => m MNIST
4040randomMnist = randomNetwork
src/Grenade.hs+4−3
@@ -13,6 +13,7 @@ import Grenade.Layers.Flatten as X
1313import Grenade.Layers.Fuse as X
1414import Grenade.Layers.FullyConnected as X
1515import Grenade.Layers.Logit as X
16−import Grenade.Layers.Convolution as X
17−import Grenade.Layers.Relu as X
18−import Grenade.Layers.Tanh as X
16+import Grenade.Layers.Convolution as X
17+import Grenade.Layers.Relu as X
18+import Grenade.Layers.Tanh as X
19+import Grenade.Layers.Softmax as X
src/Grenade/Core/Network.hs+5−3
@@ -42,7 +42,7 @@ data LearningParameters = LearningParameters {
4242
4343-- | Class for updating a layer. All layers implement this, and it is
4444-- shape independent.
45−class Show x => UpdateLayer x where
45+class UpdateLayer x where
4646 {-# MINIMAL runUpdate, createRandom #-}
4747 -- | The type for the gradient for this layer.
4848 -- Unit if there isn't a gradient to pass back.
@@ -86,9 +86,11 @@ data Network :: [*] -> [Shape] -> * where
8686 (:~>) :: (SingI i, SingI h, Layer x i h) => !x -> !(Network xs (h ': hs)) -> Network (x ': xs) (i ': h ': hs)
8787infixr 5 :~>
8888
89−instance Show (Network l h) where
89+instance Show (Network '[] '[i]) where
9090 show NNil = "NNil"
91− show (i :~> o) = show i ++ "\n:~>\n" ++ show o
91+instance (Show x, Show (Network xs rs)) => Show (Network (x ': xs) (i ': rs)) where
92+ show (x :~> xs) = show x ++ "\n~>\n" ++ show xs
93+
9294
9395-- | Gradients of a network.
9496-- Parameterised on the layers of a Network.
src/Grenade/Core/Runner.hs+3−1
@@ -14,6 +14,9 @@ Stability : experimental
1414This module defines simple back propagation and training functions
1515for a network.
1616-}
17+
18+-- GHC 7.10 doesn't think that go is complete
19+{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
1720module Grenade.Core.Runner (
1821 train
1922 , backPropagate
@@ -48,7 +51,6 @@ backPropagate network input target =
4851 (n', dWs') = go y n
4952 -- calculate the gradient for this layer to pass down,
5053 (layer', dWs) = runBackwards layer tape dWs'
51−
5254 in (layer' :/> n', dWs)
5355
5456 -- Bouncing the derivatives back down.
src/Grenade/Layers/Flatten.hs+1−1
@@ -31,7 +31,7 @@ instance UpdateLayer FlattenLayer where
3131 runUpdate _ _ _ = FlattenLayer
3232 createRandom = return FlattenLayer
3333
34−instance (KnownNat a, KnownNat x, KnownNat y, a ~ (x * z)) => Layer FlattenLayer ('D2 x y) ('D1 a) where
34+instance (KnownNat a, KnownNat x, KnownNat y, a ~ (x * y)) => Layer FlattenLayer ('D2 x y) ('D1 a) where
3535 type Tape FlattenLayer ('D2 x y) ('D1 a) = ()
3636 runForwards _ (S2D y) = ((), fromJust' . fromStorable . flatten . extract $ y)
3737 runBackwards _ _ (S1D y) = ((), fromJust' . fromStorable . extract $ y)
src/Grenade/Recurrent/Core/Network.hs+6−5
@@ -59,11 +59,12 @@ data RecurrentNetwork :: [*] -> [Shape] -> * where
5959infixr 5 :~~>
6060infixr 5 :~@>
6161
62−instance Show (RecurrentNetwork l h) where
63− show RNil = "RNil"
64− show (i :~~> o) = show i ++ "\n:~~>\n" ++ show o
65− show (i :~@> o) = show i ++ "\n:~@>\n" ++ show o
66−
62+instance Show (RecurrentNetwork '[] '[i]) where
63+ show RNil = "NNil"
64+instance (Show x, Show (RecurrentNetwork xs rs)) => Show (RecurrentNetwork (FeedForward x ': xs) (i ': rs)) where
65+ show (x :~~> xs) = show x ++ "\n~~>\n" ++ show xs
66+instance (Show x, Show (RecurrentNetwork xs rs)) => Show (RecurrentNetwork (Recurrent x ': xs) (i ': rs)) where
67+ show (x :~@> xs) = show x ++ "\n~~>\n" ++ show xs
6768
6869-- | Recurrent inputs (sideways shapes on an imaginary unrolled graph)
6970-- Parameterised on the layers of a Network.
src/Grenade/Recurrent/Core/Runner.hs+3
@@ -7,6 +7,9 @@
77{-# LANGUAGE FlexibleContexts #-}
88{-# LANGUAGE RankNTypes #-}
99{-# LANGUAGE RecordWildCards #-}
10+
11+-- GHC 7.10 doesn't think that go is complete
12+{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
1013module Grenade.Recurrent.Core.Runner (
1114 trainRecurrent
1215 , runRecurrent