dimod.higherorder.utils.poly_energy

poly_energy(sample_like: Union[Sequence[Union[float, numpy.floating, numpy.integer]], Mapping[Hashable, Union[float, numpy.floating, numpy.integer]], Tuple[Sequence[Union[float, numpy.floating, numpy.integer]], Sequence[Hashable]], Tuple[numpy.ndarray, Sequence[Hashable]], numpy.ndarray, Sequence[Sequence[Union[float, numpy.floating, numpy.integer]]], Tuple[Sequence[Sequence[Union[float, numpy.floating, numpy.integer]]], Sequence[Hashable]], Sequence[Union[Sequence[Union[float, numpy.floating, numpy.integer]], Mapping[Hashable, Union[float, numpy.floating, numpy.integer]], Tuple[Sequence[Union[float, numpy.floating, numpy.integer]], Sequence[Hashable]], Tuple[numpy.ndarray, Sequence[Hashable]], numpy.ndarray]], Iterator[Union[Sequence[Union[float, numpy.floating, numpy.integer]], Mapping[Hashable, Union[float, numpy.floating, numpy.integer]], Tuple[Sequence[Union[float, numpy.floating, numpy.integer]], Sequence[Hashable]], Tuple[numpy.ndarray, Sequence[Hashable]], numpy.ndarray]]], poly: Union[Mapping[Sequence[Hashable], Union[float, numpy.floating, numpy.integer]], dimod.higherorder.polynomial.BinaryPolynomial]) float[source]

Calculate energy of a sample from a higher order polynomial.

Parameters

sample_like

A raw sample. samples-like is an extension of NumPy’s

array_like structure. See as_samples().

poly (dict):

Either a polynomial, as a dict of form {term: bias, …}, where term is a tuple of one or more variables and bias the associated bias, or a BinaryPolynomial. Variable labeling/indexing here must match that of sample_like

Returns: Energy of the sample.

Examples

>>> poly = dimod.BinaryPolynomial({'a': -1, ('a', 'b'): 1, ('a', 'b', 'c'): -1},
...                               dimod.BINARY)
>>> sample = {'a': 1, 'b': 1, 'c': 0}
>>> dimod.poly_energy(sample, poly)
0.0