Copyright | (c) 2016 Jiasen Wu |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Jiasen Wu <jiasenwu@hotmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Data.NeuralNetwork
Description
This module defines an abstract interface for neural network and a protocol for its backends to follow.
- class Component a where
- learn :: (Component n, Monad (Run n)) => (Out n -> Out n -> Run n (Out n)) -> Float -> n -> (Inp n, Out n) -> Run n n
- relu :: (Num a, Ord a) => a -> a
- relu' :: (Num a, Ord a) => a -> a
- cost' :: (Num a, Ord a) => a -> a -> a
- class Backend b s where
- type Env b :: * -> *
- type ConvertFromSpec s :: *
- class (Monad r, Monad e) => RunInEnv r e where
- data a :++ b = a :++ b
- data SpecIn1D = In1D Int
- data SpecIn2D = In2D Int Int
- data SpecReshape2DAs1D = Reshape2DAs1D
- data SpecFullConnect = FullConnect Int
- data SpecConvolution = Convolution Int Int Int
- data SpecMaxPooling = MaxPooling Int
Documentation
class Component a where Source #
Abstraction of a neural network component
Associated Types
execution environment
the type of input and in-error
the type of output and out-error
the trace of a forward propagation
Methods
forwardT :: a -> Inp a -> Run a (Trace a) Source #
Forward propagation
forward :: Applicative (Run a) => a -> Inp a -> Run a (Out a) Source #
Forward propagation
output :: Trace a -> Out a Source #
extract the output value from the trace
backward :: a -> Trace a -> Out a -> Float -> Run a (a, Inp a) Source #
Backward propagation
Arguments
:: (Component n, Monad (Run n)) | |
=> (Out n -> Out n -> Run n (Out n)) | derivative of the error function |
-> Float | learning rate |
-> n | neuron network |
-> (Inp n, Out n) | input and expect output |
-> Run n n | updated network |
By giving a way to measure the error, learn
can update the
neural network component.
class Backend b s where Source #
Abstraction of backend to carry out the specification
Associated Types
environment to compile
the specification
type ConvertFromSpec s :: * Source #
result type of compile
Methods
witness :: b -> s -> Dict (Monad (Env b), Monad (Run (ConvertFromSpec s)), Component (ConvertFromSpec s), RunInEnv (Run (ConvertFromSpec s)) (Env b)) Source #
necessary constraints of the resulting type
compile :: b -> s -> Env b (ConvertFromSpec s) Source #
compile the specification to runnable component.
class (Monad r, Monad e) => RunInEnv r e where Source #
Lifting from one monad to another.
It is not necessary that the Env
and Run
maps to the
same execution environment, but the Run
one should be
able to be lifted to Env
one.
Minimal complete definition
data SpecFullConnect Source #
Specification: full connection layer
Constructors
FullConnect Int | number of neurals |
data SpecConvolution Source #
Specification: convolution layer
Constructors
Convolution Int Int Int | number of output channels, size of kernel, size of padding |