dwave.embedding.chain_breaks.majority_vote¶

majority_vote
(samples, chains)[source]¶ Unembed samples using the most common value for broken chains.
Parameters:  samples (samples_like) – A collection of samples. samples_like is an extension of NumPy’s
array_like. See
dimod.as_samples()
.  chains (list[array_like]) – List of chains, where each chain is an array_like collection of the variables in the same order as their represention in the given samples.
Returns: A 2tuple containing:
numpy.ndarray
: Unembedded samples as an nSbynC array of dtype ‘int8’, where nC is the number of chains and nS the number of samples. Broken chains are resolved by setting the sample value to that of most the chain’s elements or, for chains without a majority, an arbitrary value.numpy.ndarray
: Indicies of the samples. Equivalent tonp.arange(nS)
because all samples are kept and none added.Return type: Examples
This example unembeds samples from a target graph that chains nodes 0 and 1 to represent one source node and nodes 2, 3, and 4 to represent another. Both samples have one broken chain, with different majority values.
>>> import dimod >>> import numpy as np ... >>> chains = [(0, 1), (2, 3, 4)] >>> samples = np.array([[1, 1, 0, 0, 1], [1, 1, 1, 0, 1]], dtype=np.int8) >>> unembedded, idx = dwave.embedding.majority_vote(samples, chains) >>> print(unembedded) [[1 0] [1 1]] >>> print(idx) [0 1]
 samples (samples_like) – A collection of samples. samples_like is an extension of NumPy’s
array_like. See