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 initialize(self): rangePadding = abs(self.inputMax - self.inputMin) * 0.2 minVal = self.inputMin - rangePadding maxVal = (self.inputMax + rangePadding if self.inputMin != self.inputMax else self.inputMin + 1) numBuckets = 130.0 resolution = max(0.001, (maxVal - minVal) / numBuckets) self.valueEncoder = RandomDistributedScalarEncoder(resolution, w=41, seed=42) self.encodedValue = np.zeros(self.valueEncoder.getWidth(), dtype=np.uint32) self.timestampEncoder = DateEncoder(timeOfDay=( 21, 9.49, )) self.encodedTimestamp = np.zeros(self.timestampEncoder.getWidth(), dtype=np.uint32) inputWidth = self.valueEncoder.getWidth() self.sp = SpatialPooler( **{ "globalInhibition": True, "columnDimensions": [2048], "inputDimensions": [inputWidth], "potentialRadius": inputWidth, "numActiveColumnsPerInhArea": 40, "seed": 1956, "potentialPct": 0.8, "boostStrength": 0.0, "synPermActiveInc": 0.003, "synPermConnected": 0.2, "synPermInactiveDec": 0.0005, }) self.spOutput = np.zeros(2048, dtype=np.float32) self.etm = ExtendedTemporalMemory( **{ "activationThreshold": 13, "cellsPerColumn": 1, "columnDimensions": (2048, ), "basalInputDimensions": (self.timestampEncoder.getWidth(), ), "initialPermanence": 0.21, "maxSegmentsPerCell": 128, "maxSynapsesPerSegment": 32, "minThreshold": 10, "maxNewSynapseCount": 20, "permanenceDecrement": 0.1, "permanenceIncrement": 0.1, "seed": 1960, "checkInputs": False, }) learningPeriod = math.floor(self.probationaryPeriod / 2.0) self.anomalyLikelihood = anomaly_likelihood.AnomalyLikelihood( claLearningPeriod=learningPeriod, estimationSamples=self.probationaryPeriod - learningPeriod, reestimationPeriod=100)