{-# 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 :: (x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
f BackpropFunc x x
df = (x -> x)
-> Backprop (->) x (x, x)
-> Backprop (->) (x, x) x
-> BackpropFunc 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
call' Backprop (->) x (x, x)
forward' Backprop (->) (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = x -> x
f
forward' :: BackpropFunc x (x, x)
forward' :: Backprop (->) x (x, x)
forward' = Backprop (->) x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup Backprop (->) x (x, x)
-> Backprop (->) (x, x) (x, x) -> Backprop (->) 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
>>> BackpropFunc x x -> Backprop (->) (x, x) (x, x)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first ((x -> x) -> BackpropFunc x x -> BackpropFunc x x
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' :: Backprop (->) (x, x) x
backward' = BackpropFunc x x -> Backprop (->) (x, x) (x, x)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second BackpropFunc x x
df Backprop (->) (x, x) (x, x)
-> Backprop (->) (x, x) x -> Backprop (->) (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
>>> Backprop (->) (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
dup ::
forall x.
Additive x =>
BackpropFunc x (x, x)
dup :: BackpropFunc x (x, x)
dup = (x -> (x, x))
-> Backprop (->) x ((x, x), ())
-> Backprop (->) ((x, x), ()) 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' Backprop (->) x ((x, x), ())
forward' Backprop (->) ((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' :: Backprop (->) x ((x, x), ())
forward' = BackpropFunc x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup BackpropFunc x (x, x)
-> Backprop (->) (x, x) ((x, x), ())
-> Backprop (->) 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 y. Backprop (->) y (y, ())
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc ((x, x), ()) x
backward' :: Backprop (->) ((x, x), ()) x
backward' = (forall y. Backprop (->) (y, ()) y
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (y, ()) y) Backprop (->) ((x, x), ()) (x, x)
-> Backprop (->) (x, x) x -> Backprop (->) ((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
>>> Backprop (->) (x, x) x
forall x. Additive x => BackpropFunc (x, x) x
(+)
forget ::
forall x.
Additive x =>
BackpropFunc x ()
forget :: BackpropFunc x ()
forget = () -> BackpropFunc x ()
forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const ()
forgetFirst ::
forall x y.
Additive x =>
BackpropFunc (x, y) y
forgetFirst :: BackpropFunc (x, y) y
forgetFirst = Backprop (->) ((), y) y
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso Backprop (->) ((), y) y
-> Backprop (->) (x, y) ((), y) -> BackpropFunc (x, y) y
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<< Backprop (->) x () -> Backprop (->) (x, y) ((), y)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first Backprop (->) x ()
forall x. Additive x => BackpropFunc x ()
forget
forgetSecond ::
forall x y.
Additive y =>
BackpropFunc (x, y) x
forgetSecond :: BackpropFunc (x, y) x
forgetSecond = Backprop (->) (x, ()) x
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso Backprop (->) (x, ()) x
-> Backprop (->) (x, y) (x, ()) -> BackpropFunc (x, y) x
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<< Backprop (->) y () -> Backprop (->) (x, y) (x, ())
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second Backprop (->) y ()
forall x. Additive x => BackpropFunc x ()
forget
setFirst ::
forall x y c.
Additive c =>
c ->
BackpropFunc (c, x) y ->
BackpropFunc x y
setFirst :: c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst c
c BackpropFunc (c, x) y
f = (Backprop (->) x ((), x)
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc x ((), x)) Backprop (->) x ((), x)
-> Backprop (->) ((), x) y -> BackpropFunc x y
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Backprop (->) () c -> Backprop (->) ((), x) (c, x)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (c -> Backprop (->) () c
forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const c
c) Backprop (->) ((), x) (c, x)
-> BackpropFunc (c, x) y -> Backprop (->) ((), x) y
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 :: c -> BackpropFunc (x, c) y -> BackpropFunc x y
setSecond c
c BackpropFunc (x, c) y
f = (Backprop (->) x (x, ())
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc x (x, ())) Backprop (->) x (x, ())
-> Backprop (->) (x, ()) y -> BackpropFunc x y
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Backprop (->) () c -> Backprop (->) (x, ()) (x, c)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (c -> Backprop (->) () c
forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const c
c) Backprop (->) (x, ()) (x, c)
-> BackpropFunc (x, c) y -> Backprop (->) (x, ()) y
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 :: x -> BackpropFunc x x
linear x
c = (x -> x)
-> Backprop (->) x (x, ())
-> Backprop (->) (x, ()) x
-> BackpropFunc 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
call' Backprop (->) x (x, ())
forward' Backprop (->) (x, ()) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = x -> x -> x
f x
c
where
f :: x -> x -> x
f = x -> x -> x
forall a. Multiplicative a => a -> a -> a
(NH.*)
forward' :: BackpropFunc x (x, ())
forward' :: Backprop (->) x (x, ())
forward' = x -> BackpropFunc x x
forall x. Distributive x => x -> BackpropFunc x x
linear x
c BackpropFunc x x
-> Backprop (->) x (x, ()) -> Backprop (->) 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 y. Backprop (->) y (y, ())
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) x
backward' :: Backprop (->) (x, ()) x
backward' = (Backprop (->) (x, ()) x
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (x, ()) x) Backprop (->) (x, ()) x
-> BackpropFunc x x -> Backprop (->) (x, ()) x
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> x -> BackpropFunc x x
forall x. Distributive x => x -> BackpropFunc x x
linear x
c
(+) ::
forall x.
Additive x =>
BackpropFunc (x, x) x
+ :: BackpropFunc (x, x) x
(+) = ((x, x) -> x)
-> Backprop (->) (x, x) (x, ())
-> Backprop (->) (x, ()) (x, 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' Backprop (->) (x, x) (x, ())
forward' Backprop (->) (x, ()) (x, x)
backward'
where
call' :: (x, x) -> x
call' :: (x, x) -> x
call' = (x -> x -> x) -> (x, x) -> x
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry x -> x -> x
forall a. Additive a => a -> a -> a
(NH.+)
forward' :: BackpropFunc (x, x) (x, ())
forward' :: Backprop (->) (x, x) (x, ())
forward' = BackpropFunc (x, x) x
forall x. Additive x => BackpropFunc (x, x) x
(+) BackpropFunc (x, x) x
-> Backprop (->) x (x, ()) -> Backprop (->) (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 y. Backprop (->) y (y, ())
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) (x, x)
backward' :: Backprop (->) (x, ()) (x, x)
backward' = (Backprop (->) (x, ()) x
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (x, ()) x) Backprop (->) (x, ()) x
-> Backprop (->) x (x, x) -> Backprop (->) (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
>>> Backprop (->) x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup
negate ::
forall x.
Subtractive x =>
BackpropFunc x x
negate :: BackpropFunc x x
negate = (x -> x)
-> Backprop (->) x (x, ())
-> Backprop (->) (x, ()) x
-> BackpropFunc 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
call' Backprop (->) x (x, ())
forward' Backprop (->) (x, ()) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = x -> x
forall a. Subtractive a => a -> a
NH.negate
forward' :: BackpropFunc x (x, ())
forward' :: Backprop (->) x (x, ())
forward' = BackpropFunc x x
forall x. Subtractive x => BackpropFunc x x
negate BackpropFunc x x
-> Backprop (->) x (x, ()) -> Backprop (->) 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 y. Backprop (->) y (y, ())
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) x
backward' :: Backprop (->) (x, ()) x
backward' = (forall y. Backprop (->) (y, ()) y
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (y, ()) y) Backprop (->) (x, ()) x
-> BackpropFunc x x -> Backprop (->) (x, ()) x
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> BackpropFunc x x
forall x. Subtractive x => BackpropFunc x x
negate
(-) :: forall x. (Subtractive x) => BackpropFunc (x, x) x
(-) = ((x, x) -> x)
-> Backprop (->) (x, x) (x, ())
-> Backprop (->) (x, ()) (x, 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' Backprop (->) (x, x) (x, ())
forward' Backprop (->) (x, ()) (x, x)
backward'
where
call' :: (x, x) -> x
call' :: (x, x) -> x
call' = (x -> x -> x) -> (x, x) -> x
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry x -> x -> x
forall a. Subtractive a => a -> a -> a
(NH.-)
forward' :: BackpropFunc (x, x) (x, ())
forward' :: Backprop (->) (x, x) (x, ())
forward' = (-) BackpropFunc (x, x) x
-> Backprop (->) x (x, ()) -> Backprop (->) (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 y. Backprop (->) y (y, ())
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc y (y, ()))
backward' :: BackpropFunc (x, ()) (x, x)
backward' :: Backprop (->) (x, ()) (x, x)
backward' = (Backprop (->) (x, ()) x
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (x, ()) x) Backprop (->) (x, ()) x
-> Backprop (->) x (x, x) -> Backprop (->) (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
>>> Backprop (->) x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup Backprop (->) x (x, x)
-> Backprop (->) (x, x) (x, x) -> Backprop (->) 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
>>> Backprop (->) x x -> Backprop (->) (x, x) (x, x)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second Backprop (->) x x
forall x. Subtractive x => BackpropFunc x x
negate
(*) :: Distributive x => BackpropFunc (x, x) x
* :: BackpropFunc (x, x) x
(*) = ((x, x) -> x)
-> Backprop (->) (x, x) (x, (x, x))
-> Backprop (->) (x, (x, x)) (x, 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
forall x. Distributive x => (x, x) -> x
call' Backprop (->) (x, x) (x, (x, x))
forall x. Distributive x => BackpropFunc (x, x) (x, (x, x))
forward' Backprop (->) (x, (x, x)) (x, x)
forall x. Distributive x => BackpropFunc (x, (x, x)) (x, x)
backward'
where
call' :: Distributive x => (x, x) -> x
call' :: (x, x) -> x
call' = (x -> x -> x) -> (x, x) -> x
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry x -> x -> x
forall a. Multiplicative a => a -> a -> a
(NH.*)
forward' :: Distributive x => BackpropFunc (x, x) (x, (x, x))
forward' :: BackpropFunc (x, x) (x, (x, x))
forward' = BackpropFunc (x, x) ((x, x), (x, x))
forall x. Additive x => BackpropFunc x (x, x)
dup BackpropFunc (x, x) ((x, x), (x, x))
-> Backprop (->) ((x, x), (x, x)) (x, (x, x))
-> BackpropFunc (x, x) (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
>>> Backprop (->) (x, x) x
-> Backprop (->) ((x, x), (x, x)) (x, (x, x))
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first Backprop (->) (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
backward' :: Distributive x => BackpropFunc (x, (x, x)) (x, x)
backward' :: BackpropFunc (x, (x, x)) (x, x)
backward' =
Backprop (->) x (x, x)
-> Backprop (->) (x, (x, x)) ((x, x), (x, x))
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first Backprop (->) x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup
Backprop (->) (x, (x, x)) ((x, x), (x, x))
-> Backprop (->) ((x, x), (x, x)) (x, x)
-> BackpropFunc (x, (x, 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 dy x1 x2.
Backprop (->) ((dy, dy), (x1, x2)) ((dy, x1), (dy, x2))
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((dy, dy), (x1, x2)) ((dy, x1), (dy, x2)))
Backprop (->) ((x, x), (x, x)) ((x, x), (x, x))
-> Backprop (->) ((x, x), (x, x)) (x, x)
-> Backprop (->) ((x, x), (x, 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 a b. Backprop (->) (a, b) (b, a)
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (a, b) (b, a))
Backprop (->) ((x, x), (x, x)) ((x, x), (x, x))
-> Backprop (->) ((x, x), (x, x)) (x, x)
-> Backprop (->) ((x, x), (x, 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
>>> BackpropFunc (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*) BackpropFunc (x, x) x
-> BackpropFunc (x, x) x -> Backprop (->) ((x, x), (x, 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)
*** BackpropFunc (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
square :: Distributive x => BackpropFunc x x
square :: BackpropFunc x x
square = BackpropFunc x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup BackpropFunc x (x, x) -> Backprop (->) (x, x) x -> 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
>>> Backprop (->) (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
(/) ::
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
/ :: BackpropFunc (x, x) x
(/) = ((x, x) -> x)
-> Backprop (->) (x, x) (x, (x, x))
-> Backprop (->) (x, (x, x)) (x, 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' Backprop (->) (x, x) (x, (x, x))
forward' Backprop (->) (x, (x, x)) (x, x)
backward'
where
call' :: (x, x) -> x
call' :: (x, x) -> x
call' = (x -> x -> x) -> (x, x) -> x
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry x -> x -> x
forall a. Divisive a => a -> a -> a
(NH./)
forward' :: BackpropFunc (x, x) (x, (x, x))
forward' :: Backprop (->) (x, x) (x, (x, x))
forward' = BackpropFunc (x, x) ((x, x), (x, x))
forall x. Additive x => BackpropFunc x (x, x)
dup BackpropFunc (x, x) ((x, x), (x, x))
-> Backprop (->) ((x, x), (x, x)) (x, (x, x))
-> Backprop (->) (x, x) (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
>>> BackpropFunc (x, x) x -> Backprop (->) ((x, x), (x, x)) (x, (x, x))
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first BackpropFunc (x, x) x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/)
backward' :: BackpropFunc (x, (x, x)) (x, x)
backward' :: Backprop (->) (x, (x, x)) (x, x)
backward' =
BackpropFunc x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup BackpropFunc x (x, x)
-> BackpropFunc (x, x) ((x, x), (x, x))
-> Backprop (->) (x, (x, x)) ((x, x), ((x, 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)
*** BackpropFunc (x, x) ((x, x), (x, x))
forall x. Additive x => BackpropFunc x (x, x)
dup
Backprop (->) (x, (x, x)) ((x, x), ((x, x), (x, x)))
-> Backprop (->) ((x, x), ((x, x), (x, x))) (x, x)
-> Backprop (->) (x, (x, 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
>>> Backprop (->) ((x, x), (x, x)) (x, x)
-> Backprop (->) ((x, x), ((x, x), (x, x))) ((x, x), (x, x))
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (BackpropFunc (x, x) x
d1 BackpropFunc (x, x) x
-> BackpropFunc (x, x) x -> Backprop (->) ((x, x), (x, 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)
*** BackpropFunc (x, x) x
d2)
Backprop (->) ((x, x), ((x, x), (x, x))) ((x, x), (x, x))
-> Backprop (->) ((x, x), (x, x)) (x, x)
-> Backprop (->) ((x, x), ((x, x), (x, 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 dy x1 x2.
Backprop (->) ((dy, dy), (x1, x2)) ((dy, x1), (dy, x2))
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((dy, dy), (x1, x2)) ((dy, x1), (dy, x2)))
Backprop (->) ((x, x), (x, x)) ((x, x), (x, x))
-> Backprop (->) ((x, x), (x, x)) (x, x)
-> Backprop (->) ((x, x), (x, 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
>>> BackpropFunc (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*) BackpropFunc (x, x) x
-> BackpropFunc (x, x) x -> Backprop (->) ((x, x), (x, 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)
*** BackpropFunc (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
where
d1 :: BackpropFunc (x, x) x
d1 = (BackpropFunc x ()
forall x. Additive x => BackpropFunc x ()
forget BackpropFunc x ()
-> Backprop (->) x x -> Backprop (->) (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)
*** Backprop (->) x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip) Backprop (->) (x, x) ((), x)
-> Backprop (->) ((), x) 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
>>> (Backprop (->) ((), x) x
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((), x) x)
d2 :: BackpropFunc (x, x) x
d2 = (Backprop (->) x x
forall x. Subtractive x => BackpropFunc x x
negate Backprop (->) x x
-> Backprop (->) x x -> Backprop (->) (x, 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)
*** (Backprop (->) x x
forall x. Distributive x => BackpropFunc x x
square Backprop (->) x x -> Backprop (->) x x -> Backprop (->) x x
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Backprop (->) x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)) Backprop (->) (x, x) (x, x)
-> BackpropFunc (x, x) 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
>>> BackpropFunc (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
recip ::
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip :: BackpropFunc x x
recip = x -> BackpropFunc (x, x) x -> BackpropFunc x x
forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst x
forall a. Multiplicative a => a
NH.one BackpropFunc (x, x) x
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 :: Integer -> BackpropFunc x x
pow Integer
n = (x -> x)
-> Backprop (->) x (x, x)
-> Backprop (->) (x, x) x
-> BackpropFunc 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
call' Backprop (->) x (x, x)
forward' Backprop (->) (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = (x -> Int -> x) -> Int -> x -> x
forall a b c. (a -> b -> c) -> b -> a -> c
flip x -> Int -> x
forall a. Divisive a => a -> Int -> a
(NH.^) (Integer -> Int
forall a. FromInteger a => Integer -> a
fromInteger Integer
n)
forward' :: BackpropFunc x (x, x)
forward' :: Backprop (->) x (x, x)
forward' = Backprop (->) x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup Backprop (->) x (x, x)
-> Backprop (->) (x, x) (x, x) -> Backprop (->) 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
>>> BackpropFunc x x -> Backprop (->) (x, x) (x, x)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (Integer -> BackpropFunc x x
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' :: Backprop (->) (x, x) x
backward' = BackpropFunc x x -> Backprop (->) (x, x) (x, x)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second BackpropFunc x x
der Backprop (->) (x, x) (x, x)
-> Backprop (->) (x, x) x -> Backprop (->) (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
>>> Backprop (->) (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
where
der :: BackpropFunc x x
der =
if Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0
then x -> BackpropFunc x x
forall c x. (Additive c, Additive x) => c -> BackpropFunc x c
const x
forall a. Additive a => a
zero
else Integer -> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x,
FromIntegral x Integer) =>
Integer -> BackpropFunc x x
pow (Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
P.- Integer
1) BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc x x
forall x. Distributive x => x -> BackpropFunc x x
linear (Integer -> x
forall a b. FromIntegral a b => b -> a
NH.fromIntegral Integer
n)
sqrt ::
forall x.
ExpField x =>
BackpropFunc x x
sqrt :: BackpropFunc x x
sqrt = (x -> x)
-> Backprop (->) x (x, x)
-> Backprop (->) (x, x) x
-> BackpropFunc 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
call' Backprop (->) x (x, x)
forward' Backprop (->) (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = x -> x
forall a. ExpField a => a -> a
NH.sqrt
forward' :: BackpropFunc x (x, x)
forward' :: Backprop (->) x (x, x)
forward' = (BackpropFunc x x
forall x. ExpField x => BackpropFunc x x
sqrt :: BackpropFunc x x) BackpropFunc x x
-> Backprop (->) x (x, x) -> Backprop (->) 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
>>> Backprop (->) x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup
backward' :: BackpropFunc (x, x) x
backward' :: Backprop (->) (x, x) x
backward' = BackpropFunc x x -> Backprop (->) (x, x) (x, x)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc x x
forall x. Distributive x => x -> BackpropFunc x x
linear x
forall a. Field a => a
NH.half) Backprop (->) (x, x) (x, x)
-> Backprop (->) (x, x) x -> Backprop (->) (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
>>> Backprop (->) (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
(**) ::
forall a.
( ExpField a,
NH.FromIntegral a P.Integer
) =>
BackpropFunc (a, a) a
** :: BackpropFunc (a, a) a
(**) = ((a, a) -> a)
-> Backprop (->) (a, a) (a, (a, (a, a)))
-> Backprop (->) (a, (a, (a, a))) (a, a)
-> 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' Backprop (->) (a, a) (a, (a, (a, a)))
forward' Backprop (->) (a, (a, (a, a))) (a, a)
backward'
where
call' :: (a, a) -> a
call' :: (a, a) -> a
call' = (a -> a -> a) -> (a, a) -> a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((a -> a -> a) -> (a, a) -> a) -> (a -> a -> a) -> (a, a) -> a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> a -> a -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> a -> a
forall a. ExpField a => a -> a -> a
(NH.**)
forward' :: BackpropFunc (a, a) (a, (a, (a, a)))
forward' :: Backprop (->) (a, a) (a, (a, (a, a)))
forward' =
BackpropFunc (a, a) ((a, a), (a, a))
forall x. Additive x => BackpropFunc x (x, x)
dup
BackpropFunc (a, a) ((a, a), (a, a))
-> Backprop (->) ((a, a), (a, a)) (a, (a, (a, a)))
-> Backprop (->) (a, a) (a, (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
>>> Backprop (->) (a, a) (a, a)
-> Backprop (->) ((a, a), (a, a)) ((a, a), (a, a))
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (BackpropFunc (a, a) a
forall a.
(ExpField a, FromIntegral a Integer) =>
BackpropFunc (a, a) a
(**) BackpropFunc (a, a) a
-> Backprop (->) a (a, a) -> Backprop (->) (a, 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
>>> Backprop (->) a (a, a)
forall x. Additive x => BackpropFunc x (x, x)
dup)
Backprop (->) ((a, a), (a, a)) ((a, a), (a, a))
-> Backprop (->) ((a, a), (a, a)) (a, (a, (a, a)))
-> Backprop (->) ((a, a), (a, a)) (a, (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 b c. Backprop (->) ((a, b), c) (a, (b, 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' :: Backprop (->) (a, (a, (a, a))) (a, a)
backward' =
Backprop (->) a (a, a)
forall x. Additive x => BackpropFunc x (x, x)
dup Backprop (->) a (a, a)
-> Backprop (->) (a, (a, a)) (a, a)
-> Backprop (->) (a, (a, (a, a))) ((a, a), (a, a))
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, (a, a)), (a, (a, a)))
forall x. Additive x => BackpropFunc x (x, x)
dup BackpropFunc (a, (a, a)) ((a, (a, a)), (a, (a, a)))
-> Backprop (->) ((a, (a, a)), (a, (a, a))) (a, a)
-> Backprop (->) (a, (a, 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
>>> (BackpropFunc (a, (a, a)) a
dn BackpropFunc (a, (a, a)) a
-> BackpropFunc (a, (a, a)) a
-> Backprop (->) ((a, (a, a)), (a, (a, a))) (a, a)
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))
Backprop (->) (a, (a, (a, a))) ((a, a), (a, a))
-> Backprop (->) ((a, a), (a, a)) (a, a)
-> Backprop (->) (a, (a, (a, 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 b c d. Backprop (->) ((a, b), (c, d)) ((a, c), (b, d))
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((a, b), (c, d)) ((a, c), (b, d)))
Backprop (->) ((a, a), (a, a)) ((a, a), (a, a))
-> Backprop (->) ((a, a), (a, a)) (a, a)
-> Backprop (->) ((a, a), (a, 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
>>> BackpropFunc (a, a) a
forall x. Distributive x => BackpropFunc (x, x) x
(*) BackpropFunc (a, a) a
-> BackpropFunc (a, a) a -> Backprop (->) ((a, a), (a, a)) (a, a)
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
forall x. Distributive x => BackpropFunc (x, x) x
(*)
where
dn :: BackpropFunc (a, (a, a)) a
dn :: BackpropFunc (a, (a, a)) a
dn =
Backprop (->) (a, (a, a)) (a, a)
forall x y. Additive x => BackpropFunc (x, y) y
forgetFirst
Backprop (->) (a, (a, a)) (a, a)
-> BackpropFunc (a, a) a -> BackpropFunc (a, (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
>>> Backprop (->) a (a, a) -> Backprop (->) (a, a) ((a, a), a)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first Backprop (->) a (a, a)
forall x. Additive x => BackpropFunc x (x, x)
dup
Backprop (->) (a, a) ((a, a), a)
-> Backprop (->) ((a, a), a) a -> 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 b c. Backprop (->) ((a, b), c) (a, (b, c))
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc ((a, b), c) (a, (b, c)))
Backprop (->) ((a, a), a) (a, (a, a))
-> BackpropFunc (a, (a, a)) a -> Backprop (->) ((a, 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
>>> Backprop (->) (a, a) (a, a)
-> Backprop (->) (a, (a, a)) (a, (a, a))
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second (Backprop (->) a a -> Backprop (->) (a, a) (a, a)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p a c) (p b c)
first (a -> BackpropFunc (a, a) a -> Backprop (->) a a
forall x y c.
Additive c =>
c -> BackpropFunc (x, c) y -> BackpropFunc x y
setSecond (Integer -> a
forall a b. FromIntegral a b => b -> a
NH.fromIntegral (Integer
1 :: P.Integer)) (-)))
Backprop (->) (a, (a, a)) (a, (a, a))
-> BackpropFunc (a, (a, a)) a -> BackpropFunc (a, (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
>>> BackpropFunc (a, a) a -> Backprop (->) (a, (a, a)) (a, a)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second BackpropFunc (a, a) a
forall a.
(ExpField a, FromIntegral a Integer) =>
BackpropFunc (a, a) a
(**)
Backprop (->) (a, (a, a)) (a, a)
-> BackpropFunc (a, a) a -> BackpropFunc (a, (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
>>> BackpropFunc (a, a) a
forall x. Distributive x => BackpropFunc (x, x) x
(*)
dx :: BackpropFunc (a, (a, a)) a
dx :: BackpropFunc (a, (a, a)) a
dx = BackpropFunc (a, a) a -> Backprop (->) (a, (a, a)) (a, a)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second BackpropFunc (a, a) a
forall x y. Additive x => BackpropFunc (x, y) y
forgetFirst Backprop (->) (a, (a, a)) (a, a)
-> BackpropFunc (a, a) a -> BackpropFunc (a, (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
>>> Backprop (->) a a -> Backprop (->) (a, a) (a, a)
forall (p :: * -> * -> *) (cat :: * -> * -> *) a b c.
CatBiFunctor p cat =>
cat a b -> cat (p c a) (p c b)
second Backprop (->) a a
forall x. ExpField x => BackpropFunc x x
log Backprop (->) (a, a) (a, a)
-> BackpropFunc (a, a) a -> 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
>>> BackpropFunc (a, a) a
forall x. Distributive x => BackpropFunc (x, x) x
(*)
log :: ExpField x => BackpropFunc x x
log :: BackpropFunc x x
log = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. ExpField a => a -> a
NH.log BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip
logBase :: ExpField a => BackpropFunc (a, a) a
logBase :: BackpropFunc (a, a) a
logBase = (forall a b. Backprop (->) (a, b) (b, a)
forall (c :: * -> * -> *) a b.
(Isomorphism c, IsomorphicTo a b) =>
c a b
iso :: BackpropFunc (c, d) (d, c)) Backprop (->) (a, a) (a, a)
-> BackpropFunc (a, a) a -> 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
>>> BackpropFunc a a
forall x. ExpField x => BackpropFunc x x
log BackpropFunc a a -> BackpropFunc a a -> Backprop (->) (a, a) (a, a)
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
forall x. ExpField x => BackpropFunc x x
log Backprop (->) (a, a) (a, a)
-> BackpropFunc (a, a) a -> 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
>>> BackpropFunc (a, a) a
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/)
exp :: forall x. ExpField x => BackpropFunc x x
exp :: BackpropFunc x x
exp = (x -> x)
-> Backprop (->) x (x, x)
-> Backprop (->) (x, x) x
-> BackpropFunc 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
call' Backprop (->) x (x, x)
forward' Backprop (->) (x, x) x
backward'
where
call' :: x -> x
call' :: x -> x
call' = x -> x
forall a. ExpField a => a -> a
NH.exp
forward' :: BackpropFunc x (x, x)
forward' :: Backprop (->) x (x, x)
forward' = (BackpropFunc x x
forall x. ExpField x => BackpropFunc x x
exp :: BackpropFunc x x) BackpropFunc x x
-> Backprop (->) x (x, x) -> Backprop (->) 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
>>> Backprop (->) x (x, x)
forall x. Additive x => BackpropFunc x (x, x)
dup
backward' :: BackpropFunc (x, x) x
backward' :: Backprop (->) (x, x) x
backward' = Backprop (->) (x, x) x
forall x. Distributive x => BackpropFunc (x, x) x
(*)
sin :: TrigField x => BackpropFunc x x
sin :: BackpropFunc x x
sin = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.sin BackpropFunc x x
forall x. TrigField x => BackpropFunc x x
cos
cos :: TrigField x => BackpropFunc x x
cos :: BackpropFunc x x
cos = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.cos (BackpropFunc x x
forall x. TrigField x => BackpropFunc x x
sin BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. Subtractive x => BackpropFunc x x
negate)
tan :: TrigField x => BackpropFunc x x
tan :: BackpropFunc x x
tan = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.tan (BackpropFunc x x
forall x. TrigField x => BackpropFunc x x
cos BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
asin :: (TrigField x, ExpField x) => BackpropFunc x x
asin :: BackpropFunc x x
asin = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.tan (BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc (x, x) x -> BackpropFunc x x
forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst x
forall a. Multiplicative a => a
one (-) BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. ExpField x => BackpropFunc x x
sqrt BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
acos :: (TrigField x, ExpField x) => BackpropFunc x x
acos :: BackpropFunc x x
acos = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.tan (BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc (x, x) x -> BackpropFunc x x
forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst x
forall a. Multiplicative a => a
one (-) BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. ExpField x => BackpropFunc x x
sqrt BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. Subtractive x => BackpropFunc x x
negate)
atan :: TrigField x => BackpropFunc x x
atan :: BackpropFunc x x
atan = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.atan (BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc (x, x) x -> BackpropFunc x x
forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst x
forall a. Multiplicative a => a
one BackpropFunc (x, x) x
forall x. Additive x => BackpropFunc (x, x) x
(+) BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
atan2 :: TrigField a => BackpropFunc (a, a) a
atan2 :: BackpropFunc (a, a) a
atan2 = BackpropFunc (a, a) a
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc (x, x) x
(/) BackpropFunc (a, a) a -> Backprop (->) a a -> 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
>>> Backprop (->) a a
forall x. TrigField x => BackpropFunc x x
atan
sinh :: TrigField x => BackpropFunc x x
sinh :: BackpropFunc x x
sinh = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.sinh BackpropFunc x x
forall x. TrigField x => BackpropFunc x x
cosh
cosh :: TrigField x => BackpropFunc x x
cosh :: BackpropFunc x x
cosh = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.cosh BackpropFunc x x
forall x. TrigField x => BackpropFunc x x
sinh
tanh :: TrigField x => BackpropFunc x x
tanh :: BackpropFunc x x
tanh = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.tanh (BackpropFunc x x
forall x. TrigField x => BackpropFunc x x
cosh BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
asinh :: (TrigField x, ExpField x) => BackpropFunc x x
asinh :: BackpropFunc x x
asinh = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.asinh (BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc (x, x) x -> BackpropFunc x x
forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst x
forall a. Multiplicative a => a
one BackpropFunc (x, x) x
forall x. Additive x => BackpropFunc (x, x) x
(+) BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. ExpField x => BackpropFunc x x
sqrt BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
acosh :: (TrigField x, ExpField x) => BackpropFunc x x
acosh :: BackpropFunc x x
acosh = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.tan (BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc (x, x) x -> BackpropFunc x x
forall x y c.
Additive c =>
c -> BackpropFunc (x, c) y -> BackpropFunc x y
setSecond x
forall a. Multiplicative a => a
one (-) BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x. ExpField x => BackpropFunc x x
sqrt BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)
atanh :: TrigField x => BackpropFunc x x
atanh :: BackpropFunc x x
atanh = (x -> x) -> BackpropFunc x x -> BackpropFunc x x
forall x.
Distributive x =>
(x -> x) -> BackpropFunc x x -> BackpropFunc x x
simpleDifferentiable x -> x
forall a. TrigField a => a -> a
NH.tan (BackpropFunc x x
forall x. Distributive x => BackpropFunc x x
square BackpropFunc x x -> BackpropFunc x x -> 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
>>> x -> BackpropFunc (x, x) x -> BackpropFunc x x
forall x y c.
Additive c =>
c -> BackpropFunc (c, x) y -> BackpropFunc x y
setFirst x
forall a. Multiplicative a => a
one (-) BackpropFunc x x -> BackpropFunc x x -> 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
>>> BackpropFunc x x
forall x.
(Divisive x, Distributive x, Subtractive x) =>
BackpropFunc x x
recip)