Skip to content

← optimization package

ValueAndGradient

Calculate the function value and gradient for a given graph with respect to one or more of its parameters.

This node accepts a graph (a function of some inputs) that calculates a single scalar value, and returns a modified graph that will calculate, for a subset of inputs of interest, the vector (or matrix, etc.) that represents the direction of the greatest increase in the scalar value. Note: there are several restrictions on the form of the graph that is wired into this node. Consequently, the gradient can then be added to the initial input values to move them towards a local maximum of the original computational graph, i.e., the node can be used iteratively to perform gradient descent to find the optimal parameters for a given computation. Note that the gradient is different for different values of the inputs, including any extra parameters that are held fixed, and therefore the resulting function has the same number of inputs as the original graph, but returns not a scalar but a vector (or matrix, etc.) of the same shape as the subset of inputs of interest. More Info... Version 0.5.0

Ports/Properties

function

Function to process.

  • verbose name: Function
  • default value: None
  • port type: GraphPort
  • value type: Graph

function__signature

Signature for the "function" input. This represents the signature for the subgraph that is wired into the "function" port. This is formatted as in (a,b,c) ~> (b,c) where a,b,c are names of placeholders that are expected in the subgraph that goes in, and out of, the "function" port. Alternatively, it can also be provided in data structure form as a list of lists, as in: [['a','b','c'], ['b','c'].

  • verbose name: Function [Signature]
  • default value: (params)~>(params)
  • port type: Port
  • value type: object (can be None)

variables

Variables with respect to which the gradient will be calculated. If not given, this defaults to the first positional argument of the function, i.e., the first name in the signature.

  • verbose name: Differentiate With Respect To
  • default value: None
  • port type: ListPort
  • value type: list (can be None)

extra_outputs

If True, the derivative will only be calculated for the first output of the graph, with additional outputs being passed through unchanged. In this case the graph is expected to return a list of two or more elements.

  • verbose name: Have Extra Outputs
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

backend

Compute backend to use. If the chosen backend is not installed, the system will fall back to the backend configured in the backend_fallback setting (numpy by default). This computation is currently only supported by the jax backend, and the data will be converted to this backend unless the backend is set to 'keep', which you can choose to reduce overhead if you know that the data is already in the jax backend.

  • verbose name: Backend
  • default value: jax
  • port type: EnumPort
  • value type: str (can be None)

automove_data

Automatically move data to the chosen backend. This adds a slight performance overhead if the data is already on the desired backend and is only included for convenience.

  • verbose name: Automove Data
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

  • verbose name: Set Breakpoint (Debug Only)
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

  • verbose name: Metadata
  • default value: {}
  • port type: DictPort
  • value type: dict (can be None)