backprop-learn-0.1.0.0: Combinators and useful tools for ANNs using the backprop library

Safe HaskellNone
LanguageHaskell2010

Backprop.Learn.Model.State

Contents

Synopsis

To and from statelessness

trainState :: forall p s a b. (PureProd Maybe p, PureProd Maybe s, AllConstrainedProd Backprop p, AllConstrainedProd Backprop s) => Model p s a b -> Model (p :#? s) Nothing a b Source #

Make a model stateless by converting the state to a trained parameter, and dropping the modified state from the result.

One of the ways to make a model stateless for training purposes. Useful when used after Unroll. See DeState, as well.

Its parameters are:

  • If the input has no parameters, just the initial state.
  • If the input has a parameter, a :# of that parameter and initial state.

deState :: s -> (forall m. PrimMonad m => Gen (PrimState m) -> m s) -> Model p (Just s) a b -> Model p Nothing a b Source #

Make a model stateless by pre-applying a fixed state (or a stochastic one with fixed stribution) and dropping the modified state from the result.

One of the ways to make a model stateless for training purposes. Useful when used after Unroll. See TrainState, as well.

deStateD :: s -> Model p (Just s) a b -> Model p Nothing a b Source #

deState, except the state is always the same even in stochastic mode.

zeroState :: Num s => Model p (Just s) a b -> Model p Nothing a b Source #

deState with a constant state of 0.

dummyState :: forall s p a b. Model p Nothing a b -> Model p s a b Source #

Give a stateless model a "dummy" state. For now, useful for using with combinators like deState that require state. However, deState could also be made more lenient (to accept non stateful models) in the future.

Also useful for usage with combinators like . from Control.Category that requires all input models to share common state.

Manipulate model states

unroll :: (Traversable t, Backprop a, Backprop b) => Model p s a b -> Model p s (t a) (t b) Source #

Unroll a (usually) stateful model into one taking a vector of sequential inputs.

Basically applies the model to every item of input and returns all of the results, but propagating the state between every step.

Useful when used before trainState or deState. See unrollTrainState and unrollDeState.

Compare to feedbackTrace, which, instead of receiving a vector of sequential inputs, receives a single input and uses its output as the next input.

unrollFinal :: (Traversable t, Backprop a) => Model p s a b -> Model p s (t a) b Source #

Version of unroll that only keeps the "final" result, dropping all of the intermediate results.

Turns a stateful model into one that runs the model repeatedly on multiple inputs sequentially and outputs the final result after seeing all items.

Note will be partial if given an empty sequence.

recurrent Source #

Arguments

:: (AllConstrainedProd Backprop s, PureProd Maybe s, Backprop a, Backprop b) 
=> (ab -> (a, b))

split

-> (a -> b -> ab)

join

-> BFunc c b

store state

-> Model p s ab c 
-> Model p (s :#? Just b) a c 

Fix a part of a parameter of a model to be (a function of) the previous ouput of the model itself.

Essentially, takes a \( X \times Y \rightarrow Z \) into a stateful \( X \rightarrow Z \), where the Y is given by a function of the previous output of the model.

Essentially makes a model "recurrent": it receives its previous output as input.

See fcr for an application.