Esempio n. 1
0
	def nextStep(self):
		"""
		Performs actions related to time step progression.
		"""

		# Update states machine by remove the first element and add a new element in the end
		if self.inputFormat == InputFormat.raw:
			if len(self.currentValue) > maxPreviousSteps:
				self.currentValue.remove(self.currentValue[0])
				self.predictedValues.remove(self.predictedValues[0])
			self.currentValue.append(None)
			self.predictedValues.append(None)

		Node.nextStep(self)
		for bit in self.bits:
			bit.nextStep()

		# Get record value from data source
		recordValue = None
		if self.dataSourceType == DataSourceType.file:
			recordValue = self.__getNextFileRecord()
		elif self.dataSourceType == DataSourceType.database:
			pass

		# Handle the value according to its type
		self._output = []
		if self.inputFormat == InputFormat.htm:

			# Initialize the array for representing the current record
			self._output = recordValue
		elif self.inputFormat == InputFormat.raw:

			# Convert the value to its respective data type
			rawValue = None
			if self.inputRawDataType == InputRawDataType.boolean:
				rawValue = bool(recordValue)
			elif self.inputRawDataType == InputRawDataType.integer:
				rawValue = int(recordValue)
			elif self.inputRawDataType == InputRawDataType.decimal:
				rawValue = float(recordValue)
			elif self.inputRawDataType == InputRawDataType.dateTime:
				rawValue = datetime.datetime.strptime(recordValue, "%m/%d/%y %H:%M")
			elif self.inputRawDataType == InputRawDataType.string:
				rawValue = str(recordValue)
			self.currentValue[maxPreviousSteps - 1] = rawValue

			# Pass raw value to encoder and get its respective array
			self._output = self.encoder.encode(rawValue)

		# Update sensor bits
		for i in range(len(self._output)):
			if self._output[i] > 0.:
				self.bits[i].isActive[maxPreviousSteps - 1] = True
			else:
				self.bits[i].isActive[maxPreviousSteps - 1] = False

		# Mark falsely predicted bits
		for bit in self.bits:
			if bit.isPredicted[maxPreviousSteps - 2] and not bit.isActive[maxPreviousSteps - 1]:
				bit.isFalselyPredicted[maxPreviousSteps - 1] = True
Esempio n. 2
0
	def nextStep(self):
		"""
		Perfoms actions related to time step progression.
		"""

		Node.nextStep(self)
		for child in self.children:
			child.nextStep()
		for column in self.columns:
			column.nextStep()

		# Get input from sensors or lower regions and put into a single input map.
		input = self.getInput()

		# Send input to Spatial Pooler and get processed output (i.e. the active columns)
		# First initialize the vector for representing the current record
		columnDimensions = (self.width, self.height)
		columnNumber = numpy.array(columnDimensions).prod()
		activeColumns = numpy.zeros(columnNumber)
		self.spatialPooler.compute(input, self.enableSpatialPooling, activeColumns)

		# Send active columns to Temporal Pooler and get processed output (i.e. the predicting cells)
		# First convert active columns from float array to integer set
		activeColumnsSet = set()
		for colIdx in range(len(activeColumns)):
			if activeColumns[colIdx] == 1:
				activeColumnsSet.add(colIdx)
		self.temporalPooler.compute(activeColumnsSet, self.enableTemporalPooling)

		# Update elements regarding spatial pooler
		self.updateSpatialElements(activeColumns)

		# Update elements regarding temporal pooler
		self.updateTemporalElements()
Esempio n. 3
0
    def nextStep(self):
        """
		Perfoms actions related to time step progression.
		"""

        Node.nextStep(self)
        for bit in self.bits:
            bit.nextStep()

        if self.dataSourceType == DataSourceType.file:
            self.__getNextFileRecord()
        elif self.dataSourceType == DataSourceType.database:
            pass
Esempio n. 4
0
    def nextStep(self):
        """
		Perfoms actions related to time step progression.
		"""

        Node.nextStep(self)
        for bit in self.bits:
            bit.nextStep()

        if self.dataSourceType == DataSourceType.file:
            self.__getNextFileRecord()
        elif self.dataSourceType == DataSourceType.database:
            pass
Esempio n. 5
0
    def nextStep(self):
        """
		Perfoms actions related to time step progression.
		"""

        Node.nextStep(self)
        for column in self.columns:
            column.nextStep()

        # Get input from sensors or lower regions and put into a single input map.
        input = self.getInput()

        # Send input to Spatial Pooler and get processed output (i.e. the active columns)
        # First initialize the vector for representing the current record
        columnDimensions = (self.width, self.height)
        columnNumber = numpy.array(columnDimensions).prod()
        activeColumns = numpy.zeros(columnNumber)
        self.spatialPooler.compute(input, self.enableSpatialLearning,
                                   activeColumns)

        # Send active columns to Temporal Pooler and get processed output (i.e. the predicting cells)
        # First convert active columns from float array to integer set
        activeColumnsSet = set()
        for colIdx in range(len(activeColumns)):
            if activeColumns[colIdx] == 1:
                activeColumnsSet.add(colIdx)
        self.temporalPooler.compute(activeColumnsSet,
                                    self.enableTemporalLearning)

        # Update elements regarding spatial pooler
        self.updateSpatialElements(activeColumns)

        # Update elements regarding temporal pooler
        self.updateTemporalElements()

        # Get the predicted values
        self.getPredictions()
Esempio n. 6
0
    def nextStep(self):
        """
		Performs actions related to time step progression.
		"""

        # Update states machine by remove the first element and add a new element in the end
        for encoding in self.encodings:
            encoding.currentValue.rotate()
            if encoding.enableInference:
                encoding.predictedValues.rotate()
                encoding.bestPredictedValue.rotate()

        Node.nextStep(self)
        for bit in self.bits:
            bit.nextStep()

        # Get record value from data source
        # If the last record was reached just rewind it
        data = self.dataSource.getNextRecordDict()
        if not data:
            self.dataSource.rewind()
            data = self.dataSource.getNextRecordDict()

        # Pass raw values to encoder and get a concatenated array
        outputArray = numpy.zeros(self.encoder.getWidth())
        self.encoder.encodeIntoArray(data, outputArray)

        # Get values obtained from the data source.
        outputValues = self.encoder.getScalars(data)

        # Get raw values and respective encoded bit array for each field
        prevOffset = 0
        for i in range(len(self.encodings)):
            encoding = self.encodings[i]

            # Convert the value to its respective data type
            currValue = outputValues[i]
            if encoding.encoderFieldDataType == FieldDataType.boolean:
                currValue = bool(currValue)
            elif encoding.encoderFieldDataType == FieldDataType.integer:
                currValue = int(currValue)
            elif encoding.encoderFieldDataType == FieldDataType.decimal:
                currValue = float(currValue)
            elif encoding.encoderFieldDataType == FieldDataType.dateTime:
                currValue = dateutil.parser.parse(str(currValue))
            elif encoding.encoderFieldDataType == FieldDataType.string:
                currValue = str(currValue)
            encoding.currentValue.setForCurrStep(currValue)

        # Update sensor bits
        for i in range(len(outputArray)):
            if outputArray[i] > 0.:
                self.bits[i].isActive.setForCurrStep(True)
            else:
                self.bits[i].isActive.setForCurrStep(False)

        # Mark falsely predicted bits
        for bit in self.bits:
            if bit.isPredicted.atPreviousStep(
            ) and not bit.isActive.atCurrStep():
                bit.isFalselyPredicted.setForCurrStep(True)

        self._output = outputArray