dimod.higherorder.utils.poly_energy#
- poly_energy(sample_like: Sequence[float | floating | integer] | Mapping[Hashable, float | floating | integer] | Tuple[Sequence[float | floating | integer], Sequence[Hashable]] | Tuple[ndarray, Sequence[Hashable]] | ndarray | Sequence[Sequence[float | floating | integer]] | Tuple[Sequence[Sequence[float | floating | integer]], Sequence[Hashable]] | Sequence[Sequence[float | floating | integer] | Mapping[Hashable, float | floating | integer] | Tuple[Sequence[float | floating | integer], Sequence[Hashable]] | Tuple[ndarray, Sequence[Hashable]] | ndarray] | Iterator[Sequence[float | floating | integer] | Mapping[Hashable, float | floating | integer] | Tuple[Sequence[float | floating | integer], Sequence[Hashable]] | Tuple[ndarray, Sequence[Hashable]] | ndarray], poly: Mapping[Sequence[Hashable], float | floating | integer] | 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 ofsample_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