Просмотр исходного кода

reordered inputs and improved style

master
erichhasl 8 лет назад
Родитель
Сommit
5913326a24
1 измененных файлов: 7 добавлений и 5 удалений
  1. +7
    -5
      Network.hs

+ 7
- 5
Network.hs Просмотреть файл

@@ -18,7 +18,7 @@ module Network (
Layer(..), Layer(..),
newNetwork, newNetwork,
output, output,
-- * Learning functions -- * Learning functions
trainShuffled, trainShuffled,
trainNTimes, trainNTimes,
@@ -39,19 +39,19 @@ module Network (
loadNetwork loadNetwork
) where ) where


import Data.List.Split (chunksOf)
import Data.List (foldl') import Data.List (foldl')
import Data.Binary
import Data.List.Split (chunksOf)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Text.Read (readMaybe) import Text.Read (readMaybe)
import Data.Binary


import System.Directory import System.Directory
import System.Random import System.Random
import Control.Monad (zipWithM, forM) import Control.Monad (zipWithM, forM)
import Data.Array.IO import Data.Array.IO
import Debug.Trace (trace) import Debug.Trace (trace)
import Text.Regex.PCRE


import Text.Regex.PCRE
import Numeric.LinearAlgebra import Numeric.LinearAlgebra


-- | The generic feedforward network type, a binary instance is implemented. -- | The generic feedforward network type, a binary instance is implemented.
@@ -109,7 +109,8 @@ type Sample a = (Vector a, Vector a)
-- | A list of 'Sample's -- | A list of 'Sample's
type Samples a = [Sample a] type Samples a = [Sample a]


-- | A simple synonym for the (,) operator, used to create samples very
-- intuitively.
(-->) :: Vector a -> Vector a -> Sample a (-->) :: Vector a -> Vector a -> Sample a
(-->) = (,) (-->) = (,)


@@ -139,7 +140,7 @@ newNetwork layerSizes
return $ Network lays return $ Network lays
where go :: Int -> Int -> IO (Layer Double) where go :: Int -> Int -> IO (Layer Double)
go inputSize outputSize = do go inputSize outputSize = do
ws <- fmap (/ (sqrt $ fromIntegral inputSize)) (randn outputSize inputSize)
ws <- (/ (sqrt $ fromIntegral inputSize)) <$> randn outputSize inputSize
seed <- randomIO seed <- randomIO
let bs = randomVector seed Gaussian outputSize let bs = randomVector seed Gaussian outputSize
return $ Layer ws bs return $ Layer ws bs


Загрузка…
Отмена
Сохранить