예제 #1
0
	def __readNode(self, parentNode, xmlReader):

		# Read type of node
		name = self.__getStringAttribute(xmlReader.attributes(), 'name')
		type = self.__getStringAttribute(xmlReader.attributes(), 'type')
		width = self.__getIntegerAttribute(xmlReader.attributes(), 'width')
		height = self.__getIntegerAttribute(xmlReader.attributes(), 'height')

		# Initialize node
		node = None
		if type == 'Region':
			node = Region(parentNode, name)
		elif type == 'Sensor':
			node = Sensor(parentNode, name)
		node.width = width
		node.height = height

		# Read specific parameters according to node type
		if type == 'Region':
			inputMapType = self.__getStringAttribute(xmlReader.attributes(), 'inputMapType')
			if inputMapType == "Grouped":
				node.inputMapType = InputMapType.grouped
			elif inputMapType == "Combined":
				node.inputMapType = InputMapType.combined
			node.enableSpatialPooling = self.__getBooleanAttribute(xmlReader.attributes(), 'enableSpatialPooling')
			node.potentialRadius = self.__getIntegerAttribute(xmlReader.attributes(), 'potentialRadius')
			node.potentialPct = self.__getFloatAttribute(xmlReader.attributes(), 'potentialPct')
			node.globalInhibition = self.__getBooleanAttribute(xmlReader.attributes(), 'globalInhibition')
			node.localAreaDensity = self.__getFloatAttribute(xmlReader.attributes(), 'localAreaDensity')
			node.numActiveColumnsPerInhArea = self.__getFloatAttribute(xmlReader.attributes(), 'numActiveColumnsPerInhArea')
			node.stimulusThreshold = self.__getIntegerAttribute(xmlReader.attributes(), 'stimulusThreshold')
			node.proximalSynConnectedPerm = self.__getFloatAttribute(xmlReader.attributes(), 'proximalSynConnectedPerm')
			node.proximalSynPermIncrement = self.__getFloatAttribute(xmlReader.attributes(), 'proximalSynPermIncrement')
			node.proximalSynPermDecrement = self.__getFloatAttribute(xmlReader.attributes(), 'proximalSynPermDecrement')
			node.minPctOverlapDutyCycle = self.__getFloatAttribute(xmlReader.attributes(), 'minPctOverlapDutyCycle')
			node.minPctActiveDutyCycle = self.__getFloatAttribute(xmlReader.attributes(), 'minPctActiveDutyCycle')
			node.dutyCyclePeriod = self.__getIntegerAttribute(xmlReader.attributes(), 'dutyCyclePeriod')
			node.maxBoost = self.__getFloatAttribute(xmlReader.attributes(), 'maxBoost')
			node.enableTemporalPooling = self.__getBooleanAttribute(xmlReader.attributes(), 'enableTemporalPooling')
			node.numCellsPerColumn = self.__getIntegerAttribute(xmlReader.attributes(), 'numCellsPerColumn')
			node.learningRadius = self.__getIntegerAttribute(xmlReader.attributes(), 'learningRadius')
			node.distalSynInitialPerm = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynInitialPerm')
			node.distalSynConnectedPerm = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynConnectedPerm')
			node.distalSynPermIncrement = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynPermIncrement')
			node.distalSynPermDecrement = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynPermDecrement')
			node.minThreshold = self.__getIntegerAttribute(xmlReader.attributes(), 'minThreshold')
			node.activationThreshold = self.__getIntegerAttribute(xmlReader.attributes(), 'activationThreshold')
			node.maxNumNewSynapses = self.__getIntegerAttribute(xmlReader.attributes(), 'maxNumNewSynapses')
		elif type == 'Sensor':
			inputFormat = self.__getStringAttribute(xmlReader.attributes(), 'inputFormat')
			if inputFormat == "Htm":
				node.inputFormat = InputFormat.htm
			elif inputFormat == "Raw":
				node.inputFormat = InputFormat.raw
				node.encoder = self.__getStringAttribute(xmlReader.attributes(), 'encoder')
			dataSourceType = self.__getStringAttribute(xmlReader.attributes(), 'dataSourceType')
			if dataSourceType == "File":
				node.dataSourceType = DataSourceType.file
				node.fileName = self.__getStringAttribute(xmlReader.attributes(), 'fileName')
			elif dataSourceType == "Database":
				node.dataSourceType = DataSourceType.database
				node.databaseConnectionString = self.__getStringAttribute(xmlReader.attributes(), 'databaseConnectionString')
				node.databaseTable = self.__getStringAttribute(xmlReader.attributes(), 'databaseTable')
				node.databaseField = self.__getStringAttribute(xmlReader.attributes(), 'databaseField')

		# If still is not end of element it's because this node has children
		token = xmlReader.readNext()
		if not xmlReader.isEndElement():
			while xmlReader.readNextStartElement():
				childNode = self.__readNode(node, xmlReader)
				node.children.append(childNode)

		return node
예제 #2
0
	def __readNode(self, parentNode, xmlReader):

		# Read type of node
		name = self.__getStringAttribute(xmlReader.attributes(), 'name')
		type = self.__getStringAttribute(xmlReader.attributes(), 'type')
		width = self.__getIntegerAttribute(xmlReader.attributes(), 'width')
		height = self.__getIntegerAttribute(xmlReader.attributes(), 'height')

		# Initialize node
		node = None
		if type == 'Region':
			node = Region(parentNode, name)
		elif type == 'Sensor':
			node = Sensor(parentNode, name)
		node.width = width
		node.height = height

		# Read specific parameters according to node type
		if type == 'Region':
			node.enableSpatialPooling = self.__getBooleanAttribute(xmlReader.attributes(), 'enableSpatialPooling')
			node.potentialRadius = self.__getIntegerAttribute(xmlReader.attributes(), 'potentialRadius')
			node.potentialPct = self.__getFloatAttribute(xmlReader.attributes(), 'potentialPct')
			node.globalInhibition = self.__getBooleanAttribute(xmlReader.attributes(), 'globalInhibition')
			node.localAreaDensity = self.__getFloatAttribute(xmlReader.attributes(), 'localAreaDensity')
			node.numActiveColumnsPerInhArea = self.__getFloatAttribute(xmlReader.attributes(), 'numActiveColumnsPerInhArea')
			node.stimulusThreshold = self.__getIntegerAttribute(xmlReader.attributes(), 'stimulusThreshold')
			node.proximalSynConnectedPerm = self.__getFloatAttribute(xmlReader.attributes(), 'proximalSynConnectedPerm')
			node.proximalSynPermIncrement = self.__getFloatAttribute(xmlReader.attributes(), 'proximalSynPermIncrement')
			node.proximalSynPermDecrement = self.__getFloatAttribute(xmlReader.attributes(), 'proximalSynPermDecrement')
			node.minPctOverlapDutyCycle = self.__getFloatAttribute(xmlReader.attributes(), 'minPctOverlapDutyCycle')
			node.minPctActiveDutyCycle = self.__getFloatAttribute(xmlReader.attributes(), 'minPctActiveDutyCycle')
			node.dutyCyclePeriod = self.__getIntegerAttribute(xmlReader.attributes(), 'dutyCyclePeriod')
			node.maxBoost = self.__getFloatAttribute(xmlReader.attributes(), 'maxBoost')
			node.enableTemporalPooling = self.__getBooleanAttribute(xmlReader.attributes(), 'enableTemporalPooling')
			node.numCellsPerColumn = self.__getIntegerAttribute(xmlReader.attributes(), 'numCellsPerColumn')
			node.learningRadius = self.__getIntegerAttribute(xmlReader.attributes(), 'learningRadius')
			node.distalSynInitialPerm = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynInitialPerm')
			node.distalSynConnectedPerm = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynConnectedPerm')
			node.distalSynPermIncrement = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynPermIncrement')
			node.distalSynPermDecrement = self.__getFloatAttribute(xmlReader.attributes(), 'distalSynPermDecrement')
			node.minThreshold = self.__getIntegerAttribute(xmlReader.attributes(), 'minThreshold')
			node.activationThreshold = self.__getIntegerAttribute(xmlReader.attributes(), 'activationThreshold')
			node.maxNumNewSynapses = self.__getIntegerAttribute(xmlReader.attributes(), 'maxNumNewSynapses')
		elif type == 'Sensor':
			inputFormat = self.__getStringAttribute(xmlReader.attributes(), 'inputFormat')
			if inputFormat == "Htm":
				node.inputFormat = InputFormat.htm
			elif inputFormat == "Raw":
				node.inputFormat = InputFormat.raw
				node.encoder = self.__getStringAttribute(xmlReader.attributes(), 'encoder')
			dataSourceType = self.__getStringAttribute(xmlReader.attributes(), 'dataSourceType')
			if dataSourceType == "File":
				node.dataSourceType = DataSourceType.file
				node.fileName = self.__getStringAttribute(xmlReader.attributes(), 'fileName')
			elif dataSourceType == "Database":
				node.dataSourceType = DataSourceType.database
				node.databaseConnectionString = self.__getStringAttribute(xmlReader.attributes(), 'databaseConnectionString')
				node.databaseTable = self.__getStringAttribute(xmlReader.attributes(), 'databaseTable')
				node.databaseField = self.__getStringAttribute(xmlReader.attributes(), 'databaseField')

		# If still is not end of element it's because this node has children
		token = xmlReader.readNext()
		if not xmlReader.isEndElement():
			while xmlReader.readNextStartElement():
				childNode = self.__readNode(node, xmlReader)
				node.children.append(childNode)

		return node
예제 #3
0
    def __readNode(self, xmlReader):

        # Read type of node
        name = self.__getStringAttribute(xmlReader.attributes(), 'name')
        type = self.__getStringAttribute(xmlReader.attributes(), 'type')

        # Create a node from parameters
        node = None
        if type == 'Region':
            node = Region(name)
        elif type == 'Sensor':
            node = Sensor(name)
        node.width = self.__getIntegerAttribute(xmlReader.attributes(),
                                                'width')
        node.height = self.__getIntegerAttribute(xmlReader.attributes(),
                                                 'height')

        # Read specific parameters according to node type
        if type == 'Region':
            node.enableSpatialLearning = self.__getBooleanAttribute(
                xmlReader.attributes(), 'enableSpatialLearning')
            node.potentialRadius = self.__getIntegerAttribute(
                xmlReader.attributes(), 'potentialRadius')
            node.potentialPct = self.__getFloatAttribute(
                xmlReader.attributes(), 'potentialPct')
            node.globalInhibition = self.__getBooleanAttribute(
                xmlReader.attributes(), 'globalInhibition')
            node.localAreaDensity = self.__getFloatAttribute(
                xmlReader.attributes(), 'localAreaDensity')
            node.numActiveColumnsPerInhArea = self.__getFloatAttribute(
                xmlReader.attributes(), 'numActiveColumnsPerInhArea')
            node.stimulusThreshold = self.__getIntegerAttribute(
                xmlReader.attributes(), 'stimulusThreshold')
            node.proximalSynConnectedPerm = self.__getFloatAttribute(
                xmlReader.attributes(), 'proximalSynConnectedPerm')
            node.proximalSynPermIncrement = self.__getFloatAttribute(
                xmlReader.attributes(), 'proximalSynPermIncrement')
            node.proximalSynPermDecrement = self.__getFloatAttribute(
                xmlReader.attributes(), 'proximalSynPermDecrement')
            node.minPctOverlapDutyCycle = self.__getFloatAttribute(
                xmlReader.attributes(), 'minPctOverlapDutyCycle')
            node.minPctActiveDutyCycle = self.__getFloatAttribute(
                xmlReader.attributes(), 'minPctActiveDutyCycle')
            node.dutyCyclePeriod = self.__getIntegerAttribute(
                xmlReader.attributes(), 'dutyCyclePeriod')
            node.maxBoost = self.__getFloatAttribute(xmlReader.attributes(),
                                                     'maxBoost')
            node.spSeed = self.__getIntegerAttribute(xmlReader.attributes(),
                                                     'spSeed')
            node.enableTemporalLearning = self.__getBooleanAttribute(
                xmlReader.attributes(), 'enableTemporalLearning')
            node.numCellsPerColumn = self.__getIntegerAttribute(
                xmlReader.attributes(), 'numCellsPerColumn')
            node.learningRadius = self.__getIntegerAttribute(
                xmlReader.attributes(), 'learningRadius')
            node.distalSynInitialPerm = self.__getFloatAttribute(
                xmlReader.attributes(), 'distalSynInitialPerm')
            node.distalSynConnectedPerm = self.__getFloatAttribute(
                xmlReader.attributes(), 'distalSynConnectedPerm')
            node.distalSynPermIncrement = self.__getFloatAttribute(
                xmlReader.attributes(), 'distalSynPermIncrement')
            node.distalSynPermDecrement = self.__getFloatAttribute(
                xmlReader.attributes(), 'distalSynPermDecrement')
            node.minThreshold = self.__getIntegerAttribute(
                xmlReader.attributes(), 'minThreshold')
            node.activationThreshold = self.__getIntegerAttribute(
                xmlReader.attributes(), 'activationThreshold')
            node.maxNumNewSynapses = self.__getIntegerAttribute(
                xmlReader.attributes(), 'maxNumNewSynapses')
            node.tpSeed = self.__getIntegerAttribute(xmlReader.attributes(),
                                                     'tpSeed')
        elif type == 'Sensor':
            dataSourceType = self.__getStringAttribute(xmlReader.attributes(),
                                                       'dataSourceType')
            if dataSourceType == "File":
                node.dataSourceType = DataSourceType.file
                node.fileName = self.__getStringAttribute(
                    xmlReader.attributes(), 'fileName')
            elif dataSourceType == "Database":
                node.dataSourceType = DataSourceType.database
                node.databaseConnectionString = self.__getStringAttribute(
                    xmlReader.attributes(), 'databaseConnectionString')
                node.databaseTable = self.__getStringAttribute(
                    xmlReader.attributes(), 'databaseTable')
            node.predictionsMethod = self.__getStringAttribute(
                xmlReader.attributes(), 'predictionsMethod')
            if node.predictionsMethod == PredictionsMethod.classification:
                node.enableClassificationLearning = self.__getBooleanAttribute(
                    xmlReader.attributes(), 'enableClassificationLearning')
                node.enableClassificationInference = self.__getBooleanAttribute(
                    xmlReader.attributes(), 'enableClassificationInference')

            # If still is not end of element it's because this node has encodings
            token = xmlReader.readNext()
            if not xmlReader.isEndElement():
                while xmlReader.readNextStartElement():
                    encoding = self.__readEncoding(xmlReader)
                    node.encodings.append(encoding)

        token = xmlReader.readNext()

        return node