Optimisers

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

Bases: 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.

  • step_size (float or LineSearch, optional) – Step size for the update, defaults to constant 1.

  • 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.

dump(*args, **kwargs)[source]

Dump latest version of the optimiser.

Parameters:

kwargs – Extra parameters to be used by the method

load(*args, **kwargs)[source]

Load latest version of the optimiser.

Parameters:

kwargs – Extra parameters to be used by the method

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

reset(**kwargs)[source]

Reset optimiser state along with any stored buffers.

Parameters:

kwargs – Extra parameters to be used by the method.

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

abstract update_variable(step_size, variable, direction)[source]
Parameters:
  • step_size (float) – Step size to use for updating the variable.

  • variable (Data) – Variable to update.

  • direction (Data) – Direction in which to update the variable.

Returns:

Updated variable.

Return type:

Variable

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

Bases: LocalOptimiser

Implementation of a gradient descent update.

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

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

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

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

update_variable(step_size, variable, direction)[source]
Parameters:
  • step_size (float) – Step size to use for updating the variable.

  • variable (Data) – Variable to update.

  • direction (Data) – Direction in which to update the variable.

Returns:

Updated variable.

Return type:

Variable