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

Apply function of two arguments cumulatively to the quadratic biases associated with a single variable.

  • v – Variable in the quadratic model.

  • function – Function of two arguments to apply to the quadratic biases of variable v.

  • initializer – Prefixed in the calculation to the iterable containing the quadratic biases or used as the default if variable v has no quadratic biases.


Result of applying the specified function to the specified variable’s quadratic biases.


>>> from dimod import QuadraticModel
>>> qm = QuadraticModel({'x': 0.5, 's': 1, 'i': 2},
...                     {('x', 'i'): 2, ('s', 'i'): 3}, 0.0,
...                     {'x': 'BINARY', 's': 'SPIN', 'i': 'INTEGER'})
>>> qm.reduce_neighborhood('i', max)

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