def basicTest(self): """Basic test (creation, pickling, basic run of learning and inference)""" # Create TM object tm = BacktrackingTMCPP(numberOfCols=10, cellsPerColumn=3, initialPerm=.2, connectedPerm=0.8, minThreshold=2, newSynapseCount=5, permanenceInc=.1, permanenceDec=.05, permanenceMax=1, globalDecay=.05, activationThreshold=4, doPooling=False, segUpdateValidDuration=5, seed=SEED, verbosity=VERBOSITY) tm.retrieveLearningStates = True # Save and reload tm.makeCells4Ephemeral = False pickle.dump(tm, open("test_tm_cpp.pkl", "wb")) tm2 = pickle.load(open("test_tm_cpp.pkl")) self.assertTrue(fdrutils.tmDiff2(tm, tm2, VERBOSITY, checkStates=False)) # Learn for i in xrange(5): x = numpy.zeros(tm.numberOfCols, dtype='uint32') _RGEN.initializeUInt32Array(x, 2) tm.learn(x) # Save and reload after learning tm.reset() tm.makeCells4Ephemeral = False pickle.dump(tm, open("test_tm_cpp.pkl", "wb")) tm2 = pickle.load(open("test_tm_cpp.pkl")) self.assertTrue(fdrutils.tmDiff2(tm, tm2, VERBOSITY)) ## Infer patterns = numpy.zeros((4, tm.numberOfCols), dtype='uint32') for i in xrange(4): _RGEN.initializeUInt32Array(patterns[i], 2) for i in xrange(10): x = numpy.zeros(tm.numberOfCols, dtype='uint32') _RGEN.initializeUInt32Array(x, 2) tm.infer(x) if i > 0: tm._checkPrediction(patterns)
def _createTms(numCols): """Create two instances of temporal poolers (backtracking_tm.py and backtracking_tm_cpp.py) with identical parameter settings.""" # Keep these fixed: minThreshold = 4 activationThreshold = 5 newSynapseCount = 7 initialPerm = 0.3 connectedPerm = 0.5 permanenceInc = 0.1 permanenceDec = 0.05 globalDecay = 0 cellsPerColumn = 1 cppTm = BacktrackingTMCPP(numberOfCols=numCols, cellsPerColumn=cellsPerColumn, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, burnIn=1, seed=_SEED, verbosity=VERBOSITY, checkSynapseConsistency=True, pamLength=1000) # Ensure we are copying over learning states for TMDiff cppTm.retrieveLearningStates = True pyTm = BacktrackingTM(numberOfCols=numCols, cellsPerColumn=cellsPerColumn, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, burnIn=1, seed=_SEED, verbosity=VERBOSITY, pamLength=1000) return cppTm, pyTm
def _createTms(numCols): """Create two instances of temporal poolers (backtracking_tm.py and backtracking_tm_cpp.py) with identical parameter settings.""" # Keep these fixed: minThreshold = 4 activationThreshold = 5 newSynapseCount = 7 initialPerm = 0.3 connectedPerm = 0.5 permanenceInc = 0.1 permanenceDec = 0.05 globalDecay = 0 cellsPerColumn = 1 cppTm = BacktrackingTMCPP(numberOfCols=numCols, cellsPerColumn=cellsPerColumn, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, burnIn=1, seed=SEED, verbosity=VERBOSITY, checkSynapseConsistency=True, pamLength=1000) # Ensure we are copying over learning states for TPDiff cppTm.retrieveLearningStates = True pyTm = BacktrackingTM(numberOfCols=numCols, cellsPerColumn=cellsPerColumn, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, burnIn=1, seed=SEED, verbosity=VERBOSITY, pamLength=1000) return cppTm, pyTm
def basicTest(self): """Basic test (creation, pickling, basic run of learning and inference)""" # Create TM object tm = BacktrackingTMCPP(numberOfCols=10, cellsPerColumn=3, initialPerm=.2, connectedPerm= 0.8, minThreshold=2, newSynapseCount=5, permanenceInc=.1, permanenceDec= .05, permanenceMax=1, globalDecay=.05, activationThreshold=4, doPooling=False, segUpdateValidDuration=5, seed=SEED, verbosity=VERBOSITY) tm.retrieveLearningStates = True # Save and reload tm.makeCells4Ephemeral = False pickle.dump(tm, open("test_tm_cpp.pkl", "wb")) tm2 = pickle.load(open("test_tm_cpp.pkl")) self.assertTrue(fdrutils.tmDiff2(tm, tm2, VERBOSITY, checkStates=False)) # Learn for i in xrange(5): x = numpy.zeros(tm.numberOfCols, dtype='uint32') _RGEN.initializeUInt32Array(x, 2) tm.learn(x) # Save and reload after learning tm.reset() tm.makeCells4Ephemeral = False pickle.dump(tm, open("test_tm_cpp.pkl", "wb")) tm2 = pickle.load(open("test_tm_cpp.pkl")) self.assertTrue(fdrutils.tmDiff2(tm, tm2, VERBOSITY)) ## Infer patterns = numpy.zeros((4, tm.numberOfCols), dtype='uint32') for i in xrange(4): _RGEN.initializeUInt32Array(patterns[i], 2) for i in xrange(10): x = numpy.zeros(tm.numberOfCols, dtype='uint32') _RGEN.initializeUInt32Array(x, 2) tm.infer(x) if i > 0: tm.checkPrediction2(patterns)
def createTMs(includeCPP = True, includePy = True, numCols = 100, cellsPerCol = 4, activationThreshold = 3, minThreshold = 3, newSynapseCount = 3, initialPerm = 0.6, permanenceInc = 0.1, permanenceDec = 0.0, globalDecay = 0.0, pamLength = 0, checkSynapseConsistency = True, maxInfBacktrack = 0, maxLrnBacktrack = 0, **kwargs ): """Create one or more TM instances, placing each into a dict keyed by name. Parameters: ------------------------------------------------------------------ retval: tms - dict of TM instances """ # Keep these fixed: connectedPerm = 0.5 tms = dict() if includeCPP: if VERBOSITY >= 2: print "Creating BacktrackingTMCPP instance" cpp_tm = BacktrackingTMCPP(numberOfCols = numCols, cellsPerColumn = cellsPerCol, initialPerm = initialPerm, connectedPerm = connectedPerm, minThreshold = minThreshold, newSynapseCount = newSynapseCount, permanenceInc = permanenceInc, permanenceDec = permanenceDec, activationThreshold = activationThreshold, globalDecay = globalDecay, burnIn = 1, seed=SEED, verbosity=VERBOSITY, checkSynapseConsistency = checkSynapseConsistency, collectStats = True, pamLength = pamLength, maxInfBacktrack = maxInfBacktrack, maxLrnBacktrack = maxLrnBacktrack, ) # Ensure we are copying over learning states for TMDiff cpp_tm.retrieveLearningStates = True tms['CPP'] = cpp_tm if includePy: if VERBOSITY >= 2: print "Creating PY TM instance" py_tm = BacktrackingTM(numberOfCols = numCols, cellsPerColumn = cellsPerCol, initialPerm = initialPerm, connectedPerm = connectedPerm, minThreshold = minThreshold, newSynapseCount = newSynapseCount, permanenceInc = permanenceInc, permanenceDec = permanenceDec, activationThreshold = activationThreshold, globalDecay = globalDecay, burnIn = 1, seed=SEED, verbosity=VERBOSITY, collectStats = True, pamLength = pamLength, maxInfBacktrack = maxInfBacktrack, maxLrnBacktrack = maxLrnBacktrack, ) tms['PY '] = py_tm return tms
def _createTMs(self, numCols, fixedResources=False, checkSynapseConsistency = True): """Create an instance of the appropriate temporal memory. We isolate all parameters as constants specified here.""" # Keep these fixed: minThreshold = 4 activationThreshold = 8 newSynapseCount = 15 initialPerm = 0.3 connectedPerm = 0.5 permanenceInc = 0.1 permanenceDec = 0.05 if fixedResources: permanenceDec = 0.1 maxSegmentsPerCell = 5 maxSynapsesPerSegment = 15 globalDecay = 0 maxAge = 0 else: permanenceDec = 0.05 maxSegmentsPerCell = -1 maxSynapsesPerSegment = -1 globalDecay = 0.0001 maxAge = 1 if g_testCPPTM: if g_options.verbosity > 1: print "Creating BacktrackingTMCPP instance" cppTM = BacktrackingTMCPP(numberOfCols = numCols, cellsPerColumn = 4, initialPerm = initialPerm, connectedPerm = connectedPerm, minThreshold = minThreshold, newSynapseCount = newSynapseCount, permanenceInc = permanenceInc, permanenceDec = permanenceDec, activationThreshold = activationThreshold, globalDecay = globalDecay, maxAge=maxAge, burnIn = 1, seed=g_options.seed, verbosity=g_options.verbosity, checkSynapseConsistency = checkSynapseConsistency, pamLength = 1000, maxSegmentsPerCell = maxSegmentsPerCell, maxSynapsesPerSegment = maxSynapsesPerSegment, ) # Ensure we are copying over learning states for TMDiff cppTM.retrieveLearningStates = True else: cppTM = None if g_options.verbosity > 1: print "Creating PY TM instance" pyTM = BacktrackingTM(numberOfCols = numCols, cellsPerColumn = 4, initialPerm = initialPerm, connectedPerm = connectedPerm, minThreshold = minThreshold, newSynapseCount = newSynapseCount, permanenceInc = permanenceInc, permanenceDec = permanenceDec, activationThreshold = activationThreshold, globalDecay = globalDecay, maxAge=maxAge, burnIn = 1, seed=g_options.seed, verbosity=g_options.verbosity, pamLength = 1000, maxSegmentsPerCell = maxSegmentsPerCell, maxSynapsesPerSegment = maxSynapsesPerSegment, ) return cppTM, pyTM
def createTMs(includeCPP=True, includePy=True, numCols=100, cellsPerCol=4, activationThreshold=3, minThreshold=3, newSynapseCount=3, initialPerm=0.6, permanenceInc=0.1, permanenceDec=0.0, globalDecay=0.0, pamLength=0, checkSynapseConsistency=True, maxInfBacktrack=0, maxLrnBacktrack=0, **kwargs): """Create one or more TM instances, placing each into a dict keyed by name. Parameters: ------------------------------------------------------------------ retval: tms - dict of TM instances """ # Keep these fixed: connectedPerm = 0.5 tms = dict() if includeCPP: if VERBOSITY >= 2: print "Creating BacktrackingTMCPP instance" cpp_tm = BacktrackingTMCPP( numberOfCols=numCols, cellsPerColumn=cellsPerCol, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, burnIn=1, seed=SEED, verbosity=VERBOSITY, checkSynapseConsistency=checkSynapseConsistency, collectStats=True, pamLength=pamLength, maxInfBacktrack=maxInfBacktrack, maxLrnBacktrack=maxLrnBacktrack, ) # Ensure we are copying over learning states for TMDiff cpp_tm.retrieveLearningStates = True tms['CPP'] = cpp_tm if includePy: if VERBOSITY >= 2: print "Creating PY TM instance" py_tm = BacktrackingTM( numberOfCols=numCols, cellsPerColumn=cellsPerCol, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, burnIn=1, seed=SEED, verbosity=VERBOSITY, collectStats=True, pamLength=pamLength, maxInfBacktrack=maxInfBacktrack, maxLrnBacktrack=maxLrnBacktrack, ) tms['PY '] = py_tm return tms
def _createTMs(self, numCols, fixedResources=False, checkSynapseConsistency=True): """Create an instance of the appropriate temporal memory. We isolate all parameters as constants specified here.""" # Keep these fixed: minThreshold = 4 activationThreshold = 8 newSynapseCount = 15 initialPerm = 0.3 connectedPerm = 0.5 permanenceInc = 0.1 permanenceDec = 0.05 if fixedResources: permanenceDec = 0.1 maxSegmentsPerCell = 5 maxSynapsesPerSegment = 15 globalDecay = 0 maxAge = 0 else: permanenceDec = 0.05 maxSegmentsPerCell = -1 maxSynapsesPerSegment = -1 globalDecay = 0.0001 maxAge = 1 if g_testCPPTM: if g_options.verbosity > 1: print("Creating BacktrackingTMCPP instance") cppTM = BacktrackingTMCPP( numberOfCols=numCols, cellsPerColumn=4, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, maxAge=maxAge, burnIn=1, seed=g_options.seed, verbosity=g_options.verbosity, checkSynapseConsistency=checkSynapseConsistency, pamLength=1000, maxSegmentsPerCell=maxSegmentsPerCell, maxSynapsesPerSegment=maxSynapsesPerSegment, ) # Ensure we are copying over learning states for TMDiff cppTM.retrieveLearningStates = True else: cppTM = None if g_options.verbosity > 1: print("Creating PY TM instance") pyTM = BacktrackingTM( numberOfCols=numCols, cellsPerColumn=4, initialPerm=initialPerm, connectedPerm=connectedPerm, minThreshold=minThreshold, newSynapseCount=newSynapseCount, permanenceInc=permanenceInc, permanenceDec=permanenceDec, activationThreshold=activationThreshold, globalDecay=globalDecay, maxAge=maxAge, burnIn=1, seed=g_options.seed, verbosity=g_options.verbosity, pamLength=1000, maxSegmentsPerCell=maxSegmentsPerCell, maxSynapsesPerSegment=maxSynapsesPerSegment, ) return cppTM, pyTM