dimod.QuadraticModel.reduce_linear#

QuadraticModel.reduce_linear(function: Callable, initializer: float | floating | integer | None = None) Any[source]#

Apply function of two arguments cumulatively to the linear biases.

Parameters:
  • function – Function of two arguments to apply to the linear biases.

  • initializer – Prefixed in the calculation to the iterable containing the linear biases or used as the default if no linear biases are set in the quadratic model.

Returns:

Result of applying the specified function to the linear biases.

Examples

>>> from operator import add
>>> from dimod import QuadraticModel
>>> qm = QuadraticModel({'x': 0.5, 's': 1, 'i': 2},
...                     {('x', 'i'): 2}, 0.0,
...                     {'x': 'BINARY', 's': 'SPIN', 'i': 'INTEGER'})
>>> qm.reduce_linear(add)
3.5

For information on the related functional programming method see functools.reduce().