inf-backprop-0.1.0.2: Automatic differentiation and backpropagation.
Copyright(C) 2023 Alexey Tochin
LicenseBSD3 (see the file LICENSE)
MaintainerAlexey Tochin <Alexey.Tochin@gmail.com>
Safe HaskellNone
LanguageHaskell2010
Extensions
  • MonoLocalBinds
  • ScopedTypeVariables
  • TypeFamilies
  • OverloadedStrings
  • GADTs
  • GADTSyntax
  • ConstraintKinds
  • InstanceSigs
  • DeriveFunctor
  • TypeSynonymInstances
  • FlexibleContexts
  • FlexibleInstances
  • ConstrainedClassMethods
  • MultiParamTypeClasses
  • KindSignatures
  • TupleSections
  • RankNTypes
  • ExplicitNamespaces
  • ExplicitForAll

Debug.LoggingBackprop

Description

Basics for simple expressions equipped with Monadic behaviour. In particular, basic functions with logging for debug and illustration purposes. See this tutorial section for details.

Synopsis

Generic logging functions

unitConst :: (Show a, MonadLogger m) => a -> Kleisli m () a Source #

Logging constant function.

Examples of usage

Expand
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> runStdoutLoggingT $ runKleisli (unitConst 42) ()
[Info] Initializing 42
42

initUnaryFunc :: (Show a, Show b, MonadLogger m) => String -> (a -> b) -> Kleisli m a b Source #

Logging single argument function.

Examples of usage

Expand
>>> import qualified Prelude as P
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> plusTwo = initUnaryFunc "+2" (P.+2)
>>> runStdoutLoggingT $ runKleisli plusTwo 3
[Info] Calculating +2 of 3 => 5
5

initBinaryFunc :: (Show a, Show b, Show c, MonadLogger m) => String -> (a -> b -> c) -> Kleisli m (a, b) c Source #

Logging two argument (binary) function.

Examples of usage

Expand
>>> import qualified Prelude as P
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> loggingProduct = initBinaryFunc "product" (P.*)
>>> runStdoutLoggingT $ runKleisli loggingProduct (6, 7)
[Info] Calculating product of 6 and 7 => 42
42

pureKleisli :: Monad m => (a -> b) -> Kleisli m a b Source #

Returns pure Kleisli morphism given a map.

Examples of usage

Expand
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> loggingDup = pureKleisli (\x -> (x, x))
>>> runStdoutLoggingT $ runKleisli loggingDup 42
(42,42)

backpropExpr :: String -> BackpropFunc SimpleExpr SimpleExpr Source #

Returns symbolically differentiable Simple Expression.

Examples of usage

Expand
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> import Debug.SimpleExpr.Expr (variable)
>>> import InfBackprop (call, derivative, backpropExpr)
>>> x = variable "x"
>>> f = backpropExpr "f"
>>> call f x
f(x)
>>> derivative f x
1·f'(x)

loggingBackpropExpr :: forall m. MonadLogger m => String -> Backprop (Kleisli m) SimpleExpr SimpleExpr Source #

Returns symbolically differentiable logging symbolic function.

Examples of usage

Expand
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> import Debug.SimpleExpr.Expr (variable)
>>> import InfBackprop (call, derivative)
>>> x = variable "x"
>>> f = loggingBackpropExpr "f"
>>> runStdoutLoggingT $ runKleisli (call f) x
[Info] Calculating f of x => f(x)
f(x)
>>> runStdoutLoggingT $ runKleisli (derivative f) x
[Info] Calculating f of x => f(x)
[Info] Calculating f' of x => f'(x)
[Info] Calculating multiplication of 1 and f'(x) => 1·f'(x)
1·f'(x)

Logging functions examples

const :: forall c x m. (Additive c, Additive x, Show c, Show x, Monad m) => c -> Backprop (Kleisli m) x c Source #

Differentiable logging constant function.

Examples of usage

Expand
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> import Debug.SimpleExpr.Expr (variable)
>>> import InfBackprop (call, derivative)
>>> runStdoutLoggingT $ runKleisli (call (const 42)) ()
42

linear :: forall x m. (Show x, Distributive x, MonadLogger m) => x -> Backprop (Kleisli m) x x Source #

Differentiable logging linear function.

negate :: forall x m. (Show x, Subtractive x, MonadLogger m) => Backprop (Kleisli m) x x Source #

Differentiable logging negate function.

(+) :: forall x m. (Show x, Additive x, MonadLogger m) => Backprop (Kleisli m) (x, x) x Source #

Differentiable logging sum function.

Examples of usage

Expand
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> import InfBackprop (call)
>>> runStdoutLoggingT $ runKleisli (call (+)) (2, 2)
[Info] Calculating sum of 2 and 2 => 4
4

(*) :: forall x m. (Show x, Additive x, Multiplicative x, MonadLogger m) => Backprop (Kleisli m) (x, x) x Source #

Differentiable logging multiplication function.

Examples of usage

Expand
>>> import Control.Arrow (runKleisli)
>>> import Control.Monad.Logger (runStdoutLoggingT)
>>> import InfBackprop (call)
>>> runStdoutLoggingT $ runKleisli (call (*)) (6, 7)
[Info] Calculating multiplication of 6 and 7 => 42
42

pow :: forall x m. (Show x, Divisive x, Distributive x, Subtractive x, FromIntegral x Integer, MonadLogger m) => Integer -> Backprop (Kleisli m) x x Source #

Differentiable logging power function.

exp :: forall x m. (ExpField x, Show x, MonadLogger m) => Backprop (Kleisli m) x x Source #

Differentiable logging exponent function.

sin :: forall x m. (Show x, TrigField x, MonadLogger m) => Backprop (Kleisli m) x x Source #

Differentiable logging sin function.

cos :: forall x m. (Show x, TrigField x, MonadLogger m) => Backprop (Kleisli m) x x Source #

Differentiable logging cos function.