Liking cljdoc? Tell your friends :D

emmy.dual

This namespace contains an implementation of [[Dual]], a type that forms the basis for the forward-mode automatic differentiation implementation in emmy.

See emmy.calculus.derivative for a fleshed-out derivative implementation using [[Dual]].

This namespace contains an implementation of [[Dual]], a type that forms the
basis for the forward-mode automatic differentiation implementation in emmy.

See [[emmy.calculus.derivative]] for a fleshed-out derivative implementation
using [[Dual]].
raw docstring

*active-tags*clj/s

source

bundle-elementclj/s

(bundle-element primal)
(bundle-element primal tag)
(bundle-element primal tangent tag)

Returns a new [[Dual]] object with the supplied primal and tangent components, and the supplied internal tag that this [[Dual]] will carry around to prevent perturbation confusion.

If the tangent component is 0, acts as identity on primal. tangent defaults to 1.

tag defaults to a side-effecting call to fresh-tag; you can retrieve this unknown tag by calling tag on the returned [[Dual]].

Returns a new [[Dual]] object with the supplied `primal` and `tangent`
components, and the supplied internal `tag` that this [[Dual]] will
carry around to prevent perturbation confusion.

If the `tangent` component is `0`, acts as identity on `primal`. `tangent`
defaults to 1.

`tag` defaults to a side-effecting call to [[fresh-tag]]; you can retrieve
this unknown tag by calling [[tag]] on the returned [[Dual]].
sourceraw docstring

compareclj/s

(compare a b)

Comparator that compares [[Dual]] instances with each other or non-differentials using only the primal of each instance. Matches the response of equiv.

Acts as emmy.value/compare for non-differentials.

Comparator that compares [[Dual]] instances with each other or
non-differentials using only the [[primal]] of each instance. Matches the
response of [[equiv]].

Acts as [[emmy.value/compare]] for non-differentials.
sourceraw docstring

compare-fullclj/s

(compare-full a b)

Comparator that compares [[Dual]] instances with each other or non-differentials using all tangent terms each instance. Matches the response of eq.

Acts as emmy.value/compare for non-differentials.

Comparator that compares [[Dual]] instances with each other or
non-differentials using all tangent terms each instance. Matches the response
of [[eq]].

Acts as [[emmy.value/compare]] for non-differentials.
sourceraw docstring

derivativeclj/s

(derivative f)

Returns a single-argument function of that, when called with an argument x, returns the derivative of f at x using forward-mode automatic differentiation.

For numerical differentiation, see emmy.numerical.derivative/D-numeric.

f must be built out of generic operations that know how to handle [[Dual]] inputs in addition to any types that a normal (f x) call would present. This restriction does not apply to operations like putting x into a container or destructuring; just primitive function calls.

Returns a single-argument function of that, when called with an argument `x`,
returns the derivative of `f` at `x` using forward-mode automatic
differentiation.

For numerical differentiation,
see [[emmy.numerical.derivative/D-numeric]].

`f` must be built out of generic operations that know how to handle [[Dual]]
inputs in addition to any types that a normal `(f x)` call would present. This
restriction does _not_ apply to operations like putting `x` into a container
or destructuring; just primitive function calls.
sourceraw docstring

dual?clj/s

(dual? dx)

Returns true if the supplied object is an instance of [[Dual]], false otherwise.

Returns true if the supplied object is an instance of [[Dual]], false
otherwise.
sourceraw docstring

eqclj/s

(eq _)
(eq a b)
(eq a b & more)

For non-differentials, this is identical to emmy.value/=. For [[Dual]] instances, equality acts on tangent components too.

If you want to ignore the tangent components, use equiv.

For non-differentials, this is identical to [[emmy.value/=]].
For [[Dual]] instances, equality acts on tangent components too.

If you want to ignore the tangent components, use [[equiv]].
sourceraw docstring

equivclj/s

(equiv _)
(equiv a b)
(equiv a b & more)

Returns true if all of the supplied objects have equal primals, false otherwise.

Use equiv if you want to compare scalars with [[Dual]]s and ignore the tangent. If you do want to take the tangent into account, prefer eq.

Returns true if all of the supplied objects have equal [[primal]]s, false
otherwise.

Use [[equiv]] if you want to compare scalars with
[[Dual]]s and ignore the tangent. If you _do_ want to take the tangent into
account, prefer [[eq]].
sourceraw docstring

FORWARD-MODEclj/s

source

fresh-tagclj/s

(fresh-tag)

Returns a new, unique tag for use by a perturbation in an automatic differentiation pass.

Returns a new, unique tag for use by a perturbation in an automatic
differentiation pass.
sourceraw docstring

IPerturbedclj/sprotocol

extract-idclj/s

(extract-id this id)

Given an instance of [[Completed]] (or a container type with [[Completed]] instances at its leaves) and the id of an [[emmy.tape/TapeCell]], returns the partial derivative associated with that [[emmy.tape/TapeCell]]'s id.

This function is an internal implementation detail of reverse-mode automatic differentiation.

Given an instance of [[Completed]] (or a container type with [[Completed]]
instances at its leaves) and the `id` of an [[emmy.tape/TapeCell]], returns
the partial derivative associated with that [[emmy.tape/TapeCell]]'s
`id`.

This function is an internal implementation detail of reverse-mode automatic
differentiation.

extract-tangentclj/s

(extract-tangent this tag mode)

If this is perturbed, return the tangent component paired with the supplied tag. Else, returns ([[emmy.value/zero-like]] this).

If `this` is perturbed, return the tangent component paired with the
supplied tag. Else, returns `([[emmy.value/zero-like]] this)`.

replace-tagclj/s

(replace-tag this old-tag new-tag)

If this is perturbed, Returns a similar object with the perturbation modified by replacing any appearance of old-tag with new-tag. Else, return this.

If `this` is perturbed, Returns a similar object with the perturbation
modified by replacing any appearance of `old-tag` with `new-tag`. Else,
return `this`.
source

primalclj/s

(primal dx)
(primal dx tag)

If dx is an instance of [[Dual]] returns the primal component. Else, acts as identity.

If the optional tag is supplied, [[primal-part]] acts as identity for [[Dual]] instances with a non-matching tag.

If `dx` is an instance of [[Dual]] returns the `primal` component. Else, acts
as identity.

If the optional `tag` is supplied, [[primal-part]] acts as identity
for [[Dual]] instances with a non-matching tag.
sourceraw docstring

primal-tangent-pairclj/s

(primal-tangent-pair dx)
(primal-tangent-pair dx t)

Returns a pair of the primal and tangent components of the supplied dx, with respect to the supplied tag. See the docs for primal and tangent for more details.

primal-tangent-pair is equivalent to

[([[primal]] dx tag) ([[tangent]] dx tag)]

but slightly more efficient if you need both.

Returns a pair of the primal and tangent components of the supplied `dx`, with
respect to the supplied `tag`. See the docs for [[primal]]
and [[tangent]] for more details.

[[primal-tangent-pair]] is equivalent to

`[([[primal]] dx tag) ([[tangent]] dx tag)]`

but slightly more efficient if you need both.
sourceraw docstring

REVERSE-EMPTYclj/s

source

REVERSE-MODEclj/s

source

tagclj/s

(tag dx)

If dx is an instance of [[Dual]] returns the tag component. Else, acts as nil.

If `dx` is an instance of [[Dual]] returns the `tag` component. Else, acts
as nil.
sourceraw docstring

tag-active?clj/s

(tag-active? tag)

Returns true if tag is an element of *active-tags* (and therefore pending for extraction by some nested derivative), false otherwise.

Returns true if `tag` is an element of [[*active-tags*]] (and therefore pending
for extraction by some nested derivative), false otherwise.
sourceraw docstring

tangentclj/s

(tangent dx)
(tangent dx tag)

If dx is an instance of [[Dual]] returns the tangent component. Else, returns 0.

If the optional tag is supplied, [[primal-part]] returns 0 for [[Dual]] instances with a non-matching tag.

If `dx` is an instance of [[Dual]] returns the `tangent` component. Else, returns 0.

If the optional `tag` is supplied, [[primal-part]] returns 0 for [[Dual]]
instances with a non-matching tag.
sourceraw docstring

with-active-tagclj/s

(with-active-tag tag f args)

Like apply, but conj-es tag onto the dynamic variable *active-tags* inside the scope of f.

Returns the result of applying f to args.

Like `apply`, but conj-es `tag` onto the dynamic variable [[*active-tags*]]
inside the scope of `f`.

Returns the result of applying `f` to `args`.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close