- majority_vote(samples, chains)¶
Unembed samples using the most common value for broken chains.
A 2-tuple containing:
numpy.ndarray: Unembedded samples as an nS-by-nC 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 to
np.arange(nS)because all samples are kept and none added.
- Return type
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]