def run(inputFiles,
        networkConfigsFile,
        plotResults,
        runClustering):
  with open(networkConfigsFile, 'rb') as jsonFile:
    networkConfigurations = simplejson.load(jsonFile)

  expResults = []
  for networkConfig in networkConfigurations:
    for inputFile in inputFiles:
      expResult = runExperiment(networkConfig, inputFile, runClustering)
      expResults.append(expResult)
      if plotResults:
        # traces = loadTraces(fileName)
        traces = expResult['expTrace']
        tmParams = networkConfig['tmRegionConfig']['regionParams']
        numCells = tmParams['cellsPerColumn'] * tmParams['inputWidth']
        numClusters = len(set(traces['actualCategory']))
        if os.path.exists(OUTPUT_DIR):
          shutil.rmtree(OUTPUT_DIR)
        os.makedirs(OUTPUT_DIR)
        cellsType = CELLS_TO_CLUSTER
        numSteps = len(traces['recordNumber'])
        pointsToPlot = numSteps / 10

        vizInterCategoryClusters(traces,
                                 OUTPUT_DIR,
                                 cellsType,
                                 numCells,
                                 pointsToPlot)

        vizInterSequenceClusters(traces, OUTPUT_DIR, cellsType, numCells,
                                 numClusters)

        xl = None
        plotTemporalMemoryStates = False
        title = inputFile.split('/')[-1]
        outputFile = '%s.png' % inputFile[:-4]

        plotTraces(xl, traces, title, ANOMALY_SCORE, outputFile,
                   runClustering)

  traceOutputDir = os.path.join(OUTPUT_DIR, 'traces')
  if not os.path.exists(traceOutputDir):
    os.makedirs(traceOutputDir)
  saveTraces(os.path.join(traceOutputDir, '%s.csv'), expResults)
Example #2
0
def run(inputFiles, networkConfigsFile, plotResults, runClustering):
    with open(networkConfigsFile, 'rb') as jsonFile:
        networkConfigurations = simplejson.load(jsonFile)

    expResults = []
    for networkConfig in networkConfigurations:
        for inputFile in inputFiles:
            expResult = runExperiment(networkConfig, inputFile, runClustering)
            expResults.append(expResult)
            if plotResults:
                # traces = loadTraces(fileName)
                traces = expResult['expTrace']
                tmParams = networkConfig['tmRegionConfig']['regionParams']
                numCells = tmParams['cellsPerColumn'] * tmParams['inputWidth']
                numClusters = len(set(traces['actualCategory']))
                if os.path.exists(OUTPUT_DIR):
                    shutil.rmtree(OUTPUT_DIR)
                os.makedirs(OUTPUT_DIR)
                cellsType = CELLS_TO_CLUSTER
                numSteps = len(traces['recordNumber'])
                pointsToPlot = numSteps / 10

                vizInterCategoryClusters(traces, OUTPUT_DIR, cellsType,
                                         numCells, pointsToPlot)

                vizInterSequenceClusters(traces, OUTPUT_DIR, cellsType,
                                         numCells, numClusters)

                xl = None
                plotTemporalMemoryStates = False
                title = inputFile.split('/')[-1]
                outputFile = '%s.png' % inputFile[:-4]
                plotTraces(xl, traces, title, outputFile,
                           plotTemporalMemoryStates)

    traceOutputDir = os.path.join(OUTPUT_DIR, 'traces')
    if not os.path.exists(traceOutputDir):
        os.makedirs(traceOutputDir)
    saveTraces(os.path.join(traceOutputDir, '%s.csv'), expResults)
  perms = list(permutations(cluster, 2))
  for (sdr1, sdr2) in perms:
    overlap = percentOverlap(sdr1, sdr2)
    overlaps.append(overlap)
  return sum(overlaps) / len(overlaps)



if __name__ == "__main__":
  (_options, _args) = _getArgs()

  fileName = _options.fileName

  traces = loadTraces(fileName)
  outputDir = fileName[:-4]
  if not os.path.exists(outputDir):
    os.makedirs(outputDir)
  cellsType = CELLS_TO_CLUSTER
  numCells = 2048 * 32
  numSteps = len(traces['recordNumber'])
  pointsToPlot = numSteps / 10
  numClasses = len(set(traces['actualCategory']))
  vizInterCategoryClusters(traces,
                           outputDir,
                           cellsType,
                           numCells,
                           pointsToPlot)

  vizInterSequenceClusters(traces, outputDir, cellsType, numCells,
                           numClasses)