dimod.higherorder.utils.poly_energies#
- poly_energies(samples_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) 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.])