dimod.chain_break_frequency¶
-
chain_break_frequency(samples, embedding)[source]¶ Determine the frequency of chain breaks in the given samples.
Parameters: Returns: Frequency of chain breaks as a dict in the form {s: f, …}, where s is a variable in the source graph, and frequency, a float, is the 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, one ([-1, +1]) represents a broken chain.>>> import dimod >>> import numpy as np >>> samples = np.matrix([[-1, +1], [+1, +1]]) >>> embedding = {'a': {0, 1}} >>> print(dimod.chain_break_frequency(samples, embedding)['a']) 0.5
This example embeds a single source node (0) as a chain of two target nodes (a, b) and uses
chain_break_frequency()to show that out of two samples in a dimod response, one ({‘a’: 1, ‘b’: 0}) represents a broken chain.>>> import dimod >>> response = dimod.Response.from_dicts([{'a': 1, 'b': 0}, {'a': 0, 'b': 0}], {'energy': [1, 0]}) >>> embedding = {0: {'a', 'b'}} >>> print(dimod.chain_break_frequency(response, embedding)[0]) 0.5