pub trait Optimizer {
    // Required method
    fn apply_gradients(
        &self,
        scope: &mut Scope,
        opts: ApplyGradientsOptions<'_>
    ) -> Result<(Vec<Variable>, Operation)>;

    // Provided methods
    fn compute_gradients(
        &self,
        scope: &mut Scope,
        loss: Output,
        opts: ComputeGradientsOptions<'_>
    ) -> Result<Vec<(Option<Output>, Variable)>> { ... }
    fn minimize(
        &self,
        scope: &mut Scope,
        loss: Output,
        opts: MinimizeOptions<'_>
    ) -> Result<(Vec<Variable>, Operation)> { ... }
}
Expand description

An optimizer adjusts variables to minimize some specified value.

Basic usage only requires calling minimize, which calls compute_gradients and apply_gradients internally. Advanced users may want to call compute_gradients and apply_gradients manually to allow them to modify the gradients, e.g. for clipping.

Required Methods§

source

fn apply_gradients( &self, scope: &mut Scope, opts: ApplyGradientsOptions<'_> ) -> Result<(Vec<Variable>, Operation)>

Applies the given gradients to the variables.

This returns newly created variables which may be needed to track the optimizer’s internal state, as well as an operation which applies the gradients once.

Users are encouraged to call minimize instead unless they need to manually modify gradients.

Provided Methods§

source

fn compute_gradients( &self, scope: &mut Scope, loss: Output, opts: ComputeGradientsOptions<'_> ) -> Result<Vec<(Option<Output>, Variable)>>

Computes the gradient of a value with respect to the given variables. This adds nodes to the graph, so reuse its results if possible. Any variable whose gradient cannot be calculated will have a None gradient.

Users are encouraged to call minimize instead unless they need to manually modify gradients.

source

fn minimize( &self, scope: &mut Scope, loss: Output, opts: MinimizeOptions<'_> ) -> Result<(Vec<Variable>, Operation)>

Adds operations to the graph to minimize loss with respect to the variables.

This returns newly created variables which may be needed to track the optimizers internal state, as well as an operation which performs a single step of minimization.

Implementors§