Optimisers

class stride.optimisation.optimisers.optimiser.LocalOptimiser(variable, **kwargs)[source]

Bases: abc.ABC

Base class for a local optimiser. It takes the value of the gradient and applies it to the variable.

Parameters
  • variable (Variable) – Variable to which the optimiser refers.

  • process_grad (callable, optional) – Optional processing function to apply on the gradient prior to applying it.

  • process_model (callable, optional) – Optional processing function to apply on the model after updating it.

  • kwargs – Extra parameters to be used by the class.

clear_grad()[source]

Clear the internal gradient buffers of the variable.

async post_process(**kwargs)[source]

Perform any necessary post-processing of the variable.

async pre_process(grad=None, processed_grad=None, **kwargs)[source]

Pre-process the variable gradient before using it to take the step.

Parameters
  • grad (Data, optional) – Gradient to use for the step, defaults to variable gradient.

  • processed_grad (Data, optional) – Processed gradient to use for the step, defaults to processed variable gradient.

  • kwargs – Extra parameters to be used by the method.

Returns

Updated variable.

Return type

Variable

abstract step(**kwargs)[source]

Apply the optimiser.

Parameters

kwargs – Extra parameters to be used by the method.

Returns

Updated variable.

Return type

Variable

class stride.optimisation.optimisers.gradient_descent.GradientDescent(variable, **kwargs)[source]

Bases: stride.optimisation.optimisers.optimiser.LocalOptimiser

Implementation of a gradient descent update.

Parameters
  • variable (Variable) – Variable to which the optimiser refers.

  • step (float, optional) – Step size for the update, defaults to 1.

  • kwargs – Extra parameters to be used by the class.

async step(step_size=None, grad=None, processed_grad=None, **kwargs)[source]

Apply the optimiser.

Parameters
  • step_size (float, optional) – Step size to use for this application, defaults to instance step.

  • grad (Data, optional) – Gradient to use for the step, defaults to variable gradient.

  • processed_grad (Data, optional) – Processed gradient to use for the step, defaults to processed variable gradient.

  • kwargs – Extra parameters to be used by the method.

Returns

Updated variable.

Return type

Variable