From 49606406d16407b2cacce66183c3ed098ec177ba Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Wed, 20 Jul 2016 12:06:19 +0430 Subject: [PATCH] fix(run): I had written logistic' wrong, that's what happens when you write code while sleepy --- src/Sibe.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Sibe.hs b/src/Sibe.hs index 8356899..23a4308 100644 --- a/src/Sibe.hs +++ b/src/Sibe.hs @@ -37,8 +37,8 @@ module Sibe runLayer input (L !biases !weights) = input <# weights + biases forward :: Input -> Network -> Output - forward input (O l) = cmap logistic $ runLayer input l - forward input (l :- n) = forward (cmap logistic $ runLayer input l) n + forward input (O l) = logistic $ runLayer input l + forward input (l :- n) = forward (logistic $ runLayer input l) n randomLayer :: Seed -> (Int, Int) -> Layer randomLayer seed (wr, wc) = @@ -53,11 +53,11 @@ module Sibe randomLayer seed (input, h) :- randomNetwork (seed + 1) h hs output - logistic :: Double -> Double + logistic :: Vector Double -> Vector Double logistic x = 1 / (1 + exp (-x)) - logistic' :: Double -> Double - logistic' x = logistic x / max 1e-10 (1 - logistic x) + logistic' :: Vector Double -> Vector Double + logistic' x = logistic x * (1 - logistic x) train :: Input -> Network @@ -69,9 +69,9 @@ module Sibe run :: Input -> Network -> (Network, Vector Double) run input (O l@(L biases weights)) = let y = runLayer input l - o = cmap logistic y + o = logistic y delta = o - target - de = delta * cmap logistic' o + de = delta * logistic' y biases' = biases - scale alpha de weights' = weights - scale alpha (input `outer` de) -- small inputs learn slowly @@ -83,10 +83,10 @@ module Sibe in (O layer, pass) run input (l@(L biases weights) :- n) = let y = runLayer input l - o = cmap logistic y + o = logistic y (n', delta) = run o n - de = delta * cmap logistic' o + de = delta * logistic' y biases' = biases - scale alpha de weights' = weights - scale alpha (input `outer` de)