dimod.BinaryQuadraticModel.normalize¶
-
BinaryQuadraticModel.normalize(bias_range=1, quadratic_range=None, ignored_variables=None, ignored_interactions=None, ignore_offset=False)[source]¶ Normalizes the biases of the binary quadratic model such that they fall in the provided range(s), and adjusts the offset appropriately.
If quadratic_range is provided, then bias_range will be treated as the range for the linear biases and quadratic_range will be used for the range of the quadratic biases.
Parameters: - bias_range (number/pair) – Value/range by which to normalize the all the biases, or if quadratic_range is provided, just the linear biases.
- quadratic_range (number/pair) – Value/range by which to normalize the quadratic biases.
- 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
>>> bqm = dimod.BinaryQuadraticModel({'a': -2.0, 'b': 1.5}, ... {('a', 'b'): -1.0}, ... 1.0, dimod.SPIN) >>> max(abs(bias) for bias in bqm.linear.values()) 2.0 >>> max(abs(bias) for bias in bqm.quadratic.values()) 1.0 >>> bqm.normalize([-1.0, 1.0]) >>> max(abs(bias) for bias in bqm.linear.values()) 1.0 >>> max(abs(bias) for bias in bqm.quadratic.values()) 0.5