code: def _addNoise(self, pattern, noiseLevel, inputSize):
      
      if pattern is None:
        return None
  
      # Bits that could be noise. These can't be from the original set.
      candidateBits = list(set(range(inputSize)) - set(pattern))
      random.shuffle(candidateBits)
  
      newBits = set()
      for bit in pattern:
        if random.random() < noiseLevel:
          newBits.add(candidateBits.pop())
        else:
          newBits.add(bit)
  
      return newBits
docs: Adds noise to the given pattern and returns the new one.
  
      A noiseLevel of 0.1 means that 10% of the ON bits will be replaced by
      other randomly chosen ON bits.  The returned SDR will still contain the
      same number of bits.