def _generateExperiment(options, outputDirPath, hsVersion,<EOL>claDescriptionTemplateFile):

_gExperimentDescriptionSchema = _getExperimentDescriptionSchema()<EOL>try:<EOL><INDENT>validictory.validate(options, _gExperimentDescriptionSchema)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise _InvalidCommandArgException(<EOL>("<STR_LIT>" +"<STR_LIT>") % (str(e), pprint.pformat(options)))<EOL><DEDENT>streamSchema = json.load(resource_stream(jsonschema.__name__,<EOL>'<STR_LIT>'))<EOL>try:<EOL><INDENT>validictory.validate(options['<STR_LIT>'], streamSchema)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise _InvalidCommandArgException(<EOL>("<STR_LIT>" +"<STR_LIT>") % (str(e), json.dumps(options)))<EOL><DEDENT>_handleJAVAParameters(options)<EOL>for propertyName in _gExperimentDescriptionSchema['<STR_LIT>']:<EOL><INDENT>_getPropertyValue(_gExperimentDescriptionSchema, propertyName, options)<EOL><DEDENT>if options['<STR_LIT>'] is not None:<EOL><INDENT>infArgs = _gExperimentDescriptionSchema['<STR_LIT>']['<STR_LIT>']<EOL>for schema in infArgs['<STR_LIT:type>']:<EOL><INDENT>if isinstance(schema, dict):<EOL><INDENT>for propertyName in schema['<STR_LIT>']:<EOL><INDENT>_getPropertyValue(schema, propertyName, options['<STR_LIT>'])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if options['<STR_LIT>'] is not None:<EOL><INDENT>anomalyArgs = _gExperimentDescriptionSchema['<STR_LIT>']['<STR_LIT>']<EOL>for schema in anomalyArgs['<STR_LIT:type>']:<EOL><INDENT>if isinstance(schema, dict):<EOL><INDENT>for propertyName in schema['<STR_LIT>']:<EOL><INDENT>_getPropertyValue(schema, propertyName, options['<STR_LIT>'])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>predictionSteps = options['<STR_LIT>'].get('<STR_LIT>', None)<EOL>if options['<STR_LIT>'] == InferenceType.NontemporalClassification:<EOL><INDENT>if predictionSteps is not None and predictionSteps != [<NUM_LIT:0>]:<EOL><INDENT>raise RuntimeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>if predictionSteps == [<NUM_LIT:0>]and options['<STR_LIT>'] in ['<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']:<EOL><INDENT>options['<STR_LIT>'] = InferenceType.NontemporalClassification<EOL><DEDENT>if options["<STR_LIT>"] == InferenceType.NontemporalClassification:<EOL><INDENT>if options["<STR_LIT>"]["<STR_LIT>"] == "<STR_LIT:yes>"or options["<STR_LIT>"]["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>raise RuntimeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>options["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT>swarmSize = options['<STR_LIT>']<EOL>if swarmSize is None:<EOL><INDENT>if options["<STR_LIT>"]["<STR_LIT>"] is None:<EOL><INDENT>options["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT><DEDENT>elif swarmSize == '<STR_LIT>':<EOL><INDENT>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = <NUM_LIT:3><EOL><DEDENT>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = <NUM_LIT:100><EOL><DEDENT>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = <NUM_LIT:1><EOL><DEDENT>if options["<STR_LIT>"]["<STR_LIT>"] is None:<EOL><INDENT>options["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT:yes>"<EOL><DEDENT><DEDENT>elif swarmSize == '<STR_LIT>':<EOL><INDENT>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = <NUM_LIT:5><EOL><DEDENT>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = <NUM_LIT><EOL><DEDENT>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = <NUM_LIT:200><EOL><DEDENT>if options["<STR_LIT>"]["<STR_LIT>"] is None:<EOL><INDENT>options["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT><DEDENT>elif swarmSize == '<STR_LIT>':<EOL><INDENT>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = <NUM_LIT:15><EOL><DEDENT>options['<STR_LIT>'] = True<EOL>if options["<STR_LIT>"]["<STR_LIT>"] is None:<EOL><INDENT>options["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % (swarmSize))<EOL><DEDENT>tokenReplacements = dict()<EOL>includedFields = options['<STR_LIT>']<EOL>if hsVersion == '<STR_LIT>':<EOL><INDENT>(encoderSpecsStr, permEncoderChoicesStr) =_generateEncoderStringsV1(includedFields)<EOL><DEDENT>elif hsVersion in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>(encoderSpecsStr, permEncoderChoicesStr) =_generateEncoderStringsV2(includedFields, options)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % (hsVersion))<EOL><DEDENT>if options['<STR_LIT>'] is not None:<EOL><INDENT>sensorAutoResetStr = pprint.pformat(options['<STR_LIT>'],<EOL>indent=<NUM_LIT:2>*_INDENT_STEP)<EOL><DEDENT>else:<EOL><INDENT>sensorAutoResetStr = '<STR_LIT:None>'<EOL><DEDENT>aggregationPeriod = {<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>'<STR_LIT>': <NUM_LIT:0>,<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>aggFunctionsDict = {}<EOL>if '<STR_LIT>' in options['<STR_LIT>']:<EOL><INDENT>for key in list(aggregationPeriod.keys()):<EOL><INDENT>if key in options['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>aggregationPeriod[key] = options['<STR_LIT>']['<STR_LIT>'][key]<EOL><DEDENT><DEDENT>if '<STR_LIT>' in options['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>for (fieldName, func) in options['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>aggFunctionsDict[fieldName] = str(func)<EOL><DEDENT><DEDENT><DEDENT>hasAggregation = False<EOL>for v in list(aggregationPeriod.values()):<EOL><INDENT>if v != <NUM_LIT:0>:<EOL><INDENT>hasAggregation = True<EOL>break<EOL><DEDENT><DEDENT>aggFunctionList = list(aggFunctionsDict.items())<EOL>aggregationInfo = dict(aggregationPeriod)<EOL>aggregationInfo['<STR_LIT>'] = aggFunctionList<EOL>aggregationInfoStr = "<STR_LIT:%s>" % (pprint.pformat(aggregationInfo,<EOL>indent=<NUM_LIT:2>*_INDENT_STEP))<EOL>datasetSpec = options['<STR_LIT>']<EOL>if '<STR_LIT>' in datasetSpec:<EOL><INDENT>datasetSpec.pop('<STR_LIT>')<EOL><DEDENT>if hasAggregation:<EOL><INDENT>datasetSpec['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>datasetSpecStr = pprint.pformat(datasetSpec, indent=<NUM_LIT:2>*_INDENT_STEP)<EOL>datasetSpecStr = datasetSpecStr.replace(<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>datasetSpecStr = _indentLines(datasetSpecStr, <NUM_LIT:2>, indentFirstLine=False)<EOL>computeInterval = options['<STR_LIT>']<EOL>if computeInterval is not Noneand options['<STR_LIT>'] in ['<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']:<EOL><INDENT>predictionSteps = options['<STR_LIT>'].get('<STR_LIT>', [<NUM_LIT:1>])<EOL>if len(predictionSteps) > <NUM_LIT:1>:<EOL><INDENT>raise _InvalidCommandArgException("<STR_LIT>""<STR_LIT>""<STR_LIT>" % predictionSteps)<EOL><DEDENT>if max(aggregationInfo.values()) == <NUM_LIT:0>:<EOL><INDENT>raise _InvalidCommandArgException("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>numSteps = predictionSteps[<NUM_LIT:0>]<EOL>predictAheadTime = dict(aggregationPeriod)<EOL>for key in predictAheadTime.keys():<EOL><INDENT>predictAheadTime[key] *= numSteps<EOL><DEDENT>predictAheadTimeStr = pprint.pformat(predictAheadTime,<EOL>indent=<NUM_LIT:2>*_INDENT_STEP)<EOL>options['<STR_LIT>'] = True<EOL><DEDENT>else:<EOL><INDENT>options['<STR_LIT>'] = False<EOL>predictAheadTimeStr = "<STR_LIT:None>"<EOL><DEDENT>tokenReplacements['<STR_LIT>'] =_quoteAndEscape(os.path.abspath(__file__))<EOL>inferenceType = options['<STR_LIT>']<EOL>if inferenceType == '<STR_LIT>':<EOL><INDENT>inferenceType = InferenceType.TemporalMultiStep<EOL><DEDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>" % inferenceType<EOL>if inferenceType == InferenceType.NontemporalClassification:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT:False>"<EOL>tokenReplacements['<STR_LIT>'] = "<STR_LIT:False>"<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT:True>"<EOL>tokenReplacements['<STR_LIT>'] = "<STR_LIT:True>"<EOL>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>tokenReplacements['<STR_LIT>'] = pprint.pformat(<EOL>options['<STR_LIT>'], indent=<NUM_LIT:2>*_INDENT_STEP)<EOL>tokenReplacements['<STR_LIT>'] = encoderSpecsStr<EOL>tokenReplacements['<STR_LIT>'] = sensorAutoResetStr<EOL>tokenReplacements['<STR_LIT>'] = aggregationInfoStr<EOL>tokenReplacements['<STR_LIT>'] = datasetSpecStr<EOL>if options['<STR_LIT>'] is None:<EOL><INDENT>options['<STR_LIT>'] = -<NUM_LIT:1><EOL><DEDENT>tokenReplacements['<STR_LIT>']= str(options['<STR_LIT>'])<EOL>tokenReplacements['<STR_LIT>']= str(options['<STR_LIT>'])<EOL>tokenReplacements['<STR_LIT>']= str(options['<STR_LIT>'])<EOL>tokenReplacements['<STR_LIT>']= str(options['<STR_LIT>'])<EOL>tokenReplacements['<STR_LIT>']= str(options['<STR_LIT>'])<EOL>tokenReplacements['<STR_LIT>']= permEncoderChoicesStr<EOL>predictionSteps = options['<STR_LIT>'].get('<STR_LIT>', [<NUM_LIT:1>])<EOL>predictionStepsStr = '<STR_LIT:U+002C>'.join([str(x) for x in predictionSteps])<EOL>tokenReplacements['<STR_LIT>'] = "<STR_LIT>" % (predictionStepsStr)<EOL>tokenReplacements['<STR_LIT>'] = predictAheadTimeStr<EOL>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL>if options['<STR_LIT>']and options['<STR_LIT>'] != '<STR_LIT>':<EOL><INDENT>tokenReplacements['<STR_LIT>'] =_ONE_INDENT +"<STR_LIT>"<EOL><DEDENT>if options['<STR_LIT>'] in ['<STR_LIT>',<EOL>'<STR_LIT>']:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>"+ "<STR_LIT>"+ "<STR_LIT>"<EOL><DEDENT>if options['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>"+ "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options['<STR_LIT>'] in ['<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>']:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" %(options["<STR_LIT>"]["<STR_LIT>"])<EOL>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" % (options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" % (options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" % (options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" % (options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" %(options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" % (options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" % (options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options.get('<STR_LIT>', None) is not None:<EOL><INDENT>tokenReplacements['<STR_LIT>'] ="<STR_LIT>" % (options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"<EOL><DEDENT>if options['<STR_LIT>']:<EOL><INDENT>debugAgg = True<EOL>quotient = aggregationDivide(computeInterval, aggregationPeriod)<EOL>(isInt, multiple) = _isInt(quotient)<EOL>if not isInt or multiple < <NUM_LIT:1>:<EOL><INDENT>raise _InvalidCommandArgException("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (computeInterval, aggregationPeriod))<EOL><DEDENT>mTimesN = float(predictionSteps[<NUM_LIT:0>])<EOL>possibleNs = []<EOL>for n in range(<NUM_LIT:1>, int(mTimesN)+<NUM_LIT:1>):<EOL><INDENT>m = mTimesN / n<EOL>mInt = int(round(m))<EOL>if mInt < <NUM_LIT:1>:<EOL><INDENT>break<EOL><DEDENT>if abs(m - mInt) > <NUM_LIT> * m:<EOL><INDENT>continue<EOL><DEDENT>possibleNs.append(n)<EOL><DEDENT>if debugAgg:<EOL><INDENT>print("<STR_LIT>" % (mTimesN, possibleNs))<EOL><DEDENT>aggChoices = []<EOL>for n in possibleNs:<EOL><INDENT>agg = dict(aggregationPeriod)<EOL>for key in agg.keys():<EOL><INDENT>agg[key] *= n<EOL><DEDENT>quotient = aggregationDivide(computeInterval, agg)<EOL>(isInt, multiple) = _isInt(quotient)<EOL>if not isInt or multiple < <NUM_LIT:1>:<EOL><INDENT>continue<EOL><DEDENT>aggChoices.append(agg)<EOL><DEDENT>aggChoices = aggChoices[-<NUM_LIT:5>:]<EOL>if debugAgg:<EOL><INDENT>print("<STR_LIT>")<EOL>for agg in aggChoices:<EOL><INDENT>print("<STR_LIT>", agg)<EOL><DEDENT>print()<EOL><DEDENT>tokenReplacements['<STR_LIT>'] = (<EOL>"<STR_LIT>" % (<EOL>pprint.pformat(aggChoices, indent=<NUM_LIT:2>*_INDENT_STEP)))<EOL><DEDENT>else:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = aggregationInfoStr<EOL><DEDENT>_generateInferenceArgs(options, tokenReplacements)<EOL>_generateMetricsSubstitutions(options, tokenReplacements)<EOL>environment = options['<STR_LIT>']<EOL>if environment == OpfEnvironment.Nupic:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"%OpfEnvironment.Nupic<EOL>controlTemplate = "<STR_LIT>"<EOL><DEDENT>elif environment == OpfEnvironment.Experiment:<EOL><INDENT>tokenReplacements['<STR_LIT>'] = "<STR_LIT>"%OpfEnvironment.Experiment<EOL>controlTemplate = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>raise _InvalidCommandArgException("<STR_LIT>"% environment)<EOL><DEDENT>if outputDirPath is None:<EOL><INDENT>outputDirPath = tempfile.mkdtemp()<EOL><DEDENT>if not os.path.exists(outputDirPath):<EOL><INDENT>os.makedirs(outputDirPath)<EOL><DEDENT>print("<STR_LIT>" % (outputDirPath))<EOL>descriptionPyPath = os.path.join(outputDirPath, "<STR_LIT>")<EOL>_generateFileFromTemplates([claDescriptionTemplateFile, controlTemplate],<EOL>descriptionPyPath,<EOL>tokenReplacements)<EOL>permutationsPyPath = os.path.join(outputDirPath, "<STR_LIT>")<EOL>if hsVersion == '<STR_LIT>':<EOL><INDENT>_generateFileFromTemplates(['<STR_LIT>'],permutationsPyPath,<EOL>tokenReplacements)<EOL><DEDENT>elif hsVersion == '<STR_LIT>':<EOL><INDENT>_generateFileFromTemplates(['<STR_LIT>'],permutationsPyPath,<EOL>tokenReplacements)<EOL><DEDENT>elif hsVersion == '<STR_LIT>':<EOL><INDENT>_generateFileFromTemplates(['<STR_LIT>'],permutationsPyPath,<EOL>tokenReplacements)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError<EOL><DEDENT>print("<STR_LIT>")<EOL>

Executes the --description option, which includes:

        1. Perform provider compatibility checks
        2. Preprocess the training and testing datasets (filter, join providers)
        3. If test dataset omitted, split the training dataset into training
           and testing datasets.
        4. Gather statistics about the training and testing datasets.
        5. Generate experiment scripts (description.py, permutaions.py)

    Parameters:
    --------------------------------------------------------------------------
    options:  dictionary that matches the schema defined by the return value of
              _getExperimentDescriptionSchema();  NOTE: this arg may be modified
              by this function.

    outputDirPath:  where to place generated files

    hsVersion:  which version of hypersearch permutations file to generate, can
                  be 'v1' or 'v2'
    claDescriptionTemplateFile: Filename containing the template description

    Returns:    on success, returns a dictionary per _experimentResultsJSONSchema;
                raises exception on error

        Assumption1: input train and test files have identical field metadata


<EOL>options['<STR_LIT>'] = ["<STR_LIT>"]<EOL>metricList, optimizeMetricLabel = _generateMetricSpecs(options)<EOL>metricListString = "<STR_LIT>".join(metricList)<EOL>metricListString = _indentLines(metricListString, <NUM_LIT:2>, indentFirstLine=False)<EOL>permOptimizeSettingStr = '<STR_LIT>' % optimizeMetricLabel<EOL>loggedMetricsListAsStr = "<STR_LIT>" % ("<STR_LIT:U+002CU+0020>".join(["<STR_LIT>"% ptrn<EOL>for ptrn in options['<STR_LIT>']]))<EOL>tokenReplacements['<STR_LIT>']= loggedMetricsListAsStr<EOL>tokenReplacements['<STR_LIT>'] = metricListString<EOL>tokenReplacements['<STR_LIT>']= permOptimizeSettingStr<EOL>

Generate the token substitution for metrics related fields.
    This includes:
      \$METRICS
      \$LOGGED_METRICS
      \$PERM_OPTIMIZE_SETTING


inferenceType = options['<STR_LIT>']<EOL>inferenceArgs = options['<STR_LIT>']<EOL>predictionSteps = inferenceArgs['<STR_LIT>']<EOL>metricWindow = options['<STR_LIT>']<EOL>if metricWindow is None:<EOL><INDENT>metricWindow = int(Configuration.get("<STR_LIT>"))<EOL><DEDENT>metricSpecStrings = []<EOL>optimizeMetricLabel = "<STR_LIT>"<EOL>metricSpecStrings.extend(_generateExtraMetricSpecs(options))<EOL>optimizeMetricSpec = None<EOL>if options['<STR_LIT>']:<EOL><INDENT>assert len(predictionSteps) == <NUM_LIT:1><EOL>predictionSteps = ['<STR_LIT>']<EOL><DEDENT>if inferenceType in (InferenceType.TemporalNextStep,<EOL>InferenceType.TemporalAnomaly,<EOL>InferenceType.TemporalMultiStep,<EOL>InferenceType.NontemporalMultiStep,<EOL>InferenceType.NontemporalClassification,<EOL>'<STR_LIT>'):<EOL><INDENT>predictedFieldName, predictedFieldType = _getPredictedField(options)<EOL>isCategory = _isCategory(predictedFieldType)<EOL>metricNames = ('<STR_LIT>',) if isCategory else ('<STR_LIT>', '<STR_LIT>')<EOL>trivialErrorMetric = '<STR_LIT>' if isCategory else '<STR_LIT>'<EOL>oneGramErrorMetric = '<STR_LIT>' if isCategory else '<STR_LIT>'<EOL>movingAverageBaselineName = '<STR_LIT>' if isCategory else '<STR_LIT>'<EOL>for metricName in metricNames:<EOL><INDENT>metricSpec, metricLabel =_generateMetricSpecString(field=predictedFieldName,<EOL>inferenceElement=InferenceElement.multiStepBestPredictions,<EOL>metric='<STR_LIT>',<EOL>params={'<STR_LIT>': metricName,<EOL>'<STR_LIT>':metricWindow,<EOL>'<STR_LIT>': predictionSteps},<EOL>returnLabel=True)<EOL>metricSpecStrings.append(metricSpec)<EOL><DEDENT>if options["<STR_LIT>"] is not None :<EOL><INDENT>metricParams = dict(options["<STR_LIT>"])<EOL>metricParams['<STR_LIT>'] = '<STR_LIT>'<EOL>metricParams['<STR_LIT>'] = predictionSteps<EOL>if not "<STR_LIT>" in metricParams:<EOL><INDENT>metricParams["<STR_LIT>"] = metricWindow<EOL><DEDENT>metricSpec, metricLabel =_generateMetricSpecString(field=predictedFieldName,<EOL>inferenceElement=InferenceElement.multiStepPredictions,<EOL>metric="<STR_LIT>",<EOL>params=metricParams,<EOL>returnLabel=True)<EOL>metricSpecStrings.append(metricSpec)<EOL><DEDENT>optimizeMetricSpec = metricSpec<EOL>metricLabel = metricLabel.replace('<STR_LIT:[>', '<STR_LIT>')<EOL>metricLabel = metricLabel.replace('<STR_LIT:]>', '<STR_LIT>')<EOL>optimizeMetricLabel = metricLabel<EOL>if options["<STR_LIT>"] is not None :<EOL><INDENT>optimizeMetricLabel = "<STR_LIT>"<EOL><DEDENT>if options["<STR_LIT>"]and inferenceType != InferenceType.NontemporalClassification:<EOL><INDENT>for steps in predictionSteps:<EOL><INDENT>metricSpecStrings.append(<EOL>_generateMetricSpecString(field=predictedFieldName,<EOL>inferenceElement=InferenceElement.prediction,<EOL>metric="<STR_LIT>",<EOL>params={'<STR_LIT>':metricWindow,<EOL>"<STR_LIT>":trivialErrorMetric,<EOL>'<STR_LIT>': steps})<EOL>)<EOL>if isCategory:<EOL><INDENT>metricSpecStrings.append(<EOL>_generateMetricSpecString(field=predictedFieldName,<EOL>inferenceElement=InferenceElement.prediction,<EOL>metric=movingAverageBaselineName,<EOL>params={'<STR_LIT>':metricWindow<EOL>,"<STR_LIT>":"<STR_LIT>",<EOL>"<STR_LIT>":<NUM_LIT:200>,<EOL>"<STR_LIT>": steps})<EOL>)<EOL><DEDENT>else :<EOL><INDENT>metricSpecStrings.append(<EOL>_generateMetricSpecString(field=predictedFieldName,<EOL>inferenceElement=InferenceElement.prediction,<EOL>metric=movingAverageBaselineName,<EOL>params={'<STR_LIT>':metricWindow<EOL>,"<STR_LIT>":"<STR_LIT>",<EOL>"<STR_LIT>":<NUM_LIT:200>,<EOL>"<STR_LIT>": steps})<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif inferenceType in (InferenceType.TemporalClassification):<EOL><INDENT>metricName = '<STR_LIT>'<EOL>trivialErrorMetric = '<STR_LIT>'<EOL>oneGramErrorMetric = '<STR_LIT>'<EOL>movingAverageBaselineName = '<STR_LIT>'<EOL>optimizeMetricSpec, optimizeMetricLabel =_generateMetricSpecString(inferenceElement=InferenceElement.classification,<EOL>metric=metricName,<EOL>params={'<STR_LIT>':metricWindow},<EOL>returnLabel=True)<EOL>metricSpecStrings.append(optimizeMetricSpec)<EOL>if options["<STR_LIT>"]:<EOL><INDENT>if inferenceType == InferenceType.TemporalClassification:<EOL><INDENT>metricSpecStrings.append(<EOL>_generateMetricSpecString(inferenceElement=InferenceElement.classification,<EOL>metric="<STR_LIT>",<EOL>params={'<STR_LIT>':metricWindow,<EOL>"<STR_LIT>":trivialErrorMetric})<EOL>)<EOL>metricSpecStrings.append(<EOL>_generateMetricSpecString(inferenceElement=InferenceElement.classification,<EOL>metric="<STR_LIT>",<EOL>params={'<STR_LIT>':metricWindow,<EOL>"<STR_LIT>":oneGramErrorMetric})<EOL>)<EOL>metricSpecStrings.append(<EOL>_generateMetricSpecString(inferenceElement=InferenceElement.classification,<EOL>metric=movingAverageBaselineName,<EOL>params={'<STR_LIT>':metricWindow<EOL>,"<STR_LIT>":"<STR_LIT>",<EOL>"<STR_LIT>":<NUM_LIT:200>})<EOL>)<EOL><DEDENT><DEDENT>if not options["<STR_LIT>"] == None :<EOL><INDENT>if not "<STR_LIT>" in options["<STR_LIT>"]:<EOL><INDENT>options["<STR_LIT>"]["<STR_LIT>"] = metricWindow<EOL><DEDENT>optimizeMetricSpec = _generateMetricSpecString(<EOL>inferenceElement=InferenceElement.classification,<EOL>metric="<STR_LIT>",<EOL>params=options["<STR_LIT>"])<EOL>optimizeMetricLabel = "<STR_LIT>"<EOL>metricSpecStrings.append(optimizeMetricSpec)<EOL><DEDENT><DEDENT>if options['<STR_LIT>']:<EOL><INDENT>for i in range(len(metricSpecStrings)):<EOL><INDENT>metricSpecStrings[i] = metricSpecStrings[i].replace(<EOL>"<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>optimizeMetricLabel = optimizeMetricLabel.replace(<EOL>"<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>return metricSpecStrings, optimizeMetricLabel<EOL>

Generates the Metrics for a given InferenceType

    Parameters:
    -------------------------------------------------------------------------
    options: ExpGenerator options
    retval: (metricsList, optimizeMetricLabel)
              metricsList: list of metric string names
              optimizeMetricLabel: Name of the metric which to optimize over


_metricSpecSchema = {'<STR_LIT>': {}}<EOL>results = []<EOL>for metric in options['<STR_LIT>']:<EOL><INDENT>for propertyName in list(_metricSpecSchema['<STR_LIT>'].keys()):<EOL><INDENT>_getPropertyValue(_metricSpecSchema, propertyName, metric)<EOL><DEDENT>specString, label = _generateMetricSpecString(<EOL>field=metric['<STR_LIT>'],<EOL>metric=metric['<STR_LIT>'],<EOL>params=metric['<STR_LIT>'],<EOL>inferenceElement=metric['<STR_LIT>'],<EOL>returnLabel=True)<EOL>if metric['<STR_LIT>']:<EOL><INDENT>options['<STR_LIT>'].append(label)<EOL><DEDENT>results.append(specString)<EOL><DEDENT>return results<EOL>

Generates the non-default metrics specified by the expGenerator params


if not options['<STR_LIT>'] ornot options['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>return None, None<EOL><DEDENT>predictedField = options['<STR_LIT>']['<STR_LIT>']<EOL>predictedFieldInfo = None<EOL>includedFields = options['<STR_LIT>']<EOL>for info in includedFields:<EOL><INDENT>if info['<STR_LIT>'] == predictedField:<EOL><INDENT>predictedFieldInfo = info<EOL>break<EOL><DEDENT><DEDENT>if predictedFieldInfo is None:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % predictedField<EOL>)<EOL><DEDENT>predictedFieldType = predictedFieldInfo['<STR_LIT>']<EOL>return predictedField, predictedFieldType<EOL>

Gets the predicted field and it's datatype from the options dictionary

    Returns: (predictedFieldName, predictedFieldType)


inferenceType = options['<STR_LIT>']<EOL>optionInferenceArgs = options.get('<STR_LIT>', None)<EOL>resultInferenceArgs = {}<EOL>predictedField = _getPredictedField(options)[<NUM_LIT:0>]<EOL>if inferenceType in (InferenceType.TemporalNextStep,<EOL>InferenceType.TemporalAnomaly):<EOL><INDENT>assert predictedField,  "<STR_LIT>""<STR_LIT>"% inferenceType<EOL><DEDENT>if optionInferenceArgs:<EOL><INDENT>if options['<STR_LIT>']:<EOL><INDENT>altOptionInferenceArgs = copy.deepcopy(optionInferenceArgs)<EOL>altOptionInferenceArgs['<STR_LIT>'] = '<STR_LIT>'<EOL>resultInferenceArgs = pprint.pformat(altOptionInferenceArgs)<EOL>resultInferenceArgs = resultInferenceArgs.replace("<STR_LIT>",<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>resultInferenceArgs = pprint.pformat(optionInferenceArgs)<EOL><DEDENT><DEDENT>tokenReplacements['<STR_LIT>'] = resultInferenceArgs<EOL>tokenReplacements['<STR_LIT>'] = predictedField<EOL>

Generates the token substitutions related to the predicted field
    and the supplemental arguments for prediction


<EOL>parser = OptionParser()<EOL>parser.set_usage("<STR_LIT>" +"<STR_LIT>" +"<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", dest = "<STR_LIT:description>",<EOL>help = "<STR_LIT>""<STR_LIT>""<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", dest = '<STR_LIT>',<EOL>help = "<STR_LIT>""<STR_LIT>")<EOL>parser.add_option("<STR_LIT>",<EOL>dest = '<STR_LIT>',<EOL>default = '<STR_LIT>',<EOL>help = "<STR_LIT>""<STR_LIT>")<EOL>parser.add_option("<STR_LIT>",<EOL>action="<STR_LIT:store_true>", dest="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", dest = '<STR_LIT:version>', default='<STR_LIT>',<EOL>help = "<STR_LIT>"<EOL>"<STR_LIT>")<EOL>parser.add_option("<STR_LIT>",<EOL>dest = "<STR_LIT>", default=None,<EOL>help = "<STR_LIT>""<STR_LIT>"<EOL>)<EOL>(options, remainingArgs) = parser.parse_args(args)<EOL>if len(remainingArgs) > <NUM_LIT:0>:<EOL><INDENT>raise _InvalidCommandArgException(<EOL>_makeUsageErrorStr("<STR_LIT>" %('<STR_LIT:U+0020>'.join(remainingArgs),), parser.get_usage()))<EOL><DEDENT>activeOptions = [x for x in ('<STR_LIT:description>', '<STR_LIT>') if getattr(options, x) != None]<EOL>if len(activeOptions) > <NUM_LIT:1>:<EOL><INDENT>raise _InvalidCommandArgException(<EOL>_makeUsageErrorStr(("<STR_LIT>" +"<STR_LIT>") % (activeOptions,),<EOL>parser.get_usage()))<EOL><DEDENT>if options.showSchema:<EOL><INDENT>_handleShowSchemaOption()<EOL><DEDENT>elif options.description:<EOL><INDENT>_handleDescriptionOption(options.description, options.outDir,<EOL>parser.get_usage(), hsVersion=options.version,<EOL>claDescriptionTemplateFile = options.claDescriptionTemplateFile)<EOL><DEDENT>elif options.descriptionFromFile:<EOL><INDENT>_handleDescriptionFromFileOption(options.descriptionFromFile,<EOL>options.outDir, parser.get_usage(), hsVersion=options.version,<EOL>claDescriptionTemplateFile = options.claDescriptionTemplateFile)<EOL><DEDENT>else:<EOL><INDENT>raise _InvalidCommandArgException(<EOL>_makeUsageErrorStr("<STR_LIT>"<EOL>"<STR_LIT>", parser.get_usage()))<EOL><DEDENT>

Parses, validates, and executes command-line options;

    On success: Performs requested operation and exits program normally

    On Error:   Dumps exception/error info in JSON format to stdout and exits the
                program with non-zero status.


super(_CreateDirectoryException, self).__init__(<EOL>("<STR_LIT>" +"<STR_LIT>") % (str(dirPath), str(reason)))<EOL>self.reason = reason<EOL>

dirPath:    the path that we attempted to create for experiment files

reason:     any object that can be converted to a string that explains
            the reason (may be an exception)


super(_ErrorReportingException, self).__init__(<EOL>("<STR_LIT>" +"<STR_LIT>")% (problem, precursor))<EOL>

problem:    a string-convertible object that describes the problem
            experienced by the error-reporting funciton.

precursor:  a string-convertible object that explains
            the original error that the error-reporting function
            was attempting to report when it encountered its own failure.


coordinates = [<NUM_LIT:0>] * len(dimensions)<EOL>shifted = index<EOL>for i in xrange(len(dimensions) - <NUM_LIT:1>, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>coordinates[i] = shifted % dimensions[i]<EOL>shifted = shifted / dimensions[i]<EOL><DEDENT>coordinates[<NUM_LIT:0>] = shifted<EOL>return coordinates<EOL>

Translate an index into coordinates, using the given coordinate system.

Similar to ``numpy.unravel_index``.

:param index: (int) The index of the point. The coordinates are expressed as a
       single index by using the dimensions as a mixed radix definition. For
       example, in dimensions 42x10, the point [1, 4] is index
       1*420 + 4*10 = 460.

:param dimensions (list of ints) The coordinate system.

:returns: (list) of coordinates of length ``len(dimensions)``.


index = <NUM_LIT:0><EOL>for i, dimension in enumerate(dimensions):<EOL><INDENT>index *= dimension<EOL>index += coordinates[i]<EOL><DEDENT>return index<EOL>

Translate coordinates into an index, using the given coordinate system.

Similar to ``numpy.ravel_multi_index``.

:param coordinates: (list of ints) A list of coordinates of length
       ``dimensions.size()``.

:param dimensions: (list of ints) The coordinate system.

:returns: (int) The index of the point. The coordinates are expressed as a
          single index by using the dimensions as a mixed radix definition.
          For example, in dimensions 42x10, the point [1, 4] is index
          1*420 + 4*10 = 460.


def neighborhood(centerIndex, radius, dimensions):

centerPosition = coordinatesFromIndex(centerIndex, dimensions)<EOL>intervals = []<EOL>for i, dimension in enumerate(dimensions):<EOL><INDENT>left = max(<NUM_LIT:0>, centerPosition[i] - radius)<EOL>right = min(dimension - <NUM_LIT:1>, centerPosition[i] + radius)<EOL>intervals.append(xrange(left, right + <NUM_LIT:1>))<EOL><DEDENT>coords = numpy.array(list(itertools.product(*intervals)))<EOL>return numpy.ravel_multi_index(coords.T, dimensions)<EOL>

Get the points in the neighborhood of a point.

A point's neighborhood is the n-dimensional hypercube with sides ranging
[center - radius, center + radius], inclusive. For example, if there are two
dimensions and the radius is 3, the neighborhood is 6x6. Neighborhoods are
truncated when they are near an edge.

This is designed to be fast. In C++ it's fastest to iterate through neighbors
one by one, calculating them on-demand rather than creating a list of them.
But in Python it's faster to build up the whole list in batch via a few calls
to C code rather than calculating them on-demand with lots of calls to Python
code.

:param centerIndex: (int) The index of the point. The coordinates are
       expressed as a single index by using the dimensions as a mixed radix
       definition. For example, in dimensions 42x10, the point [1, 4] is index
       1*420 + 4*10 = 460.

:param radius: (int) The radius of this neighborhood about the
       ``centerIndex``.

:param dimensions: (indexable sequence) The dimensions of the world outside
       this neighborhood.

:returns: (numpy array) The points in the neighborhood, including
          ``centerIndex``.


def wrappingNeighborhood(centerIndex, radius, dimensions):

centerPosition = coordinatesFromIndex(centerIndex, dimensions)<EOL>intervals = []<EOL>for i, dimension in enumerate(dimensions):<EOL><INDENT>left = centerPosition[i] - radius<EOL>right = min(centerPosition[i] + radius,<EOL>left + dimensions[i] - <NUM_LIT:1>)<EOL>interval = [v % dimension for v in xrange(left, right + <NUM_LIT:1>)]<EOL>intervals.append(interval)<EOL><DEDENT>coords = numpy.array(list(itertools.product(*intervals)))<EOL>return numpy.ravel_multi_index(coords.T, dimensions)<EOL>

Like :meth:`neighborhood`, except that the neighborhood isn't truncated when
it's near an edge. It wraps around to the other side.

:param centerIndex: (int) The index of the point. The coordinates are
       expressed as a single index by using the dimensions as a mixed radix
       definition. For example, in dimensions 42x10, the point [1, 4] is index
       1*420 + 4*10 = 460.

:param radius: (int) The radius of this neighborhood about the
       ``centerIndex``.

:param dimensions: (indexable sequence) The dimensions of the world outside
       this neighborhood.

:returns: (numpy array) The points in the neighborhood, including
          ``centerIndex``.


stay = (r.uniform(<NUM_LIT:0>, <NUM_LIT:1>) < self.kernel)<EOL>if stay:<EOL><INDENT>logKernel = numpy.log(self.kernel)<EOL>return current, logKernel, logKernel<EOL><DEDENT>else: <EOL><INDENT>curIndex = self.keyMap[current]<EOL>ri = r.randint(<NUM_LIT:0>, self.nKeys-<NUM_LIT:1>)<EOL>logKernel = numpy.log(<NUM_LIT:1.0> - self.kernel)<EOL>lp = logKernel + self.logp<EOL>if ri < curIndex: return self.keys[ri], lp, lp<EOL>else: return self.keys[ri+<NUM_LIT:1>], lp, lp<EOL><DEDENT>

Generates a random sample from the discrete probability distribution and
        returns its value, the log of the probability of sampling that value and the
        log of the probability of sampling the current value (passed in).


curLambda = current + self.offset<EOL>x, logProb = PoissonDistribution(curLambda).sample(r)<EOL>logBackward = PoissonDistribution(x+self.offset).logDensity(current)<EOL>return x, logProb, logBackward<EOL>

Generates a random sample from the Poisson probability distribution with
        with location and scale parameter equal to the current value (passed in).
        Returns the value of the random sample, the log of the probability of
        sampling that value, and the log of the probability of sampling the current
        value if the roles of the new sample and the current sample were reversed
        (the log of the backward proposal probability).


lx = numpy.asarray(lx)<EOL>base = lx.max()<EOL>if numpy.isinf(base):<EOL><INDENT>return base<EOL><DEDENT>if (epsilon is not None) and (base < epsilon):<EOL><INDENT>return epsilon<EOL><DEDENT>x = numpy.exp(lx - base)<EOL>ssum = x.sum()<EOL>result = numpy.log(ssum) + base<EOL>return result<EOL>

Accepts log-values as input, exponentiates them, computes the sum,
then converts the sum back to log-space and returns the result.
Handles underflow by rescaling so that the largest values is exactly 1.0.


<EOL>lx = numpy.asarray(lx)<EOL>bases = lx.max(<NUM_LIT:0>) <EOL>x = numpy.exp(lx - bases)<EOL>ssum = x.sum(<NUM_LIT:0>)<EOL>result = numpy.log(ssum) + bases<EOL>try:<EOL><INDENT>conventional = numpy.log(numpy.exp(lx).sum(<NUM_LIT:0>))<EOL>if not similar(result, conventional):<EOL><INDENT>if numpy.isinf(conventional).any() and not numpy.isinf(result).any():<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>import sys<EOL>print("<STR_LIT>", file=sys.stderr)<EOL>print("<STR_LIT>", file=sys.stderr)<EOL>print(result, file=sys.stderr)<EOL>print("<STR_LIT>", file=sys.stderr)<EOL>print(conventional, file=sys.stderr)<EOL><DEDENT><DEDENT><DEDENT>except FloatingPointError as e:<EOL><INDENT>pass<EOL><DEDENT>return result<EOL>

Accepts log-values as input, exponentiates them, sums down the rows
(first dimension), then converts the sum back to log-space and returns the result.
Handles underflow by rescaling so that the largest values is exactly 1.0.


lx = numpy.asarray(lx)<EOL>base = lx.max()<EOL>x = numpy.exp(lx - base)<EOL>result = x / x.sum()<EOL>conventional = (numpy.exp(lx) / numpy.exp(lx).sum())<EOL>assert similar(result, conventional)<EOL>return result<EOL>

Accepts log-values as input, exponentiates them,
normalizes and returns the result.
Handles underflow by rescaling so that the largest values is exactly 1.0.


lx = numpy.asarray(lx)<EOL>base = lx.max()<EOL>x = numpy.exp(lx - base)<EOL>ssum = x.sum(<NUM_LIT:0>)<EOL>result = ssum / ssum.sum()<EOL>conventional = (numpy.exp(lx).sum(<NUM_LIT:0>) / numpy.exp(lx).sum())<EOL>assert similar(result, conventional)<EOL>return result<EOL>

Accepts log-values as input, exponentiates them, sums down the rows
(first dimension), normalizes and returns the result.
Handles underflow by rescaling so that the largest values is exactly 1.0.


lx = numpy.asarray(lx)<EOL>base = lx.max()<EOL>x = numpy.exp(lx - base)<EOL>ssum = x.sum(<NUM_LIT:0>)<EOL>normalized = nsum0(lx)<EOL>result = numpy.log(normalized)<EOL>conventional = numpy.log(numpy.exp(lx).sum(<NUM_LIT:0>) / numpy.exp(lx).sum())<EOL>assert similar(result, conventional)<EOL>return result<EOL>

Accepts log-values as input, exponentiates them, sums down the rows
(first dimension), normalizes, then converts the sum back to
log-space and returns the result.
Handles underflow by rescaling so that the largest values is exactly 1.0.


if out is None:<EOL><INDENT>out = numpy.zeros(A.shape)<EOL><DEDENT>indicator1 = A >= B<EOL>indicator2 = numpy.logical_not(indicator1)<EOL>out[indicator1] = A[indicator1] + numpy.log1p(numpy.exp(B[indicator1]-A[indicator1]))<EOL>out[indicator2]  = B[indicator2] + numpy.log1p(numpy.exp(A[indicator2]-B[indicator2]))<EOL>return out<EOL>

returns log(exp(A) + exp(B)). A and B are numpy arrays


if out is None:<EOL><INDENT>out = numpy.zeros(A.shape)<EOL><DEDENT>indicator1 = A >= B<EOL>assert indicator1.all(), "<STR_LIT>"<EOL>out[indicator1] = A[indicator1] + numpy.log(<NUM_LIT:1> - numpy.exp(B[indicator1]-A[indicator1]))<EOL>return out<EOL>

returns log(exp(A) - exp(B)). A and B are numpy arrays. values in A should be
    greater than or equal to corresponding values in B


if r is None:<EOL><INDENT>r = random<EOL><DEDENT>x = r.uniform(<NUM_LIT:0>, sum(distribution))<EOL>for i, d in enumerate(distribution):<EOL><INDENT>if x <= d:<EOL><INDENT>return i<EOL><DEDENT>x -= d<EOL><DEDENT>

Pick a value according to the provided distribution.

Example:

::

  pickByDistribution([.2, .1])

Returns 0 two thirds of the time and 1 one third of the time.

:param distribution: Probability distribution. Need not be normalized.
:param r: Instance of random.Random. Uses the system instance if one is
       not provided.


x = numpy.zeros(size, dtype=dtype)<EOL>x[pos] = <NUM_LIT:1><EOL>return x<EOL>

Returns an array of length size and type dtype that is everywhere 0,
except in the index in pos.

:param pos: (int) specifies the position of the one entry that will be set.
:param size: (int) The total size of the array to be returned.
:param dtype: The element type (compatible with NumPy array())
       of the array to be returned.
:returns: (list) of length ``size`` and element type ``dtype``.


m = x.max()<EOL>return (i for i, v in enumerate(x) if v == m)<EOL>

Get tuple (actually a generator) of indices where the max value of
array x occurs. Requires that x have a max() method, as x.max()
(in the case of NumPy) is much faster than max(x).
For a simpler, faster argmax when there is only a single maximum entry,
or when knowing only the first index where the maximum occurs,
call argmax() on a NumPy array.

:param x: Any sequence that has a max() method.
:returns: Generator with the indices where the max value occurs.


return bool(reduce(lambda x, y: x or y, sequence, False))<EOL>

Tests much faster (30%) than bool(sum(bool(x) for x in sequence)).

:returns: (bool) true if any element of the sequence satisfies True.

:param sequence: Any sequence whose elements can be evaluated as booleans.


return bool(reduce(lambda x, y: x and y, sequence, True))<EOL>

:param sequence: Any sequence whose elements can be evaluated as booleans.
:returns: true if all elements of the sequence satisfy True and x.


return reduce(lambda x, y: x * y, sequence)<EOL>

Returns the product of the elements of the sequence.
Use numpy.prod() if the sequence is an array, as it will be faster.
Remember that the product of many numbers may rapidly overflow or
underflow the numeric precision of the computer.
Use a sum of the logs of the sequence elements instead when precision
should be maintained.

:param sequence: Any sequence whose elements can be multiplied by their
          neighbors.
:returns: A single value that is the product of all the sequence elements.


x = numpy.zeros(size, dtype=dtype)<EOL>if hasattr(pos, '<STR_LIT>'):<EOL><INDENT>for i in pos: x[i] = <NUM_LIT:1><EOL><DEDENT>else: x[pos] = <NUM_LIT:1><EOL>return x<EOL>

Returns an array of length size and type dtype that is everywhere 0,
except in the indices listed in sequence pos.

:param pos:   A single integer or sequence of integers that specify
       the position of ones to be set.
:param size:  The total size of the array to be returned.
:param dtype: The element type (compatible with NumPy array())
       of the array to be returned.
:returns: An array of length size and element type dtype.


def Distribution(pos, size, counts, dtype):

x = numpy.zeros(size, dtype=dtype)<EOL>if hasattr(pos, '<STR_LIT>'):<EOL><INDENT>total = <NUM_LIT:0><EOL>for i in pos:<EOL><INDENT>total += counts[i]<EOL><DEDENT>total = float(total)<EOL>for i in pos:<EOL><INDENT>x[i] = counts[i]/total<EOL><DEDENT><DEDENT>else: x[pos] = <NUM_LIT:1><EOL>return x<EOL>

Returns an array of length size and type dtype that is everywhere 0,
except in the indices listed in sequence pos.  The non-zero indices
contain a normalized distribution based on the counts.

:param pos:    A single integer or sequence of integers that specify
        the position of ones to be set.
:param size:   The total size of the array to be returned.
:param counts: The number of times we have observed each index.
:param dtype:  The element type (compatible with NumPy array())
        of the array to be returned.
:returns: An array of length size and element type dtype.


if self.hist_: return self.hist_.nRows()<EOL>else: return <NUM_LIT:0><EOL>

Gets the number of rows in the histogram.

        :returns: Integer number of rows.


if self.hist_: return self.hist_.nCols()<EOL>else: return <NUM_LIT:0><EOL>


if not self.hist_:<EOL><INDENT>self.hist_ = SparseMatrix(rows, cols)<EOL>self.rowSums_ = numpy.zeros(rows, dtype=dtype)<EOL>self.colSums_ = numpy.zeros(cols, dtype=dtype)<EOL>self.hack_ = None<EOL><DEDENT>else:<EOL><INDENT>oldRows = self.hist_.nRows()<EOL>oldCols = self.hist_.nCols()<EOL>nextRows = max(oldRows, rows)<EOL>nextCols = max(oldCols, cols)<EOL>if (oldRows < nextRows) or (oldCols < nextCols):<EOL><INDENT>self.hist_.resize(nextRows, nextCols)<EOL>if oldRows < nextRows:<EOL><INDENT>oldSums = self.rowSums_<EOL>self.rowSums_ = numpy.zeros(nextRows, dtype=dtype)<EOL>self.rowSums_[<NUM_LIT:0>:len(oldSums)] = oldSums<EOL>self.hack_ = None<EOL><DEDENT>if oldCols < nextCols:<EOL><INDENT>oldSums = self.colSums_<EOL>self.colSums_ = numpy.zeros(nextCols, dtype=dtype)<EOL>self.colSums_[<NUM_LIT:0>:len(oldSums)] = oldSums<EOL>self.hack_ = None<EOL><DEDENT><DEDENT><DEDENT>

Grows the histogram to have rows rows and cols columns.
Must not have been initialized before, or already have the same
number of columns.
If rows is smaller than the current number of rows,
does not shrink.
Also updates the sizes of the row and column sums.

:param rows: Integer number of rows.
:param cols: Integer number of columns.


self.grow(row+<NUM_LIT:1>, len(distribution))<EOL>self.hist_.axby(row, <NUM_LIT:1>, <NUM_LIT:1>, distribution)<EOL>self.rowSums_[row] += distribution.sum()<EOL>self.colSums_ += distribution<EOL>self.hack_ = None<EOL>

Add distribution to row row.
Distribution should be an array of probabilities or counts.

:param row:   Integer index of the row to add to.
              May be larger than the current number of rows, in which case
              the histogram grows.
:param distribution: Array of length equal to the number of columns.


<EOL>return self.hist_ * (distribution / self.colSums_)<EOL>

Computes the sumProp probability of each row given the input probability
of each column. Normalizes the distribution in each column on the fly.

The semantics are as follows: If the distribution is P(col|e) where e is
the evidence is col is the column, and the CPD represents P(row|col), then
this calculates sum(P(col|e) P(row|col)) = P(row|e).

:param distribution: Array of length equal to the number of columns.
:returns: array of length equal to the number of rows.


<EOL>return (self.hist_ * distribution) / self.rowSums_<EOL>

Computes the probability of evidence given each row from the probability
of evidence given each column.  Essentially, this just means that it sums
probabilities over (normalized) rows.  Normalizes the distribution over
each row on the fly.

The semantics are as follows:  If the distribution is P(e|col) where e is
evidence and col is the column, and the CPD is of P(col|row), then this
calculates sum(P(e|col) P(col|row)) = P(e|row).

:param distribution: Array of length equal to the number of columns.
:returns: array of length equal to the number of rows.


if self.hack_ is None:<EOL><INDENT>self.clean_outcpd()<EOL><DEDENT>return self.hack_.vecMaxProd(distribution)<EOL>

Equivalent to the category inference of zeta1.TopLevel.
Computes the max_prod (maximum component of a component-wise multiply)
between the rows of the histogram and the incoming distribution.
May be slow if the result of clean_outcpd() is not valid.

:param distribution: Array of length equal to the number of columns.
:returns: array of length equal to the number of rows.


m = self.hist_.toDense()<EOL>for j in xrange(m.shape[<NUM_LIT:1>]): <EOL><INDENT>cmax = m[:,j].max()<EOL>if cmax:<EOL><INDENT>m[:,j] = numpy.array(m[:,j] == cmax, dtype=dtype)<EOL><DEDENT><DEDENT>self.hack_ = SparseMatrix(<NUM_LIT:0>, self.hist_.nCols())<EOL>for i in xrange(m.shape[<NUM_LIT:0>]):<EOL><INDENT>self.hack_.addRow(m[i,:])<EOL><DEDENT>

Hack to act like clean_outcpd on zeta1.TopLevelNode.
        Take the max element in each to column, set it to 1, and set all the
        other elements to 0.
        Only called by inferRowMaxProd() and only needed if an updateRow()
        has been called since the last clean_outcpd().


return lgamma(x + <NUM_LIT:1.0>)<EOL>

Approximation to the log of the factorial function.


rf = rgen.uniform(<NUM_LIT:0>, self.sum)<EOL>index = bisect.bisect(self.cdf, rf)<EOL>return self.keys[index], numpy.log(self.pmf[index])<EOL>

Generates a random sample from the discrete probability distribution
        and returns its value and the log of the probability of sampling that value.


x = numpy.asarray(distn)<EOL>n = x.sum()<EOL>return (logFactorial(n) - numpy.sum([logFactorial(k) for k in x]) +<EOL>numpy.sum(x * numpy.log(self.dist.pmf)))<EOL>

Form of distribution must be an array of counts in order of self.keys.


x = rgen.poisson(self.lambdaParameter)<EOL>return x, self.logDensity(x)<EOL>

Generates a random sample from the Poisson probability distribution and
        returns its value and the log of the probability of sampling that value.


y_true = np.ravel(y_true)<EOL>classes = np.unique(y_true)<EOL>if classes.shape[<NUM_LIT:0>] != <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y_score = np.ravel(y_score)<EOL>n_pos = float(np.sum(y_true == classes[<NUM_LIT:1>]))  <EOL>n_neg = float(np.sum(y_true == classes[<NUM_LIT:0>]))  <EOL>thresholds = np.unique(y_score)<EOL>neg_value, pos_value = classes[<NUM_LIT:0>], classes[<NUM_LIT:1>]<EOL>tpr = np.empty(thresholds.size, dtype=np.float)  <EOL>fpr = np.empty(thresholds.size, dtype=np.float)  <EOL>current_pos_count = current_neg_count = sum_pos = sum_neg = idx = <NUM_LIT:0><EOL>signal = np.c_[y_score, y_true]<EOL>sorted_signal = signal[signal[:, <NUM_LIT:0>].argsort(), :][::-<NUM_LIT:1>]<EOL>last_score = sorted_signal[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>for score, value in sorted_signal:<EOL><INDENT>if score == last_score:<EOL><INDENT>if value == pos_value:<EOL><INDENT>current_pos_count += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>current_neg_count += <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>tpr[idx] = (sum_pos + current_pos_count) / n_pos<EOL>fpr[idx] = (sum_neg + current_neg_count) / n_neg<EOL>sum_pos += current_pos_count<EOL>sum_neg += current_neg_count<EOL>current_pos_count = <NUM_LIT:1> if value == pos_value else <NUM_LIT:0><EOL>current_neg_count = <NUM_LIT:1> if value == neg_value else <NUM_LIT:0><EOL>idx += <NUM_LIT:1><EOL>last_score = score<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tpr[-<NUM_LIT:1>] = (sum_pos + current_pos_count) / n_pos<EOL>fpr[-<NUM_LIT:1>] = (sum_neg + current_neg_count) / n_neg<EOL><DEDENT>if fpr.shape[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>fpr = np.array([<NUM_LIT:0.0>, fpr[<NUM_LIT:0>], fpr[<NUM_LIT:1>]])<EOL>tpr = np.array([<NUM_LIT:0.0>, tpr[<NUM_LIT:0>], tpr[<NUM_LIT:1>]])<EOL><DEDENT>elif fpr.shape[<NUM_LIT:0>] == <NUM_LIT:1>:<EOL><INDENT>fpr = np.array([<NUM_LIT:0.0>, fpr[<NUM_LIT:0>], <NUM_LIT:1.0>])<EOL>tpr = np.array([<NUM_LIT:0.0>, tpr[<NUM_LIT:0>], <NUM_LIT:1.0>])<EOL><DEDENT>return fpr, tpr, thresholds<EOL>

compute Receiver operating characteristic (ROC)

    Note: this implementation is restricted to the binary classification task.

    Parameters
    ----------

    y_true : array, shape = [n_samples]
        true binary labels

    y_score : array, shape = [n_samples]
        target scores, can either be probability estimates of
        the positive class, confidence values, or binary decisions.

    Returns
    -------
    fpr : array, shape = [>2]
        False Positive Rates

    tpr : array, shape = [>2]
        True Positive Rates

    thresholds : array, shape = [>2]
        Thresholds on y_score used to compute fpr and tpr

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn import metrics
    >>> y = np.array([1, 1, 2, 2])
    >>> scores = np.array([0.1, 0.4, 0.35, 0.8])
    >>> fpr, tpr, thresholds = metrics.roc_curve(y, scores)
    >>> fpr
    array([ 0. ,  0.5,  0.5,  1. ])

    References
    ----------
    http://en.wikipedia.org/wiki/Receiver_operating_characteristic


<EOL>if x.shape[<NUM_LIT:0>] != y.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>% (x.shape, y.shape))<EOL><DEDENT>if x.shape[<NUM_LIT:0>] < <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % x.shape)<EOL><DEDENT>order = np.argsort(x)<EOL>x = x[order]<EOL>y = y[order]<EOL>h = np.diff(x)<EOL>area = np.sum(h * (y[<NUM_LIT:1>:] + y[:-<NUM_LIT:1>])) / <NUM_LIT><EOL>return area<EOL>

Compute Area Under the Curve (AUC) using the trapezoidal rule

    Parameters
    ----------
    x : array, shape = [n]
        x coordinates

    y : array, shape = [n]
        y coordinates

    Returns
    -------
    auc : float

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn import metrics
    >>> y = np.array([1, 1, 2, 2])
    >>> pred = np.array([0.1, 0.4, 0.35, 0.8])
    >>> fpr, tpr, thresholds = metrics.roc_curve(y, pred)
    >>> metrics.auc(fpr, tpr)
    0.75


result = [[ ]]<EOL>for seq in sequences:<EOL><INDENT>result = [sublist+[item] for sublist in result for item in seq]<EOL><DEDENT>return result<EOL>


<EOL>wheels = map(iter, sequences)<EOL>digits = [it.next( ) for it in wheels]<EOL>while True:<EOL><INDENT>yield tuple(digits)<EOL>for i in range(len(digits)-<NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>try:<EOL><INDENT>digits[i] = wheels[i].next( )<EOL>break<EOL><DEDENT>except StopIteration:<EOL><INDENT>wheels[i] = iter(sequences[i])<EOL>digits[i] = wheels[i].next( )<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>


keys = keywords.keys()<EOL>sequences = [keywords[key] for key in keys]<EOL>wheels = map(iter, sequences)<EOL>digits = [it.next( ) for it in wheels]<EOL>while True:<EOL><INDENT>yield dict(zip(keys, digits))<EOL>for i in range(len(digits)-<NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>try:<EOL><INDENT>digits[i] = wheels[i].next( )<EOL>break<EOL><DEDENT>except StopIteration:<EOL><INDENT>wheels[i] = iter(sequences[i])<EOL>digits[i] = wheels[i].next( )<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>

Similar to cross(), but generates output dictionaries instead of tuples.


def __init__(self, windowSize, existingHistoricalValues=None):

if not isinstance(windowSize, numbers.Integral):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if  windowSize <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self.windowSize = windowSize<EOL>if existingHistoricalValues is not None:<EOL><INDENT>self.slidingWindow = existingHistoricalValues[<EOL>len(existingHistoricalValues)-windowSize:]<EOL><DEDENT>else:<EOL><INDENT>self.slidingWindow = []<EOL><DEDENT>self.total = float(sum(self.slidingWindow))<EOL>

new instance of MovingAverage, so method .next() can be used
@param windowSize - length of sliding window
@param existingHistoricalValues - construct the object with already
    some values in it.


@staticmethod<EOL><INDENT>def compute(slidingWindow, total, newVal, windowSize):<DEDENT>

if len(slidingWindow) == windowSize:<EOL><INDENT>total -= slidingWindow.pop(<NUM_LIT:0>)<EOL><DEDENT>slidingWindow.append(newVal)<EOL>total += newVal<EOL>return float(total) / len(slidingWindow), slidingWindow, total<EOL>

Routine for computing a moving average.

        @param slidingWindow a list of previous values to use in computation that
            will be modified and returned
        @param total the sum of the values in slidingWindow to be used in the
            calculation of the moving average
        @param newVal a new number compute the new windowed average
        @param windowSize how many values to use in the moving window

        @returns an updated windowed average, the modified input slidingWindow list,
            and the new total sum of the sliding window


newAverage, self.slidingWindow, self.total = self.compute(<EOL>self.slidingWindow, self.total, newValue, self.windowSize)<EOL>return newAverage<EOL>


return float(self.total) / len(self.slidingWindow)<EOL>


self.__dict__.update(state)<EOL>if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>self.slidingWindow = []<EOL><DEDENT>if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>self.total = <NUM_LIT:0><EOL>self.slidingWindow = sum(self.slidingWindow)<EOL><DEDENT>


try:<EOL><INDENT>line = next(f)<EOL>while line == '<STR_LIT>':<EOL><INDENT>line = next(f)<EOL><DEDENT>name = line.split('<STR_LIT:U+002C>')[<NUM_LIT:0>]<EOL>if name not in clubs:<EOL><INDENT>clubs[name] = Club(name)<EOL><DEDENT>c = clubs[name]<EOL>c.processAttendance(f)      <EOL>return True<EOL><DEDENT>except StopIteration:<EOL><INDENT>return False<EOL><DEDENT>

Process the attendance data of one club

    If the club already exists in the list update its data.
    If the club is new create a new Club object and add it to the dict

    The next step is to iterate over all the lines and add a record for each line.
    When reaching an empty line it means there are no more records for this club.

    Along the way some redundant lines are skipped. When the file ends the f.next()
    call raises a StopIteration exception and that's the sign to return False,
    which indicates to the caller that there are no more clubs to process.


try:<EOL><INDENT>line = next(f)<EOL>assert line.endswith('<STR_LIT>')<EOL>valid_times = list(range(<NUM_LIT>))<EOL>t = <NUM_LIT:0> <EOL>club = None<EOL>clubName = None<EOL>lastDate = None<EOL>while True:<EOL><INDENT>assert t in valid_times<EOL>consumption = <NUM_LIT:0><EOL>for x in range(<NUM_LIT:4>):<EOL><INDENT>line = f.next()[:-<NUM_LIT:1>]<EOL>fields = line.split('<STR_LIT:U+002C>')<EOL>assert len(fields) == <NUM_LIT:4><EOL>for i, field in enumerate(fields):<EOL><INDENT>assert field[<NUM_LIT:0>] == '<STR_LIT:">' and field[-<NUM_LIT:1>] == '<STR_LIT:">'<EOL>fields[i] = field[<NUM_LIT:1>:-<NUM_LIT:1>]<EOL><DEDENT>name = fields[<NUM_LIT:1>]<EOL>partialNames = ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>for pn in partialNames:<EOL><INDENT>if pn in name:<EOL><INDENT>name = pn<EOL><DEDENT><DEDENT>if name != clubName:<EOL><INDENT>clubName = name<EOL>club = clubs[name]<EOL><DEDENT>tokens = fields[<NUM_LIT:2>].split()<EOL>if len(tokens) == <NUM_LIT:1>:<EOL><INDENT>assert consumption == <NUM_LIT:0> and t == <NUM_LIT:0><EOL><DEDENT>date = tokens[<NUM_LIT:0>]<EOL>consumption += float(fields[<NUM_LIT:3>])<EOL><DEDENT>club.updateRecord(date, t, consumption)<EOL>t += <NUM_LIT:1><EOL>t %= <NUM_LIT><EOL><DEDENT><DEDENT>except StopIteration:<EOL><INDENT>return<EOL><DEDENT>

Process the consumption a club

    - Skip the header line
    - Iterate over lines
      - Read 4 records at a time
        - Parse each line: club, date, time, consumption
        - Get club object from dictionary if needed
        - Aggregate consumption
      - Call club.processConsumption() with data


<EOL>initProb = numpy.zeros(numCategories)<EOL>initProb[<NUM_LIT:0>] = <NUM_LIT:0.5><EOL>initProb[<NUM_LIT:4>] = <NUM_LIT:0.5><EOL>firstOrder = dict()<EOL>for catIdx in range(numCategories):<EOL><INDENT>key = str([catIdx])<EOL>probs = numpy.ones(numCategories) / numCategories<EOL>if catIdx == <NUM_LIT:0> or catIdx == <NUM_LIT:4>:<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT:1>] = <NUM_LIT:1.0>    <EOL><DEDENT>firstOrder[key] = probs<EOL><DEDENT>secondOrder = dict()<EOL>for firstIdx in range(numCategories):<EOL><INDENT>for secondIdx in range(numCategories):<EOL><INDENT>key = str([firstIdx, secondIdx])<EOL>probs = numpy.ones(numCategories) / numCategories<EOL>if key == str([<NUM_LIT:0>,<NUM_LIT:1>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT:2>] = <NUM_LIT>   <EOL>probs[<NUM_LIT:3>] = <NUM_LIT>   <EOL><DEDENT>elif key == str([<NUM_LIT:4>,<NUM_LIT:1>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT:2>] = <NUM_LIT>   <EOL>probs[<NUM_LIT:3>] = <NUM_LIT>   <EOL><DEDENT>secondOrder[key] = probs<EOL><DEDENT><DEDENT>return (initProb, firstOrder, secondOrder, <NUM_LIT:3>)<EOL>

Generate the initial, first order, and second order transition
    probabilities for 'model0'. For this model, we generate the following
    set of sequences:

    1-2-3   (4X)
    1-2-4   (1X)
    5-2-3   (1X)
    5-2-4   (4X)

    Parameters:
    ----------------------------------------------------------------------
    numCategories:      Number of categories
    retval: (initProb, firstOrder, secondOrder, seqLen)
              initProb:     Initial probability for each category. This is a vector
                              of length len(categoryList).
              firstOrder:   A dictionary of the 1st order probabilities. The key
                              is the 1st element of the sequence, the value is
                              the probability of each 2nd element given the first.
              secondOrder:  A dictionary of the 2nd order probabilities. The key
                              is the first 2 elements of the sequence, the value is
                              the probability of each possible 3rd element given the
                              first two.
              seqLen:       Desired length of each sequence. The 1st element will
                            be generated using the initProb, the 2nd element by the
                            firstOrder table, and the 3rd and all successive
                            elements by the secondOrder table.

    Here is an example of some return values:
    initProb:         [0.7, 0.2, 0.1]

    firstOrder:       {'[0]': [0.3, 0.3, 0.4],
                       '[1]': [0.3, 0.3, 0.4],
                       '[2]': [0.3, 0.3, 0.4]}

    secondOrder:      {'[0,0]': [0.3, 0.3, 0.4],
                       '[0,1]': [0.3, 0.3, 0.4],
                       '[0,2]': [0.3, 0.3, 0.4],
                       '[1,0]': [0.3, 0.3, 0.4],
                       '[1,1]': [0.3, 0.3, 0.4],
                       '[1,2]': [0.3, 0.3, 0.4],
                       '[2,0]': [0.3, 0.3, 0.4],
                       '[2,1]': [0.3, 0.3, 0.4],
                       '[2,2]': [0.3, 0.3, 0.4]}


<EOL>initProb = numpy.zeros(numCategories)<EOL>initProb[<NUM_LIT:0>] = <NUM_LIT:0.5><EOL>initProb[<NUM_LIT:1>] = <NUM_LIT:0.5><EOL>firstOrder = dict()<EOL>for catIdx in range(numCategories):<EOL><INDENT>key = str([catIdx])<EOL>probs = numpy.ones(numCategories) / numCategories<EOL>if catIdx == <NUM_LIT:0> or catIdx == <NUM_LIT:1>:<EOL><INDENT>indices = numpy.array([<NUM_LIT:10>,<NUM_LIT:11>,<NUM_LIT:12>,<NUM_LIT>,<NUM_LIT>])<EOL>probs.fill(<NUM_LIT:0>)<EOL>probs[indices] = <NUM_LIT:1.0>    <EOL>probs /= probs.sum()<EOL><DEDENT>firstOrder[key] = probs<EOL><DEDENT>secondOrder = dict()<EOL>for firstIdx in range(numCategories):<EOL><INDENT>for secondIdx in range(numCategories):<EOL><INDENT>key = str([firstIdx, secondIdx])<EOL>probs = numpy.ones(numCategories) / numCategories<EOL>if key == str([<NUM_LIT:0>,<NUM_LIT:10>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT:15>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:0>,<NUM_LIT:11>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT:16>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:0>,<NUM_LIT:12>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:0>,<NUM_LIT>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:0>,<NUM_LIT>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:1>,<NUM_LIT:10>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT:20>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:1>,<NUM_LIT:11>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:1>,<NUM_LIT:12>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:1>,<NUM_LIT>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT>] = <NUM_LIT:1><EOL><DEDENT>elif key == str([<NUM_LIT:1>,<NUM_LIT>]):<EOL><INDENT>probs.fill(<NUM_LIT:0>)<EOL>probs[<NUM_LIT>] = <NUM_LIT:1><EOL><DEDENT>secondOrder[key] = probs<EOL><DEDENT><DEDENT>return (initProb, firstOrder, secondOrder, <NUM_LIT:3>)<EOL>

Generate the initial, first order, and second order transition
    probabilities for 'model1'. For this model, we generate the following
    set of sequences:

    0-10-15 (1X)
    0-11-16 (1X)
    0-12-17 (1X)
    0-13-18 (1X)
    0-14-19 (1X)

    1-10-20 (1X)
    1-11-21 (1X)
    1-12-22 (1X)
    1-13-23 (1X)
    1-14-24 (1X)

    Parameters:
    ----------------------------------------------------------------------
    numCategories:      Number of categories
    retval: (initProb, firstOrder, secondOrder, seqLen)
              initProb:     Initial probability for each category. This is a vector
                              of length len(categoryList).
              firstOrder:   A dictionary of the 1st order probabilities. The key
                              is the 1st element of the sequence, the value is
                              the probability of each 2nd element given the first.
              secondOrder:  A dictionary of the 2nd order probabilities. The key
                              is the first 2 elements of the sequence, the value is
                              the probability of each possible 3rd element given the
                              first two.
              seqLen:       Desired length of each sequence. The 1st element will
                            be generated using the initProb, the 2nd element by the
                            firstOrder table, and the 3rd and all successive
                            elements by the secondOrder table.

    Here is an example of some return values:
    initProb:         [0.7, 0.2, 0.1]

    firstOrder:       {'[0]': [0.3, 0.3, 0.4],
                       '[1]': [0.3, 0.3, 0.4],
                       '[2]': [0.3, 0.3, 0.4]}

    secondOrder:      {'[0,0]': [0.3, 0.3, 0.4],
                       '[0,1]': [0.3, 0.3, 0.4],
                       '[0,2]': [0.3, 0.3, 0.4],
                       '[1,0]': [0.3, 0.3, 0.4],
                       '[1,1]': [0.3, 0.3, 0.4],
                       '[1,2]': [0.3, 0.3, 0.4],
                       '[2,0]': [0.3, 0.3, 0.4],
                       '[2,1]': [0.3, 0.3, 0.4],
                       '[2,2]': [0.3, 0.3, 0.4]}


<EOL>initProb = numpy.ones(numCategories)/numCategories<EOL>def generatePeakedProbabilities(lastIdx,<EOL>numCategories=numCategories, <EOL>alpha=alpha):<EOL><INDENT>probs = numpy.random.dirichlet(alpha=[alpha]*numCategories)<EOL>probs[lastIdx] = <NUM_LIT:0.0><EOL>probs /= probs.sum()<EOL>return probs <EOL><DEDENT>firstOrder = dict()<EOL>for catIdx in range(numCategories):<EOL><INDENT>key = str([catIdx])<EOL>probs = generatePeakedProbabilities(catIdx) <EOL>firstOrder[key] = probs<EOL><DEDENT>secondOrder = dict()<EOL>for firstIdx in range(numCategories):<EOL><INDENT>for secondIdx in range(numCategories):<EOL><INDENT>key = str([firstIdx, secondIdx])<EOL>probs = generatePeakedProbabilities(secondIdx) <EOL>secondOrder[key] = probs<EOL><DEDENT><DEDENT>return (initProb, firstOrder, secondOrder, None)<EOL>

Generate the initial, first order, and second order transition
    probabilities for 'model2'. For this model, we generate peaked random
    transitions using dirichlet distributions.

    Parameters:
    ----------------------------------------------------------------------
    numCategories:      Number of categories
    alpha:              Determines the peakedness of the transitions. Low alpha
                        values (alpha=0.01) place the entire weight on a single
                        transition. Large alpha values (alpha=10) distribute the
                        evenly among all transitions. Intermediate values (alpha=0.5)
                        give a moderately peaked transitions.
    retval: (initProb, firstOrder, secondOrder, seqLen)
              initProb:     Initial probability for each category. This is a vector
                              of length len(categoryList).
              firstOrder:   A dictionary of the 1st order probabilities. The key
                              is the 1st element of the sequence, the value is
                              the probability of each 2nd element given the first.
              secondOrder:  A dictionary of the 2nd order probabilities. The key
                              is the first 2 elements of the sequence, the value is
                              the probability of each possible 3rd element given the
                              first two.
              seqLen:       Desired length of each sequence. The 1st element will
                            be generated using the initProb, the 2nd element by the
                            firstOrder table, and the 3rd and all successive
                            elements by the secondOrder table. None means infinite
                            length.

    Here is an example of some return values for an intermediate alpha value:
    initProb:         [0.33, 0.33, 0.33]

    firstOrder:       {'[0]': [0.2, 0.7, 0.1],
                       '[1]': [0.1, 0.1, 0.8],
                       '[2]': [0.1, 0.0, 0.9]}

    secondOrder:      {'[0,0]': [0.1, 0.0, 0.9],
                       '[0,1]': [0.0, 0.2, 0.8],
                       '[0,2]': [0.1, 0.8, 0.1],
                       ...
                       '[2,2]': [0.8, 0.2, 0.0]}


def _generateFile(filename, numRecords, categoryList, initProb, <EOL>firstOrderProb, secondOrderProb, seqLen, numNoise=<NUM_LIT:0>, resetsEvery=None):

<EOL>print("<STR_LIT>" % (filename))<EOL>fields = [('<STR_LIT>', '<STR_LIT:int>', '<STR_LIT:R>'), ('<STR_LIT:name>', '<STR_LIT:string>', '<STR_LIT>')]<EOL>outFile = FileRecordStream(filename, write=True, fields=fields)<EOL>initCumProb = initProb.cumsum()<EOL>firstOrderCumProb = dict()<EOL>for (key,value) in firstOrderProb.items():<EOL><INDENT>firstOrderCumProb[key] = value.cumsum()<EOL><DEDENT>secondOrderCumProb = dict()<EOL>for (key,value) in secondOrderProb.items():<EOL><INDENT>secondOrderCumProb[key] = value.cumsum()<EOL><DEDENT>elementsInSeq = []<EOL>numElementsSinceReset = <NUM_LIT:0><EOL>maxCatIdx = len(categoryList) - <NUM_LIT:1><EOL>for i in range(numRecords):<EOL><INDENT>if numElementsSinceReset == <NUM_LIT:0>:<EOL><INDENT>reset = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>reset = <NUM_LIT:0><EOL><DEDENT>rand = numpy.random.rand()<EOL>if len(elementsInSeq) == <NUM_LIT:0>:<EOL><INDENT>catIdx = numpy.searchsorted(initCumProb, rand)<EOL><DEDENT>elif len(elementsInSeq) == <NUM_LIT:1>:<EOL><INDENT>catIdx = numpy.searchsorted(firstOrderCumProb[str(elementsInSeq)], rand)<EOL><DEDENT>elif (len(elementsInSeq) >=<NUM_LIT:2>) and(seqLen is None or len(elementsInSeq) < seqLen-numNoise):<EOL><INDENT>catIdx = numpy.searchsorted(secondOrderCumProb[str(elementsInSeq[-<NUM_LIT:2>:])], rand)<EOL><DEDENT>else:   <EOL><INDENT>catIdx = numpy.random.randint(len(categoryList))<EOL><DEDENT>catIdx = min(maxCatIdx, catIdx)<EOL>outFile.appendRecord([reset,categoryList[catIdx]])    <EOL>elementsInSeq.append(catIdx)<EOL>numElementsSinceReset += <NUM_LIT:1><EOL>if resetsEvery is not None and numElementsSinceReset == resetsEvery:<EOL><INDENT>numElementsSinceReset = <NUM_LIT:0><EOL>elementsInSeq = []<EOL><DEDENT>if seqLen is not None and (len(elementsInSeq) == seqLen+numNoise):<EOL><INDENT>elementsInSeq = []<EOL><DEDENT><DEDENT>outFile.close()<EOL>

Generate a set of records reflecting a set of probabilities.

    Parameters:
    ----------------------------------------------------------------
    filename:         name of .csv file to generate
    numRecords:       number of records to generate
    categoryList:     list of category names
    initProb:         Initial probability for each category. This is a vector
                        of length len(categoryList).
    firstOrderProb:   A dictionary of the 1st order probabilities. The key
                        is the 1st element of the sequence, the value is
                        the probability of each 2nd element given the first.
    secondOrderProb:  A dictionary of the 2nd order probabilities. The key
                        is the first 2 elements of the sequence, the value is
                        the probability of each possible 3rd element given the
                        first two.
    seqLen:           Desired length of each sequence. The 1st element will
                        be generated using the initProb, the 2nd element by the
                        firstOrder table, and the 3rd and all successive
                        elements by the secondOrder table. None means infinite
                        length.
    numNoise:         Number of noise elements to place between each
                        sequence. The noise elements are evenly distributed from
                        all categories.
    resetsEvery:      If not None, generate a reset every N records

    Here is an example of some parameters:

    categoryList:     ['cat1', 'cat2', 'cat3']

    initProb:         [0.7, 0.2, 0.1]

    firstOrderProb:   {'[0]': [0.3, 0.3, 0.4],
                       '[1]': [0.3, 0.3, 0.4],
                       '[2]': [0.3, 0.3, 0.4]}

    secondOrderProb:  {'[0,0]': [0.3, 0.3, 0.4],
                       '[0,1]': [0.3, 0.3, 0.4],
                       '[0,2]': [0.3, 0.3, 0.4],
                       '[1,0]': [0.3, 0.3, 0.4],
                       '[1,1]': [0.3, 0.3, 0.4],
                       '[1,2]': [0.3, 0.3, 0.4],
                       '[2,0]': [0.3, 0.3, 0.4],
                       '[2,1]': [0.3, 0.3, 0.4],
                       '[2,2]': [0.3, 0.3, 0.4]}


<EOL>print("<STR_LIT>" % (filename))<EOL>numRecords, numFields = data.shape<EOL>fields = [('<STR_LIT>'%(i+<NUM_LIT:1>), '<STR_LIT:float>', '<STR_LIT>') for i in range(numFields)]<EOL>outFile = File(filename, fields)<EOL>for i in range(numRecords):<EOL><INDENT>outFile.write(data[i].tolist())<EOL><DEDENT>outFile.close()<EOL>


if temporalImp == '<STR_LIT>':<EOL><INDENT>return backtracking_tm.BacktrackingTM<EOL><DEDENT>elif temporalImp == '<STR_LIT>':<EOL><INDENT>return backtracking_tm_cpp.BacktrackingTMCPP<EOL><DEDENT>elif temporalImp == '<STR_LIT>':<EOL><INDENT>return backtracking_tm_shim.TMShim<EOL><DEDENT>elif temporalImp == '<STR_LIT>':<EOL><INDENT>return backtracking_tm_shim.TMCPPShim<EOL><DEDENT>elif temporalImp == '<STR_LIT>':<EOL><INDENT>return backtracking_tm_shim.MonitoredTMShim<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>"<EOL>"<STR_LIT>" % (temporalImp))<EOL><DEDENT>

Return the class corresponding to the given temporalImp string


def _buildArgs(f, self=None, kwargs={}):

<EOL>argTuples = getArgumentDescriptions(f)<EOL>argTuples = argTuples[<NUM_LIT:1>:]  <EOL>init = TMRegion.__init__<EOL>ourArgNames = [t[<NUM_LIT:0>] for t in getArgumentDescriptions(init)]<EOL>ourArgNames += [<EOL>'<STR_LIT>',    <EOL>]<EOL>for argTuple in argTuples[:]:<EOL><INDENT>if argTuple[<NUM_LIT:0>] in ourArgNames:<EOL><INDENT>argTuples.remove(argTuple)<EOL><DEDENT><DEDENT>if self:<EOL><INDENT>for argTuple in argTuples:<EOL><INDENT>argName = argTuple[<NUM_LIT:0>]<EOL>if argName in kwargs:<EOL><INDENT>argValue = kwargs.pop(argName)<EOL><DEDENT>else:<EOL><INDENT>if len(argTuple) == <NUM_LIT:2>:<EOL><INDENT>raise TypeError("<STR_LIT>" % argName)<EOL><DEDENT>argValue = argTuple[<NUM_LIT:2>]<EOL><DEDENT>setattr(self, argName, argValue)<EOL><DEDENT><DEDENT>return argTuples<EOL>

Get the default arguments from the function and assign as instance vars.

Return a list of 3-tuples with (name, description, defaultValue) for each
  argument to the function.

Assigns all arguments to the function as instance variables of TMRegion.
If the argument was not provided, uses the default value.

Pops any values from kwargs that go to the function.


typeNames = {int: '<STR_LIT>', float: '<STR_LIT>', str: '<STR_LIT>', bool: '<STR_LIT:bool>', tuple: '<STR_LIT>'}<EOL>def getArgType(arg):<EOL><INDENT>t = typeNames.get(type(arg), '<STR_LIT>')<EOL>count = <NUM_LIT:0> if t == '<STR_LIT>' else <NUM_LIT:1><EOL>if t == '<STR_LIT>':<EOL><INDENT>t = typeNames.get(type(arg[<NUM_LIT:0>]), '<STR_LIT>')<EOL>count = len(arg)<EOL><DEDENT>if t == '<STR_LIT:bool>':<EOL><INDENT>t = '<STR_LIT>'<EOL><DEDENT>return (t, count)<EOL><DEDENT>def getConstraints(arg):<EOL><INDENT>t = typeNames.get(type(arg), '<STR_LIT>')<EOL>if t == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif t == '<STR_LIT:bool>':<EOL><INDENT>return '<STR_LIT:bool>'<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>TemporalClass = _getTPClass(temporalImp)<EOL>tArgTuples = _buildArgs(TemporalClass.__init__)<EOL>temporalSpec = {}<EOL>for argTuple in tArgTuples:<EOL><INDENT>d = dict(<EOL>description=argTuple[<NUM_LIT:1>],<EOL>accessMode='<STR_LIT>',<EOL>dataType=getArgType(argTuple[<NUM_LIT:2>])[<NUM_LIT:0>],<EOL>count=getArgType(argTuple[<NUM_LIT:2>])[<NUM_LIT:1>],<EOL>constraints=getConstraints(argTuple[<NUM_LIT:2>]))<EOL>temporalSpec[argTuple[<NUM_LIT:0>]] = d<EOL><DEDENT>temporalSpec.update(dict(<EOL>columnCount=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>constraints='<STR_LIT>'),<EOL>cellsPerColumn=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>constraints='<STR_LIT>'),<EOL>inputWidth=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>constraints='<STR_LIT>'),<EOL>predictedSegmentDecrement=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>constraints='<STR_LIT>'),<EOL>orColumnOutputs=dict(<EOL>description="""<STR_LIT>""",<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>constraints='<STR_LIT:bool>'),<EOL>cellsSavePath=dict(<EOL>description="""<STR_LIT>""",<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:0>,<EOL>constraints='<STR_LIT>'),<EOL>temporalImp=dict(<EOL>description="""<STR_LIT>""",<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:0>,<EOL>constraints='<STR_LIT>'),<EOL>))<EOL>otherSpec = dict(<EOL>learningMode=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>defaultValue=True,<EOL>constraints='<STR_LIT:bool>'),<EOL>inferenceMode=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>defaultValue=False,<EOL>constraints='<STR_LIT:bool>'),<EOL>computePredictedActiveCellIndices=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>defaultValue=False,<EOL>constraints='<STR_LIT:bool>'),<EOL>anomalyMode=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>defaultValue=False,<EOL>constraints='<STR_LIT:bool>'),<EOL>topDownMode=dict(<EOL>description='<STR_LIT>'<EOL>'<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>defaultValue=False,<EOL>constraints='<STR_LIT:bool>'),<EOL>activeOutputCount=dict(<EOL>description='<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>constraints='<STR_LIT>'),<EOL>storeDenseOutput=dict(<EOL>description="""<STR_LIT>""",<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:1>,<EOL>constraints='<STR_LIT:bool>'),<EOL>logPathOutput=dict(<EOL>description='<STR_LIT>'<EOL>'<STR_LIT>',<EOL>accessMode='<STR_LIT>',<EOL>dataType='<STR_LIT>',<EOL>count=<NUM_LIT:0>,<EOL>constraints='<STR_LIT>'),<EOL>)<EOL>return temporalSpec, otherSpec<EOL>

Build the additional specs in three groups (for the inspector)

    Use the type of the default argument to set the Spec type, defaulting
    to 'Byte' for None and complex types

    Determines the spatial parameters based on the selected implementation.
    It defaults to TemporalMemory.
    Determines the temporal parameters based on the temporalImp


for attrName in self._getEphemeralMembersBase():<EOL><INDENT>if attrName != "<STR_LIT>":<EOL><INDENT>if hasattr(self, attrName):<EOL><INDENT>if self._loaded:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>print(self.__class__.__name__, "<STR_LIT>" %attrName)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if not self._loaded:<EOL><INDENT>for attrName in self._getEphemeralMembersBase():<EOL><INDENT>if attrName != "<STR_LIT>":<EOL><INDENT>assert not hasattr(self, attrName)<EOL><DEDENT>else:<EOL><INDENT>assert hasattr(self, attrName)<EOL><DEDENT><DEDENT><DEDENT>self._profileObj = None<EOL>self._iterations = <NUM_LIT:0><EOL>self._initEphemerals()<EOL>self._checkEphemeralMembers()<EOL>

Initialize all ephemeral data members, and give the derived
class the opportunity to do the same by invoking the
virtual member _initEphemerals(), which is intended to be
overridden.


<EOL>autoArgs = dict((name, getattr(self, name))<EOL>for name in self._temporalArgNames)<EOL>if self._tfdr is None:<EOL><INDENT>tpClass = _getTPClass(self.temporalImp)<EOL>if self.temporalImp in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT:r>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>',]:<EOL><INDENT>self._tfdr = tpClass(<EOL>numberOfCols=self.columnCount,<EOL>cellsPerColumn=self.cellsPerColumn,<EOL>**autoArgs)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT><DEDENT>


<EOL>if False and self.learningModeand self._iterations > <NUM_LIT:0> and self._iterations <= <NUM_LIT:10>:<EOL><INDENT>import hotshot<EOL>if self._iterations == <NUM_LIT:10>:<EOL><INDENT>print("<STR_LIT>")<EOL>stats = hotshot.stats.load("<STR_LIT>")<EOL>stats.strip_dirs()<EOL>stats.sort_stats('<STR_LIT:time>', '<STR_LIT>')<EOL>stats.print_stats()<EOL><DEDENT>if self._profileObj is None:<EOL><INDENT>print("<STR_LIT>")<EOL>if os.path.exists('<STR_LIT>'):<EOL><INDENT>os.remove('<STR_LIT>')<EOL><DEDENT>self._profileObj = hotshot.Profile("<STR_LIT>", <NUM_LIT:1>, <NUM_LIT:1>)<EOL><DEDENT>self._profileObj.runcall(self._compute, *[inputs, outputs])<EOL><DEDENT>else:<EOL><INDENT>self._compute(inputs, outputs)<EOL><DEDENT>

Run one iteration of :class:`~nupic.regions.tm_region.TMRegion` compute,
profiling it if requested.

:param inputs: (dict) mapping region input names to numpy.array values
:param outputs: (dict) mapping region output names to numpy.arrays that
       should be populated with output values by this method


<EOL>if self._tfdr is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>self._conditionalBreak()<EOL>self._iterations += <NUM_LIT:1><EOL>buInputVector = inputs['<STR_LIT>']<EOL>resetSignal = False<EOL>if '<STR_LIT>' in inputs:<EOL><INDENT>assert len(inputs['<STR_LIT>']) == <NUM_LIT:1><EOL>if inputs['<STR_LIT>'][<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>self._tfdr.reset()<EOL>self._sequencePos = <NUM_LIT:0>  <EOL><DEDENT><DEDENT>if self.computePredictedActiveCellIndices:<EOL><INDENT>prevPredictedState = self._tfdr.getPredictedState().reshape(-<NUM_LIT:1>).astype('<STR_LIT>')<EOL><DEDENT>if self.anomalyMode:<EOL><INDENT>prevPredictedColumns = self._tfdr.topDownCompute().copy().nonzero()[<NUM_LIT:0>]<EOL><DEDENT>tpOutput = self._tfdr.compute(buInputVector, self.learningMode, self.inferenceMode)<EOL>self._sequencePos += <NUM_LIT:1><EOL>if self.orColumnOutputs:<EOL><INDENT>tpOutput= tpOutput.reshape(self.columnCount,<EOL>self.cellsPerColumn).max(axis=<NUM_LIT:1>)<EOL><DEDENT>if self._fpLogTPOutput:<EOL><INDENT>output = tpOutput.reshape(-<NUM_LIT:1>)<EOL>outputNZ = tpOutput.nonzero()[<NUM_LIT:0>]<EOL>outStr = "<STR_LIT:U+0020>".join(["<STR_LIT>" % int(token) for token in outputNZ])<EOL>print(output.size, outStr, file=self._fpLogTPOutput)<EOL><DEDENT>outputs['<STR_LIT>'][:] = tpOutput.flat<EOL>if self.topDownMode:<EOL><INDENT>outputs['<STR_LIT>'][:] = self._tfdr.topDownCompute().copy()<EOL><DEDENT>if self.anomalyMode:<EOL><INDENT>activeLearnCells = self._tfdr.getLearnActiveStateT()<EOL>size = activeLearnCells.shape[<NUM_LIT:0>] * activeLearnCells.shape[<NUM_LIT:1>]<EOL>outputs['<STR_LIT>'][:] = activeLearnCells.reshape(size)<EOL>activeColumns = buInputVector.nonzero()[<NUM_LIT:0>]<EOL>outputs['<STR_LIT>'][:] = anomaly.computeRawAnomalyScore(<EOL>activeColumns, prevPredictedColumns)<EOL><DEDENT>if self.computePredictedActiveCellIndices:<EOL><INDENT>activeState = self._tfdr._getActiveState().reshape(-<NUM_LIT:1>).astype('<STR_LIT>')<EOL>activeIndices = numpy.where(activeState != <NUM_LIT:0>)[<NUM_LIT:0>]<EOL>predictedIndices= numpy.where(prevPredictedState != <NUM_LIT:0>)[<NUM_LIT:0>]<EOL>predictedActiveIndices = numpy.intersect1d(activeIndices, predictedIndices)<EOL>outputs["<STR_LIT>"].fill(<NUM_LIT:0>)<EOL>outputs["<STR_LIT>"][activeIndices] = <NUM_LIT:1><EOL>outputs["<STR_LIT>"].fill(<NUM_LIT:0>)<EOL>outputs["<STR_LIT>"][predictedActiveIndices] = <NUM_LIT:1><EOL><DEDENT>


Doesn't include the spatial, temporal and other parameters

:returns: (dict) the base Spec for TMRegion.


spec = cls.getBaseSpec()<EOL>t, o = _getAdditionalSpecs(temporalImp=gDefaultTemporalImp)<EOL>spec['<STR_LIT>'].update(t)<EOL>spec['<STR_LIT>'].update(o)<EOL>return spec<EOL>

Overrides :meth:`~nupic.bindings.regions.PyRegion.PyRegion.getSpec`.

The parameters collection is constructed based on the parameters specified
by the various components (spatialSpec, temporalSpec and otherSpec)


return self._tfdr<EOL>

:returns: instance of the underlying
          :class:`~nupic.algorithms.temporal_memory.TemporalMemory`
          algorithm object.


def getParameter(self, parameterName, index=-<NUM_LIT:1>):

if parameterName in self._temporalArgNames:<EOL><INDENT>return getattr(self._tfdr, parameterName)<EOL><DEDENT>else:<EOL><INDENT>return PyRegion.getParameter(self, parameterName, index)<EOL><DEDENT>

Overrides :meth:`~nupic.bindings.regions.PyRegion.PyRegion.getParameter`.

Get the value of a parameter. Most parameters are handled automatically by
:class:`~nupic.bindings.regions.PyRegion.PyRegion`'s parameter get mechanism. The
ones that need special treatment are explicitly handled here.


def setParameter(self, parameterName, index, parameterValue):

if parameterName in self._temporalArgNames:<EOL><INDENT>setattr(self._tfdr, parameterName, parameterValue)<EOL><DEDENT>elif parameterName == "<STR_LIT>":<EOL><INDENT>self.logPathOutput = parameterValue<EOL>if self._fpLogTPOutput is not None:<EOL><INDENT>self._fpLogTPOutput.close()<EOL>self._fpLogTPOutput = None<EOL><DEDENT>if parameterValue:<EOL><INDENT>self._fpLogTPOutput = open(self.logPathOutput, '<STR_LIT:w>')<EOL><DEDENT><DEDENT>elif hasattr(self, parameterName):<EOL><INDENT>setattr(self, parameterName, parameterValue)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>' + parameterName)<EOL><DEDENT>


self._tfdr.reset()<EOL>self._sequencePos = <NUM_LIT:0>  <EOL>return<EOL>


if self._tfdr is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>if hasattr(self._tfdr, '<STR_LIT>'):<EOL><INDENT>self.resetSequenceStates()<EOL>self._tfdr.finishLearning()<EOL><DEDENT>

Perform an internal optimization step that speeds up inference if we know
learning will not be performed anymore. This call may, for example, remove
all potential inputs to each column.


return TMRegionProto<EOL>


proto.temporalImp = self.temporalImp<EOL>proto.columnCount = self.columnCount<EOL>proto.inputWidth = self.inputWidth<EOL>proto.cellsPerColumn = self.cellsPerColumn<EOL>proto.learningMode = self.learningMode<EOL>proto.inferenceMode = self.inferenceMode<EOL>proto.anomalyMode = self.anomalyMode<EOL>proto.topDownMode = self.topDownMode<EOL>proto.computePredictedActiveCellIndices = (<EOL>self.computePredictedActiveCellIndices)<EOL>proto.orColumnOutputs = self.orColumnOutputs<EOL>if self.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.init("<STR_LIT>")<EOL><DEDENT>elif self.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.init("<STR_LIT>")<EOL><DEDENT>elif self.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.init("<STR_LIT>")<EOL><DEDENT>elif self.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.init("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>".format(<EOL>self.temporalImp))<EOL><DEDENT>self._tfdr.write(tmProto)<EOL>

Overrides :meth:`~nupic.bindings.regions.PyRegion.PyRegion.writeToProto`.

Write state to proto object.

:param proto: TMRegionProto capnproto object


instance = cls(proto.columnCount, proto.inputWidth, proto.cellsPerColumn)<EOL>instance.temporalImp = proto.temporalImp<EOL>instance.learningMode = proto.learningMode<EOL>instance.inferenceMode = proto.inferenceMode<EOL>instance.anomalyMode = proto.anomalyMode<EOL>instance.topDownMode = proto.topDownMode<EOL>instance.computePredictedActiveCellIndices = (<EOL>proto.computePredictedActiveCellIndices)<EOL>instance.orColumnOutputs = proto.orColumnOutputs<EOL>if instance.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.backtrackingTM<EOL><DEDENT>elif instance.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.backtrackingTMCpp<EOL><DEDENT>elif instance.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.temporalMemory<EOL><DEDENT>elif instance.temporalImp == "<STR_LIT>":<EOL><INDENT>tmProto = proto.temporalMemory<EOL><DEDENT>else:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>".format(<EOL>instance.temporalImp))<EOL><DEDENT>instance._tfdr = _getTPClass(proto.temporalImp).read(tmProto)<EOL>return instance<EOL>

Overrides :meth:`~nupic.bindings.regions.PyRegion.PyRegion.readFromProto`.

Read state from proto object.

:param proto: TMRegionProto capnproto object


state = self.__dict__.copy()<EOL>for ephemeralMemberName in self._getEphemeralMembersAll():<EOL><INDENT>state.pop(ephemeralMemberName, None)<EOL><DEDENT>return state<EOL>

Return serializable state.  This function will return a version of the
__dict__ with all "ephemeral" members stripped out.  "Ephemeral" members
are defined as those that do not need to be (nor should be) stored
in any kind of persistent file (e.g., NuPIC network XML file.)


if self._tfdr is not None:<EOL><INDENT>self._tfdr.saveToFile(filePath)<EOL><DEDENT>


if self._tfdr is not None:<EOL><INDENT>self._tfdr.loadFromFile(filePath)<EOL><DEDENT>

Overrides :meth:`~nupic.bindings.regions.PyRegion.PyRegion.deSerializeExtraData`.

This method is called during network deserialization with an external
filename that can be used to bypass pickle for loading large binary states.

:param filePath: (string) absolute file path


if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.storeDenseOutput = False<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.computePredictedActiveCellIndices = False<EOL><DEDENT>self.__dict__.update(state)<EOL>self._loaded = True<EOL>self._initialize()<EOL>

Set the state of ourself from a serialized state.


self._sequencePos = <NUM_LIT:0><EOL>self._fpLogTPOutput = None<EOL>self.logPathOutput = None<EOL>

Initialize all ephemerals used by derived classes.


return ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>',]<EOL>

Callback that returns a list of all "ephemeral" members (i.e., data members
that should not and/or cannot be pickled.)


return [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>]<EOL>


return self._getEphemeralMembersBase() + self._getEphemeralMembers()<EOL>

Returns a concatenated list of both the standard base class
ephemeral members, as well as any additional ephemeral members
(e.g., file handles, etc.).


if name == '<STR_LIT>':<EOL><INDENT>return self.outputWidth<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>return self.columnCount<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>return self.outputWidth<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self.outputWidth<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self.outputWidth<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>


def getParameterArrayCount(self, name, index):

p = self.getParameter(name)<EOL>if (not hasattr(p, '<STR_LIT>')):<EOL><INDENT>raise Exception("<STR_LIT>" % name)<EOL><DEDENT>return len(p)<EOL>


def getParameterArray(self, name, index, a):

p = self.getParameter(name)<EOL>if (not hasattr(p, '<STR_LIT>')):<EOL><INDENT>raise Exception("<STR_LIT>" % name)<EOL><DEDENT>if len(p) >  <NUM_LIT:0>:<EOL><INDENT>a[:] = p[:]<EOL><DEDENT>


if self._sdrClassifier is None:<EOL><INDENT>self._sdrClassifier = SDRClassifierFactory.create(<EOL>steps=self.stepsList,<EOL>alpha=self.alpha,<EOL>verbosity=self.verbosity,<EOL>implementation=self.implementation,<EOL>)<EOL><DEDENT>

Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.initialize`.

Is called once by NuPIC before the first call to compute().
Initializes self._sdrClassifier if it is not already initialized.


return self._sdrClassifier<EOL>


def getParameter(self, name, index=-<NUM_LIT:1>):

<EOL>return PyRegion.getParameter(self, name, index)<EOL>


def setParameter(self, name, index, value):

if name == "<STR_LIT>":<EOL><INDENT>self.learningMode = bool(int(value))<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>self.inferenceMode = bool(int(value))<EOL><DEDENT>else:<EOL><INDENT>return PyRegion.setParameter(self, name, index, value)<EOL><DEDENT>


return SDRClassifierRegionProto<EOL>

:returns: the pycapnp proto type that the class uses for serialization.


proto.implementation = self.implementation<EOL>proto.steps = self.steps<EOL>proto.alpha = self.alpha<EOL>proto.verbosity = self.verbosity<EOL>proto.maxCategoryCount = self.maxCategoryCount<EOL>proto.learningMode = self.learningMode<EOL>proto.inferenceMode = self.inferenceMode<EOL>proto.recordNum = self.recordNum<EOL>self._sdrClassifier.write(proto.sdrClassifier)<EOL>

Write state to proto object.

:param proto: SDRClassifierRegionProto capnproto object


instance = cls()<EOL>instance.implementation = proto.implementation<EOL>instance.steps = proto.steps<EOL>instance.stepsList = [int(i) for i in proto.steps.split("<STR_LIT:U+002C>")]<EOL>instance.alpha = proto.alpha<EOL>instance.verbosity = proto.verbosity<EOL>instance.maxCategoryCount = proto.maxCategoryCount<EOL>instance._sdrClassifier = SDRClassifierFactory.read(proto)<EOL>instance.learningMode = proto.learningMode<EOL>instance.inferenceMode = proto.inferenceMode<EOL>instance.recordNum = proto.recordNum<EOL>return instance<EOL>

Read state from proto object.

:param proto: SDRClassifierRegionProto capnproto object


<EOL>self._computeFlag = True<EOL>patternNZ = inputs["<STR_LIT>"].nonzero()[<NUM_LIT:0>]<EOL>if self.learningMode:<EOL><INDENT>categories = [category for category in inputs["<STR_LIT>"]<EOL>if category >= <NUM_LIT:0>]<EOL>if len(categories) > <NUM_LIT:0>:<EOL><INDENT>bucketIdxList = []<EOL>actValueList = []<EOL>for category in categories:<EOL><INDENT>bucketIdxList.append(int(category))<EOL>if "<STR_LIT>" not in inputs:<EOL><INDENT>actValueList.append(int(category))<EOL><DEDENT>else:<EOL><INDENT>actValueList.append(float(inputs["<STR_LIT>"]))<EOL><DEDENT><DEDENT>classificationIn = {"<STR_LIT>": bucketIdxList,<EOL>"<STR_LIT>": actValueList}<EOL><DEDENT>else:<EOL><INDENT>if "<STR_LIT>" not in inputs:<EOL><INDENT>raise KeyError("<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" not in inputs:<EOL><INDENT>raise KeyError("<STR_LIT>")<EOL><DEDENT>classificationIn = {"<STR_LIT>": int(inputs["<STR_LIT>"]),<EOL>"<STR_LIT>": float(inputs["<STR_LIT>"])}<EOL><DEDENT><DEDENT>else:<EOL><INDENT>classificationIn = {"<STR_LIT>": <NUM_LIT:0>, "<STR_LIT>": <NUM_LIT:0>}<EOL><DEDENT>clResults = self._sdrClassifier.compute(recordNum=self.recordNum,<EOL>patternNZ=patternNZ,<EOL>classification=classificationIn,<EOL>learn=self.learningMode,<EOL>infer=self.inferenceMode)<EOL>if clResults is not None and len(clResults) > <NUM_LIT:0>:<EOL><INDENT>outputs['<STR_LIT>'][:len(clResults["<STR_LIT>"])] =clResults["<STR_LIT>"]<EOL>for step in self.stepsList:<EOL><INDENT>stepIndex = self.stepsList.index(step)<EOL>categoryOut = clResults["<STR_LIT>"][clResults[step].argmax()]<EOL>outputs['<STR_LIT>'][stepIndex] = categoryOut<EOL>stepProbabilities = clResults[step]<EOL>for categoryIndex in xrange(self.maxCategoryCount):<EOL><INDENT>flatIndex = categoryIndex + stepIndex * self.maxCategoryCount<EOL>if categoryIndex < len(stepProbabilities):<EOL><INDENT>outputs['<STR_LIT>'][flatIndex] =stepProbabilities[categoryIndex]<EOL><DEDENT>else:<EOL><INDENT>outputs['<STR_LIT>'][flatIndex] = <NUM_LIT:0.0><EOL><DEDENT><DEDENT><DEDENT><DEDENT>self.recordNum += <NUM_LIT:1><EOL>

Process one input sample.
This method is called by the runtime engine.

:param inputs: (dict) mapping region input names to numpy.array values
:param outputs: (dict) mapping region output names to numpy.arrays that
       should be populated with output values by this method


def customCompute(self, recordNum, patternNZ, classification):

<EOL>if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>self._computeFlag = False<EOL><DEDENT>if self._computeFlag:<EOL><INDENT>warnings.simplefilter('<STR_LIT:error>', DeprecationWarning)<EOL>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>DeprecationWarning)<EOL><DEDENT>return self._sdrClassifier.compute(recordNum,<EOL>patternNZ,<EOL>classification,<EOL>self.learningMode,<EOL>self.inferenceMode)<EOL>

Just return the inference value from one input sample. The actual
learning happens in compute() -- if, and only if learning is enabled --
which is called when you run the network.

.. warning:: This method is deprecated and exists only to maintain backward
   compatibility. This method is deprecated, and will be removed. Use
   :meth:`nupic.engine.Network.run` instead, which will call
   :meth:`~nupic.regions.sdr_classifier_region.compute`.

:param recordNum: (int) Record number of the input sample.
:param patternNZ: (list) of the active indices from the output below
:param classification: (dict) of the classification information:

       * ``bucketIdx``: index of the encoder bucket
       * ``actValue``:  actual value going into the encoder

:returns: (dict) containing inference results, one entry for each step in
          ``self.steps``. The key is the number of steps, the value is an
          array containing the relative likelihood for each ``bucketIdx``
          starting from 0.

          For example:

          ::

            {'actualValues': [0.0, 1.0, 2.0, 3.0]
              1 : [0.1, 0.3, 0.2, 0.7]
              4 : [0.2, 0.4, 0.3, 0.5]}


if outputName == "<STR_LIT>":<EOL><INDENT>return len(self.stepsList)<EOL><DEDENT>elif outputName == "<STR_LIT>":<EOL><INDENT>return len(self.stepsList) * self.maxCategoryCount<EOL><DEDENT>elif outputName == "<STR_LIT>":<EOL><INDENT>return self.maxCategoryCount<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>".format(outputName))<EOL><DEDENT>


return ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>']<EOL>

List of attributes to not save with serialized state.


self._firstComputeCall = True<EOL>self._accuracy = None<EOL>self._protoScores = None<EOL>self._categoryDistances = None<EOL>self._knn = knn_classifier.KNNClassifier(**self.knnParams)<EOL>for x in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if not hasattr(self, x):<EOL><INDENT>setattr(self, x, None)<EOL><DEDENT><DEDENT>

Initialize attributes that are not saved with the checkpoint.


if '<STR_LIT:version>' not in state:<EOL><INDENT>self.__dict__.update(state)<EOL><DEDENT>elif state['<STR_LIT:version>'] == <NUM_LIT:1>:<EOL><INDENT>if "<STR_LIT>" in state:<EOL><INDENT>state.pop("<STR_LIT>")<EOL><DEDENT>knnState = state['<STR_LIT>']<EOL>del state['<STR_LIT>']<EOL>self.__dict__.update(state)<EOL>self._initEphemerals()<EOL>self._knn.__setstate__(knnState)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>self.version = KNNClassifierRegion.__VERSION__<EOL>


state = self.__dict__.copy()<EOL>state['<STR_LIT>'] = self._knn.__getstate__()<EOL>del state['<STR_LIT>']<EOL>for field in self._getEphemeralAttributes():<EOL><INDENT>del state[field]<EOL><DEDENT>return state<EOL>


return self._knn<EOL>


if name == "<STR_LIT>":<EOL><INDENT>return self._knn._numPatterns<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._getPatternMatrix()<EOL><DEDENT>elif name == "<STR_LIT:k>":<EOL><INDENT>return self._knn.k<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.distanceNorm<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.distanceMethod<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.distThreshold<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.binarizationThreshold<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.doBinarization<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.useSparseMemory<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.sparseThreshold<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.numWinners<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.relativeThreshold<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>v = self._knn.numSVDSamples<EOL>return v if v is not None else <NUM_LIT:0><EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>v = self._knn.numSVDDims<EOL>return v if v is not None else <NUM_LIT:0><EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>v = self._knn.fractionOfMax<EOL>return v if v is not None else <NUM_LIT:0><EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._useAuxiliary<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._justUseAuxiliary<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._doSphering<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self._knn.cellsPerCol<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>return self.maxStoredPatterns<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>return self._knn._categoryRecencyList<EOL><DEDENT>else:<EOL><INDENT>return PyRegion.getParameter(self, name, index)<EOL><DEDENT>