class ExtendedTMCPP_ApicalTiebreakTests(ApicalTiebreakTestBase, unittest.TestCase): """ Run the apical tiebreak tests on the C++ ExtendedTemporalMemory. """ def constructTM(self, columnCount, basalInputSize, apicalInputSize, cellsPerColumn, initialPermanence, connectedPermanence, minThreshold, sampleSize, permanenceIncrement, permanenceDecrement, predictedSegmentDecrement, activationThreshold, seed): params = { "columnDimensions": (columnCount,), "basalInputDimensions": (basalInputSize,), "apicalInputDimensions": (apicalInputSize,), "cellsPerColumn": cellsPerColumn, "initialPermanence": initialPermanence, "connectedPermanence": connectedPermanence, "minThreshold": minThreshold, "maxNewSynapseCount": sampleSize, "permanenceIncrement": permanenceIncrement, "permanenceDecrement": permanenceDecrement, "predictedSegmentDecrement": predictedSegmentDecrement, "activationThreshold": activationThreshold, "seed": seed, "learnOnOneCell": False, "formInternalBasalConnections": False, } self.tm = ExtendedTemporalMemory(**params) def compute(self, activeColumns, basalInput, apicalInput, learn): activeColumns = sorted(activeColumns) basalInput = sorted(basalInput) apicalInput = sorted(apicalInput) # Use depolarizeCells + activateCells rather than tm.compute so that # getPredictiveCells returns predictions for the current timestep. self.tm.depolarizeCells(activeCellsExternalBasal=basalInput, activeCellsExternalApical=apicalInput, learn=learn) self.tm.activateCells(activeColumns, reinforceCandidatesExternalBasal=basalInput, growthCandidatesExternalBasal=basalInput, reinforceCandidatesExternalApical=apicalInput, growthCandidatesExternalApical=apicalInput, learn=learn) def getActiveCells(self): return self.tm.getActiveCells() def getPredictedCells(self): return self.tm.getPredictiveCells()
class ExtendedTMCPP_SequenceMemoryTests(SequenceMemoryTestBase, unittest.TestCase): """ Run the sequence memory tests on the C++ ExtendedTemporalMemory. """ def constructTM(self, columnCount, cellsPerColumn, initialPermanence, connectedPermanence, minThreshold, sampleSize, permanenceIncrement, permanenceDecrement, predictedSegmentDecrement, activationThreshold, seed): params = { "columnDimensions": (columnCount,), "cellsPerColumn": cellsPerColumn, "initialPermanence": initialPermanence, "connectedPermanence": connectedPermanence, "minThreshold": minThreshold, "maxNewSynapseCount": sampleSize, "permanenceIncrement": permanenceIncrement, "permanenceDecrement": permanenceDecrement, "predictedSegmentDecrement": predictedSegmentDecrement, "activationThreshold": activationThreshold, "seed": seed, "learnOnOneCell": False, } self.tm = ExtendedTemporalMemory(**params) def compute(self, activeColumns, learn): # Use depolarizeCells + activateCells rather than tm.compute so that # getPredictiveCells returns predictions for the current timestep. self.tm.depolarizeCells(learn=learn) self.tm.activateCells(sorted(activeColumns), learn=learn) def reset(self): self.tm.reset() def getActiveCells(self): return self.tm.getActiveCells() def getPredictedCells(self): return self.tm.getPredictiveCells()