本文整理汇总了Python中nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase.mmPrettyPrintMetrics方法的典型用法代码示例。如果您正苦于以下问题:Python MonitorMixinBase.mmPrettyPrintMetrics方法的具体用法?Python MonitorMixinBase.mmPrettyPrintMetrics怎么用?Python MonitorMixinBase.mmPrettyPrintMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase
的用法示例。
在下文中一共展示了MonitorMixinBase.mmPrettyPrintMetrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trainTwoPass
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例2: train
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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()
示例3: runTMtrainingPhase
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例4: trainTemporalMemory
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例5: trainUP
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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()
示例6: run
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例7: runNetworkOnSequences
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例8: trainOnline
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例9: _printInfo
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例10: runNetworkOnSequence
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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:
elapsed = (time.time() - currentTime) / 60.0
print ("Ran {0} / {1} elements of sequence in "
"{2:0.2f} minutes.".format(i, len(sensorSequences), 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
示例11: runTestPhase
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例12: runUP
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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
示例13: run
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
def run(params, paramDir, outputDir, plotVerbosity=0, consoleVerbosity=0):
"""
Runs the noise robustness experiment.
:param params: A dict containing the following experiment parameters:
patternDimensionality - Dimensionality of sequence patterns
patternCardinality - Cardinality (# ON bits) of sequence patterns
sequenceLength - Length of sequences shown to network
sequenceCount - Number of unique sequences used
trainingPasses - Number of times Temporal Memory is trained on each
sequence
testPresentations - Number of sequences presented in test phase
perturbationChance - Chance of sequence perturbations during test phase
temporalMemoryParams - A dict of Temporal Memory parameter overrides
unionPoolerParams - A dict of Union Pooler parameter overrides
: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 Noise robustness experiment...\n"
print "Params dir: {0}".format(os.path.join(os.path.dirname(__file__),
paramDir))
print "Output dir: {0}\n".format(os.path.join(os.path.dirname(__file__),
outputDir))
patternDimensionality = params["patternDimensionality"]
patternCardinality = params["patternCardinality"]
sequenceLength = params["sequenceLength"]
sequenceCount = params["numberOfSequences"]
trainingPasses = params["trainingPasses"]
testPresentations = params["testPresentations"]
perturbationChance = params["perturbationChance"]
tmParamOverrides = params["temporalMemoryParams"]
upParamOverrides = params["unionPoolerParams"]
# 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"]
# Generate a sequence list and an associated labeled list (both containing a
# set of sequences separated by None)
start = time.time()
print "Generating sequences..."
patternAlphabetSize = sequenceLength * sequenceCount
patternMachine = PatternMachine(patternDimensionality, patternCardinality,
patternAlphabetSize)
sequenceMachine = SequenceMachine(patternMachine)
numbers = sequenceMachine.generateNumbers(sequenceCount, sequenceLength)
generatedSequences = sequenceMachine.generateFromNumbers(numbers)
sequenceLabels = [str(numbers[i + i*sequenceLength: i + (i+1)*sequenceLength])
for i in xrange(sequenceCount)]
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 = UnionPoolerExperiment(tmParamOverrides, upParamOverrides)
# Train only the Temporal Memory on the generated sequences
if trainingPasses > 0:
print "\nTraining Temporal Memory..."
if consoleVerbosity > 0:
print "\nPass\tMean\t\tStdDev\t\tMax\t\t(Bursting Columns)"
for i in xrange(trainingPasses):
experiment.runNetworkOnSequence(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..."
# Input sequence pattern by pattern. Sequence-to-sequence
#.........这里部分代码省略.........
示例14: run
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
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()
#.........这里部分代码省略.........
示例15: run
# 需要导入模块: from nupic.research.monitor_mixin.monitor_mixin_base import MonitorMixinBase [as 别名]
# 或者: from nupic.research.monitor_mixin.monitor_mixin_base.MonitorMixinBase import mmPrettyPrintMetrics [as 别名]
def run(params, paramDir, outputDir, plotVerbosity=0, consoleVerbosity=0):
"""
Runs the Union Pooler capacity experiment.
:param params: A dict containing the following experiment parameters:
patternDimensionality - Dimensionality of sequence patterns
patternCardinality - Cardinality (# ON bits) of sequence patterns
sequenceLength - Length of sequences shown to network
sequenceCount - Number of unique sequences used
trainingPasses - Number of times Temporal Memory is trained on each
sequence
temporalMemoryParams - A dict of Temporal Memory parameter overrides
unionPoolerParams - A dict of Union Pooler parameter overrides
:param paramDir: Path of parameter file
:param outputDir: Output will be written to this path
:param plotVerbosity: Plotting verbosity
:param consoleVerbosity: Console output verbosity
"""
start = time.time()
print "Running Union Pooler Capacity Experiment...\n"
print "Params dir: {0}".format(os.path.join(os.path.dirname(__file__),
paramDir))
print "Output dir: {0}\n".format(os.path.join(os.path.dirname(__file__),
outputDir))
patternDimensionality = params["patternDimensionality"]
patternCardinality = params["patternCardinality"]
sequenceLength = params["sequenceLength"]
sequenceCount = params["numberOfSequences"]
trainingPasses = params["trainingPasses"]
tmParamOverrides = params["temporalMemoryParams"]
upParamOverrides = params["unionPoolerParams"]
# Generate input data
inputSequences, seqLabels = generateSequences(patternDimensionality,
patternCardinality,
sequenceLength,
sequenceCount)
print "\nCreating Network..."
experiment = UnionPoolerExperiment(tmParamOverrides, upParamOverrides)
# Train the Temporal Memory on the generated sequences
print "\nTraining Temporal Memory..."
for i in xrange(trainingPasses):
print "\nTraining pass {0} ...\n".format(i)
experiment.runNetworkOnSequences(inputSequences,
seqLabels,
tmLearn=True,
upLearn=None,
verbosity=consoleVerbosity,
progressInterval=_SHOW_PROGRESS_INTERVAL)
if consoleVerbosity > 0:
stats = experiment.getBurstingColumnsStats()
print "\nPass\tMean\t\tStdDev\t\tMax\t\t(Bursting Columns)"
print "{0}\t{1}\t{2}\t{3}".format(i, stats[0], stats[1], stats[2])
print
print MonitorMixinBase.mmPrettyPrintMetrics(
experiment.tm.mmGetDefaultMetrics())
print
experiment.tm.mmClearHistory()
# Run test phase recording Union SDRs
unionSdrs = runTestPhase(experiment, inputSequences, seqLabels, sequenceCount,
sequenceLength, consoleVerbosity)
# Output distinctness metric
print "\nSequences\tDistinctness Ave\tStdDev\tMax"
ave, stdDev, maxDist = getDistinctness(unionSdrs)
print "{0}\t{1}\t{2}\t{3}".format(sequenceCount, ave, stdDev, maxDist)
# Check bursting columns metric during test phase
print "\nSequences\tBursting Columns Mean\tStdDev\tMax"
stats = experiment.getBurstingColumnsStats()
print "{0}\t{1}\t{2}\t{3}".format(sequenceCount, stats[0], stats[1], stats[2])
if trainingPasses > 0 and stats[0] > 0:
print "***Warning! Mean bursing columns > 0 in test phase***"
print
print MonitorMixinBase.mmPrettyPrintMetrics(
experiment.tm.mmGetDefaultMetrics() + experiment.up.mmGetDefaultMetrics())
print
print "Total time: {0:2} seconds.".format(int(time.time() - start))