pub trait Differentiable<T: Identifier>: Node {
type Adjoint: Node;
// Required method
fn adjoint(&self, target: T) -> Self::Adjoint;
// Provided methods
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>
fn evaluate_adjoint<C: Context, CR: AsRef<C>>( &self, target: T, ctx: CR, ) -> AegirResult<Self::Adjoint, 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.