if len(tms) == <NUM_LIT:1>:<EOL><INDENT>return<EOL><DEDENT>if len(tms) > <NUM_LIT:2>:<EOL><INDENT>raise "<STR_LIT>"<EOL><DEDENT>same = fdrutils.tmDiff2(*list(tms.values()), verbosity=VERBOSITY)<EOL>assert(same)<EOL>return<EOL>

Check for diffs among the TM instances in the passed in tms dict and
raise an assert if any are detected

Parameters:
---------------------------------------------------------------------
tms:                  dict of TM instances


numCols = numOnes * numPatterns<EOL>p = []<EOL>for i in range(numPatterns):<EOL><INDENT>x = numpy.zeros(numCols, dtype='<STR_LIT>')<EOL>x[i*numOnes:(i+<NUM_LIT:1>)*numOnes] = <NUM_LIT:1><EOL>p.append(x)<EOL><DEDENT>return p<EOL>

Very simple patterns. Each pattern has numOnes consecutive
    bits on. There are numPatterns*numOnes bits in the vector.


numPatterns = <NUM_LIT:7><EOL>p = _getSimplePatterns(numOnes, numPatterns)<EOL>s1 = [p[<NUM_LIT:0>], p[<NUM_LIT:1>], p[<NUM_LIT:2>], p[<NUM_LIT:3>], p[<NUM_LIT:4>]]<EOL>s2 = [p[<NUM_LIT:0>], p[<NUM_LIT:1>], p[<NUM_LIT:2>], p[<NUM_LIT:3>], p[<NUM_LIT:5>]]<EOL>s3 = [p[<NUM_LIT:0>], p[<NUM_LIT:1>], p[<NUM_LIT:2>], p[<NUM_LIT:3>], p[<NUM_LIT:6>]]<EOL>trainingSequences = [s1, s2, s3]<EOL>allPatterns = p<EOL>return (trainingSequences, relativeFrequencies, allPatterns)<EOL>

Two very simple high order sequences for debugging. Each pattern in the
    sequence has a series of 1's in a specific set of columns.


def _createTMs(numCols, cellsPerColumn=<NUM_LIT:4>, checkSynapseConsistency=True):

<EOL>minThreshold = <NUM_LIT:4><EOL>activationThreshold = <NUM_LIT:4><EOL>newSynapseCount = <NUM_LIT:5><EOL>initialPerm = <NUM_LIT><EOL>connectedPerm = <NUM_LIT:0.5><EOL>permanenceInc = <NUM_LIT:0.1><EOL>permanenceDec = <NUM_LIT><EOL>globalDecay = <NUM_LIT:0.0><EOL>if VERBOSITY > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>cppTm = BacktrackingTMCPP(numberOfCols=numCols, cellsPerColumn=cellsPerColumn,<EOL>initialPerm=initialPerm, connectedPerm=connectedPerm,<EOL>minThreshold=minThreshold, newSynapseCount=newSynapseCount,<EOL>permanenceInc=permanenceInc, permanenceDec=permanenceDec,<EOL>activationThreshold=activationThreshold,<EOL>globalDecay=globalDecay, burnIn=<NUM_LIT:1>,<EOL>seed=SEED, verbosity=VERBOSITY,<EOL>checkSynapseConsistency=checkSynapseConsistency,<EOL>pamLength=<NUM_LIT:1000>)<EOL>if VERBOSITY > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>pyTm = BacktrackingTM(numberOfCols=numCols, cellsPerColumn=cellsPerColumn,<EOL>initialPerm=initialPerm, connectedPerm=connectedPerm,<EOL>minThreshold=minThreshold, newSynapseCount=newSynapseCount,<EOL>permanenceInc=permanenceInc, permanenceDec=permanenceDec,<EOL>activationThreshold=activationThreshold,<EOL>globalDecay=globalDecay, burnIn=<NUM_LIT:1>,<EOL>seed=SEED, verbosity=VERBOSITY,<EOL>pamLength=<NUM_LIT:1000>)<EOL>return cppTm, pyTm<EOL>

Create TM and BacktrackingTMCPP instances with identical parameters.


def _computeTMMetric(tm=None, sequences=None, useResets=True, verbosity=<NUM_LIT:1>):

datasetScore = <NUM_LIT:0><EOL>numPredictions = <NUM_LIT:0><EOL>tm.resetStats()<EOL>for seqIdx, seq in enumerate(sequences):<EOL><INDENT>if useResets:<EOL><INDENT>tm.reset()<EOL><DEDENT>seq = numpy.array(seq, dtype='<STR_LIT>')<EOL>if verbosity > <NUM_LIT:2>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>for i, inputPattern in enumerate(seq):<EOL><INDENT>if verbosity > <NUM_LIT:2>:<EOL><INDENT>print("<STR_LIT>" % (seqIdx, i), end='<STR_LIT:U+0020>')<EOL>print("<STR_LIT>", inputPattern)<EOL><DEDENT>y = tm.infer(inputPattern)<EOL>if verbosity > <NUM_LIT:2>:<EOL><INDENT>stats = tm.getStats()<EOL>if stats['<STR_LIT>'] > <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>", stats['<STR_LIT>'])<EOL><DEDENT><DEDENT>if verbosity > <NUM_LIT:3>:<EOL><INDENT>print("<STR_LIT>")<EOL>predOut = numpy.sum(tm.predictedState['<STR_LIT:t>'], axis=<NUM_LIT:1>)<EOL>actOut  = numpy.sum(tm.activeState['<STR_LIT:t>'], axis=<NUM_LIT:1>)<EOL>outout  = numpy.sum(y.reshape(tm.activeState['<STR_LIT:t>'].shape), axis=<NUM_LIT:1>)<EOL>print("<STR_LIT>", predOut.nonzero())<EOL>print("<STR_LIT>", actOut.nonzero())<EOL>print("<STR_LIT>", inputPattern.nonzero())<EOL>print("<STR_LIT>", outout.nonzero())<EOL><DEDENT><DEDENT><DEDENT>stats = tm.getStats()<EOL>datasetScore = stats['<STR_LIT>']<EOL>numPredictions = stats['<STR_LIT>']<EOL>print("<STR_LIT>", datasetScore, end='<STR_LIT:U+0020>')<EOL>print("<STR_LIT>", numPredictions)<EOL>return datasetScore, numPredictions<EOL>

Given a trained TM and a list of sequences, compute the temporal memory
    performance metric on those sequences.

    Parameters:
    ===========
    tm:               A trained temporal memory.
    sequences:        A list of sequences. Each sequence is a list of numpy
                      vectors.
    useResets:        If True, the TM's reset method will be called before the
                      the start of each new sequence.
    verbosity:        An integer controlling the level of printouts. The higher
                      the number the more debug printouts.

    Return value:
    ============
    The following pair is returned:  (score, numPredictions)

    score:            The average prediction score per pattern.
    numPredictions:   The total number of predictions that were made.


def _createDataset(numSequences, originalSequences, relativeFrequencies):

dataSet = []<EOL>trainingCummulativeFrequencies = numpy.cumsum(relativeFrequencies)<EOL>for _ in range(numSequences):<EOL><INDENT>whichSequence = numpy.searchsorted(trainingCummulativeFrequencies,<EOL>_RGEN.random_sample())<EOL>dataSet.append(originalSequences[whichSequence])<EOL><DEDENT>return dataSet<EOL>

Given a set of sequences, create a dataset consisting of numSequences
    sequences. The i'th pattern in this dataset is chosen from originalSequences
    according to the relative frequencies specified in relativeFrequencies.


print('<STR_LIT>'.join('<STR_LIT:1>' if k != <NUM_LIT:0> else '<STR_LIT:.>' for k in x))<EOL>


for i, trainingSequence in enumerate(trainingSequences):<EOL><INDENT>print("<STR_LIT>", i, "<STR_LIT>")<EOL>for pattern in trainingSequence:<EOL><INDENT>self._printOneTrainingVector(pattern)<EOL><DEDENT><DEDENT>


def _setVerbosity(self, verbosity, tm, tmPy):

tm.cells4.setVerbosity(verbosity)<EOL>tm.verbosity = verbosity<EOL>tmPy.verbosity = verbosity<EOL>


def _createTMs(self, numCols, fixedResources=False,<EOL>checkSynapseConsistency = True):

<EOL>minThreshold = <NUM_LIT:4><EOL>activationThreshold = <NUM_LIT:8><EOL>newSynapseCount = <NUM_LIT:15><EOL>initialPerm = <NUM_LIT><EOL>connectedPerm = <NUM_LIT:0.5><EOL>permanenceInc = <NUM_LIT:0.1><EOL>permanenceDec = <NUM_LIT><EOL>if fixedResources:<EOL><INDENT>permanenceDec = <NUM_LIT:0.1><EOL>maxSegmentsPerCell = <NUM_LIT:5><EOL>maxSynapsesPerSegment = <NUM_LIT:15><EOL>globalDecay = <NUM_LIT:0><EOL>maxAge = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>permanenceDec = <NUM_LIT><EOL>maxSegmentsPerCell = -<NUM_LIT:1><EOL>maxSynapsesPerSegment = -<NUM_LIT:1><EOL>globalDecay = <NUM_LIT><EOL>maxAge = <NUM_LIT:1><EOL><DEDENT>if g_testCPPTM:<EOL><INDENT>if g_options.verbosity > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>cppTM = BacktrackingTMCPP(numberOfCols = numCols, cellsPerColumn = <NUM_LIT:4>,<EOL>initialPerm = initialPerm, connectedPerm = connectedPerm,<EOL>minThreshold = minThreshold,<EOL>newSynapseCount = newSynapseCount,<EOL>permanenceInc = permanenceInc,<EOL>permanenceDec = permanenceDec,<EOL>activationThreshold = activationThreshold,<EOL>globalDecay = globalDecay, maxAge=maxAge, burnIn = <NUM_LIT:1>,<EOL>seed=g_options.seed, verbosity=g_options.verbosity,<EOL>checkSynapseConsistency = checkSynapseConsistency,<EOL>pamLength = <NUM_LIT:1000>,<EOL>maxSegmentsPerCell = maxSegmentsPerCell,<EOL>maxSynapsesPerSegment = maxSynapsesPerSegment,<EOL>)<EOL>cppTM.retrieveLearningStates = True<EOL><DEDENT>else:<EOL><INDENT>cppTM = None<EOL><DEDENT>if g_options.verbosity > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>pyTM = BacktrackingTM(numberOfCols = numCols, cellsPerColumn = <NUM_LIT:4>,<EOL>initialPerm = initialPerm,<EOL>connectedPerm = connectedPerm,<EOL>minThreshold = minThreshold,<EOL>newSynapseCount = newSynapseCount,<EOL>permanenceInc = permanenceInc,<EOL>permanenceDec = permanenceDec,<EOL>activationThreshold = activationThreshold,<EOL>globalDecay = globalDecay, maxAge=maxAge, burnIn = <NUM_LIT:1>,<EOL>seed=g_options.seed, verbosity=g_options.verbosity,<EOL>pamLength = <NUM_LIT:1000>,<EOL>maxSegmentsPerCell = maxSegmentsPerCell,<EOL>maxSynapsesPerSegment = maxSynapsesPerSegment,<EOL>)<EOL>return cppTM, pyTM<EOL>

Create an instance of the appropriate temporal memory. We isolate
        all parameters as constants specified here.


def _getSimplePatterns(self, numOnes, numPatterns):

Very simple patterns. Each pattern has numOnes consecutive
        bits on. There are numPatterns*numOnes bits in the vector. These patterns
        are used as elements of sequences when building up a training set.


def _buildSegmentLearningTrainingSet(self, numOnes=<NUM_LIT:10>, numRepetitions= <NUM_LIT:10>):

numPatterns = <NUM_LIT:5><EOL>numCols = <NUM_LIT:2> * numPatterns * numOnes<EOL>halfCols = numPatterns * numOnes<EOL>numNoiseBits = numOnes<EOL>p = self._getSimplePatterns(numOnes, numPatterns)<EOL>trainingSequences = []<EOL>for i in range(numRepetitions):<EOL><INDENT>sequence = []<EOL>for j in range(numPatterns):<EOL><INDENT>v = numpy.zeros(numCols)<EOL>v[<NUM_LIT:0>:halfCols] = p[j]<EOL>noiseIndices = (self._rgen.permutation(halfCols)<EOL>+ halfCols)[<NUM_LIT:0>:numNoiseBits]<EOL>v[noiseIndices] = <NUM_LIT:1><EOL>sequence.append(v)<EOL><DEDENT>trainingSequences.append(sequence)<EOL><DEDENT>testSequence = []<EOL>for j in range(numPatterns):<EOL><INDENT>v = numpy.zeros(numCols, dtype='<STR_LIT>')<EOL>v[<NUM_LIT:0>:halfCols] = p[j]<EOL>testSequence.append(v)<EOL><DEDENT>if g_options.verbosity > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL>self.printAllTrainingSequences(trainingSequences)<EOL>print("<STR_LIT>")<EOL>self.printAllTrainingSequences([testSequence])<EOL><DEDENT>return (trainingSequences, [testSequence])<EOL>

A simple sequence of 5 patterns. The left half of the vector contains
        the pattern elements, each with numOnes consecutive bits. The right half
        contains numOnes random bits. The function returns a pair:

        trainingSequences:    A list containing numRepetitions instances of the
                              above sequence
        testSequence:         A single clean test sequence containing the 5 patterns
                              but with no noise on the right half


def _buildSL2TrainingSet(self, numOnes=<NUM_LIT:10>, numRepetitions= <NUM_LIT:10>):

numPatterns = <NUM_LIT:5><EOL>numCols = <NUM_LIT:2> * numPatterns * numOnes<EOL>halfCols = numPatterns * numOnes<EOL>numNoiseBits = numOnes<EOL>p = self._getSimplePatterns(numOnes, numPatterns)<EOL>numSequences = <NUM_LIT:3><EOL>indices = [<EOL>[<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:4>],<EOL>[<NUM_LIT:4>, <NUM_LIT:3>, <NUM_LIT:2>, <NUM_LIT:1>, <NUM_LIT:0>],<EOL>[<NUM_LIT:2>, <NUM_LIT:0>, <NUM_LIT:4>, <NUM_LIT:1>, <NUM_LIT:3>],<EOL>]<EOL>trainingSequences = []<EOL>for i in range(numRepetitions*numSequences):<EOL><INDENT>sequence = []<EOL>for j in range(numPatterns):<EOL><INDENT>v = numpy.zeros(numCols, dtype='<STR_LIT>')<EOL>v[<NUM_LIT:0>:halfCols] = p[indices[i % numSequences][j]]<EOL>noiseIndices = (self._rgen.permutation(halfCols)<EOL>+ halfCols)[<NUM_LIT:0>:numNoiseBits]<EOL>v[noiseIndices] = <NUM_LIT:1><EOL>sequence.append(v)<EOL><DEDENT>trainingSequences.append(sequence)<EOL><DEDENT>testSequences = []<EOL>for i in range(numSequences):<EOL><INDENT>sequence = []<EOL>for j in range(numPatterns):<EOL><INDENT>v = numpy.zeros(numCols, dtype='<STR_LIT>')<EOL>v[<NUM_LIT:0>:halfCols] = p[indices[i % numSequences][j]]<EOL>sequence.append(v)<EOL><DEDENT>testSequences.append(sequence)<EOL><DEDENT>if g_options.verbosity > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL>self.printAllTrainingSequences(trainingSequences)<EOL>print("<STR_LIT>")<EOL>self.printAllTrainingSequences(testSequences)<EOL><DEDENT>return (trainingSequences, testSequences)<EOL>

Three simple sequences, composed of the same 5 static patterns. The left
        half of the vector contains the pattern elements, each with numOnes
        consecutive bits. The right half contains numOnes random bits.

        Sequence 1 is: p0, p1, p2, p3, p4
        Sequence 2 is: p4, p3, p2, p1, p0
        Sequence 3 is: p2, p0, p4, p1, p3

        The function returns a pair:

        trainingSequences:    A list containing numRepetitions instances of the
                              above sequences
        testSequence:         Clean test sequences with no noise on the right half


failures = "<STR_LIT>"<EOL>LOGGER.info("<STR_LIT>")<EOL>knn = KNNClassifier(k=<NUM_LIT:1>, distanceNorm=<NUM_LIT:1.0>, useSparseMemory=True)<EOL>for i in range(<NUM_LIT:0>, numSamples):<EOL><INDENT>c = <NUM_LIT:2>*numpy.random.randint(<NUM_LIT:0>, <NUM_LIT:50>) + <NUM_LIT:50><EOL>v = createPattern(c, numDimensions)<EOL>knn.learn(v, c)<EOL><DEDENT>for i in range(<NUM_LIT:0>, <NUM_LIT:50>):<EOL><INDENT>c = <NUM_LIT:2>*i+<NUM_LIT:50><EOL>v = createPattern(c, numDimensions)<EOL>knn.learn(v, c)<EOL><DEDENT>errors = <NUM_LIT:0><EOL>for i in range(<NUM_LIT:0>, numSamples):<EOL><INDENT>c = <NUM_LIT:2>*numpy.random.randint(<NUM_LIT:0>, <NUM_LIT:50>) + <NUM_LIT:50><EOL>v = createPattern(c, numDimensions)<EOL>inferCat, _kir, _kd, _kcd = knn.infer(v)<EOL>if inferCat != c:<EOL><INDENT>LOGGER.info("<STR_LIT>", v[v.nonzero()],"<STR_LIT>", inferCat, "<STR_LIT>", c)<EOL>LOGGER.info("<STR_LIT>", v.nonzero())<EOL>errors += <NUM_LIT:1><EOL><DEDENT><DEDENT>if errors != <NUM_LIT:0>:<EOL><INDENT>failures += "<STR_LIT>"<EOL><DEDENT>errors = <NUM_LIT:0><EOL>for i in range(<NUM_LIT:0>, <NUM_LIT:10>):<EOL><INDENT>c = <NUM_LIT:2>*numpy.random.randint(<NUM_LIT:0>, <NUM_LIT:50>) + <NUM_LIT:50><EOL>v = createPattern(c, numDimensions)<EOL>p = knn.closestTrainingPattern(v, c)<EOL>if not (c in p.nonzero()[<NUM_LIT:0>]):<EOL><INDENT>LOGGER.info("<STR_LIT>", p.nonzero(), v.nonzero())<EOL>LOGGER.info("<STR_LIT>", p[p.nonzero()], v[v.nonzero()])<EOL>errors += <NUM_LIT:1><EOL><DEDENT><DEDENT>if errors != <NUM_LIT:0>:<EOL><INDENT>failures += "<STR_LIT>"<EOL><DEDENT>return failures, knn<EOL>

Simulate running KNN classifier on many disjoint categories


v = numpy.zeros(numDimensions)<EOL>v[c] = <NUM_LIT:5>*numpy.random.random() + <NUM_LIT:10><EOL>v[c+<NUM_LIT:1>] = numpy.random.random()<EOL>if c > <NUM_LIT:0>:<EOL><INDENT>v[c-<NUM_LIT:1>] = numpy.random.random()<EOL><DEDENT>return v<EOL>

Create a sparse pattern from category c with the given number of dimensions.
The pattern is created by setting element c to be a high random number.
Element c-1 and c+1 are set to low random numbers. numDimensions must be > c.


failures = "<STR_LIT>"<EOL>LOGGER.info("<STR_LIT>")<EOL>knn = KNNClassifier(k=<NUM_LIT:3>)<EOL>v = numpy.zeros((<NUM_LIT:6>, <NUM_LIT:2>))<EOL>v[<NUM_LIT:0>] = [<NUM_LIT:1.0>, <NUM_LIT:0.0>]<EOL>v[<NUM_LIT:1>] = [<NUM_LIT:1.0>, <NUM_LIT>]<EOL>v[<NUM_LIT:2>] = [<NUM_LIT:1.0>, <NUM_LIT>]<EOL>v[<NUM_LIT:3>] = [<NUM_LIT:1.0>, <NUM_LIT>]<EOL>v[<NUM_LIT:4>] = [<NUM_LIT:1.0>, <NUM_LIT>]<EOL>v[<NUM_LIT:5>] = [<NUM_LIT:1.0>, <NUM_LIT>]<EOL>knn.learn(v[<NUM_LIT:0>], <NUM_LIT:0>)<EOL>knn.learn(v[<NUM_LIT:1>], <NUM_LIT:0>)<EOL>knn.learn(v[<NUM_LIT:2>], <NUM_LIT:0>)<EOL>knn.learn(v[<NUM_LIT:3>], <NUM_LIT:1>)<EOL>knn.learn(v[<NUM_LIT:4>], <NUM_LIT:1>)<EOL>knn.learn(v[<NUM_LIT:5>], <NUM_LIT:1>)<EOL>winner, _inferenceResult, _dist, _categoryDist = knn.infer(v[<NUM_LIT:0>])<EOL>if winner != <NUM_LIT:0>:<EOL><INDENT>failures += "<STR_LIT>"<EOL><DEDENT>winner, _inferenceResult, _dist, _categoryDist = knn.infer(v[<NUM_LIT:2>])<EOL>if winner != <NUM_LIT:0>:<EOL><INDENT>failures += "<STR_LIT>"<EOL><DEDENT>winner, _inferenceResult, _dist, _categoryDist = knn.infer(v[<NUM_LIT:3>])<EOL>if winner != <NUM_LIT:0>:<EOL><INDENT>failures += "<STR_LIT>"<EOL><DEDENT>winner, _inferenceResult, _dist, _categoryDist = knn.infer(v[<NUM_LIT:5>])<EOL>if winner != <NUM_LIT:1>:<EOL><INDENT>failures += "<STR_LIT>"<EOL><DEDENT>if len(failures) == <NUM_LIT:0>:<EOL><INDENT>LOGGER.info("<STR_LIT>")<EOL><DEDENT>return failures<EOL>


if short==<NUM_LIT:0>:<EOL><INDENT>LOGGER.info("<STR_LIT>")<EOL>numPatterns = numpy.random.randint(<NUM_LIT>, <NUM_LIT>)<EOL>numClasses = numpy.random.randint(<NUM_LIT:50>, <NUM_LIT>)<EOL><DEDENT>elif short==<NUM_LIT:1>:<EOL><INDENT>LOGGER.info("<STR_LIT>")<EOL>numPatterns = numpy.random.randint(<NUM_LIT>, <NUM_LIT>)<EOL>numClasses = numpy.random.randint(<NUM_LIT:50>, <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.info("<STR_LIT>")<EOL>numPatterns = numpy.random.randint(<NUM_LIT>, <NUM_LIT>)<EOL>numClasses = numpy.random.randint(<NUM_LIT:30>, <NUM_LIT:1000>)<EOL><DEDENT>LOGGER.info("<STR_LIT>", numPatterns)<EOL>LOGGER.info("<STR_LIT>", numClasses)<EOL>return numPatterns, numClasses<EOL>

Return the number of patterns and classes the test should use.


def runTestKNNClassifier(self, short = <NUM_LIT:0>):

failures = "<STR_LIT>"<EOL>if short != <NUM_LIT:2>:<EOL><INDENT>numpy.random.seed(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>seed_value = int(time.time())<EOL>numpy.random.seed(seed_value)<EOL>LOGGER.info('<STR_LIT>', seed_value)<EOL>f = open('<STR_LIT>', '<STR_LIT:a>')<EOL>f.write(str(seed_value))<EOL>f.write('<STR_LIT:\n>')<EOL>f.close()<EOL><DEDENT>failures += simulateKMoreThanOne()<EOL>LOGGER.info("<STR_LIT>")<EOL>numPatterns, numClasses = getNumTestPatterns(short)<EOL>patternSize = <NUM_LIT:100><EOL>patterns = numpy.random.rand(numPatterns, patternSize)<EOL>patternDict = dict()<EOL>testDict = dict()<EOL>for i in xrange(numPatterns):<EOL><INDENT>patternDict[i] = dict()<EOL>patternDict[i]['<STR_LIT>'] = patterns[i]<EOL>patternDict[i]['<STR_LIT>'] = numpy.random.randint(<NUM_LIT:0>, numClasses-<NUM_LIT:1>)<EOL>testDict[i] = copy.deepcopy(patternDict[i])<EOL>testDict[i]['<STR_LIT>'][:int(<NUM_LIT>*patternSize)] = numpy.random.rand()<EOL>testDict[i]['<STR_LIT>'] = None<EOL><DEDENT>LOGGER.info("<STR_LIT>")<EOL>knn = KNNClassifier(k=<NUM_LIT:1>)<EOL>failures += simulateClassifier(knn, patternDict,"<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>knnL1 = KNNClassifier(k=<NUM_LIT:1>, distanceNorm=<NUM_LIT:1.0>)<EOL>failures += simulateClassifier(knnL1, patternDict,"<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>knnExact = KNNClassifier(k=<NUM_LIT:1>, exact=True)<EOL>failures += simulateClassifier(knnExact,<EOL>patternDict,<EOL>"<STR_LIT>",<EOL>testDict=testDict)<EOL>numPatterns, numClasses = getNumTestPatterns(short)<EOL>patterns = (numpy.random.rand(numPatterns, <NUM_LIT>) > <NUM_LIT>).astype(RealNumpyDType)<EOL>patternDict = dict()<EOL>for i in patterns:<EOL><INDENT>iString = str(i.tolist())<EOL>if not patternDict.has_key(iString):<EOL><INDENT>randCategory = numpy.random.randint(<NUM_LIT:0>, numClasses-<NUM_LIT:1>)<EOL>patternDict[iString] = dict()<EOL>patternDict[iString]['<STR_LIT>'] = i<EOL>patternDict[iString]['<STR_LIT>'] = randCategory<EOL><DEDENT><DEDENT>LOGGER.info("<STR_LIT>")<EOL>knnDense = KNNClassifier(k=<NUM_LIT:1>)<EOL>failures += simulateClassifier(knnDense, patternDict,"<STR_LIT>")<EOL>self.assertEqual(len(failures), <NUM_LIT:0>,<EOL>"<STR_LIT>" + failures)<EOL>if short == <NUM_LIT:2>:<EOL><INDENT>f = open('<STR_LIT>', '<STR_LIT:a>')<EOL>f.write('<STR_LIT>')<EOL>f.close()<EOL><DEDENT>

Test the KNN classifier in this module. short can be:
            0 (short), 1 (medium), or 2 (long)


tmpDir = tempfile.mkdtemp()<EOL>tmpFileName = os.path.join(tmpDir, os.path.basename(filename))<EOL>return tmpDir, tmpFileName<EOL>

Create a temp directory, and return path to filename in that directory


encoder = MultiEncoder()<EOL>encoder.addMultipleEncoders({<EOL>'<STR_LIT>': dict(fieldname='<STR_LIT>', type='<STR_LIT>',<EOL>timeOfDay=(<NUM_LIT:5>,<NUM_LIT:5>), forced=True),<EOL>'<STR_LIT>': dict(fieldname='<STR_LIT>', type='<STR_LIT>',<EOL>name='<STR_LIT>', minval=<NUM_LIT:0>, maxval=<NUM_LIT>,<EOL>clipInput=True, w=<NUM_LIT:5>, resolution=<NUM_LIT:10>, forced=True),<EOL>'<STR_LIT>': dict(fieldname='<STR_LIT>',type='<STR_LIT>',<EOL>name='<STR_LIT>', minval=<NUM_LIT:0>,maxval=<NUM_LIT>,<EOL>clipInput=True, w=<NUM_LIT:5>, resolution=<NUM_LIT:5>, forced=True),<EOL>})<EOL>return encoder<EOL>

Create the encoder instance for our test and return it.


def _createOPFNetwork(addSP = True, addTP = False):

<EOL>sensorParams = dict(verbosity = _VERBOSITY)<EOL>encoder = _createEncoder()<EOL>trainFile = resource_filename("<STR_LIT>", "<STR_LIT>")<EOL>dataSource = FileRecordStream(streamID=trainFile)<EOL>dataSource.setAutoRewind(True)<EOL>n = Network()<EOL>n.addRegion("<STR_LIT>", "<STR_LIT>", json.dumps(sensorParams))<EOL>sensor = n.regions['<STR_LIT>'].getSelf()<EOL>sensor.encoder = encoder<EOL>sensor.dataSource = dataSource<EOL>if addSP:<EOL><INDENT>print("<STR_LIT>")<EOL>g_spRegionConfig['<STR_LIT>'] = encoder.getWidth()<EOL>n.addRegion("<STR_LIT>", "<STR_LIT>", json.dumps(g_spRegionConfig))<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL><DEDENT>if addTP and addSP:<EOL><INDENT>print("<STR_LIT>")<EOL>g_tpRegionConfig['<STR_LIT>'] = g_spRegionConfig['<STR_LIT>']<EOL>n.addRegion("<STR_LIT>", "<STR_LIT>", json.dumps(g_tpRegionConfig))<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL><DEDENT>elif addTP:<EOL><INDENT>print("<STR_LIT>")<EOL>g_tpRegionConfig['<STR_LIT>'] = encoder.getWidth()<EOL>n.addRegion("<STR_LIT>", "<STR_LIT>", json.dumps(g_tpRegionConfig))<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>n.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL><DEDENT>return n<EOL>

Create a 'new-style' network ala OPF and return it.
    If addSP is true, an SPRegion will be added named 'level1SP'.
    If addTP is true, a TMRegion will be added named 'level1TP'


_debugOut(("<STR_LIT>") %(args,))<EOL>p = subprocess.Popen(args,<EOL>env=os.environ,<EOL>stdout=subprocess.PIPE,<EOL>stderr=subprocess.PIPE)<EOL>_debugOut(("<STR_LIT>") % (args,))<EOL>(stdoutData, stderrData) = p.communicate()<EOL>_debugOut(("<STR_LIT>" +<EOL>"<STR_LIT>") %(args, p.returncode, type(stdoutData), stdoutData, stderrData))<EOL>result = dict(<EOL>exitStatus = p.returncode,<EOL>stdoutData = stdoutData,<EOL>stderrData = stderrData,<EOL>)<EOL>_debugOut(("<STR_LIT>") %(args, pprint.pformat(result, indent=<NUM_LIT:4>)))<EOL>return result<EOL>

args:     Args list as defined for the args parameter in subprocess.Popen()

Returns:  result dicionary:
            {
              'exitStatus':<exit-status-of-external-command>,
              'stdoutData':"string",
              'stderrData':"string"
            }


suiteNames = ['<STR_LIT>']<EOL>testNames = []<EOL>for suite in suiteNames:<EOL><INDENT>for f in dir(eval(suite)):<EOL><INDENT>if f.startswith('<STR_LIT:test>'):<EOL><INDENT>testNames.append('<STR_LIT>' % (suite, f))<EOL><DEDENT><DEDENT><DEDENT>return testNames<EOL>

Get the list of tests that can be run from this module


global g_myEnv<EOL>if not g_myEnv:<EOL><INDENT>params = type('<STR_LIT>', (object,), {'<STR_LIT>' : resource_filename("<STR_LIT>", "<STR_LIT>")})<EOL>g_myEnv = MyTestEnvironment(params)<EOL><DEDENT>

Method called to prepare the test fixture. This is called by the
        unittest framework immediately before calling the test method; any exception
        raised by this method will be considered an error rather than a test
        failure. The default implementation does nothing.


self.resetExtraLogItems()<EOL>g_myEnv.cleanUp()<EOL>

Method called immediately after the test method has been called and the
        result recorded. This is called even if the test method raised an exception,
        so the implementation in subclasses may need to be particularly careful
        about checking internal state. Any exception raised by this method will be
        considered an error rather than a test failure. This method will only be
        called if the setUp() succeeds, regardless of the outcome of the test
        method. The default implementation does nothing.


return None<EOL>

Override to force unittest framework to use test method names instead
        of docstrings in the report.


def getModules(self, expDesc, hsVersion='<STR_LIT>'):

<EOL>shutil.rmtree(g_myEnv.testOutDir, ignore_errors=True)<EOL>args = [<EOL>"<STR_LIT>" % (json.dumps(expDesc)),<EOL>"<STR_LIT>" % (g_myEnv.testOutDir),<EOL>"<STR_LIT>" % (hsVersion)<EOL>]<EOL>self.addExtraLogItem({'<STR_LIT:args>':args})<EOL>experiment_generator.expGenerator(args)<EOL>descriptionPyPath = os.path.join(g_myEnv.testOutDir, "<STR_LIT>")<EOL>permutationsPyPath = os.path.join(g_myEnv.testOutDir, "<STR_LIT>")<EOL>return (self.checkPythonScript(descriptionPyPath),<EOL>self.checkPythonScript(permutationsPyPath))<EOL>

This does the following:

        1.) Calls ExpGenerator to generate a base description file and permutations
        file from expDescription.

        2.) Verifies that description.py and permutations.py are valid python
        modules that can be loaded

        3.) Returns the loaded base description module and permutations module

        Parameters:
        -------------------------------------------------------------------
        expDesc:       JSON format experiment description
        hsVersion:     which version of hypersearch to use ('v2'; 'v1' was dropped)
        retval:        (baseModule, permutationsModule)


def runBaseDescriptionAndPermutations(self, expDesc, hsVersion, maxModels=<NUM_LIT:2>):

<EOL>self.getModules(expDesc, hsVersion=hsVersion)<EOL>permutationsPyPath = os.path.join(g_myEnv.testOutDir, "<STR_LIT>")<EOL>args = [g_myEnv.testOutDir]<EOL>from nupic.frameworks.opf.experiment_runner import runExperiment<EOL>LOGGER.info("<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>runExperiment(args)<EOL>jobParams = {'<STR_LIT>' : generatePersistentJobGUID(),<EOL>'<STR_LIT>': permutationsPyPath,<EOL>'<STR_LIT>': hsVersion,<EOL>}<EOL>if maxModels is not None:<EOL><INDENT>jobParams['<STR_LIT>'] = maxModels<EOL><DEDENT>args = ['<STR_LIT>', '<STR_LIT>' % (json.dumps(jobParams))]<EOL>self.resetExtraLogItems()<EOL>self.addExtraLogItem({'<STR_LIT>':jobParams})<EOL>LOGGER.info("<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>jobID = hypersearch_worker.main(args)<EOL>cjDAO = ClientJobsDAO.get()<EOL>models = cjDAO.modelsGetUpdateCounters(jobID)<EOL>modelIDs = [model.modelId for model in models]<EOL>results = cjDAO.modelsGetResultAndStatus(modelIDs)<EOL>if maxModels is not None:<EOL><INDENT>self.assertEqual(len(results), maxModels, "<STR_LIT>"<EOL>"<STR_LIT>" % (maxModels, len(results)))<EOL><DEDENT>for result in results:<EOL><INDENT>self.assertEqual(result.completionReason, cjDAO.CMPL_REASON_EOF,<EOL>"<STR_LIT>" % (result.completionMsg))<EOL><DEDENT>return results<EOL>

This does the following:

        1.) Calls ExpGenerator to generate a base description file and permutations
        file from expDescription.

        2.) Verifies that description.py and permutations.py are valid python
        modules that can be loaded

        3.) Runs the base description.py as an experiment using OPF RunExperiment.

        4.) Runs a Hypersearch using the generated permutations.py by passing it
        to HypersearchWorker.

        Parameters:
        -------------------------------------------------------------------
        expDesc:       JSON format experiment description
        hsVersion:     which version of hypersearch to use ('v2'; 'v1' was dropped)
        retval:        list of model results


def assertValidSwarmingAggregations(self, expDesc, expectedAttempts):

<EOL>minAggregation = dict(expDesc['<STR_LIT>']['<STR_LIT>'])<EOL>minAggregation.pop('<STR_LIT>')<EOL>(base, perms) = self.getModules(expDesc)<EOL>predictionSteps = expDesc['<STR_LIT>']['<STR_LIT>'][<NUM_LIT:0>]<EOL>self.assertEqual(base.control['<STR_LIT>']['<STR_LIT>'],<EOL>expDesc['<STR_LIT>']['<STR_LIT>'])<EOL>tmpAggregationInfo = rCopy(<EOL>base.config['<STR_LIT>'],<EOL>lambda value, _: value)<EOL>tmpAggregationInfo.pop('<STR_LIT>')<EOL>self.assertDictEqual(tmpAggregationInfo, minAggregation)<EOL>predictAheadTime = dict(minAggregation)<EOL>for key in predictAheadTime.keys():<EOL><INDENT>predictAheadTime[key] *=  predictionSteps<EOL><DEDENT>self.assertEqual(base.config['<STR_LIT>'],<EOL>predictAheadTime)<EOL>self.assertEqual(<EOL>perms.minimize,<EOL>("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL>metrics = base.control['<STR_LIT>']<EOL>metricTuples = [(metric.metric, metric.inferenceElement, metric.params)for metric in metrics]<EOL>self.assertIn(('<STR_LIT>',<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': <NUM_LIT:1000>, '<STR_LIT>': [predictionSteps],<EOL>'<STR_LIT>': '<STR_LIT>'}),<EOL>metricTuples)<EOL>aggPeriods = perms.permutations['<STR_LIT>']<EOL>aggAttempts = []<EOL>for agg in aggPeriods.choices:<EOL><INDENT>multipleOfMinAgg = aggregationDivide(agg, minAggregation)<EOL>self.assertIsInt(multipleOfMinAgg,<EOL>"<STR_LIT>""<STR_LIT>" % (agg, minAggregation))<EOL>self.assertGreaterEqual(int(round(multipleOfMinAgg)), <NUM_LIT:1>,<EOL>"<STR_LIT>" %(agg, minAggregation))<EOL>requiredSteps = aggregationDivide(predictAheadTime, agg)<EOL>self.assertIsInt(requiredSteps,<EOL>"<STR_LIT>""<STR_LIT>" % (agg, predictAheadTime))<EOL>self.assertGreaterEqual(int(round(requiredSteps)), <NUM_LIT:1>,<EOL>"<STR_LIT>""<STR_LIT>" % (agg, predictAheadTime))<EOL>quotient = aggregationDivide(expDesc['<STR_LIT>'], agg)<EOL>self.assertIsInt(quotient,<EOL>"<STR_LIT>""<STR_LIT>" % (agg, expDesc['<STR_LIT>']))<EOL>self.assertGreaterEqual(int(round(quotient)), <NUM_LIT:1>,<EOL>"<STR_LIT>""<STR_LIT:%s>" % (agg, expDesc['<STR_LIT>']))<EOL>aggAttempts.append((int(round(multipleOfMinAgg)), int(requiredSteps)))<EOL><DEDENT>LOGGER.info("<STR_LIT>", aggAttempts)<EOL>aggAttempts.sort()<EOL>expectedAttempts.sort()<EOL>self.assertEqual(aggAttempts, expectedAttempts, "<STR_LIT>""<STR_LIT>""<STR_LIT>" %(expectedAttempts, aggAttempts))<EOL>

Test that the set of aggregations produced for a swarm are correct

        Parameters:
        -----------------------------------------------------------------------
        expDesc:   JSON experiment description
        expectedAttempts: list of (minAggregationMultiple, predictionSteps) pairs
                          that we expect to find in the aggregation choices.


return None<EOL>


def compareOPFPredictionFiles(self, path1, path2, temporal,<EOL>maxMismatches=None):

experimentLabel = "<STR_LIT>" %("<STR_LIT>" if temporal else "<STR_LIT>")<EOL>print("<STR_LIT>" % (<EOL>experimentLabel, path1, path2))<EOL>self.assertTrue(<EOL>os.path.isfile(path1),<EOL>msg="<STR_LIT>" % (<EOL>path1))<EOL>(opf1CsvReader, opf1FieldNames) = self._openOpfPredictionCsvFile(path1)<EOL>self.assertTrue(<EOL>os.path.isfile(path2),<EOL>msg="<STR_LIT>" % (<EOL>path2))<EOL>(opf2CsvReader, opf2FieldNames) = self._openOpfPredictionCsvFile(path2)<EOL>self.assertEqual(len(opf1FieldNames), len(opf2FieldNames),<EOL>("<STR_LIT>"<EOL>"<STR_LIT>") % (<EOL>experimentLabel, len(opf1FieldNames),<EOL>len(opf2FieldNames)))<EOL>self.assertEqual(opf1FieldNames, opf2FieldNames)<EOL>opf1EOF = False<EOL>opf2EOF = False<EOL>opf1CurrentDataRowIndex = -<NUM_LIT:1><EOL>opf2CurrentDataRowIndex = -<NUM_LIT:1><EOL>if temporal:<EOL><INDENT>_skipOpf1Row = next(opf1CsvReader)<EOL>opf1CurrentDataRowIndex += <NUM_LIT:1><EOL>_skipOpf2Row = next(opf2CsvReader)<EOL>opf2CurrentDataRowIndex += <NUM_LIT:1><EOL><DEDENT>fieldsIndexesToCompare = tuple(range(<NUM_LIT:2>, len(opf1FieldNames), <NUM_LIT:2>))<EOL>self.assertGreater(len(fieldsIndexesToCompare), <NUM_LIT:0>)<EOL>print(("<STR_LIT>"<EOL>"<STR_LIT>") % (<EOL>experimentLabel,<EOL>fieldsIndexesToCompare,<EOL>[opf1FieldNames[i] for i in fieldsIndexesToCompare],<EOL>[opf2FieldNames[i] for i in fieldsIndexesToCompare]))<EOL>for i in fieldsIndexesToCompare:<EOL><INDENT>self.assertTrue(opf1FieldNames[i].endswith("<STR_LIT>"),<EOL>msg="<STR_LIT>" % opf1FieldNames[i])<EOL>self.assertTrue(opf2FieldNames[i].endswith("<STR_LIT>"),<EOL>msg="<STR_LIT>" % opf2FieldNames[i])<EOL><DEDENT>mismatchCount = <NUM_LIT:0><EOL>while True:<EOL><INDENT>try:<EOL><INDENT>opf1Row = next(opf1CsvReader)<EOL><DEDENT>except StopIteration:<EOL><INDENT>opf1EOF = True<EOL><DEDENT>else:<EOL><INDENT>opf1CurrentDataRowIndex += <NUM_LIT:1><EOL><DEDENT>try:<EOL><INDENT>opf2Row = next(opf2CsvReader)<EOL><DEDENT>except StopIteration:<EOL><INDENT>opf2EOF = True<EOL><DEDENT>else:<EOL><INDENT>opf2CurrentDataRowIndex += <NUM_LIT:1><EOL><DEDENT>if opf1EOF != opf2EOF:<EOL><INDENT>print(("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>") % (<EOL>experimentLabel,<EOL>opf1EOF, opf1CurrentDataRowIndex,<EOL>opf2EOF, opf2CurrentDataRowIndex))<EOL>return False<EOL><DEDENT>if opf1EOF and opf2EOF:<EOL><INDENT>break<EOL><DEDENT>self.assertEqual(len(opf1Row), len(opf2Row))<EOL>for i in fieldsIndexesToCompare:<EOL><INDENT>opf1FloatValue = float(opf1Row[i])<EOL>opf2FloatValue = float(opf2Row[i])<EOL>if opf1FloatValue != opf2FloatValue:<EOL><INDENT>mismatchCount += <NUM_LIT:1><EOL>print(("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>") % (<EOL>experimentLabel,<EOL>opf1CurrentDataRowIndex,<EOL>i,<EOL>opf1FieldNames[i],<EOL>opf1Row[i],<EOL>opf2Row[i],<EOL>opf1FloatValue,<EOL>opf2FloatValue,<EOL>opf1Row,<EOL>opf2Row))<EOL>if maxMismatches is not None and mismatchCount >= maxMismatches:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if mismatchCount != <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>" % (<EOL>experimentLabel, mismatchCount, path1, path2))<EOL>return False<EOL><DEDENT>self.assertEqual(opf1CurrentDataRowIndex, opf2CurrentDataRowIndex)<EOL>print(("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>") %(experimentLabel,<EOL>opf1CurrentDataRowIndex + <NUM_LIT:1>,<EOL>path1,<EOL>path2))<EOL>return True<EOL>

Compare temporal or non-temporal predictions for the given experiment
        that just finished executing

        experimentName:     e.g., "gym"; this string will be used to form
                            a directory path to the experiments.

        maxMismatches:      Maximum number of row mismatches to report before
                            terminating the comparison; None means: report all
                            mismatches

        Returns:            True if equal; False if different


<EOL>csvReader = self._openCsvFile(filepath)<EOL>names = next(csvReader)<EOL>_types = next(csvReader)<EOL>_specials = next(csvReader)<EOL>return (csvReader, names)<EOL>

Open an OPF prediction CSV file and advance it to the first data row

        Returns:      the tuple (csvReader, fieldNames), where 'csvReader' is the
                      csv reader object, and 'fieldNames' is a sequence of field
                      names.


import subprocess<EOL>_debugOut(("<STR_LIT>") %(args,))<EOL>p = subprocess.Popen(args,<EOL>env=os.environ,<EOL>stdout=subprocess.PIPE,<EOL>stderr=subprocess.PIPE)<EOL>_debugOut(("<STR_LIT>") % (args,))<EOL>(stdoutData, stderrData) = p.communicate()<EOL>_debugOut(("<STR_LIT>" +"<STR_LIT>") %(args, p.returncode, type(stdoutData), stdoutData, stderrData))<EOL>result = dict(<EOL>exitStatus = p.returncode,<EOL>stdoutData = stdoutData,<EOL>stderrData = stderrData,<EOL>)<EOL>_debugOut(("<STR_LIT>") %(args, pprint.pformat(result, indent=<NUM_LIT:4>)))<EOL>return result<EOL>


import inspect<EOL>frameObj = inspect.stack()[<NUM_LIT:2>][<NUM_LIT:0>]<EOL>return inspect.getframeinfo(frameObj)<EOL>

Returns: Traceback namedtuple for our caller's caller


path = os.path.join(self.__opfExperimentsParentDir, experimentName)<EOL>assert os.path.isdir(path),"<STR_LIT>" % (path,)<EOL>return path<EOL>

experimentName:     e.g., "gym"; this string will be used to form
                    a directory path to the experiment.

Returns:            absolute path to the experiment directory


global g_myEnv<EOL>if not g_myEnv:<EOL><INDENT>g_myEnv = MyTestEnvironment()<EOL><DEDENT>

Method called to prepare the test fixture. This is called immediately
        before calling the test method; any exception raised by this method will be
        considered an error rather than a test failure. The default implementation
        does nothing.


<EOL>self.resetExtraLogItems()<EOL>


def executePositiveOpfExperiment(self, experimentName, short=False):

opfRunner = g_myEnv.getOpfRunExperimentPyPath()<EOL>opfExpDir = g_myEnv.getOpfExperimentPath(experimentName)<EOL>r = self.__executePositiveRunExperimentTest(runnerPath=opfRunner,<EOL>experimentDirPath=opfExpDir,<EOL>short=short)<EOL>return r<EOL>

Executes a positive OPF RunExperiment test as a subprocess and validates
        its exit status.

        experimentName:     e.g., "gym"; this string will be used to form
                            a directory path to the experiment.

        short:              if True, attempt to run the experiment with --testMode
                            flag turned on, which causes all inference and training
                            iteration counts to be overridden with small counts.

        Returns:            result from _executeExternalCmdAndReapOutputs


<EOL>command = [<EOL>"<STR_LIT>",<EOL>runnerPath,<EOL>experimentDirPath,<EOL>]<EOL>command.extend(customOptions)<EOL>if short:<EOL><INDENT>command.append("<STR_LIT>")<EOL><DEDENT>self.addExtraLogItem({'<STR_LIT>':command})<EOL>r = _executeExternalCmdAndReapOutputs(command)<EOL>self.addExtraLogItem({'<STR_LIT:result>':r})<EOL>_debugOut(("<STR_LIT>") % (command, r))<EOL>self.assertEqual(r['<STR_LIT>'], <NUM_LIT:0>,<EOL>("<STR_LIT>") %(runnerPath, r['<STR_LIT>'],))<EOL>self.resetExtraLogItems()<EOL>return r<EOL>

Executes a positive RunExperiment.py test and performs
        basic validation

        runnerPath:         experiment running (LPF or OPF RunExperiment.py path)

        experimentDirPath:  directory containing the description.py file of interest

        short:              if True, attempt to run the experiment with --testMode
                            flag turned on, which causes all inference and training
                            iteration counts to be overridden with small counts.
                            NOTE: if the (possibly aggregated) dataset has fewer
                            rows than the count overrides, then an LPF experiment
                            will fail.

        Returns:            result from _executeExternalCmdAndReapOutputs


def getAllDirectoriesWithFile(path, filename, excludeDirs):

directoryList = []<EOL>for dirpath, dirnames, filenames in os.walk(path):<EOL><INDENT>for d in dirnames[:]:<EOL><INDENT>if d in excludeDirs:<EOL><INDENT>dirnames.remove(d)<EOL>print("<STR_LIT>" % (os.path.join(dirpath, d)))<EOL><DEDENT>elif '<STR_LIT>' in os.listdir(os.path.join(dirpath, d)):<EOL><INDENT>dirnames.remove(d)<EOL>print("<STR_LIT>" % (os.path.join(dirpath, d)))<EOL><DEDENT><DEDENT>for f in filenames:<EOL><INDENT>if f==filename:<EOL><INDENT>directoryList.append(dirpath)<EOL><DEDENT><DEDENT><DEDENT>return directoryList<EOL>

Returns a list of directories in the <path> with a given <filename>, excluding
<excludeDirs>


excludedDirectories = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>excludedDirectories.extend(excludedExperiments)<EOL>return getAllDirectoriesWithFile(<EOL>path="<STR_LIT>",<EOL>filename="<STR_LIT>",<EOL>excludeDirs=excludedDirectories)<EOL>

Experiment directories are the directories with a description.py file


initExperimentPrng()<EOL>if reduced:<EOL><INDENT>args = [path, '<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>args = [path]<EOL><DEDENT>runExperiment(args)<EOL>

Run the experiment in the <path> with a reduced iteration count


handle = tempfile.NamedTemporaryFile(prefix="<STR_LIT:test>", suffix="<STR_LIT>", dir="<STR_LIT:.>")<EOL>filename = handle.name<EOL>handle.close()<EOL>return filename<EOL>


def _aggregate(input, options, output, timeFieldName):

aggregator = Aggregator(aggregationInfo=options, <EOL>inputFields=input.getFields(),<EOL>timeFieldName=timeFieldName)<EOL>while True:<EOL><INDENT>inRecord = input.getNextRecord()<EOL>print("<STR_LIT>", inRecord)<EOL>(outRecord, aggBookmark) = aggregator.next(record = inRecord, <EOL>curInputBookmark = None)<EOL>print("<STR_LIT>", outRecord)<EOL>if outRecord is not None:<EOL><INDENT>output.appendRecord(outRecord, None)<EOL><DEDENT>if inRecord is None and outRecord is None:<EOL><INDENT>break<EOL><DEDENT><DEDENT>

Aggregate the input stream and write aggregated records to the output
    stream


<EOL>print()<EOL>return<EOL>

Method called to prepare the test fixture. This is called immediately
        before calling the test method; any exception raised by this method will be
        considered an error rather than a test failure. The default implementation
        does nothing.

        NOTE: this is called once for every sub-test and a new AggregationTests
          instance is constructed for every sub-test.


errScore = <NUM_LIT:100><EOL>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:address>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:0><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:10><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is not None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is not None:<EOL><INDENT>errScore -= <NUM_LIT:50><EOL><DEDENT>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>metricFunctions = None,<EOL>)<EOL>return dummyModelParams<EOL>

This function can be used for Hypersearch algorithm development. When
    present, Hypersearch doesn't actually run the CLA model in the OPF, but instead run
    a dummy model. This function returns the dummy model params that will be
    used. See the OPFDummyModelRunner class source code (in
    nupic.swarming.ModelRunner) for a description of the schema for
    the dummy model params.


<EOL>limit = int(os.environ.get('<STR_LIT>', <NUM_LIT>))<EOL>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] > limit:<EOL><INDENT>return False;<EOL><DEDENT>return True<EOL>

This function can be used to selectively filter out specific permutation
    combinations. It is called by RunPermutations for every possible permutation
    of the variables in the permutations dict. It should return True for valid a
    combination of permutation values and False for an invalid one.

    Parameters:
    ---------------------------------------------------------
    perm: dict of one possible combination of name:value
          pairs chosen from permutations.


<EOL>errScore = <NUM_LIT:100><EOL>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is None:<EOL><INDENT>errScore -= <NUM_LIT><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:15><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:10><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:5><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore += <NUM_LIT:10><EOL><DEDENT>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>metricFunctions = None,<EOL>)<EOL>return dummyModelParams<EOL>

This function can be used for Hypersearch algorithm development. When
    present, we don't actually run the CLA model in the OPF, but instead run
    a dummy model. This function returns the dummy model params that will be
    used. See the OPFDummyModelRunner class source code (in
    nupic.swarming.ModelRunner) for a description of the schema for
    the dummy model params.


<EOL>return True<EOL>


errScore = <NUM_LIT:50><EOL>errScore += abs(perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] - <NUM_LIT>)<EOL>errScore += abs(perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:n>'] - <NUM_LIT>)<EOL>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:address>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:10><EOL><DEDENT>waitTime = None<EOL>if eval(os.environ.get('<STR_LIT>', '<STR_LIT:False>')):<EOL><INDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>waitTime = <NUM_LIT><EOL><DEDENT><DEDENT>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>iterations = int(os.environ.get('<STR_LIT>', '<STR_LIT:1>')),<EOL>waitTime = waitTime,<EOL>sysExitModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>errModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>jobFailErr = bool(os.environ.get('<STR_LIT>', False))<EOL>)<EOL>return dummyModelParams<EOL>

This function can be used for Hypersearch algorithm development. When
    present, Hypersearch doesn't actually run the CLA model in the OPF, but
    instead runs a dummy model. This function returns the dummy model params that
    will be used. See the OPFDummyModelRunner class source code (in
    nupic.swarming.ModelRunner) for a description of the schema
    for the dummy model params.


errScore = <NUM_LIT><EOL>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:A>'] is None:<EOL><INDENT>errScore -= <NUM_LIT><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:B>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:30><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:C>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT>delay = <NUM_LIT:0><EOL>encoderCount = <NUM_LIT:0><EOL>encoders = perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>for field,encoder in encoders.items():<EOL><INDENT>if encoder is not None:<EOL><INDENT>encoderCount += <NUM_LIT:1><EOL><DEDENT><DEDENT>if encoderCount == <NUM_LIT:2>:<EOL><INDENT>delay = <NUM_LIT:0.1><EOL><DEDENT>elif encoderCount == <NUM_LIT:3>and perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']["<STR_LIT:A>"] is None:<EOL><INDENT>delay = <NUM_LIT><EOL><DEDENT>elif encoderCount == <NUM_LIT:3>:<EOL><INDENT>delay = <NUM_LIT><EOL><DEDENT>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>metricFunctions = None,<EOL>delay=delay,<EOL>)<EOL>return dummyModelParams<EOL>


<EOL>errScore = <NUM_LIT><EOL>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is None:<EOL><INDENT>errScore -= <NUM_LIT:6><EOL>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is None:<EOL><INDENT>errScore -= <NUM_LIT><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is None:<EOL><INDENT>errScore -= <NUM_LIT><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:30><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is None:<EOL><INDENT>errScore -= <NUM_LIT:5><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:4><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:3><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:2><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore += <NUM_LIT:2><EOL><DEDENT>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>metricFunctions = None,<EOL>)<EOL>return dummyModelParams<EOL>


<EOL>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] > <NUM_LIT>:<EOL><INDENT>return False;<EOL><DEDENT>return True<EOL>


errScore = <NUM_LIT><EOL>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:A>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:50><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:B>'] is None:<EOL><INDENT>errScore -= <NUM_LIT><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:C>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:30><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:D>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:E>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:15><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:F>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:10><EOL><DEDENT>if not perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is None:<EOL><INDENT>errScore -= <NUM_LIT:5><EOL><DEDENT>delay = <NUM_LIT:0><EOL>encoderCount = <NUM_LIT:0><EOL>for key in perm.keys():<EOL><INDENT>if '<STR_LIT>' in key and not perm[key] is None:<EOL><INDENT>encoderCount += <NUM_LIT:1><EOL><DEDENT><DEDENT>delay = encoderCount*encoderCount*<NUM_LIT><EOL>dummyModelParams = dict(<EOL>metricValue=errScore,<EOL>metricFunctions=None,<EOL>delay=delay,<EOL>)<EOL>return dummyModelParams<EOL>


<EOL>errScore = <NUM_LIT:50><EOL>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:address>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:10><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is not None:<EOL><INDENT>errScore += <NUM_LIT:30><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is not None:<EOL><INDENT>errScore += <NUM_LIT><EOL><DEDENT>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>iterations = int(os.environ.get('<STR_LIT>', '<STR_LIT:1>')),<EOL>waitTime = None,<EOL>sysExitModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>errModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>jobFailErr = bool(os.environ.get('<STR_LIT>', False))<EOL>)<EOL>return dummyModelParams<EOL>


<EOL>errScore = <NUM_LIT:50><EOL>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>errScore += <NUM_LIT:10><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT:address>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:10><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>errScore -= <NUM_LIT:20><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is not None:<EOL><INDENT>errScore -= <NUM_LIT:30><EOL><DEDENT>if perm['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']is not None:<EOL><INDENT>errScore -= <NUM_LIT><EOL><DEDENT>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>iterations = int(os.environ.get('<STR_LIT>', '<STR_LIT:1>')),<EOL>waitTime = None,<EOL>sysExitModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>errModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>jobFailErr = bool(os.environ.get('<STR_LIT>', False))<EOL>)<EOL>return dummyModelParams<EOL>


errScore = <NUM_LIT:50><EOL>waitTime = <NUM_LIT><EOL>dummyModelParams = dict(<EOL>metricValue = errScore,<EOL>iterations = int(os.environ.get('<STR_LIT>', '<STR_LIT:5>')),<EOL>waitTime = waitTime,<EOL>sysExitModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>delayModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>errModelRange = os.environ.get('<STR_LIT>',<EOL>None),<EOL>jobFailErr = bool(os.environ.get('<STR_LIT>', False))<EOL>)<EOL>return dummyModelParams<EOL>


cjDAO = ClientJobsDAO.get()<EOL>jobResults = cjDAO.jobGetFields(jobID, ['<STR_LIT>'])[<NUM_LIT:0>]<EOL>print("<STR_LIT>" % (jobResults,))<EOL>jobResults = json.loads(jobResults)<EOL>return jobResults['<STR_LIT>']<EOL>

Parameters:
-------------------------------------------------------------------
jobID:            jobID of successfully-completed Hypersearch job

retval:           modelID of the winning model


_debugOut(("<STR_LIT>") %(args,))<EOL>p = subprocess.Popen(args,<EOL>env=os.environ,<EOL>stdout=subprocess.PIPE,<EOL>stderr=subprocess.PIPE)<EOL>_debugOut(("<STR_LIT>") % (args,))<EOL>(stdoutData, stderrData) = p.communicate()<EOL>_debugOut(("<STR_LIT>" +"<STR_LIT>") %(args, p.returncode, type(stdoutData), stdoutData, stderrData))<EOL>result = dict(<EOL>exitStatus = p.returncode,<EOL>stdoutData = stdoutData,<EOL>stderrData = stderrData,<EOL>)<EOL>_debugOut(("<STR_LIT>") %(args, pprint.pformat(result, indent=<NUM_LIT:4>)))<EOL>return result<EOL>

args:     Args list as defined for the args parameter in subprocess.Popen()

Returns:  result dicionary:
            {
              'exitStatus':<exit-status-of-external-command>,
              'stdoutData':"string",
              'stderrData':"string"
            }


suiteNames = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>]<EOL>testNames = []<EOL>for suite in suiteNames:<EOL><INDENT>for f in dir(eval(suite)):<EOL><INDENT>if f.startswith('<STR_LIT:test>'):<EOL><INDENT>testNames.append('<STR_LIT>' % (suite, f))<EOL><DEDENT><DEDENT><DEDENT>return testNames<EOL>

Get the list of tests that can be run from this module


pass<EOL>

Method called to prepare the test fixture. This is called by the
        unittest framework immediately before calling the test method; any exception
        raised by this method will be considered an error rather than a test
        failure. The default implementation does nothing.


<EOL>self.resetExtraLogItems()<EOL>

Method called immediately after the test method has been called and the
        result recorded. This is called even if the test method raised an exception,
        so the implementation in subclasses may need to be particularly careful
        about checking internal state. Any exception raised by this method will be
        considered an error rather than a test failure. This method will only be
        called if the setUp() succeeds, regardless of the outcome of the test
        method. The default implementation does nothing.


return None<EOL>

Override to force unittest framework to use test method names instead
        of docstrings in the report.


print("<STR_LIT>")<EOL>print("<STR_LIT>" % (self.__class__, self._testMethodName))<EOL>


assert env is not None<EOL>if "<STR_LIT>" in env:<EOL><INDENT>newPath = "<STR_LIT>" % (env["<STR_LIT>"], os.pathsep, g_myEnv.testSrcDataDir)<EOL><DEDENT>else:<EOL><INDENT>newPath = g_myEnv.testSrcDataDir<EOL><DEDENT>env["<STR_LIT>"] = newPath<EOL>

Put the path to our datasets int the NTA_DATA_PATH variable which
        will be used to set the environment for each of the workers

        Parameters:
        ---------------------------------------------------------------------
        env: The current environment dict


def _launchWorkers(self, cmdLine, numWorkers):

workers = []<EOL>for i in range(numWorkers):<EOL><INDENT>stdout = tempfile.TemporaryFile()<EOL>stderr = tempfile.TemporaryFile()<EOL>p = subprocess.Popen(cmdLine, bufsize=<NUM_LIT:1>, env=os.environ, shell=True,<EOL>stdin=None, stdout=stdout, stderr=stderr)<EOL>workers.append(p)<EOL><DEDENT>return workers<EOL>

Launch worker processes to execute the given command line

        Parameters:
        -----------------------------------------------
        cmdLine: The command line for each worker
        numWorkers: number of workers to launch
        retval: list of workers


def _getJobInfo(self, cjDAO, workers, jobID):

<EOL>jobInfo = cjDAO.jobInfo(jobID)<EOL>runningCount = <NUM_LIT:0><EOL>for worker in workers:<EOL><INDENT>retCode = worker.poll()<EOL>if retCode is None:<EOL><INDENT>runningCount += <NUM_LIT:1><EOL><DEDENT><DEDENT>if runningCount > <NUM_LIT:0>:<EOL><INDENT>status = ClientJobsDAO.STATUS_RUNNING<EOL><DEDENT>else:<EOL><INDENT>status = ClientJobsDAO.STATUS_COMPLETED<EOL><DEDENT>jobInfo = jobInfo._replace(status=status)<EOL>if status == ClientJobsDAO.STATUS_COMPLETED:<EOL><INDENT>jobInfo = jobInfo._replace(<EOL>completionReason=ClientJobsDAO.CMPL_REASON_SUCCESS)<EOL><DEDENT>return jobInfo<EOL>

Return the job info for a job

        Parameters:
        -----------------------------------------------
        cjDAO:   client jobs database instance
        workers: list of workers for this job
        jobID:   which job ID

        retval: job info


if expDirectory is not None:<EOL><INDENT>descriptionPyPath = os.path.join(expDirectory, "<STR_LIT>")<EOL>permutationsPyPath = os.path.join(expDirectory, "<STR_LIT>")<EOL>permutationsPyContents = open(permutationsPyPath, '<STR_LIT:r>').read()<EOL>descriptionPyContents = open(descriptionPyPath, '<STR_LIT:r>').read()<EOL>jobParams = {'<STR_LIT>' : generatePersistentJobGUID(),<EOL>'<STR_LIT>': permutationsPyContents,<EOL>'<STR_LIT>': descriptionPyContents,<EOL>'<STR_LIT>': maxModels,<EOL>'<STR_LIT>': hsImp}<EOL>if predictionCacheMaxRecords is not None:<EOL><INDENT>jobParams['<STR_LIT>'] = predictionCacheMaxRecords<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if dataPath is None:<EOL><INDENT>dataPath = resource_filename("<STR_LIT>",<EOL>os.path.join("<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>"))<EOL><DEDENT>streamDef = dict(<EOL>version = <NUM_LIT:1>,<EOL>info = "<STR_LIT>",<EOL>streams = [<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info=dataPath,<EOL>columns=["<STR_LIT:*>"],<EOL>first_record=<NUM_LIT:0>,<EOL>last_record=maxRecords),<EOL>],<EOL>)<EOL>expDesc = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:string>"<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:float>",<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": <NUM_LIT:200>,<EOL>},<EOL>],<EOL>"<STR_LIT>": maxRecords,<EOL>"<STR_LIT>": {<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>'<STR_LIT>': <NUM_LIT:8>,<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>},<EOL>}<EOL>jobParams = {<EOL>"<STR_LIT>": generatePersistentJobGUID(),<EOL>"<STR_LIT:description>":expDesc,<EOL>"<STR_LIT>": maxModels,<EOL>"<STR_LIT>": hsImp,<EOL>}<EOL>if predictionCacheMaxRecords is not None:<EOL><INDENT>jobParams['<STR_LIT>'] = predictionCacheMaxRecords<EOL><DEDENT><DEDENT>return jobParams<EOL>

This method generates a canned Hypersearch Job Params structure based
on some high level options

Parameters:
---------------------------------------------------------------------
predictionCacheMaxRecords:
               If specified, determine the maximum number of records in
               the prediction cache.
dataPath:      When expDirectory is not specified, this is the data file
               to be used for the operation. If this value is not specified,
               it will use the /extra/qa/hotgym/qa_hotgym.csv.


def _runPermutationsLocal(self, jobParams, loggingLevel=logging.INFO,<EOL>env=None, waitForCompletion=True,<EOL>continueJobId=None, ignoreErrModels=False):

print()<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>if env is not None:<EOL><INDENT>saveEnvState = copy.deepcopy(os.environ)<EOL>os.environ.update(env)<EOL><DEDENT>cjDAO = ClientJobsDAO.get()<EOL>if continueJobId is None:<EOL><INDENT>jobID = cjDAO.jobInsert(client='<STR_LIT:test>', cmdLine='<STR_LIT>',<EOL>params=json.dumps(jobParams),<EOL>alreadyRunning=True, minimumWorkers=<NUM_LIT:1>, maximumWorkers=<NUM_LIT:1>,<EOL>jobType = cjDAO.JOB_TYPE_HS)<EOL><DEDENT>else:<EOL><INDENT>jobID = continueJobId<EOL><DEDENT>args = ['<STR_LIT>', '<STR_LIT>' % (jobID),<EOL>'<STR_LIT>' % (loggingLevel)]<EOL>if continueJobId is None:<EOL><INDENT>args.append('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>hypersearch_worker.main(args)<EOL><DEDENT>except SystemExit:<EOL><INDENT>pass<EOL><DEDENT>except:<EOL><INDENT>raise<EOL><DEDENT>if env is not None:<EOL><INDENT>os.environ = saveEnvState<EOL><DEDENT>models = cjDAO.modelsGetUpdateCounters(jobID)<EOL>modelIDs = [model.modelId for model in models]<EOL>if len(modelIDs) > <NUM_LIT:0>:<EOL><INDENT>results = cjDAO.modelsGetResultAndStatus(modelIDs)<EOL><DEDENT>else:<EOL><INDENT>results = []<EOL><DEDENT>metricResults = []<EOL>for result in results:<EOL><INDENT>if result.results is not None:<EOL><INDENT>metricResults.append(list(json.loads(result.results)[<NUM_LIT:1>].values())[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>metricResults.append(None)<EOL><DEDENT>if not ignoreErrModels:<EOL><INDENT>self.assertNotEqual(result.completionReason, cjDAO.CMPL_REASON_ERROR,<EOL>"<STR_LIT>" % (result.completionMsg))<EOL><DEDENT><DEDENT>jobInfo = cjDAO.jobInfo(jobID)<EOL>return (jobID, jobInfo, results, metricResults)<EOL>

This runs permutations on the given experiment using just 1 worker
        in the current process

        Parameters:
        -------------------------------------------------------------------
        jobParams:        filled in job params for a hypersearch
        loggingLevel:    logging level to use in the Hypersearch worker
        env:             if not None, this is a dict of environment variables
                            that should be sent to each worker process. These can
                            aid in re-using the same description/permutations file
                            for different tests.
        waitForCompletion: If True, wait for job to complete before returning
                           If False, then return resultsInfoForAllModels and
                           metricResults will be None
        continueJobId:    If not None, then this is the JobId of a job we want
                          to continue working on with another worker.
        ignoreErrModels:  If true, ignore erred models
        retval:          (jobId, jobInfo, resultsInfoForAllModels, metricResults)


print()<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>if env is not None and len(env) > <NUM_LIT:0>:<EOL><INDENT>envItems = []<EOL>for (key, value) in env.items():<EOL><INDENT>if (sys.platform.startswith('<STR_LIT>')):<EOL><INDENT>envItems.append("<STR_LIT>" % (key, value))<EOL><DEDENT>else:<EOL><INDENT>envItems.append("<STR_LIT>" % (key, value))<EOL><DEDENT><DEDENT>if (sys.platform.startswith('<STR_LIT>')):<EOL><INDENT>envStr = "<STR_LIT>" % ('<STR_LIT>'.join(envItems))<EOL><DEDENT>else:<EOL><INDENT>envStr = "<STR_LIT>" % ('<STR_LIT:;>'.join(envItems))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>envStr = '<STR_LIT>'<EOL><DEDENT>cmdLine = '<STR_LIT>''<STR_LIT>'% (envStr, loggingLevel)<EOL>cjDAO = ClientJobsDAO.get()<EOL>jobID = cjDAO.jobInsert(client='<STR_LIT:test>', cmdLine=cmdLine,<EOL>params=json.dumps(jobParams),<EOL>minimumWorkers=<NUM_LIT:1>, maximumWorkers=maxNumWorkers,<EOL>jobType = cjDAO.JOB_TYPE_HS)<EOL>workerCmdLine = '<STR_LIT>''<STR_LIT>'% (envStr, jobID, loggingLevel)<EOL>workers = self._launchWorkers(cmdLine=workerCmdLine, numWorkers=maxNumWorkers)<EOL>print("<STR_LIT>" % (jobID))<EOL>print("<STR_LIT>" % (maxNumWorkers),cmdLine)<EOL>if not waitForCompletion:<EOL><INDENT>return (jobID, None, None)<EOL><DEDENT>if timeoutSec is None:<EOL><INDENT>timeout=DEFAULT_JOB_TIMEOUT_SEC<EOL><DEDENT>else:<EOL><INDENT>timeout=timeoutSec<EOL><DEDENT>startTime = time.time()<EOL>lastUpdate = time.time()<EOL>lastCompleted = <NUM_LIT:0><EOL>lastCompletedWithError = <NUM_LIT:0><EOL>lastCompletedAsOrphan = <NUM_LIT:0><EOL>lastStarted = <NUM_LIT:0><EOL>lastJobStatus = "<STR_LIT>"<EOL>lastJobResults = None<EOL>lastActiveSwarms = None<EOL>lastEngStatus = None<EOL>modelIDs = []<EOL>print("<STR_LIT>" % ("<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>"))<EOL>print("<STR_LIT>")<EOL>while (lastJobStatus != ClientJobsDAO.STATUS_COMPLETED)and (time.time() - lastUpdate < timeout):<EOL><INDENT>printUpdate = False<EOL>if g_myEnv.options.verbosity == <NUM_LIT:0>:<EOL><INDENT>time.sleep(<NUM_LIT:0.5>)<EOL><DEDENT>jobInfo = self._getJobInfo(cjDAO, workers, jobID)<EOL>if jobInfo.status != lastJobStatus:<EOL><INDENT>if jobInfo.status == ClientJobsDAO.STATUS_RUNNINGand lastJobStatus != ClientJobsDAO.STATUS_RUNNING:<EOL><INDENT>print("<STR_LIT>"% (jobInfo.jobId))<EOL><DEDENT>lastJobStatus = jobInfo.status<EOL>printUpdate = True<EOL><DEDENT>if g_myEnv.options.verbosity >= <NUM_LIT:1>:<EOL><INDENT>if jobInfo.engWorkerState is not None:<EOL><INDENT>activeSwarms = json.loads(jobInfo.engWorkerState)['<STR_LIT>']<EOL>if activeSwarms != lastActiveSwarms:<EOL><INDENT>print("<STR_LIT>", '<STR_LIT>'.join(activeSwarms))<EOL>lastActiveSwarms = activeSwarms<EOL>print()<EOL><DEDENT><DEDENT>if jobInfo.results != lastJobResults:<EOL><INDENT>print("<STR_LIT>", jobInfo.results, "<STR_LIT>")<EOL>lastJobResults = jobInfo.results<EOL><DEDENT>if jobInfo.engStatus != lastEngStatus:<EOL><INDENT>print('<STR_LIT>' % jobInfo.engStatus)<EOL>print()<EOL>lastEngStatus = jobInfo.engStatus<EOL><DEDENT><DEDENT>modelCounters = cjDAO.modelsGetUpdateCounters(jobID)<EOL>if len(modelCounters) != lastStarted:<EOL><INDENT>modelIDs = [x.modelId for x in modelCounters]<EOL>lastStarted = len(modelCounters)<EOL>printUpdate = True<EOL><DEDENT>if len(modelIDs) > <NUM_LIT:0>:<EOL><INDENT>completed = <NUM_LIT:0><EOL>completedWithError = <NUM_LIT:0><EOL>completedAsOrphan = <NUM_LIT:0><EOL>infos = cjDAO.modelsGetResultAndStatus(modelIDs)<EOL>for info in infos:<EOL><INDENT>if info.status == ClientJobsDAO.STATUS_COMPLETED:<EOL><INDENT>completed += <NUM_LIT:1><EOL>if info.completionReason == ClientJobsDAO.CMPL_REASON_ERROR:<EOL><INDENT>completedWithError += <NUM_LIT:1><EOL><DEDENT>if info.completionReason == ClientJobsDAO.CMPL_REASON_ORPHAN:<EOL><INDENT>completedAsOrphan += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>if completed != lastCompletedor completedWithError != lastCompletedWithErroror completedAsOrphan != lastCompletedAsOrphan:<EOL><INDENT>lastCompleted = completed<EOL>lastCompletedWithError = completedWithError<EOL>lastCompletedAsOrphan = completedAsOrphan<EOL>printUpdate = True<EOL><DEDENT><DEDENT>if printUpdate:<EOL><INDENT>lastUpdate = time.time()<EOL>if g_myEnv.options.verbosity >= <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>", end='<STR_LIT:U+0020>')<EOL><DEDENT>print("<STR_LIT>" % (lastJobStatus, lastStarted,<EOL>lastCompleted,<EOL>lastCompletedWithError,<EOL>lastCompletedAsOrphan))<EOL><DEDENT><DEDENT>print("<STR_LIT>" % (lastJobStatus, lastStarted,<EOL>lastCompleted,<EOL>lastCompletedWithError,<EOL>lastCompletedAsOrphan))<EOL>jobInfo = self._getJobInfo(cjDAO, workers, jobID)<EOL>if not ignoreErrModels:<EOL><INDENT>self.assertEqual (jobInfo.completionReason,<EOL>ClientJobsDAO.CMPL_REASON_SUCCESS)<EOL><DEDENT>models = cjDAO.modelsGetUpdateCounters(jobID)<EOL>modelIDs = [model.modelId for model in models]<EOL>if len(modelIDs) > <NUM_LIT:0>:<EOL><INDENT>results = cjDAO.modelsGetResultAndStatus(modelIDs)<EOL><DEDENT>else:<EOL><INDENT>results = []<EOL><DEDENT>metricResults = []<EOL>for result in results:<EOL><INDENT>if result.results is not None:<EOL><INDENT>metricResults.append(list(json.loads(result.results)[<NUM_LIT:1>].values())[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>metricResults.append(None)<EOL><DEDENT>if not ignoreErrModels:<EOL><INDENT>self.assertNotEqual(result.completionReason, cjDAO.CMPL_REASON_ERROR,<EOL>"<STR_LIT>" % (result.completionMsg))<EOL><DEDENT><DEDENT>return (jobID, jobInfo, results, metricResults)<EOL>

Given a prepared, filled in jobParams for a hypersearch, this starts
        the job, waits for it to complete, and returns the results for all
        models.

        Parameters:
        -------------------------------------------------------------------
        jobParams:        filled in job params for a hypersearch
        loggingLevel:    logging level to use in the Hypersearch worker
        maxNumWorkers:    max # of worker processes to use
        env:             if not None, this is a dict of environment variables
                            that should be sent to each worker process. These can
                            aid in re-using the same description/permutations file
                            for different tests.
        waitForCompletion: If True, wait for job to complete before returning
                           If False, then return resultsInfoForAllModels and
                           metricResults will be None
        ignoreErrModels:  If true, ignore erred models
        retval:          (jobID, jobInfo, resultsInfoForAllModels, metricResults)


def runPermutations(self, expDirectory, hsImp='<STR_LIT>', maxModels=<NUM_LIT:2>,<EOL>maxNumWorkers=<NUM_LIT:4>, loggingLevel=logging.INFO,<EOL>onCluster=False, env=None, waitForCompletion=True,<EOL>continueJobId=None, dataPath=None, maxRecords=None,<EOL>timeoutSec=None, ignoreErrModels=False,<EOL>predictionCacheMaxRecords=None, **kwargs):

<EOL>if env is None:<EOL><INDENT>env = dict()<EOL><DEDENT>self._setDataPath(env)<EOL>jobParams = self._generateHSJobParams(expDirectory=expDirectory,<EOL>hsImp=hsImp, maxModels=maxModels,<EOL>maxRecords=maxRecords,<EOL>dataPath=dataPath,<EOL>predictionCacheMaxRecords=predictionCacheMaxRecords)<EOL>jobParams.update(kwargs)<EOL>if onCluster:<EOL><INDENT>(jobID, jobInfo, resultInfos, metricResults)=  self._runPermutationsCluster(jobParams=jobParams,<EOL>loggingLevel=loggingLevel,<EOL>maxNumWorkers=maxNumWorkers,<EOL>env=env,<EOL>waitForCompletion=waitForCompletion,<EOL>ignoreErrModels=ignoreErrModels,<EOL>timeoutSec=timeoutSec)<EOL><DEDENT>else:<EOL><INDENT>(jobID, jobInfo, resultInfos, metricResults)= self._runPermutationsLocal(jobParams=jobParams,<EOL>loggingLevel=loggingLevel,<EOL>env=env,<EOL>waitForCompletion=waitForCompletion,<EOL>continueJobId=continueJobId,<EOL>ignoreErrModels=ignoreErrModels)<EOL><DEDENT>if not waitForCompletion:<EOL><INDENT>return (jobID, jobInfo, resultInfos, metricResults, None)<EOL><DEDENT>print("<STR_LIT>")<EOL>print("<STR_LIT>" % (jobInfo.completionReason))<EOL>print("<STR_LIT>" % (jobInfo.workerCompletionReason))<EOL>print("<STR_LIT>" % (jobInfo.workerCompletionMsg))<EOL>if jobInfo.engWorkerState is not None:<EOL><INDENT>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>pprint.pprint(json.loads(jobInfo.engWorkerState))<EOL><DEDENT>minErrScore=None<EOL>metricAmts = []<EOL>for result in metricResults:<EOL><INDENT>if result is None:<EOL><INDENT>metricAmts.append(numpy.inf)<EOL><DEDENT>else:<EOL><INDENT>metricAmts.append(result)<EOL><DEDENT><DEDENT>metricAmts = numpy.array(metricAmts)<EOL>if len(metricAmts) > <NUM_LIT:0>:<EOL><INDENT>minErrScore = metricAmts.min()<EOL>minModelID = resultInfos[metricAmts.argmin()].modelId<EOL>cjDAO = ClientJobsDAO.get()<EOL>modelParams = cjDAO.modelsGetParams([minModelID])[<NUM_LIT:0>].params<EOL>print("<STR_LIT>"% (pprint.pformat(json.loads(modelParams))))<EOL>print("<STR_LIT>" % (minErrScore))<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return (jobID, jobInfo, resultInfos, metricResults, minErrScore)<EOL>

This runs permutations on the given experiment using just 1 worker

        Parameters:
        -------------------------------------------------------------------
        expDirectory:    directory containing the description.py and permutations.py
        hsImp:           which implementation of Hypersearch to use
        maxModels:       max # of models to generate
        maxNumWorkers:   max # of workers to use, N/A if onCluster is False
        loggingLevel:    logging level to use in the Hypersearch worker
        onCluster:       if True, run on the Hadoop cluster
        env:             if not None, this is a dict of environment variables
                            that should be sent to each worker process. These can
                            aid in re-using the same description/permutations file
                            for different tests.
        waitForCompletion: If True, wait for job to complete before returning
                           If False, then return resultsInfoForAllModels and
                           metricResults will be None
        continueJobId:    If not None, then this is the JobId of a job we want
                          to continue working on with another worker.
        ignoreErrModels:  If true, ignore erred models
        maxRecords:       This value is passed to the function, _generateHSJobParams(),
                          to represent the maximum number of records to generate for
                          the operation.
        dataPath:         This value is passed to the function, _generateHSJobParams(),
                          which points to the data file for the operation.
        predictionCacheMaxRecords:
                          If specified, determine the maximum number of records in
                          the prediction cache.

        retval:          (jobID, jobInfo, resultsInfoForAllModels, metricResults,
                            minErrScore)


helpString ="""<STR_LIT>"""<EOL>allTests = _getTestList()<EOL>for test in allTests:<EOL><INDENT>helpString += "<STR_LIT>" % (test)<EOL><DEDENT>parser = OptionParser(helpString,conflict_handler="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", default=<NUM_LIT:0>, type="<STR_LIT:int>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", action="<STR_LIT:store>", type="<STR_LIT:int>",<EOL>default=logging.INFO,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", dest="<STR_LIT>", default=<NUM_LIT:2>, type='<STR_LIT:int>',<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL>return parser.parse_args(args=cls.args)<EOL>

Parse our command-line args/options and strip them from sys.argv
Returns the tuple (parsedOptions, remainingArgs)


return cls._processArgs()[<NUM_LIT:0>]<EOL>

Returns the test arguments after parsing


return cls._processArgs()[<NUM_LIT:1>]<EOL>

Consumes the test arguments and returns the remaining arguments meant
        for unittest.man


newcounter = <NUM_LIT:0><EOL>for job in self.__procs:<EOL><INDENT>if job.is_alive():<EOL><INDENT>newcounter+=<NUM_LIT:1><EOL><DEDENT><DEDENT>self.__numRunningProcs = newcounter<EOL>return newcounter<EOL>

Function that iterates through the running Processes
        and counts the number of processes that are currently alive.
        Sets numRunningProcs to this count


print("<STR_LIT>")<EOL>for proc in self.__procs:<EOL><INDENT>if not proc.is_alive():<EOL><INDENT>proc.terminate()<EOL><DEDENT><DEDENT>print("<STR_LIT>")<EOL>

Function that cancels all the jobs in the
        process queue.


jobsrunning = self.__numRunningProcs<EOL>if(maxJobs > <NUM_LIT:1>):<EOL><INDENT>jobsindx = <NUM_LIT:0><EOL>while(jobsindx<len(self.testQ) or jobsrunning><NUM_LIT:0>):<EOL><INDENT>if(jobsindx<len(self.testQ) and jobsrunning<maxJobs):<EOL><INDENT>curJob = self.testQ[jobsindx]<EOL>p = Process(target = curJob[<NUM_LIT:0>], args = curJob[<NUM_LIT:1>])<EOL>p.start()<EOL>self.__procs.append(p)<EOL>jobsindx+=<NUM_LIT:1><EOL><DEDENT>if jobsrunning >= maxJobs:<EOL><INDENT>time.sleep(<NUM_LIT:30>)<EOL>print ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>elif jobsindx == len(self.testQ):<EOL><INDENT>time.sleep(<NUM_LIT:30>)<EOL>print("<STR_LIT>")<EOL><DEDENT>jobsrunning = self.__updateProcessCounter()<EOL>for proc in self.__procs:<EOL><INDENT>if proc.exitcode == <NUM_LIT:1>:<EOL><INDENT>self.cancelJobs()<EOL>assert False, ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>while True:<EOL><INDENT>result = self.__resultQ.get(True, <NUM_LIT:5>)<EOL>self.assertBenchmarks(result)<EOL><DEDENT><DEDENT>except Empty:<EOL><INDENT>pass<EOL><DEDENT>

Function that launched Hypersearch benchmark jobs.
        Runs jobs contained in self.testQ, until maxJobs are running
        in parallel at which point it waits until some jobs finish.


ret = []<EOL>if self.maxBranchings is None:<EOL><INDENT>self.maxBranchings = [None]<EOL><DEDENT>else:<EOL><INDENT>self.maxBranchings = self.maxBranchings.split('<STR_LIT:U+002C>')<EOL><DEDENT>if self.maxParticles is None:<EOL><INDENT>self.maxParticles = [None]<EOL><DEDENT>else:<EOL><INDENT>self.maxParticles = self.maxParticles.split("<STR_LIT:U+002C>")<EOL><DEDENT>for branch in self.maxBranchings:<EOL><INDENT>for part in self.maxParticles:<EOL><INDENT>curdict = dict()<EOL>if not branch is None:<EOL><INDENT>curdict[self.BRANCHING_PROP] = branch<EOL><DEDENT>if not part is None:<EOL><INDENT>curdict[self.PARTICLE_PROP] = part<EOL><DEDENT>ret+=[curdict]<EOL><DEDENT><DEDENT>return ret<EOL>

Setup up a dict of branchings and particles


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>'],)<EOL>],<EOL>aggregation={<EOL>'<STR_LIT>' : <NUM_LIT:1>,<EOL>'<STR_LIT>' : [<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>]<EOL>},<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>"<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:float>",<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:string>",<EOL>},<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>

Try running a basic experiment and permutations.


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>","<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>']),<EOL>],<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:float>",<EOL>"<STR_LIT>":  -<NUM_LIT:1.0>,<EOL>"<STR_LIT>":  <NUM_LIT:1.0>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:float>",<EOL>"<STR_LIT>":  <NUM_LIT:0.0>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>

Try running a basic experiment and permutations


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>","<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>'],),<EOL>],<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>","<STR_LIT>","<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>']),<EOL>],<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>}<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>']),<EOL>],<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>}<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>","<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>']),<EOL>],<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:string>",<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:string>",<EOL>}<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>","<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>']),<EOL>],<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":  -<NUM_LIT:10>,<EOL>"<STR_LIT>":  <NUM_LIT>,<EOL>}<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT:value>"],<EOL>last_record=self.splits['<STR_LIT>'],),<EOL>],<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT:value>"<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT:value>",<EOL>"<STR_LIT>": "<STR_LIT:int>",<EOL>"<STR_LIT>":True,<EOL>},<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>


<EOL>dataPath = os.path.join(self.datadir, "<STR_LIT>", "<STR_LIT>")<EOL>streamDef = dict(<EOL>version=<NUM_LIT:1>,<EOL>info="<STR_LIT>",<EOL>streams=[<EOL>dict(source="<STR_LIT>" % (dataPath),<EOL>info="<STR_LIT>",<EOL>columns=["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>last_record=self.splits['<STR_LIT>'],)<EOL>],<EOL>aggregation={<EOL>'<STR_LIT>' : <NUM_LIT:1>,<EOL>'<STR_LIT>' : [<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>]<EOL>},<EOL>)<EOL>expDesc = OPFBenchmarkRunner.EXP_COMMON.copy()<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL>expDesc["<STR_LIT>"]["<STR_LIT>"] = [<NUM_LIT:0>]<EOL>expDesc.update({<EOL>"<STR_LIT>": streamDef,<EOL>"<STR_LIT>": [<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>"<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:float>",<EOL>"<STR_LIT>":  <NUM_LIT:0>,<EOL>"<STR_LIT>":  <NUM_LIT:100>,<EOL>},<EOL>{ "<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:string>",<EOL>},<EOL>],<EOL>"<STR_LIT>": self.__recordsToProcess,<EOL>})<EOL>expdir = os.path.join(self.outdir,  "<STR_LIT>")<EOL>self.generateModules(expDesc,  expdir)<EOL>self.descriptions["<STR_LIT>"]=(expdir, expDesc)<EOL>return expdir<EOL>

The HotGym dataset, only the first gym, solved using spatial
        classification. This model learns the association between the date/time
        stamp and the consumption - the model does not get consumption fed in at
        the bottom.


def generateModules(self, expDesc, outdir):

<EOL>jobParams = dict(<EOL>desription=expDesc<EOL>)<EOL>shutil.rmtree(outdir, ignore_errors=True)<EOL>outdirv2term = os.path.join(outdir, "<STR_LIT>", "<STR_LIT>")<EOL>outdirv2noterm = os.path.join(outdir, "<STR_LIT>", "<STR_LIT>")<EOL>outdirdef = os.path.join(outdir, "<STR_LIT>", "<STR_LIT>")<EOL>if self.__doV2Term:<EOL><INDENT>experiment_generator.expGenerator(args)<EOL><DEDENT>args = [<EOL>"<STR_LIT>" % (json.dumps(expDesc)),<EOL>"<STR_LIT>",<EOL>"<STR_LIT>" % (outdirv2noterm)<EOL>]<EOL>if self.__doV2noTerm:<EOL><INDENT>experiment_generator.expGenerator(args)<EOL><DEDENT>args = [<EOL>"<STR_LIT>" % (json.dumps(expDesc)),<EOL>"<STR_LIT>",<EOL>"<STR_LIT>" % (outdirdef)<EOL>]<EOL>if self.__doClusterDef:<EOL><INDENT>experiment_generator.expGenerator(args)<EOL><DEDENT>

This calls ExpGenerator to generate a base description file and
        permutations file from expDesc.

        Parameters:
        -------------------------------------------------------------------
        expDesc:       Experiment description dict
        outDir:        Which output directory to use


encoder = MultiEncoder()<EOL>encoder.addMultipleEncoders({<EOL>"<STR_LIT>": {"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>"<STR_LIT:name>": "<STR_LIT>",<EOL>"<STR_LIT>": <NUM_LIT:0.0>,<EOL>"<STR_LIT>": <NUM_LIT>,<EOL>"<STR_LIT>": True,<EOL>"<STR_LIT:w>": <NUM_LIT>,<EOL>"<STR_LIT:n>": <NUM_LIT>},<EOL>"<STR_LIT>": {"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>"<STR_LIT:name>": "<STR_LIT>",<EOL>"<STR_LIT>": (<NUM_LIT>, <NUM_LIT>)}<EOL>})<EOL>return encoder<EOL>

Creates and returns a #MultiEncoder including a ScalarEncoder for
energy consumption and a DateEncoder for the time of the day.

@see nupic/encoders/__init__.py for type to file-name mapping
@see nupic/encoders for encoder source files


def createRecordSensor(network, name, dataSource):

<EOL>regionType = "<STR_LIT>"<EOL>regionParams = json.dumps({"<STR_LIT>": _VERBOSITY})<EOL>network.addRegion(name, regionType, regionParams)<EOL>sensorRegion = network.regions[name].getSelf()<EOL>sensorRegion.encoder = createEncoder()<EOL>network.regions[name].setParameter("<STR_LIT>", "<STR_LIT>")<EOL>sensorRegion.dataSource = dataSource<EOL>return sensorRegion<EOL>

Creates a RecordSensor region that allows us to specify a file record
stream as the input source.


network = Network()<EOL>sensor = createRecordSensor(network, name=_RECORD_SENSOR,<EOL>dataSource=dataSource)<EOL>createSpatialPooler(network, name=_L1_SPATIAL_POOLER,<EOL>inputWidth=sensor.encoder.getWidth())<EOL>linkType = "<STR_LIT>"<EOL>linkParams = "<STR_LIT>"<EOL>network.link(_RECORD_SENSOR, _L1_SPATIAL_POOLER, linkType, linkParams)<EOL>l1temporalMemory = createTemporalMemory(network, _L1_TEMPORAL_MEMORY)<EOL>network.link(_L1_SPATIAL_POOLER, _L1_TEMPORAL_MEMORY, linkType, linkParams)<EOL>classifierParams = {  <EOL>'<STR_LIT>': <NUM_LIT>,<EOL>'<STR_LIT>': '<STR_LIT:1>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': <NUM_LIT:0>}<EOL>l1Classifier = network.addRegion(_L1_CLASSIFIER, "<STR_LIT>",<EOL>json.dumps(classifierParams))<EOL>l1Classifier.setParameter('<STR_LIT>', True)<EOL>l1Classifier.setParameter('<STR_LIT>', True)<EOL>network.link(_L1_TEMPORAL_MEMORY, _L1_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link(_RECORD_SENSOR, _L1_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link(_RECORD_SENSOR, _L1_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link(_RECORD_SENSOR, _L1_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>l2inputWidth = l1temporalMemory.getSelf().getOutputElementCount("<STR_LIT>")<EOL>createSpatialPooler(network, name=_L2_SPATIAL_POOLER, inputWidth=l2inputWidth)<EOL>network.link(_L1_TEMPORAL_MEMORY, _L2_SPATIAL_POOLER, linkType, linkParams)<EOL>createTemporalMemory(network, _L2_TEMPORAL_MEMORY)<EOL>network.link(_L2_SPATIAL_POOLER, _L2_TEMPORAL_MEMORY, linkType, linkParams)<EOL>l2Classifier = network.addRegion(_L2_CLASSIFIER, "<STR_LIT>",<EOL>json.dumps(classifierParams))<EOL>l2Classifier.setParameter('<STR_LIT>', True)<EOL>l2Classifier.setParameter('<STR_LIT>', True)<EOL>network.link(_L2_TEMPORAL_MEMORY, _L2_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link(_RECORD_SENSOR, _L2_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link(_RECORD_SENSOR, _L2_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link(_RECORD_SENSOR, _L2_CLASSIFIER, linkType, linkParams,<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>return network<EOL>

Creates and returns a new Network with a sensor region reading data from
    'dataSource'. There are two hierarchical levels, each with one SP and one TM.
    @param dataSource - A RecordStream containing the input data
    @returns a Network ready to run


def runNetwork(network, numRecords, writer):

sensorRegion = network.regions[_RECORD_SENSOR]<EOL>l1SpRegion = network.regions[_L1_SPATIAL_POOLER]<EOL>l1TpRegion = network.regions[_L1_TEMPORAL_MEMORY]<EOL>l1Classifier = network.regions[_L1_CLASSIFIER]<EOL>l2SpRegion = network.regions[_L2_SPATIAL_POOLER]<EOL>l2TpRegion = network.regions[_L2_TEMPORAL_MEMORY]<EOL>l2Classifier = network.regions[_L2_CLASSIFIER]<EOL>l1PreviousPredictedColumns = []<EOL>l2PreviousPredictedColumns = []<EOL>l1PreviousPrediction = None<EOL>l2PreviousPrediction = None<EOL>l1ErrorSum = <NUM_LIT:0.0><EOL>l2ErrorSum = <NUM_LIT:0.0><EOL>for record in range(numRecords):<EOL><INDENT>network.run(<NUM_LIT:1>)<EOL>actual = float(sensorRegion.getOutputData("<STR_LIT>")[<NUM_LIT:0>])<EOL>l1Predictions = l1Classifier.getOutputData("<STR_LIT>")<EOL>l1Probabilities = l1Classifier.getOutputData("<STR_LIT>")<EOL>l1Prediction = l1Predictions[l1Probabilities.argmax()]<EOL>if l1PreviousPrediction is not None:<EOL><INDENT>l1ErrorSum += math.fabs(l1PreviousPrediction - actual)<EOL><DEDENT>l1PreviousPrediction = l1Prediction<EOL>l2Predictions = l2Classifier.getOutputData("<STR_LIT>")<EOL>l2Probabilities = l2Classifier.getOutputData("<STR_LIT>")<EOL>l2Prediction = l2Predictions[l2Probabilities.argmax()]<EOL>if l2PreviousPrediction is not None:<EOL><INDENT>l2ErrorSum += math.fabs(l2PreviousPrediction - actual)<EOL><DEDENT>l2PreviousPrediction = l2Prediction<EOL>l1AnomalyScore = l1TpRegion.getOutputData("<STR_LIT>")[<NUM_LIT:0>]<EOL>l2AnomalyScore = l2TpRegion.getOutputData("<STR_LIT>")[<NUM_LIT:0>]<EOL>writer.writerow((record, actual, l1PreviousPrediction, l1AnomalyScore, l2PreviousPrediction, l2AnomalyScore))<EOL>l1PredictedColumns = l1TpRegion.getOutputData("<STR_LIT>").nonzero()[<NUM_LIT:0>]<EOL>l1PreviousPredictedColumns = copy.deepcopy(l1PredictedColumns)<EOL>l2PredictedColumns = l2TpRegion.getOutputData("<STR_LIT>").nonzero()[<NUM_LIT:0>]<EOL>l2PreviousPredictedColumns = copy.deepcopy(l2PredictedColumns)<EOL><DEDENT>if numRecords > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>" % (l1ErrorSum / (numRecords - <NUM_LIT:1>)))<EOL>print("<STR_LIT>" % (l2ErrorSum / (numRecords - <NUM_LIT:1>)))<EOL><DEDENT>

Runs specified Network writing the ensuing anomaly
scores to writer.

@param network: The Network instance to be run
@param writer: A csv.writer used to write to output file.


consumption_encoder = ScalarEncoder(<NUM_LIT>, <NUM_LIT:0.0>, <NUM_LIT>, n=<NUM_LIT:50>, name="<STR_LIT>",<EOL>clipInput=True)<EOL>time_encoder = DateEncoder(timeOfDay=(<NUM_LIT>, <NUM_LIT>), name="<STR_LIT>")<EOL>encoder = MultiEncoder()<EOL>encoder.addEncoder("<STR_LIT>", consumption_encoder)<EOL>encoder.addEncoder("<STR_LIT>", time_encoder)<EOL>return encoder<EOL>

Create the encoder instance for our test and return it.


network = Network()<EOL>network.addRegion("<STR_LIT>", "<STR_LIT>",<EOL>json.dumps({"<STR_LIT>": _VERBOSITY}))<EOL>sensor = network.regions["<STR_LIT>"].getSelf()<EOL>sensor.encoder = createEncoder()<EOL>sensor.dataSource = dataSource<EOL>SP_PARAMS["<STR_LIT>"] = sensor.encoder.getWidth()<EOL>network.addRegion("<STR_LIT>", "<STR_LIT>", json.dumps(SP_PARAMS))<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.addRegion("<STR_LIT>", "<STR_LIT>",<EOL>json.dumps(TM_PARAMS))<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.addRegion("<STR_LIT>", "<STR_LIT>",<EOL>json.dumps({}))<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>network.link("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>srcOutput="<STR_LIT>", destInput="<STR_LIT>")<EOL>spatialPoolerRegion = network.regions["<STR_LIT>"]<EOL>spatialPoolerRegion.setParameter("<STR_LIT>", True)<EOL>spatialPoolerRegion.setParameter("<STR_LIT>", False)<EOL>temporalPoolerRegion = network.regions["<STR_LIT>"]<EOL>temporalPoolerRegion.setParameter("<STR_LIT>", True)<EOL>temporalPoolerRegion.setParameter("<STR_LIT>", True)<EOL>temporalPoolerRegion.setParameter("<STR_LIT>", True)<EOL>temporalPoolerRegion.setParameter("<STR_LIT>", True)<EOL>return network<EOL>

Create the Network instance.

    The network has a sensor region reading data from `dataSource` and passing
    the encoded representation to an SPRegion. The SPRegion output is passed to
    a TMRegion.

    :param dataSource: a RecordStream instance to get data from
    :returns: a Network instance ready to run


sensorRegion = network.regions["<STR_LIT>"]<EOL>spatialPoolerRegion = network.regions["<STR_LIT>"]<EOL>temporalPoolerRegion = network.regions["<STR_LIT>"]<EOL>anomalyLikelihoodRegion = network.regions["<STR_LIT>"]<EOL>prevPredictedColumns = []<EOL>for i in range(_NUM_RECORDS):<EOL><INDENT>network.run(<NUM_LIT:1>)<EOL>consumption = sensorRegion.getOutputData("<STR_LIT>")[<NUM_LIT:0>]<EOL>anomalyScore = temporalPoolerRegion.getOutputData("<STR_LIT>")[<NUM_LIT:0>]<EOL>anomalyLikelihood = anomalyLikelihoodRegion.getOutputData("<STR_LIT>")[<NUM_LIT:0>]<EOL>writer.writerow((i, consumption, anomalyScore, anomalyLikelihood))<EOL><DEDENT>

Run the network and write output to writer.

    :param network: a Network instance to run
    :param writer: a csv.writer instance to write output to


outputs["<STR_LIT>"][:] = inputs["<STR_LIT>"]<EOL>

Run one iteration of IdentityRegion's compute