dwave.embedding.broken_chains#

broken_chains(samples, chains)[source]#

Find the broken chains for the given samples.

Parameters:
  • samples (array-like) – Samples as an \(nS \times nV\) array-like object where \(nS\) is the number of samples and \(nV\) is the number of variables. The values should all be \(0/1\) or \(\pm 1\).

  • chains (list[array-like]) – Chains in a list of length \(nC\) (the number of chains). Each chain is an array-like collection of column indices in samples.

Returns:

A \(nS \times nC\) Boolean array. If element \(i, j\) is True, then chain \(j\) in sample \(i\) is broken.

Return type:

numpy.ndarray

Examples

>>> import numpy as np
>>> from dwave.embedding import broken_chains
...
>>> samples = np.array([[-1, +1, -1, +1], [-1, -1, +1, +1]], dtype=np.int8)
>>> chains = [[0, 1], [2, 3]]
>>> broken_chains(samples, chains).tolist()      # tolist() for example formatting
[[True, True], [False, False]]
>>> chains = [[0, 2], [1, 3]]
>>> broken_chains(samples, chains).tolist()      # tolist() for example formatting
[[False, False], [True, True]]