Skip to main content

Differentiable

Struct Differentiable 

Source
pub struct Differentiable<V, G> {
    pub value: V,
    pub derivative: G,
}
Expand description

A function and its derivative, from two closures. As an Objective, value gives the value and derivative writes the gradient. As a Mapping, value writes the values and derivative takes (u, x, out) and writes the vector–Jacobian product.

Fields§

§value: V§derivative: G

Trait Implementations§

Source§

impl<F, E, V, G> Mapping<F> for Differentiable<V, G>
where V: FnMut(&[F], &mut [F]) -> Result<(), E>, G: FnMut(&[F], &[F], &mut [F]) -> Result<(), E>,

Source§

type Error = E

What stops an evaluation, as for Objective.
Source§

fn value(&mut self, x: &[F], out: &mut [F]) -> Result<(), E>

The values at x, into out.
Source§

fn has_vjp(&self) -> bool

Whether vjp gives vector–Jacobian products. Least squares in solve_linear needs them.
Source§

fn vjp(&mut self, u: &[F], x: &[F], out: &mut [F]) -> Result<(), E>

uᵀJ, the product of u with the Jacobian at x, into out. For a linear mapping it’s the product of the transpose with u, at any x. Methods call it only where has_vjp is true.
Source§

fn has_jvp(&self) -> bool

Whether jvp gives Jacobian–vector products.
Source§

fn jvp(&mut self, v: &[F], x: &[F], out: &mut [F]) -> Result<bool, Self::Error>

Jv, the product of the Jacobian at x with v, into out. For a linear mapping it’s the product of the matrix with v, at any x. It gives false where it declines, as for a function it can’t differentiate at x, and the caller then takes differences instead. Methods call it only where has_jvp is true.
Source§

fn jacobian(&mut self, x: &[F], j: &mut [F]) -> Result<bool, Self::Error>
where F: Native,

The Jacobian at x, with a row of x.len() items for each value, into j, or false where Levenberg–Marquardt should take forward differences instead. By default, a mapping builds it from vjp, one row per product, when it has no more values than variables or no jvp. Otherwise it builds it from jvp, one column per product. Each takes no more calls than differences do. It gives false for a mapping with neither, or where jvp declines.
Source§

fn has_preconditioner(&self) -> bool

Whether precondition gives a preconditioner’s products. solve_linear runs without one otherwise.
Source§

fn precondition(&mut self, v: &[F], out: &mut [F]) -> Result<(), Self::Error>

The product with v of a preconditioner for solve_linear, into out: M, an approximation to the inverse of the matrix, or of AᵀA for least squares. CG and MINRES need M symmetric positive definite. Methods call it only where has_preconditioner is true.
Source§

impl<F, E, V, G> Objective<F> for Differentiable<V, G>
where V: FnMut(&[F]) -> Result<F, E>, G: FnMut(&[F], &mut [F]) -> Result<(), E>,

Source§

type Error = E

What stops an evaluation, such as an error in the caller’s function or an interrupt.
Source§

fn value(&mut self, x: &[F]) -> Result<F, E>

The value at x.
Source§

fn has_gradient(&self) -> bool

Whether gradient gives the gradient. L-BFGS needs one, and Method::choose picks L-BFGS for an objective that has one.
Source§

fn gradient(&mut self, x: &[F], g: &mut [F]) -> Result<(), E>

The gradient at x, into g. Methods call it only where has_gradient is true.
Source§

fn batch(&self) -> bool

Whether values evaluates a batch of points in one call. Nelder–Mead evaluates its first simplex and each shrink as a batch, and differential evolution each generation. Without batch, a search calls value on each point.
Source§

fn values(&mut self, xs: &[F], out: &mut [F]) -> Result<(), Self::Error>

The value at each row of xs, into out, with xs.len() / out.len() items to a row. Methods call it only where batch is true.

Auto Trait Implementations§

§

impl<V, G> Forget for Differentiable<V, G>

§

impl<V, G> Freeze for Differentiable<V, G>
where V: Freeze, G: Freeze,

§

impl<V, G> RefUnwindSafe for Differentiable<V, G>

§

impl<V, G> Send for Differentiable<V, G>
where V: Send, G: Send,

§

impl<V, G> Sync for Differentiable<V, G>
where V: Sync, G: Sync,

§

impl<V, G> Unpin for Differentiable<V, G>
where V: Unpin, G: Unpin,

§

impl<V, G> UnsafeUnpin for Differentiable<V, G>
where V: UnsafeUnpin, G: UnsafeUnpin,

§

impl<V, G> UnwindSafe for Differentiable<V, G>
where V: UnwindSafe, G: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.