本文整理汇总了Python中nupic.research.TP.TP.loadFromFile方法的典型用法代码示例。如果您正苦于以下问题:Python TP.loadFromFile方法的具体用法?Python TP.loadFromFile怎么用?Python TP.loadFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.TP.TP
的用法示例。
在下文中一共展示了TP.loadFromFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Model
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import loadFromFile [as 别名]
class Model():
def __init__(self,
numberOfCols=16384, cellsPerColumn=8,
initialPerm=0.5, connectedPerm=0.5,
minThreshold=164, newSynapseCount=164,
permanenceInc=0.1, permanenceDec=0.0,
activationThreshold=164,
pamLength=10,
checkpointDir=None):
self.tp = TP(numberOfCols=numberOfCols, cellsPerColumn=cellsPerColumn,
initialPerm=initialPerm, connectedPerm=connectedPerm,
minThreshold=minThreshold, newSynapseCount=newSynapseCount,
permanenceInc=permanenceInc, permanenceDec=permanenceDec,
# 1/2 of the on bits = (16384 * .02) / 2
activationThreshold=activationThreshold,
globalDecay=0, burnIn=1,
#verbosity=3, # who knows what this does...
checkSynapseConsistency=False,
pamLength=pamLength)
self.checkpointDir = checkpointDir
self.checkpointPklPath = None
self.checkpointDataPath = None
self._initCheckpoint()
def _initCheckpoint(self):
if self.checkpointDir:
if not os.path.exists(self.checkpointDir):
os.makedirs(self.checkpointDir)
self.checkpointPklPath = self.checkpointDir + "/model.pkl"
self.checkpointDataPath = self.checkpointDir + "/model.data"
def canCheckpoint(self):
return self.checkpointDir != None
def hasCheckpoint(self):
return (os.path.exists(self.checkpointPklPath) and
os.path.exists(self.checkpointDataPath))
def load(self):
if not self.checkpointDir:
raise(Exception("No checkpoint directory specified"))
if not self.hasCheckpoint():
raise(Exception("Could not find checkpoint file"))
with open(self.checkpointPklPath, 'rb') as f:
self.tp = pickle.load(f)
self.tp.loadFromFile(self.checkpointDataPath)
def save(self):
if not self.checkpointDir:
raise(Exception("No checkpoint directory specified"))
self.tp.saveToFile(self.checkpointDataPath)
with open(self.checkpointPklPath, 'wb') as f:
pickle.dump(self.tp, f)
def feedTerm(self, term, learn=True):
""" Feed a Term to model, returning next predicted Term """
tp = self.tp
array = numpy.array(term.toArray(), dtype="uint32")
tp.resetStats()
tp.compute(array, enableLearn = learn, computeInfOutput = True)
#print "ret: " + repr(ret)
#if ret.all() == array.all():
# print "EQUAL to input"
ret = tp.getStats()
#ret = tp.printStates()
print "ret: " + repr(ret)
print
print
print "*****************************************"
predictedCells = tp.getPredictedState()
predictedColumns = predictedCells.max(axis=1)
predictedBitmap = predictedColumns.nonzero()[0].tolist()
return Term().createFromBitmap(predictedBitmap)
def resetSequence(self):
print "RESET"
self.tp.reset()