code: 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...
      differences = []
      for k, v in counts.items():
          counts[k] = v / len(samples)
          difference = abs(counts.get(k, 0) - query_result[k])
          differences.append(difference)
      return all(
          not round(difference, 2) > 0.01 for difference in differences
      )
  
imports: from __future__ import division
  import copy
  from collections import Counter
  import pytest
  from causalnex.ebaybbn import BBNNode, JoinTree, JoinTreeCliqueNode, SepSet, build_bbn, build_bbn_from_conditionals, build_join_tree, combinations, make_moralized_copy, make_node_func, make_undirected_copy, priority_func, triangulate
  from causalnex.ebaybbn.exceptions import VariableNotInGraphError, VariableValueNotInDomainError
  from causalnex.ebaybbn.graph import Node, UndirectedNode
  from causalnex.ebaybbn.utils import get_args, get_original_factors, make_key
label_desc: Use image node_id 6 for calling a global function with example usage: valid_sample(samples, query_result) and returns: all