| Safe Haskell | None |
|---|
Network
- data Network a = Network {}
- data Layer a = Layer {}
- data CostFunction
- getDelta :: Floating a => CostFunction -> a -> a -> a -> a
- type ActivationFunction a = a -> a
- type ActivationFunctionDerivative a = a -> a
- type Sample a = (Vector a, Vector a)
- type Samples a = [Sample a]
- (-->) :: Vector a -> Vector a -> Sample a
- type LearningRate = Double
- type Lambda = Double
- type TrainingDataLength = Int
- newNetwork :: [Int] -> IO (Network Double)
- output :: (Numeric a, Num (Vector a)) => Network a -> ActivationFunction a -> Vector a -> Vector a
- outputs :: (Numeric a, Num (Vector a)) => Network a -> ActivationFunction a -> Vector a -> [Vector a]
- rawOutputs :: (Numeric a, Num (Vector a)) => Network a -> ActivationFunction a -> Vector a -> [(Vector a, Vector a)]
- trainShuffled :: Int -> (Network Double -> Int -> String) -> Network Double -> CostFunction -> Lambda -> Samples Double -> Int -> Double -> IO (Network Double)
- trainNTimes :: Int -> (Network Double -> Int -> String) -> Network Double -> CostFunction -> Lambda -> Samples Double -> Int -> Double -> Network Double
- trainSGD :: (Numeric Double, Floating Double) => Network Double -> CostFunction -> Lambda -> Samples Double -> Int -> Double -> Network Double
- update :: LearningRate -> CostFunction -> Lambda -> TrainingDataLength -> Network Double -> Samples Double -> Network Double
- backprop :: Network Double -> CostFunction -> Sample Double -> [Layer Double]
- sigmoid :: Floating a => ActivationFunction a
- sigmoid' :: Floating a => ActivationFunctionDerivative a
- shuffle :: [a] -> IO [a]
- saveNetwork :: (Element a, Binary a) => FilePath -> Network a -> IO ()
- newFileName :: FilePath -> FilePath
- loadNetwork :: (Element a, Binary a) => FilePath -> IO (Network a)
Documentation
data Network a
The generic feedforward network type, a binary instance is implemented.
+ It takes a list of layers
+ with a minimum of one (output layer).
+ It is usually constructed using the newNetwork function, initializing the matrices
+ with some default random values.
net <- newNetwork [2, 3, 4]
data Layer a
One layer of a network, storing the weights matrix and the biases vector + of this layer.
data CostFunction
Cost Function Enum
Constructors
| QuadraticCost | |
| CrossEntropyCost |
Instances
| Eq CostFunction | |
| Show CostFunction |
getDelta :: Floating a => CostFunction -> a -> a -> a -> a
getDelta based on the raw input, the activated input and the desired output + results in different values depending on the CostFunction type.
type ActivationFunction a = a -> a
type ActivationFunctionDerivative a = a -> a
type Sample a = (Vector a, Vector a)
(-->) :: Vector a -> Vector a -> Sample a
A simple synonym for the (,) operator, used to create samples very intuitively.
type LearningRate = Double
type Lambda = Double
type TrainingDataLength = Int
newNetwork :: [Int] -> IO (Network Double)
output :: (Numeric a, Num (Vector a)) => Network a -> ActivationFunction a -> Vector a -> Vector a
outputs :: (Numeric a, Num (Vector a)) => Network a -> ActivationFunction a -> Vector a -> [Vector a]
rawOutputs :: (Numeric a, Num (Vector a)) => Network a -> ActivationFunction a -> Vector a -> [(Vector a, Vector a)]
trainShuffled :: Int -> (Network Double -> Int -> String) -> Network Double -> CostFunction -> Lambda -> Samples Double -> Int -> Double -> IO (Network Double)
The most used training function, randomly shuffling the training set before + every training epoch
trainShuffled 30 (\n e -> "") net CrossEntropyCost 0.5 trainData 10 0.1
trainNTimes :: Int -> (Network Double -> Int -> String) -> Network Double -> CostFunction -> Lambda -> Samples Double -> Int -> Double -> Network Double
trainSGD :: (Numeric Double, Floating Double) => Network Double -> CostFunction -> Lambda -> Samples Double -> Int -> Double -> Network Double
update :: LearningRate -> CostFunction -> Lambda -> TrainingDataLength -> Network Double -> Samples Double -> Network Double
backprop :: Network Double -> CostFunction -> Sample Double -> [Layer Double]
sigmoid :: Floating a => ActivationFunction a
sigmoid' :: Floating a => ActivationFunctionDerivative a
shuffle :: [a] -> IO [a]
saveNetwork :: (Element a, Binary a) => FilePath -> Network a -> IO ()
newFileName :: FilePath -> FilePath
loadNetwork :: (Element a, Binary a) => FilePath -> IO (Network a)