(sourceid_to_exids, rs)
return _dedup_mixes(mixes)
Generates mixes guaranteed to use every example at least once.
Generates mixes guaranteed to use every example at least once.
Generates mixes guaranteed to use every example at least once .
def generate_mixes_using_all_examples(sourceid_to_exids, rs):
  """Generates mixes guaranteed to use every example at least once."""
  # Brute force way to ensure every example from every source is used at least
  # once. Just goes through every source, selects each example, and generates
  # a mix using random examples from other sources.
  # Number of final outputs is variable, depending on how many end up getting
  # deduped.
  sourceid_to_exids = copy.deepcopy(sourceid_to_exids)
  mixes = []
  for current_source in sourceid_to_exids:
    for current_exid in sourceid_to_exids[current_source]:
      mix = [current_exid]
      for other_source in sourceid_to_exids.keys() - set([current_source]):
        rs.shuffle(sourceid_to_exids[other_source])
        mix.append(next(x for x in sourceid_to_exids[other_source]
                        if x not in mix))
      mixes.append(mix)
  return _dedup_mixes(mixes)
def generate_mixes_using_all_examples ( sourceid_to_exids , rs ) : # Brute force way to ensure every example from every source is used at least # once. Just goes through every source, selects each example, and generates # a mix using random examples from other sources. # Number of final outputs is variable, depending on how many end up getting # deduped. sourceid_to_exids = copy . deepcopy ( sourceid_to_exids ) mixes = [ ] for current_source in sourceid_to_exids : for current_exid in sourceid_to_exids [ current_source ] : mix = [ current_exid ] for other_source in sourceid_to_exids . keys ( ) - set ( [ current_source ] ) : rs . shuffle ( sourceid_to_exids [ other_source ] ) mix . append ( next ( x for x in sourceid_to_exids [ other_source ] if x not in mix ) ) mixes . append ( mix ) return _dedup_mixes ( mixes )