{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# OPTIONS_HADDOCK show-extensions #-}
module Prelude.InfBackprop
(
linear,
(+),
(-),
negate,
(*),
(/),
dup,
setFirst,
setSecond,
forget,
forgetFirst,
forgetSecond,
log,
logBase,
exp,
(**),
pow,
cos,
sin,
tan,
asin,
acos,
atan,
atan2,
sinh,
cosh,
tanh,
asinh,
acosh,
atanh,
simpleDifferentiable,
)
where
import Control.CatBifunctor (first, second, (***))
import Control.Category ((<<<), (>>>))
import InfBackprop.Common (Backprop (MkBackprop), BackpropFunc, const)
import IsomorphismClass.Isomorphism (iso)
import NumHask (Additive, Distributive, Divisive, ExpField, Subtractive, TrigField, fromInteger, zero)
import qualified NumHask as NH
import NumHask.Prelude (one)
import qualified NumHask.Prelude as NHP
import Prelude (flip, uncurry, ($), (==))
import qualified Prelude as P
simpleDifferentiable :: forall x. Distributive x => (x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable :: forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
f BackpropFunc x x
df = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop x -> x
call' BackpropFunc x (x, x)
forward' BackpropFunc (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = x -> x
f
forward' :: BackpropFunc x (x, x)
forward' :: BackpropFunc x (x, x)
forward' = forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
f BackpropFunc x x
df)
backward' :: BackpropFunc (x, x) x
backward' :: BackpropFunc (x, x) x
backward' = forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second BackpropFunc x x
df forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*)
dup ::
forall x.
Additive x =>
BackpropFunc x (x, x)
dup :: forall x. Additive x => BackpropFunc x (x, x)
dup = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop x -> (x, x)
call' BackpropFunc x ((x, x), ())
forward' BackpropFunc ((x, x), ()) x
backward'
where
call' :: x -> (x, x)
call' :: x -> (x, x)
call' x
x = (x
x, x
x)
forward' :: BackpropFunc x ((x, x), ())
forward' :: BackpropFunc x ((x, x), ())
forward' = forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc ((x, x), ()) x
backward' :: BackpropFunc ((x, x), ()) x
backward' = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (y, ()) y) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Additive x => BackpropFunc (x, x) x
(+)
forget ::
forall x.
Additive x =>
BackpropFunc x ()
forget :: forall x. Additive x => BackpropFunc x ()
forget = forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const ()
forgetFirst ::
forall x y.
Additive x =>
BackpropFunc (x, y) y
forgetFirst :: forall x y. Additive x => BackpropFunc (x, y) y
forgetFirst = forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<< forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first forall x. Additive x => BackpropFunc x ()
forget
forgetSecond ::
forall x y.
Additive y =>
BackpropFunc (x, y) x
forgetSecond :: forall x y. Additive y => BackpropFunc (x, y) x
forgetSecond = forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<< forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second forall x. Additive x => BackpropFunc x ()
forget
setFirst ::
forall x y c.
Additive c =>
c ->
BackpropFunc (c, x) y ->
BackpropFunc x y
setFirst :: forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst c
c BackpropFunc (c, x) y
f = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc x ((), x)) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const c
c) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> BackpropFunc (c, x) y
f
setSecond ::
forall x y c.
Additive c =>
c ->
BackpropFunc (x, c) y ->
BackpropFunc x y
setSecond :: forall x y c.
Additive c =>
c -> BackpropFunc (x, c) y -> BackpropFunc x y
setSecond c
c BackpropFunc (x, c) y
f = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc x (x, ())) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const c
c) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> BackpropFunc (x, c) y
f
linear ::
forall x.
NH.Distributive x =>
x ->
BackpropFunc x x
linear :: forall x. Distributive x => x -> BackpropFunc x x
linear x
c = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop x -> x
call' BackpropFunc x (x, ())
forward' BackpropFunc (x, ()) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = x -> x -> x
f x
c
where
f :: x -> x -> x
f = forall a. Multiplicative a => a -> a -> a
(NH.*)
forward' :: BackpropFunc x (x, ())
forward' :: BackpropFunc x (x, ())
forward' = forall x. Distributive x => x -> BackpropFunc x x
linear x
c forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) x
backward' :: BackpropFunc (x, ()) x
backward' = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (x, ()) x) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => x -> BackpropFunc x x
linear x
c
(+) ::
forall x.
Additive x =>
BackpropFunc (x, x) x
+ :: forall x. Additive x => BackpropFunc (x, x) x
(+) = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop (x, x) -> x
call' BackpropFunc (x, x) (x, ())
forward' BackpropFunc (x, ()) (x, x)
backward'
where
call' :: (x, x) -> x
call' :: (x, x) -> x
call' = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Additive a => a -> a -> a
(NH.+)
forward' :: BackpropFunc (x, x) (x, ())
forward' :: BackpropFunc (x, x) (x, ())
forward' = forall x. Additive x => BackpropFunc (x, x) x
(+) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) (x, x)
backward' :: BackpropFunc (x, ()) (x, x)
backward' = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (x, ()) x) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Additive x => BackpropFunc x (x, x)
dup
negate ::
forall x.
Subtractive x =>
BackpropFunc x x
negate :: forall x. Subtractive x => BackpropFunc x x
negate = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop x -> x
call' BackpropFunc x (x, ())
forward' BackpropFunc (x, ()) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = forall a. Subtractive a => a -> a
NH.negate
forward' :: BackpropFunc x (x, ())
forward' :: BackpropFunc x (x, ())
forward' = forall x. Subtractive x => BackpropFunc x x
negate forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) x
backward' :: BackpropFunc (x, ()) x
backward' = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (y, ()) y) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Subtractive x => BackpropFunc x x
negate
(-) :: forall x. (Subtractive x) => BackpropFunc (x, x) x
(-) = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop (x, x) -> x
call' BackpropFunc (x, x) (x, ())
forward' BackpropFunc (x, ()) (x, x)
backward'
where
call' :: (x, x) -> x
call' :: (x, x) -> x
call' = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Subtractive a => a -> a -> a
(NH.-)
forward' :: BackpropFunc (x, x) (x, ())
forward' :: BackpropFunc (x, x) (x, ())
forward' = (-) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) (x, x)
backward' :: BackpropFunc (x, ()) (x, x)
backward' = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (x, ()) x) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second forall x. Subtractive x => BackpropFunc x x
negate
(*) :: Distributive x => BackpropFunc (x, x) x
* :: forall x. Distributive x => BackpropFunc (x, x) x
(*) = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop forall x. Distributive x => (x, x) -> x
call' forall x. Distributive x => BackpropFunc (x, x) (x, (x, x))
forward' forall x. Distributive x => BackpropFunc (x, (x, x)) (x, x)
backward'
where
call' :: Distributive x => (x, x) -> x
call' :: forall x. Distributive x => (x, x) -> x
call' = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Multiplicative a => a -> a -> a
(NH.*)
forward' :: Distributive x => BackpropFunc (x, x) (x, (x, x))
forward' :: forall x. Distributive x => BackpropFunc (x, x) (x, (x, x))
forward' = forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first forall x. Distributive x => BackpropFunc (x, x) x
(*)
backward' :: Distributive x => BackpropFunc (x, (x, x)) (x, x)
backward' :: forall x. Distributive x => BackpropFunc (x, (x, x)) (x, x)
backward' =
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first forall x. Additive x => BackpropFunc x (x, x)
dup
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((dy, dy), (x1, x2)) ((dy, x1), (dy, x2)))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (a, b) (b, a))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*) forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** forall x. Distributive x => BackpropFunc (x, x) x
(*)
square :: Distributive x => BackpropFunc x x
square :: forall x. Distributive x => BackpropFunc x x
square = forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*)
(/) ::
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
/ :: forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/) = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop (x, x) -> x
call' BackpropFunc (x, x) (x, (x, x))
forward' BackpropFunc (x, (x, x)) (x, x)
backward'
where
call' :: (x, x) -> x
call' :: (x, x) -> x
call' = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Divisive a => a -> a -> a
(NH./)
forward' :: BackpropFunc (x, x) (x, (x, x))
forward' :: BackpropFunc (x, x) (x, (x, x))
forward' = forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/)
backward' :: BackpropFunc (x, (x, x)) (x, x)
backward' :: BackpropFunc (x, (x, x)) (x, x)
backward' =
forall x. Additive x => BackpropFunc x (x, x)
dup forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** forall x. Additive x => BackpropFunc x (x, x)
dup
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (Backprop (->) (x, x) x
d1 forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** Backprop (->) (x, x) x
d2)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((dy, dy), (x1, x2)) ((dy, x1), (dy, x2)))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*) forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** forall x. Distributive x => BackpropFunc (x, x) x
(*)
where
d1 :: Backprop (->) (x, x) x
d1 = (forall x. Additive x => BackpropFunc x ()
forget forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((), x) x)
d2 :: Backprop (->) (x, x) x
d2 = (forall x. Subtractive x => BackpropFunc x x
negate forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** (forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*)
recip ::
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip :: forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip = forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst forall a. Multiplicative a => a
NH.one forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/)
pow ::
forall x.
( Divisive x,
Distributive x,
Subtractive x,
NH.FromIntegral x NHP.Integer
) =>
NHP.Integer ->
BackpropFunc x x
pow :: forall x.
(Divisive x, Distributive x, Subtractive x,
FromIntegral x Integer) =>
Integer -> BackpropFunc x x
pow Integer
n = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop x -> x
call' BackpropFunc x (x, x)
forward' BackpropFunc (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Divisive a => a -> Int -> a
(NH.^) (forall a. FromInteger a => Integer -> a
fromInteger Integer
n)
forward' :: BackpropFunc x (x, x)
forward' :: BackpropFunc x (x, x)
forward' = forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (forall x.
(Divisive x, Distributive x, Subtractive x,
FromIntegral x Integer) =>
Integer -> BackpropFunc x x
pow Integer
n :: BackpropFunc x x)
backward' :: BackpropFunc (x, x) x
backward' :: BackpropFunc (x, x) x
backward' = forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second BackpropFunc x x
der forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*)
where
der :: BackpropFunc x x
der =
if Integer
n forall a. Eq a => a -> a -> Bool
== Integer
0
then forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const forall a. Additive a => a
zero
else forall x.
(Divisive x, Distributive x, Subtractive x,
FromIntegral x Integer) =>
Integer -> BackpropFunc x x
pow (Integer
n forall a. Num a => a -> a -> a
P.- Integer
1) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => x -> BackpropFunc x x
linear (forall a b. FromIntegral a b => b -> a
NH.fromIntegral Integer
n)
sqrt ::
forall x.
ExpField x =>
BackpropFunc x x
sqrt :: forall x. ExpField x => BackpropFunc x x
sqrt = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop x -> x
call' BackpropFunc x (x, x)
forward' BackpropFunc (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = forall a. ExpField a => a -> a
NH.sqrt
forward' :: BackpropFunc x (x, x)
forward' :: BackpropFunc x (x, x)
forward' = (forall x. ExpField x => BackpropFunc x x
sqrt :: BackpropFunc x x) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Additive x => BackpropFunc x (x, x)
dup
backward' :: BackpropFunc (x, x) x
backward' :: BackpropFunc (x, x) x
backward' = forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => x -> BackpropFunc x x
linear forall a. Field a => a
NH.half) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*)
(**) ::
forall a.
( ExpField a,
NH.FromIntegral a P.Integer
) =>
BackpropFunc (a, a) a
** :: forall a.
(ExpField a, FromIntegral a Integer) =>
BackpropFunc (a, a) a
(**) = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop (a, a) -> a
call' BackpropFunc (a, a) (a, (a, (a, a)))
forward' BackpropFunc (a, (a, (a, a))) (a, a)
backward'
where
call' :: (a, a) -> a
call' :: (a, a) -> a
call' = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. ExpField a => a -> a -> a
(NH.**)
forward' :: BackpropFunc (a, a) (a, (a, (a, a)))
forward' :: BackpropFunc (a, a) (a, (a, (a, a)))
forward' =
forall x. Additive x => BackpropFunc x (x, x)
dup
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (forall a.
(ExpField a, FromIntegral a Integer) =>
BackpropFunc (a, a) a
(**) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Additive x => BackpropFunc x (x, x)
dup)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((a, b), c) (a, (b, c)))
backward' :: BackpropFunc (a, (a, (a, a))) (a, a)
backward' :: BackpropFunc (a, (a, (a, a))) (a, a)
backward' =
forall x. Additive x => BackpropFunc x (x, x)
dup forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** (forall x. Additive x => BackpropFunc x (x, x)
dup forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (BackpropFunc (a, (a, a)) a
dn forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** BackpropFunc (a, (a, a)) a
dx))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((a, b), (c, d)) ((a, c), (b, d)))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*) forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** forall x. Distributive x => BackpropFunc (x, x) x
(*)
where
dn :: BackpropFunc (a, (a, a)) a
dn :: BackpropFunc (a, (a, a)) a
dn =
forall x y. Additive x => BackpropFunc (x, y) y
forgetFirst
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first forall x. Additive x => BackpropFunc x (x, x)
dup
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((a, b), c) (a, (b, c)))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (forall x y c.
Additive c =>
c -> BackpropFunc (x, c) y -> BackpropFunc x y
setSecond (forall a b. FromIntegral a b => b -> a
NH.fromIntegral (Integer
1 :: P.Integer)) (-)))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second forall a.
(ExpField a, FromIntegral a Integer) =>
BackpropFunc (a, a) a
(**)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*)
dx :: BackpropFunc (a, (a, a)) a
dx :: BackpropFunc (a, (a, a)) a
dx = forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second forall x y. Additive x => BackpropFunc (x, y) y
forgetFirst forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second forall x. ExpField x => BackpropFunc x x
log forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc (x, x) x
(*)
log :: ExpField x => BackpropFunc x x
log :: forall x. ExpField x => BackpropFunc x x
log = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. ExpField a => a -> a
NH.log forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip
logBase :: ExpField a => BackpropFunc (a, a) a
logBase :: forall a. ExpField a => BackpropFunc (a, a) a
logBase = (forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (c, d) (d, c)) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. ExpField x => BackpropFunc x x
log forall (p :: * -> * -> *) (cat :: * -> * -> *) a1 b1 a2 b2.
CatBiFunctor p cat =>
cat a1 b1 -> cat a2 b2 -> cat (p a1 a2) (p b1 b2)
*** forall x. ExpField x => BackpropFunc x x
log forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/)
exp :: forall x. ExpField x => BackpropFunc x x
exp :: forall x. ExpField x => BackpropFunc x x
exp = forall (cat :: * -> * -> *) input output cache.
cat input output
-> Backprop cat input (output, cache)
-> Backprop cat (output, cache) input
-> Backprop cat input output
MkBackprop x -> x
call' BackpropFunc x (x, x)
forward' BackpropFunc (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = forall a. ExpField a => a -> a
NH.exp
forward' :: BackpropFunc x (x, x)
forward' :: BackpropFunc x (x, x)
forward' = (forall x. ExpField x => BackpropFunc x x
exp :: BackpropFunc x x) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Additive x => BackpropFunc x (x, x)
dup
backward' :: BackpropFunc (x, x) x
backward' :: BackpropFunc (x, x) x
backward' = forall x. Distributive x => BackpropFunc (x, x) x
(*)
sin :: TrigField x => BackpropFunc x x
sin :: forall x. TrigField x => BackpropFunc x x
sin = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.sin forall x. TrigField x => BackpropFunc x x
cos
cos :: TrigField x => BackpropFunc x x
cos :: forall x. TrigField x => BackpropFunc x x
cos = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.cos (forall x. TrigField x => BackpropFunc x x
sin forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Subtractive x => BackpropFunc x x
negate)
tan :: TrigField x => BackpropFunc x x
tan :: forall x. TrigField x => BackpropFunc x x
tan = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.tan (forall x. TrigField x => BackpropFunc x x
cos forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
asin :: (TrigField x, ExpField x) => BackpropFunc x x
asin :: forall x. (TrigField x, ExpField x) => BackpropFunc x x
asin = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.tan (forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst forall a. Multiplicative a => a
one (-) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. ExpField x => BackpropFunc x x
sqrt forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
acos :: (TrigField x, ExpField x) => BackpropFunc x x
acos :: forall x. (TrigField x, ExpField x) => BackpropFunc x x
acos = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.tan (forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst forall a. Multiplicative a => a
one (-) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. ExpField x => BackpropFunc x x
sqrt forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Subtractive x => BackpropFunc x x
negate)
atan :: TrigField x => BackpropFunc x x
atan :: forall x. TrigField x => BackpropFunc x x
atan = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.atan (forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst forall a. Multiplicative a => a
one forall x. Additive x => BackpropFunc (x, x) x
(+) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
atan2 :: TrigField a => BackpropFunc (a, a) a
atan2 :: forall a. TrigField a => BackpropFunc (a, a) a
atan2 = forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. TrigField x => BackpropFunc x x
atan
sinh :: TrigField x => BackpropFunc x x
sinh :: forall x. TrigField x => BackpropFunc x x
sinh = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.sinh forall x. TrigField x => BackpropFunc x x
cosh
cosh :: TrigField x => BackpropFunc x x
cosh :: forall x. TrigField x => BackpropFunc x x
cosh = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.cosh forall x. TrigField x => BackpropFunc x x
sinh
tanh :: TrigField x => BackpropFunc x x
tanh :: forall x. TrigField x => BackpropFunc x x
tanh = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.tanh (forall x. TrigField x => BackpropFunc x x
cosh forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
asinh :: (TrigField x, ExpField x) => BackpropFunc x x
asinh :: forall x. (TrigField x, ExpField x) => BackpropFunc x x
asinh = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.asinh (forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst forall a. Multiplicative a => a
one forall x. Additive x => BackpropFunc (x, x) x
(+) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. ExpField x => BackpropFunc x x
sqrt forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
acosh :: (TrigField x, ExpField x) => BackpropFunc x x
acosh :: forall x. (TrigField x, ExpField x) => BackpropFunc x x
acosh = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.tan (forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x y c.
Additive c =>
c -> BackpropFunc (x, c) y -> BackpropFunc x y
setSecond forall a. Multiplicative a => a
one (-) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x. ExpField x => BackpropFunc x x
sqrt forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
atanh :: TrigField x => BackpropFunc x x
atanh :: forall x. TrigField x => BackpropFunc x x
atanh = forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable forall a. TrigField a => a -> a
NH.tan (forall x. Distributive x => BackpropFunc x x
square forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst forall a. Multiplicative a => a
one (-) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)