当前位置: 首页>>代码示例>>Python>>正文


Python monitor_mixin_base.MonitorMixinBase类代码示例

本文整理汇总了Python中nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase的典型用法代码示例。如果您正苦于以下问题:Python MonitorMixinBase类的具体用法?Python MonitorMixinBase怎么用?Python MonitorMixinBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MonitorMixinBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: trainTemporalMemory

def trainTemporalMemory(experiment, inputSequences, inputCategories,
                        trainingPasses, consoleVerbosity):
  burstingColsString = ""
  for i in xrange(trainingPasses):
    experiment.runNetworkOnSequences(inputSequences,
                                     inputCategories,
                                     tmLearn=True,
                                     upLearn=None,
                                     classifierLearn=False,
                                     verbosity=consoleVerbosity,
                                     progressInterval=_SHOW_PROGRESS_INTERVAL)

    if consoleVerbosity > 1:
      print
      print MonitorMixinBase.mmPrettyPrintMetrics(
        experiment.tm.mmGetDefaultMetrics())
      print
    stats = experiment.getBurstingColumnsStats()
    burstingColsString += "{0}\t{1}\t{2}\t{3}\n".format(i, stats[0], stats[1],
                                                        stats[2])

    experiment.tm.mmClearHistory()
    experiment.up.mmClearHistory()

  if consoleVerbosity > 0:
    print "\nTemporal Memory Bursting Columns stats..."
    print "Pass\tMean\t\tStdDev\t\tMax"
    print burstingColsString
开发者ID:akhilaananthram,项目名称:nupic.research,代码行数:28,代码来源:variation_robustness_experiment.py

示例2: trainTwoPass

def trainTwoPass(runner, exhaustiveAgents, completeSequenceLength, verbosity):
  print "Training temporal memory..."
  sequences = runner.generateSequences(completeSequenceLength *
                                       TWOPASS_TM_TRAINING_REPS,
                                       exhaustiveAgents,
                                       verbosity=verbosity)
  runner.feedLayers(sequences, tmLearn=True, tpLearn=False,
                    verbosity=verbosity,
                    showProgressInterval=SHOW_PROGRESS_INTERVAL)
  print
  print MonitorMixinBase.mmPrettyPrintMetrics(runner.tp.mmGetDefaultMetrics() +
                                              runner.tm.mmGetDefaultMetrics())
  print
  print "Training temporal pooler..."

  runner.tm.mmClearHistory()
  runner.tp.mmClearHistory()
  sequences = runner.generateSequences(completeSequenceLength *
                                       TWOPASS_TP_TRAINING_REPS,
                                       exhaustiveAgents,
                                       verbosity=verbosity)
  runner.feedLayers(sequences, tmLearn=False, tpLearn=True,
                    verbosity=verbosity,
                    showProgressInterval=SHOW_PROGRESS_INTERVAL)
  print
  print MonitorMixinBase.mmPrettyPrintMetrics(runner.tp.mmGetDefaultMetrics() +
                                              runner.tm.mmGetDefaultMetrics())
  print
开发者ID:Starcounter-Jack,项目名称:nupic.research,代码行数:28,代码来源:experimentCosynePlot.py

示例3: train

def train(tm, sequences, feedback_seq=None, trials=trials,
          feedback_buffer=10, clearhistory=True, verbose=0):

  for i in range(trials):
    for j, sensorPattern in enumerate(sequences):
      if sensorPattern is None:
        tm.reset()
      else:
        if i<feedback_buffer:
          feedback = set([random.randint(0, 2047) for _ in range(feedback_n)])
        elif feedback_seq is not None:
          feedback = feedback_seq[j]
        else:
          feedback = set()
        tm.compute(sensorPattern, activeApicalCells=feedback,
                   learn=True, sequenceLabel=None)

    if clearhistory:
      if i == trials-1:
        if verbose > 0:
          print " TM metrics after training"
          print MonitorMixinBase.mmPrettyPrintMetrics(tm.mmGetDefaultMetrics())

        if verbose > 1:
          print " TM traces after training"
          print MonitorMixinBase.mmPrettyPrintTraces(tm.mmGetDefaultTraces(verbosity=True),
                                                     breakOnResets=tm.mmGetTraceResets())

      tm.mmClearHistory()
开发者ID:hernandezurbina,项目名称:nupic.research,代码行数:29,代码来源:feedback_experiment.py

示例4: trainUP

def trainUP(tm, sequences, up=None, trials=trials, clearhistory=True, verbose=0):

  for i in range(trials):
    for j, sensorPattern in enumerate(sequences):
      if sensorPattern is None:
        tm.reset()
        if up is not None:
          up.reset()
      else:
        if up is None:
          feedback = set()
        else:
          feedback = set(np.nonzero(up.getUnionSDR())[0])
        tm.compute(sensorPattern, activeApicalCells=feedback,
                   learn=True, sequenceLabel=None)
        if up is not None:
          activeCells, predActiveCells, burstingCols, = getUnionTemporalPoolerInput(tm)
          up.compute(activeCells, predActiveCells, learn=False)

    if clearhistory:
      if i == trials-1:
        if verbose > 0:
          print " TM metrics after training"
          print MonitorMixinBase.mmPrettyPrintMetrics(tm.mmGetDefaultMetrics())

        if verbose > 1:
          print " TM traces after training"
          print MonitorMixinBase.mmPrettyPrintTraces(tm.mmGetDefaultTraces(verbosity=True),
                                                     breakOnResets=tm.mmGetTraceResets())

      tm.mmClearHistory()
开发者ID:hernandezurbina,项目名称:nupic.research,代码行数:31,代码来源:feedback_experiment.py

示例5: runTMtrainingPhase

def runTMtrainingPhase(experiment):

  # Train only the Temporal Memory on the generated sequences
  if trainingPasses > 0:

    print "\nTraining Temporal Memory..."
    if consoleVerbosity > 0:
      print "\nPass\tBursting Columns Mean\tStdDev\tMax"

    for i in xrange(trainingPasses):
      experiment.runNetworkOnSequences(generatedSequences,
                                       labeledSequences,
                                       tmLearn=True,
                                       upLearn=None,
                                       verbosity=consoleVerbosity,
                                       progressInterval=_SHOW_PROGRESS_INTERVAL)

      if consoleVerbosity > 0:
        stats = experiment.getBurstingColumnsStats()
        print "{0}\t{1}\t{2}\t{3}".format(i, stats[0], stats[1], stats[2])

      # Reset the TM monitor mixin's records accrued during this training pass
      # experiment.tm.mmClearHistory()

    print
    print MonitorMixinBase.mmPrettyPrintMetrics(
      experiment.tm.mmGetDefaultMetrics())
    print
开发者ID:chanceraine,项目名称:nupic.research,代码行数:28,代码来源:tp_trained_tm_backwardLearning.py

示例6: run

def run(tm, mutate_times, sequences, alphabet, feedback_seq=None, mutation=0, verbose=0):

  allLabels = []
  tm.reset()
  for j, sensorPattern in enumerate(sequences):
    if sensorPattern is None:
      tm.reset()
    else:
      if j in mutate_times:
        if mutation:
          continue
        else:
          sensorPattern = set([random.randint(0, 2047) for _ in sensorPattern])

      if feedback_seq is not None:
        feedback = feedback_seq[j]
      else:
        feedback = set()

      tm.compute(sensorPattern, activeApicalCells=feedback,
                 learn=True, sequenceLabel=None)

      allLabels.append(labelPattern(sensorPattern, alphabet))

  ys = [len(x) for x in tm.mmGetTraceUnpredictedActiveColumns().data]

  if verbose > 0:
    print " TM metrics on test sequence"
    print MonitorMixinBase.mmPrettyPrintMetrics(tm.mmGetDefaultMetrics())

  if verbose > 1:
    print MonitorMixinBase.mmPrettyPrintTraces(tm.mmGetDefaultTraces(verbosity=True),
                                               breakOnResets=tm.mmGetTraceResets())

  return ys, allLabels
开发者ID:hernandezurbina,项目名称:nupic.research,代码行数:35,代码来源:feedback_experiment.py

示例7: trainOnline

def trainOnline(runner, exhaustiveAgents, completeSequenceLength, reps, verbosity):
    print "Training temporal memory and temporal pooler..."
    sequences = runner.generateSequences(completeSequenceLength * reps, exhaustiveAgents, verbosity=verbosity)
    runner.feedLayers(
        sequences, tmLearn=True, tpLearn=True, verbosity=verbosity, showProgressInterval=SHOW_PROGRESS_INTERVAL
    )
    print
    print MonitorMixinBase.mmPrettyPrintMetrics(runner.tp.mmGetDefaultMetrics() + runner.tm.mmGetDefaultMetrics())
    print
开发者ID:jaredweiss,项目名称:nupic.research,代码行数:9,代码来源:experimentCosynePlot.py

示例8: _printInfo

  def _printInfo(self):
    if VERBOSITY >= 2:
      print MonitorMixinBase.mmPrettyPrintTraces(
        self.tp.mmGetDefaultTraces(verbosity=3) +
        self.tm.mmGetDefaultTraces(verbosity=3),
        breakOnResets=self.tm.mmGetTraceResets())
      print

    if VERBOSITY >= 1:
      print MonitorMixinBase.mmPrettyPrintMetrics(
        self.tp.mmGetDefaultMetrics() + self.tm.mmGetDefaultMetrics())
      print
开发者ID:Starcounter-Jack,项目名称:nupic.research,代码行数:12,代码来源:stp_test.py

示例9: feedLayers

  def feedLayers(self, sequences, tmLearn=True, tpLearn=None, verbosity=0,
                 showProgressInterval=None):
    """
    Feed the given sequences to the HTM algorithms.

    @param tmLearn:   (bool)      Either False, or True
    @param tpLearn:   (None,bool) Either None, False, or True. If None,
                                  temporal pooler will be skipped.

    @param showProgressInterval: (int) Prints progress every N iterations,
                                       where N is the value of this param
    """
    (sensorSequence,
     motorSequence,
     sensorimotorSequence,
     sequenceLabels) = sequences

    currentTime = time.time()

    for i in xrange(len(sensorSequence)):
      sensorPattern = sensorSequence[i]
      motorPattern = motorSequence[i]
      sensorimotorPattern = sensorimotorSequence[i]
      sequenceLabel = sequenceLabels[i]

      self.feedTransition(sensorPattern, motorPattern, sensorimotorPattern,
                          tmLearn=tmLearn, tpLearn=tpLearn,
                          sequenceLabel=sequenceLabel)

      if (showProgressInterval is not None and
          i > 0 and
          i % showProgressInterval == 0):
        print ("Fed {0} / {1} elements of the sequence "
               "in {2:0.2f} seconds.".format(
                 i, len(sensorSequence), time.time() - currentTime))
        currentTime = time.time()

    if verbosity >= 2:
      # Print default TM traces
      traces = self.tm.mmGetDefaultTraces(verbosity=verbosity)
      print MonitorMixinBase.mmPrettyPrintTraces(traces,
                                                 breakOnResets=
                                                 self.tm.mmGetTraceResets())

      if tpLearn is not None:
        # Print default TP traces
        traces = self.tp.mmGetDefaultTraces(verbosity=verbosity)
        print MonitorMixinBase.mmPrettyPrintTraces(traces,
                                                   breakOnResets=
                                                   self.tp.mmGetTraceResets())
      print
开发者ID:oxtopus,项目名称:nupic.research,代码行数:51,代码来源:sensorimotor_experiment_runner.py

示例10: runNetworkOnSequence

  def runNetworkOnSequence(self, sensorSequences, sequencesLabels, tmLearn=True,
                           upLearn=None, verbosity=0, progressInterval=None):
    """
    Runs Union Pooler network on specified sequence.

    @param sensorSequences        A sequence of sensor sequences. Each
                                  sequence is terminated by None.

    @param sequenceLabels         A sequence of string representations of the
                                  current sequence. Each sequence is terminated
                                  by None.

    @param tmLearn:   (bool)      Either False, or True
    @param upLearn:   (None,bool) Either None, False, or True. If None,
                                  union pooler will be skipped.

    @param progressInterval: (int) Prints progress every N iterations,
                                   where N is the value of this param
    """

    currentTime = time.time()

    for i in xrange(len(sensorSequences)):
      sensorPattern = sensorSequences[i]
      sequenceLabel = sequencesLabels[i]

      self.runNetworkOnPattern(sensorPattern,
                               tmLearn=tmLearn,
                               upLearn=upLearn,
                               sequenceLabel=sequenceLabel)

      if progressInterval is not None and i > 0 and i % progressInterval == 0:
        print ("Ran {0} / {1} elements of sequence in "
               "{2:0.2f} seconds.".format(i, len(sensorSequences),
                                          time.time() - currentTime))
        currentTime = time.time()

    if verbosity >= 2:
      traces = self.tm.mmGetDefaultTraces(verbosity=verbosity)
      print MonitorMixinBase.mmPrettyPrintTraces(traces,
                                                 breakOnResets=
                                                 self.tm.mmGetTraceResets())

      if upLearn is not None:
        traces = self.up.mmGetDefaultTraces(verbosity=verbosity)
        print MonitorMixinBase.mmPrettyPrintTraces(traces,
                                                   breakOnResets=
                                                   self.up.mmGetTraceResets())
      print
开发者ID:lessc0de,项目名称:nupic.research,代码行数:49,代码来源:union_pooler_experiment.py

示例11: runTestPhase

def runTestPhase(runner, randomAgents, numWorlds, numElements, completeSequenceLength, verbosity):
    print "Testing (worlds: {0}, elements: {1})...".format(numWorlds, numElements)
    runner.tm.mmClearHistory()
    runner.tp.mmClearHistory()
    sequences = runner.generateSequences(
        completeSequenceLength / NUM_TEST_SEQUENCES, randomAgents, verbosity=verbosity, numSequences=NUM_TEST_SEQUENCES
    )
    runner.feedLayers(
        sequences, tmLearn=False, tpLearn=False, verbosity=verbosity, showProgressInterval=SHOW_PROGRESS_INTERVAL
    )
    print "Done testing.\n"
    if verbosity >= 2:
        print "Overlap:"
        print
        print runner.tp.mmPrettyPrintDataOverlap()
        print
    print MonitorMixinBase.mmPrettyPrintMetrics(runner.tp.mmGetDefaultMetrics() + runner.tm.mmGetDefaultMetrics())
    print
开发者ID:jaredweiss,项目名称:nupic.research,代码行数:18,代码来源:experimentCosynePlot.py

示例12: runUP

def runUP(tm, mutate_times, sequences, alphabet, up=None, mutation=0, verbose=0):

  allLabels = []

  for j, sensorPattern in enumerate(sequences):
    if sensorPattern is None:
      tm.reset()
    else:
      if j in mutate_times:
        if mutation:
          continue
        else:
          sensorPattern = set([random.randint(0, 2047) for _ in sensorPattern])

      if up is None:
        feedback = set()
      else:
        feedback = set(np.nonzero(up.getUnionSDR())[0])

      tm.compute(sensorPattern, activeApicalCells=feedback,
                 learn=True, sequenceLabel=None)

      if up is not None:
        activeCells, predActiveCells, burstingCols, = getUnionTemporalPoolerInput(tm)
        up.compute(activeCells, predActiveCells, learn=False)

      allLabels.append(labelPattern(sensorPattern, alphabet))

  ys = [len(x) for x in tm.mmGetTraceUnpredictedActiveColumns().data]

  if verbose > 0:
    print " TM metrics on test sequence"
    print MonitorMixinBase.mmPrettyPrintMetrics(tm.mmGetDefaultMetrics())

  if verbose > 1:
    print MonitorMixinBase.mmPrettyPrintTraces(tm.mmGetDefaultTraces(verbosity=True),
                                               breakOnResets=tm.mmGetTraceResets())

  return ys, allLabels
开发者ID:hernandezurbina,项目名称:nupic.research,代码行数:39,代码来源:feedback_experiment.py

示例13: runNetworkOnSequences

  def runNetworkOnSequences(self, inputSequences, inputCategories, tmLearn=True,
                            upLearn=None, classifierLearn=False, verbosity=0,
                            progressInterval=None):
    """
    Runs Union Pooler network on specified sequence.

    @param inputSequences           One or more sequences of input patterns.
                                    Each should be terminated with None.

    @param inputCategories          A sequence of category representations
                                    for each element in inputSequences
                                    Each should be terminated with None.

    @param tmLearn:   (bool)        Temporal Memory learning mode
    @param upLearn:   (None, bool)  Union Pooler learning mode. If None,
                                    Union Pooler will not be run.
    @param classifierLearn: (bool)  Classifier learning mode

    @param progressInterval: (int)  Interval of console progress updates
                                    in terms of timesteps.
    """

    currentTime = time.time()
    for i in xrange(len(inputSequences)):
      sensorPattern = inputSequences[i]
      inputCategory = inputCategories[i]

      self.runNetworkOnPattern(sensorPattern,
                               tmLearn=tmLearn,
                               upLearn=upLearn,
                               sequenceLabel=inputCategory)

      if classifierLearn and sensorPattern is not None:
        unionSDR = self.up.getUnionSDR()
        upCellCount = self.up.getColumnDimensions()
        self.classifier.learn(unionSDR, inputCategory, isSparse=upCellCount)
        if verbosity > 1:
          pprint.pprint("{0} is category {1}".format(unionSDR, inputCategory))

      if progressInterval is not None and i > 0 and i % progressInterval == 0:
        elapsed = (time.time() - currentTime) / 60.0
        print ("Ran {0} / {1} elements of sequence in "
               "{2:0.2f} minutes.".format(i, len(inputSequences), elapsed))
        currentTime = time.time()
        print MonitorMixinBase.mmPrettyPrintMetrics(
          self.tm.mmGetDefaultMetrics())

    if verbosity >= 2:
      traces = self.tm.mmGetDefaultTraces(verbosity=verbosity)
      print MonitorMixinBase.mmPrettyPrintTraces(traces,
                                                 breakOnResets=
                                                 self.tm.mmGetTraceResets())

      if upLearn is not None:
        traces = self.up.mmGetDefaultTraces(verbosity=verbosity)
        print MonitorMixinBase.mmPrettyPrintTraces(traces,
                                                   breakOnResets=
                                                   self.up.mmGetTraceResets())
      print
开发者ID:chanceraine,项目名称:nupic.research,代码行数:59,代码来源:union_pooler_experiment.py

示例14: run

def run(params, paramDir, outputDir, plotVerbosity=0, consoleVerbosity=0):
  """
  Runs the union overlap experiment.

  :param params: A dict of experiment parameters
  :param paramDir: Path of parameter file
  :param outputDir: Output will be written to this path
  :param plotVerbosity: Plotting verbosity
  :param consoleVerbosity: Console output verbosity
  """
  print "Running SDR overlap experiment...\n"
  print "Params dir: {0}".format(paramDir)
  print "Output dir: {0}\n".format(outputDir)

  # Dimensionality of sequence patterns
  patternDimensionality = params["patternDimensionality"]

  # Cardinality (ON / true bits) of sequence patterns
  patternCardinality = params["patternCardinality"]

  # TODO If this parameter is to be supported, the sequence generation code
  # below must change
  # Number of unique patterns from which sequences are built
  # patternAlphabetSize = params["patternAlphabetSize"]

  # Length of sequences shown to network
  sequenceLength = params["sequenceLength"]

  # Number of sequences used. Sequences may share common elements.
  numberOfSequences = params["numberOfSequences"]

  # Number of sequence passes for training the TM. Zero => no training.
  trainingPasses = params["trainingPasses"]

  tmParamOverrides = params["temporalMemoryParams"]
  upParamOverrides = params["unionPoolerParams"]

  # Generate a sequence list and an associated labeled list (both containing a
  # set of sequences separated by None)
  start = time.time()
  print "\nGenerating sequences..."
  patternAlphabetSize = sequenceLength * numberOfSequences
  patternMachine = PatternMachine(patternDimensionality, patternCardinality,
                                  patternAlphabetSize)
  sequenceMachine = SequenceMachine(patternMachine)

  numbers = sequenceMachine.generateNumbers(numberOfSequences, sequenceLength)
  generatedSequences = sequenceMachine.generateFromNumbers(numbers)
  sequenceLabels = [str(numbers[i + i*sequenceLength: i + (i+1)*sequenceLength])
                    for i in xrange(numberOfSequences)]
  labeledSequences = []
  for label in sequenceLabels:
    for _ in xrange(sequenceLength):
      labeledSequences.append(label)
    labeledSequences.append(None)

  # Set up the Temporal Memory and Union Pooler network
  print "\nCreating network..."
  experiment = UnionTemporalPoolerExperiment(tmParamOverrides, upParamOverrides)

  # Train only the Temporal Memory on the generated sequences
  if trainingPasses > 0:

    print "\nTraining Temporal Memory..."
    if consoleVerbosity > 0:
      print "\nPass\tBursting Columns Mean\tStdDev\tMax"

    for i in xrange(trainingPasses):
      experiment.runNetworkOnSequences(generatedSequences,
                                       labeledSequences,
                                       tmLearn=True,
                                       upLearn=None,
                                       verbosity=consoleVerbosity,
                                       progressInterval=_SHOW_PROGRESS_INTERVAL)

      if consoleVerbosity > 0:
        stats = experiment.getBurstingColumnsStats()
        print "{0}\t{1}\t{2}\t{3}".format(i, stats[0], stats[1], stats[2])

      # Reset the TM monitor mixin's records accrued during this training pass
      experiment.tm.mmClearHistory()

    print
    print MonitorMixinBase.mmPrettyPrintMetrics(
      experiment.tm.mmGetDefaultMetrics())
    print
    if plotVerbosity >= 2:
      plotNetworkState(experiment, plotVerbosity, trainingPasses,
                       phase="Training")

  print "\nRunning test phase..."
  experiment.runNetworkOnSequences(generatedSequences,
                                   labeledSequences,
                                   tmLearn=False,
                                   upLearn=False,
                                   verbosity=consoleVerbosity,
                                   progressInterval=_SHOW_PROGRESS_INTERVAL)

  print "\nPass\tBursting Columns Mean\tStdDev\tMax"
  stats = experiment.getBurstingColumnsStats()
#.........这里部分代码省略.........
开发者ID:Starcounter-Jack,项目名称:nupic.research,代码行数:101,代码来源:union_sdr_overlap_experiment.py

示例15: RandomOneDAgent

      randomAgents.append(
        RandomOneDAgent(OneDWorld(universe, elements), numElements / 2,
                        possibleMotorValues=possibleMotorValues))


    print "Training (worlds: {0}, elements: {1})...".format(numWorlds,
                                                            numElements)
    sequences = runner.generateSequences(completeSequenceLength * 2,
                                         exhaustiveAgents,
                                         verbosity=VERBOSITY)
    runner.feedLayers(sequences, tmLearn=True, tpLearn=True,
                      verbosity=VERBOSITY,
                      showProgressInterval=SHOW_PROGRESS_INTERVAL)
    print "Done training.\n"

    print MonitorMixinBase.mmPrettyPrintMetrics(
      runner.tp.mmGetDefaultMetrics() + runner.tm.mmGetDefaultMetrics())
    print

    if PLOT >= 1:
      runner.tp.mmGetPlotConnectionsPerColumn(
        title="worlds: {0}, elements: {1}".format(numWorlds, numElements))


    print "Testing (worlds: {0}, elements: {1})...".format(numWorlds,
                                                           numElements)
    sequences = runner.generateSequences(completeSequenceLength,
                                         randomAgents,
                                         verbosity=VERBOSITY)
    runner.feedLayers(sequences, tmLearn=False, tpLearn=False,
                      verbosity=VERBOSITY,
                      showProgressInterval=SHOW_PROGRESS_INTERVAL)
开发者ID:r0k3,项目名称:nupic.research,代码行数:32,代码来源:memorization_capacity_test.py


注:本文中的nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。