dimod.BinaryQuadraticModel.scale

BinaryQuadraticModel.scale(scalar, ignored_variables=None, ignored_interactions=None, ignore_offset=False)[source]

Multiply by the specified scalar all the biases and offset of a binary quadratic model.

Parameters:
  • scalar (number) – Value by which to scale the energy range of the binary quadratic model.
  • ignored_variables (iterable, optional) – Biases associated with these variables are not scaled.
  • ignored_interactions (iterable[tuple], optional) – As an iterable of 2-tuples. Biases associated with these interactions are not scaled.
  • ignore_offset (bool, default=False) – If True, the offset is not scaled.

Examples

This example creates a binary quadratic model and then scales it to half the original energy range.

>>> import dimod
...
>>> bqm = dimod.BinaryQuadraticModel({'a': -2.0, 'b': 2.0}, {('a', 'b'): -1.0}, 1.0, dimod.SPIN)
>>> bqm.scale(0.5)
>>> bqm.linear['a']
-1.0
>>> bqm.quadratic[('a', 'b')]
-0.5
>>> bqm.offset
0.5