dwave.embedding.chain_break_frequency#
- chain_break_frequency(samples_like, embedding)[source]#
Determine the frequency of chain breaks in the given samples.
- Parameters:
samples_like (samples_like/
dimod.SampleSet) – A collection of raw samples.samples_likeis an extension of NumPy’s array-like. Seedimod.as_samples().embedding (dict) – Mapping from source graph to target graph as a dict of form
{s: {t, ...}, ...}, wheresis a source-model variable andtis a target-model variable.
- Returns:
Frequency of chain breaks as a dict in the form
{s: f, ...}, wheresis a variable in the source graph and floatfthe fraction of broken chains.- Return type:
Examples
This example embeds a single source node, \(a\), as a chain of two target nodes \((0, 1)\) and uses
chain_break_frequency()to show that out of two synthetic samples, \([-1, +1]\) represents a broken chain.>>> import numpy as np ... >>> samples = np.array([[-1, +1], [+1, +1]]) >>> embedding = {'a': {0, 1}} >>> print(dwave.embedding.chain_break_frequency(samples, embedding)['a']) 0.5