dimod.higherorder.utils.poly_energies¶
- poly_energies(samples_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]) numpy.ndarray [source]¶
Calculates energy of samples from a higher order polynomial.
- Parameters
samples_like – A collection of raw samples. samples-like is an extension of NumPy’s array_like structure. See
as_samples()
.poly – 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 ofsamples_like
.
Returns: Energies of the samples.
Examples
>>> poly = dimod.BinaryPolynomial({'a': -1, ('a', 'b'): 1, ('a', 'b', 'c'): -1}, ... dimod.BINARY) >>> samples = [{'a': 1, 'b': 1, 'c': 0}, ... {'a': 1, 'b': 1, 'c': 1}] >>> dimod.poly_energies(samples, poly) array([ 0., -1.])