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

  Args:
    num_patterns (int): Number of unique patterns in the sequence
    num_patterns_store (int): Number of patterns we actually have to store
    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 we need to remember (that may be queried) have their last bit set
      to 1, otherwise 0.
  """
  patterns = []
  for _ in range(num_patterns):
    pattern = np.random.choice([-1, 1], size=(pattern_size,), p=[.5, .5])
    patterns.append(pattern)

  # Choose patterns that are important to remember
  remember_idxs = np.random.choice(
      range(num_patterns), size=num_patterns_store, replace=False)
  patterns = [
      np.append(p, [1]) if i in remember_idxs else np.append(p, [0])
      for i, p in enumerate(patterns)
  ]

  # 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
    num_patterns_store (int): Number of patterns we actually have to store
    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 we need to remember (that may be queried) have their last bit set
      to 1, otherwise 0.
  
language/labs/memory/synthetic_dataset.py