def frequency(self,<EOL>n=<NUM_LIT:15>,<EOL>w=<NUM_LIT:7>,<EOL>columnDimensions = <NUM_LIT>,<EOL>numActiveColumnsPerInhArea = <NUM_LIT>,<EOL>stimulusThreshold = <NUM_LIT:0>,<EOL>spSeed = <NUM_LIT:1>,<EOL>spVerbosity = <NUM_LIT:0>,<EOL>numColors = <NUM_LIT:2>,<EOL>seed=<NUM_LIT>,<EOL>minVal=<NUM_LIT:0>,<EOL>maxVal=<NUM_LIT:10>,<EOL>encoder = '<STR_LIT>',<EOL>forced=True):
print("<STR_LIT>")<EOL>print(encoder, '<STR_LIT>', '<STR_LIT>', seed, '<STR_LIT>', numColors, '<STR_LIT>')<EOL>spImpl = SpatialPooler(<EOL>columnDimensions=(columnDimensions, <NUM_LIT:1>),<EOL>inputDimensions=(<NUM_LIT:1>, n),<EOL>potentialRadius=n/<NUM_LIT:2>,<EOL>numActiveColumnsPerInhArea=numActiveColumnsPerInhArea,<EOL>spVerbosity=spVerbosity,<EOL>stimulusThreshold=stimulusThreshold,<EOL>potentialPct=<NUM_LIT:0.5>,<EOL>seed=spSeed,<EOL>globalInhibition=True,<EOL>)<EOL>rnd.seed(seed)<EOL>numpy.random.seed(seed)<EOL>colors = []<EOL>coincs = []<EOL>reUsedCoincs = []<EOL>spOutput = []<EOL>patterns = set([])<EOL>if encoder=='<STR_LIT>':<EOL><INDENT>enc = scalar.ScalarEncoder(name='<STR_LIT>', w=w, n=n, minval=minVal,<EOL>maxval=maxVal, periodic=False, forced=True) <EOL>for y in range(numColors):<EOL><INDENT>temp = enc.encode(rnd.random()*maxVal)<EOL>colors.append(numpy.array(temp, dtype=numpy.uint32))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for y in range(numColors):<EOL><INDENT>sdr = numpy.zeros(n, dtype=numpy.uint32)<EOL>sdr[rnd.sample(range(n), w)] = <NUM_LIT:1><EOL>colors.append(sdr)<EOL><DEDENT><DEDENT>print('<STR_LIT>', numColors, '<STR_LIT>')<EOL>startTime = time.time()<EOL>for i in range(numColors):<EOL><INDENT>spInput = colors[i]<EOL>onCells = numpy.zeros(columnDimensions, dtype=numpy.uint32)<EOL>spImpl.compute(spInput, True, onCells)<EOL>spOutput.append(onCells.tolist())<EOL>activeCoincIndices = set(onCells.nonzero()[<NUM_LIT:0>])<EOL>reUsed = activeCoincIndices.intersection(patterns)<EOL>if len(reUsed) == <NUM_LIT:0>:<EOL><INDENT>coincs.append((i, activeCoincIndices, colors[i]))<EOL><DEDENT>else:<EOL><INDENT>reUsedCoincs.append((i, activeCoincIndices, colors[i]))<EOL><DEDENT>patterns.update(activeCoincIndices)<EOL>if (i + <NUM_LIT:1>) % <NUM_LIT:100> == <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>', i + <NUM_LIT:1>)<EOL>print("<STR_LIT>" % (time.time() - startTime))<EOL>print(len(reUsedCoincs), "<STR_LIT>")<EOL><DEDENT><DEDENT>summ = []<EOL>for z in coincs:<EOL><INDENT>summ.append(sum([len(z[<NUM_LIT:1>].intersection(y[<NUM_LIT:1>])) for y in reUsedCoincs]))<EOL><DEDENT>zeros = len([x for x in summ if x==<NUM_LIT:0>])<EOL>factor = max(summ)*len(summ)/sum(summ)<EOL>if len(reUsed) < <NUM_LIT:10>:<EOL><INDENT>self.assertLess(factor, <NUM_LIT>,<EOL>"<STR_LIT>" % (<EOL>factor, <NUM_LIT>))<EOL>self.assertLess(zeros, <NUM_LIT>*len(summ),<EOL>"<STR_LIT>" % (<EOL>zeros, <NUM_LIT>*len(summ)))<EOL><DEDENT>else:<EOL><INDENT>self.assertLess(factor, <NUM_LIT:8>,<EOL>"<STR_LIT>" % (<EOL>factor, <NUM_LIT:8>))<EOL>self.assertLess(zeros, <NUM_LIT:12>,<EOL>"<STR_LIT>" % (<EOL>zeros, <NUM_LIT:12>))<EOL><DEDENT>
Helper function that tests whether the SP predicts the most
        frequent record