Higher-Order Models¶
Sometimes it is nice to work with problems that are not restricted to quadratic interactions.
Binary Polynomials¶
- class BinaryPolynomial(poly, vartype)[source]¶
A polynomial with binary variables and real-valued coefficients.
- Parameters
poly (mapping/iterable) – Polynomial as a mapping of form {term: bias, …}, where term is a collection of variables and bias the associated bias. It can also be an iterable of 2-tuples (term, bias).
vartype (
Vartype
/str/set) –Variable type for the binary quadratic model. Accepted input values:
Examples
Binary polynomials can be constructed in many different ways. The following are all equivalent
>>> poly = dimod.BinaryPolynomial({'a': -1, 'ab': 1}, dimod.SPIN) >>> poly = dimod.BinaryPolynomial({('a',): -1, ('a', 'b'): 1}, dimod.SPIN) >>> poly = dimod.BinaryPolynomial([('a', -1), (('a', 'b'), 1)], dimod.SPIN) >>> poly = dimod.BinaryPolynomial({'a': -1, 'ab': .5, 'ba': .5}, dimod.SPIN)
Binary polynomials act a mutable mappings but the terms can be accessed with any sequence.
>>> poly = dimod.BinaryPolynomial({'a': -1, 'ab': 1}, dimod.BINARY) >>> poly['ab'] 1 >>> poly['ba'] 1 >>> poly[{'a', 'b'}] 1 >>> poly[('a', 'b')] 1 >>> poly['cd'] = 4 >>> poly['dc'] 4
Methods¶
Create a shallow copy. |
|
|
Energies of the given samples. |
|
Energy of the given sample. |
|
Construct a binary polynomial from a higher-order Ising problem. |
|
Construct a binary polynomial from a higher-order unconstrained binary optimization (HUBO) problem. |
|
Normalize biases of the binary polynomial to fit the provided range(s). |
|
Relabel variables of a binary polynomial as specified by mapping. |
|
Multiply the polynomial by the given scalar. |
|
Return a binary polynomial over {0, 1} variables. |
Construct a higher-order Ising problem from a binary polynomial. |
|
Construct a higher-order unconstrained binary optimization (HUBO) problem from a binary polynomial. |
|
|
Return a binary polynomial over {-1, +1} variables. |
Functions¶
|
Calculates energy of samples from a higher order polynomial. |
|
Calculate energy of a sample from a higher order polynomial. |
Reducing to a Binary Quadratic Model¶
|
Create a binary quadratic model from a higher order polynomial. |
|
Create a constrained quadratic model from a higher order polynomial. |
|
Reduce a binary polynomial to linear and quadratic terms, plus constraints. |