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§
Required Methods§
sourcefn adjoint(&self, target: T) -> Self::Adjoint
fn adjoint(&self, target: T) -> Self::Adjoint
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§
sourcefn 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_adjoint<C: Context, CR: AsRef<C>>(
&self,
target: T,
ctx: CR
) -> AegirResult<Self::Adjoint, C>where
Self: Function<C>,
Self::Adjoint: Function<C>,
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.
sourcefn 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>,
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>,
Helper method that evaluates the function and its adjoint, wrapping up in a Dual.