def generate_pattern_data(num_patterns, pattern_size):
  """Generates a sequence of patterns followed by a degraded query pattern.

  Args:
    num_patterns (int): Number of unique patterns in the sequence
    pattern_size (int): Dimensionality of each pattern

  Returns:
    seq: Numpy array, the sequence of patterns to be presented
      shape [num_patterns + 1, pattern_size]
    target: Numpy array, the pattern we expect to retrieve for the degraded
      query pattern
      shape [pattern_size,]
    target_idx (int): The index into the list of unique patterns for the target
    patterns: List of np arrays, all unique patterns
  """
  patterns = []
  for _ in range(num_patterns):
    pattern = np.random.choice([-1, 1], size=(pattern_size,), p=[.5, .5])
    patterns.append(pattern)

  # Choose one pattern to degrade
  target_idx = random.choice(range(num_patterns))
  target = patterns[target_idx]
  degraded = target.copy()
  degraded_idxs = np.random.choice(
      pattern_size, pattern_size // 2, replace=False)
  degraded[degraded_idxs] = 0
  patterns.append(degraded)

  seq = np.array(patterns)

  return seq, target, target_idx, patterns
Generates a sequence of patterns followed by a degraded query pattern.

  Args:
    num_patterns (int): Number of unique patterns in the sequence
    pattern_size (int): Dimensionality of each pattern

  Returns:
    seq: Numpy array, the sequence of patterns to be presented
      shape [num_patterns + 1, pattern_size]
    target: Numpy array, the pattern we expect to retrieve for the degraded
      query pattern
      shape [pattern_size,]
    target_idx (int): The index into the list of unique patterns for the target
    patterns: List of np arrays, all unique patterns
  
language/labs/memory/synthetic_dataset.py