on master help sign in
Remove Show constraint on UpdateLayer
d82a121Huw Campbell
mafia+1−1
@@ -120,4 +120,4 @@ case "$MODE" in
120upgrade) shift; run_upgrade "$@" ;;
120upgrade) shift; run_upgrade "$@" ;;
121*) exec_mafia "$@"
121*) exec_mafia "$@"
122esac
122esac
123−# Version: 3044e63eb472fb9e16926d4ab2ca9dd9e255829c
123+# Version: 360716306a06db842ec022a7b9f161d2208483f0
main/mnist.hs+2−2
@@ -33,8 +33,8 @@ import Grenade.Utils.OneHot
33
33
34-- With the mnist data from Kaggle normalised to doubles between 0 and 1, learning rate of 0.01 and 15 iterations,
34-- With the mnist data from Kaggle normalised to doubles between 0 and 1, learning rate of 0.01 and 15 iterations,
35-- this network should get down to about a 1.3% error rate.
35-- 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]
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, 'D1 256, 'D1 256, 'D1 80, 'D1 80, 'D1 10, 'D1 10]
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]
38
38
39randomMnist :: MonadRandom m => m MNIST
39randomMnist :: MonadRandom m => m MNIST
40randomMnist = randomNetwork
40randomMnist = randomNetwork
src/Grenade.hs+4−3
@@ -13,6 +13,7 @@ import Grenade.Layers.Flatten as X
13import Grenade.Layers.Fuse as X
13import Grenade.Layers.Fuse as X
14import Grenade.Layers.FullyConnected as X
14import Grenade.Layers.FullyConnected as X
15import Grenade.Layers.Logit as X
15import Grenade.Layers.Logit as X
16−import Grenade.Layers.Convolution as X
16+import Grenade.Layers.Convolution as X
17−import Grenade.Layers.Relu as X
17+import Grenade.Layers.Relu as X
18−import Grenade.Layers.Tanh 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 {
42
42
43-- | Class for updating a layer. All layers implement this, and it is
43-- | Class for updating a layer. All layers implement this, and it is
44-- shape independent.
44-- shape independent.
45−class Show x => UpdateLayer x where
45+class UpdateLayer x where
46 {-# MINIMAL runUpdate, createRandom #-}
46 {-# MINIMAL runUpdate, createRandom #-}
47 -- | The type for the gradient for this layer.
47 -- | The type for the gradient for this layer.
48 -- Unit if there isn't a gradient to pass back.
48 -- Unit if there isn't a gradient to pass back.
@@ -86,9 +86,11 @@ data Network :: [*] -> [Shape] -> * where
86 (:~>) :: (SingI i, SingI h, Layer x i h) => !x -> !(Network xs (h ': hs)) -> Network (x ': xs) (i ': h ': hs)
86 (:~>) :: (SingI i, SingI h, Layer x i h) => !x -> !(Network xs (h ': hs)) -> Network (x ': xs) (i ': h ': hs)
87infixr 5 :~>
87infixr 5 :~>
88
88
89−instance Show (Network l h) where
89+instance Show (Network '[] '[i]) where
90 show NNil = "NNil"
90 show NNil = "NNil"
91+instance (Show x, Show (Network xs rs)) => Show (Network (x ': xs) (i ': rs)) where
91− show (i :~> o) = show i ++ "\n:~>\n" ++ show o
92+ show (x :~> xs) = show x ++ "\n~>\n" ++ show xs
93+
92
94
93-- | Gradients of a network.
95-- | Gradients of a network.
94-- Parameterised on the layers of a Network.
96-- Parameterised on the layers of a Network.
src/Grenade/Core/Runner.hs+3−1
@@ -14,6 +14,9 @@ Stability : experimental
14This module defines simple back propagation and training functions
14This module defines simple back propagation and training functions
15for a network.
15for a network.
16-}
16-}
17+
18+-- GHC 7.10 doesn't think that go is complete
19+{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
17module Grenade.Core.Runner (
20module Grenade.Core.Runner (
18 train
21 train
19 , backPropagate
22 , backPropagate
@@ -48,7 +51,6 @@ backPropagate network input target =
48 (n', dWs') = go y n
51 (n', dWs') = go y n
49 -- calculate the gradient for this layer to pass down,
52 -- calculate the gradient for this layer to pass down,
50 (layer', dWs) = runBackwards layer tape dWs'
53 (layer', dWs) = runBackwards layer tape dWs'
51−
52 in (layer' :/> n', dWs)
54 in (layer' :/> n', dWs)
53
55
54 -- Bouncing the derivatives back down.
56 -- Bouncing the derivatives back down.
src/Grenade/Layers/Flatten.hs+1−1
@@ -31,7 +31,7 @@ instance UpdateLayer FlattenLayer where
31 runUpdate _ _ _ = FlattenLayer
31 runUpdate _ _ _ = FlattenLayer
32 createRandom = return FlattenLayer
32 createRandom = return FlattenLayer
33
33
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
35 type Tape FlattenLayer ('D2 x y) ('D1 a) = ()
35 type Tape FlattenLayer ('D2 x y) ('D1 a) = ()
36 runForwards _ (S2D y) = ((), fromJust' . fromStorable . flatten . extract $ y)
36 runForwards _ (S2D y) = ((), fromJust' . fromStorable . flatten . extract $ y)
37 runBackwards _ _ (S1D y) = ((), fromJust' . fromStorable . extract $ y)
37 runBackwards _ _ (S1D y) = ((), fromJust' . fromStorable . extract $ y)
src/Grenade/Recurrent/Core/Network.hs+6−5
@@ -59,11 +59,12 @@ data RecurrentNetwork :: [*] -> [Shape] -> * where
59infixr 5 :~~>
59infixr 5 :~~>
60infixr 5 :~@>
60infixr 5 :~@>
61
61
62−instance Show (RecurrentNetwork l h) where
62+instance Show (RecurrentNetwork '[] '[i]) where
63− show RNil = "RNil"
63+ show RNil = "NNil"
64+instance (Show x, Show (RecurrentNetwork xs rs)) => Show (RecurrentNetwork (FeedForward x ': xs) (i ': rs)) where
64− show (i :~~> o) = show i ++ "\n:~~>\n" ++ show o
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
65− show (i :~@> o) = show i ++ "\n:~@>\n" ++ show o
67+ show (x :~@> xs) = show x ++ "\n~~>\n" ++ show xs
66−
67
68
68-- | Recurrent inputs (sideways shapes on an imaginary unrolled graph)
69-- | Recurrent inputs (sideways shapes on an imaginary unrolled graph)
69-- Parameterised on the layers of a Network.
70-- Parameterised on the layers of a Network.
src/Grenade/Recurrent/Core/Runner.hs+3
@@ -7,6 +7,9 @@
7{-# LANGUAGE FlexibleContexts #-}
7{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE RankNTypes #-}
8{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE RecordWildCards #-}
9{-# LANGUAGE RecordWildCards #-}
10+
11+-- GHC 7.10 doesn't think that go is complete
12+{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
10module Grenade.Recurrent.Core.Runner (
13module Grenade.Recurrent.Core.Runner (
11 trainRecurrent
14 trainRecurrent
12 , runRecurrent
15 , runRecurrent