def plotNetworkState(experiment, plotVerbosity, trainingPasses, phase=""):

  if plotVerbosity >= 1:
    rcParams["figure.figsize"] = _PLOT_WIDTH, _PLOT_HEIGHT

    # Plot Union SDR trace
    dataTrace = experiment.up._mmTraces["activeCells"].data
    unionSizeTrace = [len(datum) for datum in dataTrace]
    x = [i for i in xrange(len(unionSizeTrace))]
    stdDevs = None
    title = "Union Size; {0} training passses vs. Time".format(trainingPasses)
    data_utils.getErrorbarFigure(title, x, unionSizeTrace, stdDevs, "Time",
                                 "Union Size")
    if plotVerbosity >= 2:
      title = "training passes: {0}, phase: {1}".format(trainingPasses, phase)
      experiment.up.mmGetPlotConnectionsPerColumn(title=title)
      experiment.tm.mmGetCellActivityPlot(title=title,
                                          activityType="activeCells",
                                          showReset=True,
                                          resetShading=_PLOT_RESET_SHADING)
      experiment.tm.mmGetCellActivityPlot(title=title,
                                          activityType="predictedActiveCells",
                                          showReset=True,
                                          resetShading=_PLOT_RESET_SHADING)
      experiment.up.mmGetCellActivityPlot(title=title,
                                          showReset=True,
                                          resetShading=_PLOT_RESET_SHADING)
def main(inputPath, csvOutputPath, imgOutputPath):
  # remove existing /overlaps.csv if present
  if os.path.exists(csvOutputPath + _OVERLAPS_FILE_NAME):
    os.remove(csvOutputPath + _OVERLAPS_FILE_NAME)

  if not os.path.exists(csvOutputPath):
    os.makedirs(csvOutputPath)

  if not os.path.exists(imgOutputPath):
    os.makedirs(imgOutputPath)

  print "Computing Union SDR overlap between SDR traces in following dir:"
  print inputPath + "\n"

  filesAll = os.listdir(inputPath)
  files = []
  for _ in xrange(len(filesAll)):
    if filesAll[_].find('unionSdrTrace') != -1:
      files.append(filesAll[_])

  if len(files) != 2:
    print "Found {0} files at input path {1} - Requires exactly 2.".format(
      len(files), inputPath)
    sys.exit(1)

  pathNoLearn = inputPath + "/" + files[0]
  pathLearn = inputPath + "/" + files[1]

  print "Comparing files..."
  print pathLearn
  print pathNoLearn + "\n"

  # Load source A
  with open(pathLearn, "rU") as fileA:
    csvReader = csv.reader(fileA)
    dataA = [line for line in csvReader]
  unionSizeA = [len(datum) for datum in dataA]

  # Load source B
  with open(pathNoLearn, "rU") as fileB:
    csvReader = csv.reader(fileB)
    dataB = [line for line in csvReader]
  unionSizeB = [len(datum) for datum in dataB]

  assert len(dataA) == len(dataB)

  # To display all plots on the same y scale
  yRangeMax = 1.05 * max(max(unionSizeA), max(unionSizeB))

  # Plot union size for data A
  x = [i for i in xrange(len(dataA))]
  stdDevs = None
  title = "Union Size with Learning vs. Time"
  data_utils.getErrorbarFigure(title, x, unionSizeA, stdDevs, "Time",
                               "Union Size", yRangeMax=yRangeMax)
  figPath = "{0}/{1}.png".format(imgOutputPath, title)
  plt.savefig(figPath, bbox_inches="tight")

  # Plot union size for data B and save image
  title = "Union Size without Learning vs. Time"
  data_utils.getErrorbarFigure(title, x, unionSizeB, stdDevs, "Time",
                               "Union Size", yRangeMax=yRangeMax)
  figPath = "{0}/{1}.png".format(imgOutputPath, title)
  plt.savefig(figPath, bbox_inches="tight")

  with open(csvOutputPath + _OVERLAPS_FILE_NAME, "wb") as outputFile:
    csvWriter = csv.writer(outputFile)
    overlaps = [getOverlap(dataA[i], dataB[i]) for i in xrange(len(dataA))]
    csvWriter.writerow(overlaps)
    outputFile.flush()

  # Plot overlap and save image
  title = "Learn-NoLearn Union SDR Overlap vs. Time"
  data_utils.getErrorbarFigure(title, x, overlaps, stdDevs, "Time","Overlap",
                               yRangeMax=yRangeMax)
  figPath = "{0}/{1}.png".format(imgOutputPath, title)
  plt.savefig(figPath, bbox_inches="tight")

  raw_input("Press any key to exit...")