Trait aegir::Differentiable

source ·
pub trait Differentiable<T: Identifier>: Node {
    type Adjoint: Node;

    fn adjoint(&self, target: T) -> Self::Adjoint;

    fn evaluate_adjoint<C: Context, CR: AsRef<C>>(
        &self,
        target: T,
        ctx: CR
    ) -> AegirResult<Self::Adjoint, C>
    where
        Self: Function<C>,
        Self::Adjoint: Function<C>
, { ... } fn evaluate_dual<C: Context, CR: AsRef<C>>(
        &self,
        target: T,
        ctx: CR
    ) -> Result<DualOf<Self, C, T>, BinaryError<Self::Error, <AdjointOf<Self, T> as Function<C>>::Error, NoError>>
    where
        Self: Function<C>,
        Self::Adjoint: Function<C>
, { ... } }
Expand description

Trait for operator Nodes with a well-defined adjoint.

Required Associated Types§

The adjoint operator; i.e. the gradient.

Required Methods§

Transform the node into its Adjoint operator tree.

This is the key method used to perform differentiation in aegir. For a given node, the derivative can be found by first computing the adjoint tree and then evaluating against a database as per Function.

Examples
let c = 2.0f64.into_constant();
let grad = X.into_var().mul(c).adjoint(X);

assert_eq!(grad.evaluate(ctx!{X = 10.0}).unwrap(), 2.0);

Provided Methods§

Helper method that computes the adjoint and evaluates its value.

Note: this method can be more efficient than explicitly solving for the adjoint tree. In particular, this method can be implemented using direct numerical calculations.

Helper method that evaluates the function and its adjoint, wrapping up in a Dual.

Implementors§