Determines the frequency of chain breaks in the given samples.

    Args:
        samples (iterable): An iterable of samples where each sample
            is a dict of the form {v: val, ...} where v is a variable
            in the target graph and val is the associated value as
            determined by a binary quadratic model sampler.
        embedding (dict): The mapping from the source graph to the target graph.
            Should be of the form {v: {s, ...}, ...} where v is a variable in the
            source model and s is a variable in the target model.

    Returns:
        dict: The frequency of chain breaks in the form {v: f, ...} where v
        is a variable in the source graph and frequency is the fraction
        of chains that were broken as a float.

def chain_break_frequency(samples, embedding):
    """Determines the frequency of chain breaks in the given samples.

    Args:
        samples (iterable): An iterable of samples where each sample
            is a dict of the form {v: val, ...} where v is a variable
            in the target graph and val is the associated value as
            determined by a binary quadratic model sampler.
        embedding (dict): The mapping from the source graph to the target graph.
            Should be of the form {v: {s, ...}, ...} where v is a variable in the
            source model and s is a variable in the target model.

    Returns:
        dict: The frequency of chain breaks in the form {v: f, ...} where v
        is a variable in the source graph and frequency is the fraction
        of chains that were broken as a float.

    """
    counts = {v: 0 for v in embedding}
    total = 0
    for sample in samples:
        for v, chain in iteritems(embedding):
            vals = [sample[u] for u in chain]

            if not _all_equal(vals):
                counts[v] += 1
        total += 1

    return {v: counts[v] / total for v in embedding}