Copyright | (c) Lars Brünjes, 2016 |
---|---|
License | MIT |
Maintainer | brunjlar@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Extensions |
|
This module defines parameterized functions, components and models. The parameterized functions and components
are instances of the Arrow
typeclass and can therefore be combined easily and flexibly.
Models contain a component, can measure their error with regard to samples and can be trained by gradient descent/ backpropagation.
- newtype ParamFun t a b = ParamFun {}
- data Component a b = forall t . (Traversable t, Applicative t) => Component {}
- _weights :: Lens' (Component a b) [Double]
- activate :: Component a b -> a -> b
- data Model :: (* -> *) -> (* -> *) -> * -> * -> * -> * where
- _component :: Lens' (Model f g a b c) (Component (f Analytic) (g Analytic))
- model :: Model f g a b c -> b -> c
- modelR :: MonadRandom m => Model f g a b c -> m (Model f g a b c)
- modelError :: Foldable h => Model f g a b c -> h a -> Double
- descent :: Foldable h => Model f g a b c -> Double -> h a -> (Double, Model f g a b c)
- type StdModel f g b c = Model f g (b, c) b c
- mkStdModel :: (Functor f, Functor g) => Component (f Analytic) (g Analytic) -> (c -> g Analytic -> Analytic) -> (b -> f Double) -> (g Double -> c) -> StdModel f g b c
Documentation
A
is a parameterized function from Component
a ba
to b
, combined with some collection of analytic parameters,
In contrast to ParamFun
, when components are composed, parameters are not shared.
Each component carries its own collection of parameters instead.
forall t . (Traversable t, Applicative t) => Component | |
_weights :: Lens' (Component a b) [Double] Source
A Lens'
to get or set the weights of a component.
The shape of the parameter collection is hidden by existential quantification,
so this lens has to use simple generic lists.
activate :: Component a b -> a -> b Source
Activates a component, i.e. applies it to the specified input, using the current parameter values.
data Model :: (* -> *) -> (* -> *) -> * -> * -> * -> * where Source
A
wraps a Model
f g a b c
and models functions Component
(f Analytic
) (g Analytic
)b -> c
with "samples" (for model error determination)
of type a
.
_component :: Lens' (Model f g a b c) (Component (f Analytic) (g Analytic)) Source
A Lens
for accessing the component embedded in a model.
modelR :: MonadRandom m => Model f g a b c -> m (Model f g a b c) Source
Generates a model with randomly initialized weights. All other properties are copied from the provided model.
modelError :: Foldable h => Model f g a b c -> h a -> Double Source
Calculates the avarage model error for a "mini-batch" of samples.
:: Foldable h | |
=> Model f g a b c | the model whose error should be decreased |
-> Double | the learning rate |
-> h a | a mini-batch of samples |
-> (Double, Model f g a b c) | returns the average sample error and the improved model |
Performs one step of gradient descent/ backpropagation on the model,