dimod.embedding.majority_vote

majority_vote(sample, embedding)[source]

Determine the sample values for chains by majority vote.

Parameters:
  • sample (Mapping) – Sample as a dict of form {t: val, …}, where t is a variable in the target graph and val its associated value as determined by a binary quadratic model sampler.
  • embedding (dict) – Mapping from source graph to target graph as a dict of form {s: {t, …}, …}, where s is a source-model variable and t is a target-model variable.
Yields:

dict – The unembedded sample. When there is a chain break, the value is chosen to match the most common value in the chain. For broken chains without a majority, one of the two values is chosen arbitrarily.

Examples

This example unembeds a sample from a target graph that chains nodes 0 and 1 to represent source node a and nodes 2, 3, and 4 to represent source node b. Both samples have broken chains for source node b, with different majority values.

>>> import dimod
>>> embedding = {'a': {0, 1}, 'b': {2, 3, 4}}
>>> samples = {0: 1, 1: 1, 2: 0, 3: 0, 4: 1}
>>> next(dimod.embedding.majority_vote(samples, embedding), 'No sample')['b']
0
>>> samples = {0: 1, 1: 1, 2: 1, 3: 0, 4: 1}
>>> next(dimod.embedding.majority_vote(samples, embedding), 'No sample')['b']
1