dimod.QuadraticModel.reduce_neighborhood

QuadraticModel.reduce_neighborhood(v: Hashable, function: collections.abc.Callable, initializer: Optional[Union[int, float, numpy.number]] = None) Any[source]

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

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

Returns

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

Examples

>>> 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)
3.0

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