Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- module Backprop.Learn.Model.Types
- module Backprop.Learn.Model.Stochastic
- module Backprop.Learn.Model.State
- module Backprop.Learn.Model.Regression
- module Backprop.Learn.Model.Parameter
- module Backprop.Learn.Model.Neural.LSTM
- module Backprop.Learn.Model.Neural
- module Backprop.Learn.Model.Function
- module Backprop.Learn.Model.Combinator
- class Backprop a where
- runModel :: forall p s a b. (AllConstrainedProd Backprop s, Backprop b) => Model p s a b -> TMaybe p -> a -> TMaybe s -> (b, TMaybe s)
- runModelStoch :: forall p s a b m. (AllConstrainedProd Backprop s, Backprop b, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> a -> TMaybe s -> m (b, TMaybe s)
- runModelStateless :: Model p Nothing a b -> TMaybe p -> a -> b
- runModelStochStateless :: PrimMonad m => Model p Nothing a b -> Gen (PrimState m) -> TMaybe p -> a -> m b
- gradModel :: (Backprop a, Backprop b, AllConstrainedProd Backprop p) => Model p Nothing a b -> TMaybe p -> a -> (TMaybe p, a)
- gradModelStoch :: (Backprop a, Backprop b, AllConstrainedProd Backprop p, PrimMonad m) => Model p Nothing a b -> Gen (PrimState m) -> TMaybe p -> a -> m (TMaybe p, a)
- initParam :: (Initialize p, ContGen d, PrimMonad m) => model (Just p) s a b -> d -> Gen (PrimState m) -> m p
- initParamNormal :: (Initialize p, PrimMonad m) => model (Just p) s a b -> Double -> Gen (PrimState m) -> m p
- encodeParam :: Binary p => model (Just p) s a b -> p -> ByteString
- decodeParam :: Binary p => model (Just p) s a b -> ByteString -> p
- decodeParamOrFail :: Binary p => model (Just p) s a b -> ByteString -> Either String p
- saveParam :: Binary p => model (Just p) s a b -> FilePath -> p -> IO ()
- loadParam :: Binary p => model (Just p) s a b -> FilePath -> IO p
- loadParamOrFail :: Binary p => model (Just p) s a b -> FilePath -> IO (Either String p)
- iterateModel :: (Backprop b, AllConstrainedProd Backprop s) => (b -> a) -> Int -> Model p s a b -> TMaybe p -> a -> TMaybe s -> ([b], TMaybe s)
- iterateModelM :: (Backprop b, AllConstrainedProd Backprop s, Monad m) => (b -> m a) -> Int -> Model p s a b -> TMaybe p -> a -> TMaybe s -> m ([b], TMaybe s)
- iterateModelStoch :: (Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => (b -> m a) -> Int -> Model p s a b -> Gen (PrimState m) -> TMaybe p -> a -> TMaybe s -> m ([b], TMaybe s)
- scanModel :: (Traversable t, Backprop b, AllConstrainedProd Backprop s) => Model p s a b -> TMaybe p -> t a -> TMaybe s -> (t b, TMaybe s)
- scanModelStoch :: (Traversable t, Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> t a -> TMaybe s -> m (t b, TMaybe s)
- iterateModel_ :: (Backprop b, AllConstrainedProd Backprop s) => (b -> a) -> Model p s a b -> TMaybe p -> a -> TMaybe s -> [b]
- iterateModelM_ :: (Backprop b, AllConstrainedProd Backprop s, Monad m) => (b -> m a) -> Int -> Model p s a b -> TMaybe p -> a -> TMaybe s -> m [b]
- iterateModelStoch_ :: (Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => (b -> m a) -> Int -> Model p s a b -> Gen (PrimState m) -> TMaybe p -> a -> TMaybe s -> m [b]
- scanModel_ :: (Traversable t, Backprop b, AllConstrainedProd Backprop s) => Model p s a b -> TMaybe p -> t a -> TMaybe s -> t b
- scanModelStoch_ :: (Traversable t, Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> t a -> TMaybe s -> m (t b)
- primeModel :: (Foldable t, Backprop b, AllConstrainedProd Backprop s) => Model p s a b -> TMaybe p -> t a -> TMaybe s -> TMaybe s
- primeModelStoch :: (Foldable t, Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> t a -> TMaybe s -> m (TMaybe s)
- selfPrime :: (Backprop b, AllConstrainedProd Backprop s) => (b -> a) -> Model p s a b -> TMaybe p -> a -> TMaybe s -> [TMaybe s]
- selfPrimeM :: (Backprop b, AllConstrainedProd Backprop s, Monad m) => (b -> m a) -> Int -> Model p s a b -> TMaybe p -> a -> TMaybe s -> m (TMaybe s)
Documentation
module Backprop.Learn.Model.Types
module Backprop.Learn.Model.State
module Backprop.Learn.Model.Neural
Class of values that can be backpropagated in general.
For instances of Num
, these methods can be given by zeroNum
,
addNum
, and oneNum
. There are also generic options given in
Numeric.Backprop.Class for functors, IsList
instances, and Generic
instances.
instanceBackprop
Double
wherezero
=zeroNum
add
=addNum
one
=oneNum
If you leave the body of an instance declaration blank, GHC Generics
will be used to derive instances if the type has a single constructor
and each field is an instance of Backprop
.
To ensure that backpropagation works in a sound way, should obey the laws:
- identity
Also implies preservation of information, making
an
illegal implementation for lists and vectors.zipWith
(+
)
This is only expected to be true up to potential "extra zeroes" in x
and y
in the result.
- commutativity
- associativity
- idempotence
- unital
Note that not all values in the backpropagation process needs all of
these methods: Only the "final result" needs one
, for example. These
are all grouped under one typeclass for convenience in defining
instances, and also to talk about sensible laws. For fine-grained
control, use the "explicit" versions of library functions (for example,
in Numeric.Backprop.Explicit) instead of Backprop
based ones.
This typeclass replaces the reliance on Num
of the previous API
(v0.1). Num
is strictly more powerful than Backprop
, and is
a stronger constraint on types than is necessary for proper
backpropagating. In particular, fromInteger
is a problem for many
types, preventing useful backpropagation for lists, variable-length
vectors (like Data.Vector) and variable-size matrices from linear
algebra libraries like hmatrix and accelerate.
Since: backprop-0.2.0.0
Nothing
"Zero out" all components of a value. For scalar values, this
should just be
. For vectors and matrices, this should
set all components to zero, the additive identity.const
0
Should be idempotent:
Should be as lazy as possible. This behavior is observed for all instances provided by this library.
See zeroNum
for a pre-built definition for instances of Num
and
zeroFunctor
for a definition for instances of Functor
. If left
blank, will automatically be genericZero
, a pre-built definition
for instances of Generic
whose fields are all themselves
instances of Backprop
.
Add together two values of a type. To combine contributions of gradients, so should be information-preserving:
Should be as strict as possible. This behavior is observed for all instances provided by this library.
See addNum
for a pre-built definition for instances of Num
and
addIsList
for a definition for instances of IsList
. If left
blank, will automatically be genericAdd
, a pre-built definition
for instances of Generic
with one constructor whose fields are
all themselves instances of Backprop
.
One all components of a value. For scalar values, this should
just be
. For vectors and matrices, this should set all
components to one, the multiplicative identity.const
1
As the library uses it, the most important law is:
That is,
is the gradient of the identity function with
respect to its input.one
x
Ideally should be idempotent:
Should be as lazy as possible. This behavior is observed for all instances provided by this library.
See oneNum
for a pre-built definition for instances of Num
and
oneFunctor
for a definition for instances of Functor
. If left
blank, will automatically be genericOne
, a pre-built definition
for instances of Generic
whose fields are all themselves
instances of Backprop
.
Instances
Backprop Double | |
Backprop Float | |
Backprop Int | |
Backprop Integer | |
Backprop Natural | Since: backprop-0.2.1.0 |
Backprop Word | Since: backprop-0.2.2.0 |
Backprop Word8 | Since: backprop-0.2.2.0 |
Backprop Word16 | Since: backprop-0.2.2.0 |
Backprop Word32 | Since: backprop-0.2.2.0 |
Backprop Word64 | Since: backprop-0.2.2.0 |
Backprop () |
|
Backprop Void | |
Backprop a => Backprop [a] |
|
Backprop a => Backprop (Maybe a) |
|
Integral a => Backprop (Ratio a) | |
Num a => Backprop (NumBP a) | |
RealFloat a => Backprop (Complex a) | |
Backprop a => Backprop (First a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (Last a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (Option a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (Identity a) | |
Backprop a => Backprop (First a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (Last a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (Dual a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (Sum a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (Product a) | Since: backprop-0.2.2.0 |
Backprop a => Backprop (NonEmpty a) |
|
Backprop a => Backprop (IntMap a) |
|
Backprop a => Backprop (Seq a) |
|
(Storable a, Backprop a) => Backprop (Vector a) | |
(Unbox a, Backprop a) => Backprop (Vector a) | |
(Prim a, Backprop a) => Backprop (Vector a) | |
Backprop a => Backprop (Vector a) | |
Backprop (Label field) | Since: backprop-0.2.6.3 |
Backprop a => Backprop (Identity a) | Since: backprop-0.2.6.3 |
Backprop a => Backprop (Thunk a) | Since: backprop-0.2.6.3 |
Backprop t => Backprop (ElField ((,) s t)) | Since: backprop-0.2.6.3 |
PureProdC Maybe Backprop as => Backprop (TMaybe as) Source # | |
Backprop a => Backprop (TF a) Source # | |
Backprop a => Backprop (NoRegularize a) Source # | |
Defined in Backprop.Learn.Regularize zero :: NoRegularize a -> NoRegularize a # add :: NoRegularize a -> NoRegularize a -> NoRegularize a # one :: NoRegularize a -> NoRegularize a # | |
Backprop a => Backprop (RegularizeMetric a) Source # | |
Defined in Backprop.Learn.Regularize zero :: RegularizeMetric a -> RegularizeMetric a # add :: RegularizeMetric a -> RegularizeMetric a -> RegularizeMetric a # one :: RegularizeMetric a -> RegularizeMetric a # | |
Backprop a => Backprop (r -> a) |
Since: backprop-0.2.2.0 |
Backprop (V1 p) | Since: backprop-0.2.2.0 |
Backprop (U1 p) | Since: backprop-0.2.2.0 |
(Backprop a, Backprop b) => Backprop (a, b) |
|
(Backprop a, Ord k) => Backprop (Map k a) |
|
(Backprop a, Reifies s W) => Backprop (BVar s a) | Since: backprop-0.2.2.0 |
(Vector v a, Num a) => Backprop (NumVec v a) | |
(Applicative f, Backprop a) => Backprop (ABP f a) | |
(Backprop a, Backprop b) => Backprop (Arg a b) | Since: backprop-0.2.2.0 |
Backprop (Proxy a) | |
Backprop (SField field) | Since: backprop-0.2.6.3 |
(Backprop a, Backprop b) => Backprop (a :# b) Source # | |
(KnownNat o, KnownNat i) => Backprop (LRp i o) Source # | |
Backprop (ARIMAp a b) Source # | |
KnownNat o => Backprop (LSTMp i o) Source # | |
KnownNat o => Backprop (GRUp i o) Source # | |
(Backprop a, Backprop b, Backprop c) => Backprop (a, b, c) |
|
(ReifyConstraint Backprop f rs, RMap rs, RApply rs) => Backprop (Rec f rs) | Since: backprop-0.2.6.3 |
(Backprop a, Applicative m) => Backprop (Kleisli m r a) | Since: backprop-0.2.2.0 |
Backprop w => Backprop (Const w a) | Since: backprop-0.2.2.0 |
(ReifyConstraint Backprop f rs, RMap rs, RApply rs, IsoXRec f rs) => Backprop (XRec f rs) | Since: backprop-0.2.6.3 |
Backprop (HKD t a) => Backprop (XData t a) | Since: backprop-0.2.6.3 |
(ReifyConstraint Backprop f rs, RMap rs, RApply rs, RecApplicative rs, NatToInt (RLength rs), RPureConstrained (IndexableField rs) rs) => Backprop (ARec f rs) | Since: backprop-0.2.6.3 |
(ReifyConstraint Backprop f rs, RMap rs, RApply rs, Storable (Rec f rs)) => Backprop (SRec f rs) | Since: backprop-0.2.6.3 |
Backprop w => Backprop (Const w a) | Since: backprop-0.2.6.3 |
Backprop (ARIMAs a b c) Source # | |
Backprop a => Backprop (K1 i a p) | Since: backprop-0.2.2.0 |
(Backprop (f p), Backprop (g p)) => Backprop ((f :*: g) p) | Since: backprop-0.2.2.0 |
(Backprop a, Backprop b, Backprop c, Backprop d) => Backprop (a, b, c, d) |
|
(Backprop (f a), Backprop (g a)) => Backprop (Product f g a) | Since: backprop-0.2.2.0 |
Backprop (f p) => Backprop (M1 i c f p) | Since: backprop-0.2.2.0 |
Backprop (f (g a)) => Backprop ((f :.: g) a) | Since: backprop-0.2.6.3 |
(Backprop a, Backprop b, Backprop c, Backprop d, Backprop e) => Backprop (a, b, c, d, e) |
|
Backprop (f (g a)) => Backprop (Compose f g a) | Since: backprop-0.2.2.0 |
Backprop (f (g a)) => Backprop (Compose f g a) | Since: backprop-0.2.6.3 |
Backprop (op (f a) (g a)) => Backprop (Lift op f g a) | Since: backprop-0.2.6.3 |
Running and Grad
runModel :: forall p s a b. (AllConstrainedProd Backprop s, Backprop b) => Model p s a b -> TMaybe p -> a -> TMaybe s -> (b, TMaybe s) Source #
runModelStoch :: forall p s a b m. (AllConstrainedProd Backprop s, Backprop b, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> a -> TMaybe s -> m (b, TMaybe s) Source #
runModelStochStateless :: PrimMonad m => Model p Nothing a b -> Gen (PrimState m) -> TMaybe p -> a -> m b Source #
gradModel :: (Backprop a, Backprop b, AllConstrainedProd Backprop p) => Model p Nothing a b -> TMaybe p -> a -> (TMaybe p, a) Source #
gradModelStoch :: (Backprop a, Backprop b, AllConstrainedProd Backprop p, PrimMonad m) => Model p Nothing a b -> Gen (PrimState m) -> TMaybe p -> a -> m (TMaybe p, a) Source #
Work with parameters
:: Binary p | |
=> model (Just p) s a b | ignored |
-> p | |
-> ByteString |
:: Binary p | |
=> model (Just p) s a b | ignored |
-> ByteString | |
-> p |
:: Binary p | |
=> model (Just p) s a b | ignored |
-> ByteString | |
-> Either String p |
Iterated runners
scanModel :: (Traversable t, Backprop b, AllConstrainedProd Backprop s) => Model p s a b -> TMaybe p -> t a -> TMaybe s -> (t b, TMaybe s) Source #
scanModelStoch :: (Traversable t, Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> t a -> TMaybe s -> m (t b, TMaybe s) Source #
No final state
scanModel_ :: (Traversable t, Backprop b, AllConstrainedProd Backprop s) => Model p s a b -> TMaybe p -> t a -> TMaybe s -> t b Source #
scanModelStoch_ :: (Traversable t, Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> t a -> TMaybe s -> m (t b) Source #
Prime runners
primeModel :: (Foldable t, Backprop b, AllConstrainedProd Backprop s) => Model p s a b -> TMaybe p -> t a -> TMaybe s -> TMaybe s Source #
primeModelStoch :: (Foldable t, Backprop b, AllConstrainedProd Backprop s, PrimMonad m) => Model p s a b -> Gen (PrimState m) -> TMaybe p -> t a -> TMaybe s -> m (TMaybe s) Source #