def valid_sample(samples, query_result):
    '''For a group of samples from
    a query result ensure that
    the sample is approximately equivalent
    to the query_result which is the
    true distribution.'''
    counts = Counter()
    for sample in samples:
        for var, val in sample.items():
            counts[(var, val)] += 1
    # Now lets normalize for each count...
    result = True
    for k, v in counts.items():
        counts[k] = v / len(samples)
        difference = abs(counts.get(k, 0) - query_result[k])
        if round(difference, 2) > 0.01:
            result = False
    return result
dataset/ETHPy150Open eBay/bayesian-belief-networks/bayesian/test/test_bbn.py/valid_sample/original