예제 #1
0
    def __init__(self):
        """
		Initializes a new instance of this class.
		"""

        QtGui.QWidget.__init__(self)

        #region Instance fields

        self.topRegion = Region("TopRegion")
        """Node that is on top of the hierarchy."""

        self.selectedNode = None
        """Node that is selected for visualization of its details."""

        self.underMouseNode = None
        """Node that is highlighted due to mouse is on it."""

        # Space to skip horizontally between siblings
        # and vertically between generations
        self._offsetHorizontal = 15
        self._offsetVertical = 30

        #endregion

        self.initUI()
예제 #2
0
    def __menuNodeAddRegion_Click(self, event):
        """
		Add a feeder region to the selected region.
		"""

        # Ask for region's name
        enteredText, ok = QtGui.QInputDialog.getText(self, "Input Dialog",
                                                     "Enter region's name:")
        if ok:
            validExpr = QtCore.QRegExp('[a-zA-Z0-9_]+')
            if not validExpr.exactMatch(enteredText):
                QtGui.QMessageBox.warning(
                    self, "Warning", "'" + enteredText +
                    "' is not a valid name. Only characters, numbers and _ are accepted."
                )
                return

            Global.mainForm.markProjectChanges(True)

            # Add new region below highlighted region
            newRegion = Region(enteredText)
            Global.project.network.addFeederNode(newRegion,
                                                 self.underMouseNode)

            # Redraw the tree to show the updates.
            self.repaint()
            Global.architectureForm.updateCode()
예제 #3
0
	def new(self):
		"""
		Initializes a new instance of this class.
		"""

		# Initialize metadata
		self.fileName = ''
		self.name = "Untitled"
		self.author = ""
		self.description = ""

		# Initialize top region params
		self.topRegion = Region(None, "Top Region")
예제 #4
0
	def new(self):
		"""
		Initializes a new instance of the Project class and sets it to a singleton instance.
		"""

		# Initialize metadata
		self.fileName = ''
		self.name = "Untitled"
		self.author = ""
		self.description = ""

		# Initialize top region params
		self.topRegion = Region(None, "Top Region")

		# Create a sensor and add it as lower node to top region
		self.sensor = Sensor(self.topRegion, "Sensor")
		self.topRegion.addChild(self.sensor)
예제 #5
0
    def __menuNodeAddChildRegion_Click(self, event):
        """
		Add a child region to the selected region.
		"""

        # Ask for region's name
        enteredText, ok = QtGui.QInputDialog.getText(self, "Input Dialog",
                                                     "Enter region's name:")
        if ok:
            Global.mainForm.markProjectChanges(True)

            # Add new region bellow highlighted region
            self.underMouseNode.addChild(
                Region(self.underMouseNode, enteredText))

            # Redraw the tree to show the updates.
            self.repaint()
예제 #6
0
    def new(self):
        """
		Initializes a new instance of this class.
		"""

        # Initialize metadata
        self.fileName = ''
        self.name = "Untitled"
        self.author = ""
        self.description = ""

        # Create the top region
        topRegion = Region("TopRegion")

        # Create the network and add topRegion as its starting node
        self.network = Network()
        self.network.nodes.append(topRegion)
        self.network.preparePhases()
예제 #7
0
	def __init__(self):
		"""
		Initializes a new instance of the Project class.
		"""

		#region Instance fields

		self.fileName = ''
		"""Project file"""

		self.name = "Untitled"
		"""Name of the project."""

		self.author = ""
		"""Author of the project."""

		self.description = ""
		"""Description of the project."""

		self.topRegion = Region(None, "Top Region")
		"""Parameters for the regions."""
예제 #8
0
	def __init__(self):
		"""
		Initializes a new instance of this class.
		"""

		#region Instance fields

		self.fileName = ''
		"""Project file"""

		self.name = "Untitled"
		"""Name of the project."""

		self.author = ""
		"""Author of the project."""

		self.description = ""
		"""Description of the project."""

		self.topRegion = Region(None, "Top Region")
		"""Parameters for the regions."""
예제 #9
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
예제 #10
0
class Project:
	"""
	Loads and saves the Elements of the Project file, that contains user entries for Network configuration
	Provides loaded elements as a structure to return.
	"""

	#region Constructor

	def __init__(self):
		"""
		Initializes a new instance of the Project class.
		"""

		#region Instance fields

		self.fileName = ''
		"""Project file"""

		self.name = "Untitled"
		"""Name of the project."""

		self.author = ""
		"""Author of the project."""

		self.description = ""
		"""Description of the project."""

		self.topRegion = Region(None, "Top Region")
		"""Parameters for the regions."""

		#endregion

	#endregion

	#region Methods

	def new(self):
		"""
		Initializes a new instance of the Project class and sets it to a singleton instance.
		"""

		# Initialize metadata
		self.fileName = ''
		self.name = "Untitled"
		self.author = ""
		self.description = ""

		# Initialize top region params
		self.topRegion = Region(None, "Top Region")

		# Create a sensor and add it as lower node to top region
		self.sensor = Sensor(self.topRegion, "Sensor")
		self.topRegion.addChild(self.sensor)

	def open(self, fileName):
		"""
		Loads the content from XML file to Project instance.
		"""

		self.fileName = fileName
		file = QtCore.QFile(self.fileName)
		if (file.open(QtCore.QIODevice.ReadOnly)):
			xmlReader = QtCore.QXmlStreamReader()
			xmlReader.setDevice(file)
			while (not xmlReader.isEndDocument()):
				if xmlReader.isStartElement():
					if xmlReader.name().toString() == 'MetaData':
						self.name = self.__getStringAttribute(xmlReader.attributes(), 'name')
						self.author = self.__getStringAttribute(xmlReader.attributes(), 'author')
						self.description = self.__getStringAttribute(xmlReader.attributes(), 'description')
					elif xmlReader.name().toString() == 'Net':
						xmlReader.readNextStartElement()
						self.topRegion = self.__readNode(None, xmlReader)

				xmlReader.readNext()
			if (xmlReader.hasError()):
				QtGui.QMessageBox.critical(self, "Critical", "Ocurred a XML error: " + xmlReader.errorString().data(), QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default, QtGui.QMessageBox.NoButton)
		else:
			QtGui.QMessageBox.critical(self, "Critical", "Cannot read the project file!", QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default, QtGui.QMessageBox.NoButton)

	def __getStringAttribute(self, attributes, attributeName):
		if attributes.value(attributeName).toString() != "":
			attributeValue = str(attributes.value(attributeName).toString())
		else:
			attributeValue = ""
		return attributeValue

	def __getIntegerAttribute(self, attributes, attributeName):
		attributeValue = 0
		if attributes.value(attributeName).toString() != "":
			attributeValue = int(attributes.value(attributeName).toString())
		return attributeValue

	def __getFloatAttribute(self, attributes, attributeName):
		attributeValue = 0.0
		if attributes.value(attributeName).toString() != "":
			attributeValue = float(attributes.value(attributeName).toString())
		return attributeValue

	def __getBooleanAttribute(self, attributes, attributeName):
		attributeValue = False
		if attributes.value(attributeName).toString() == "True":
			attributeValue = True
		return attributeValue

	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
		
	def save(self, fileName):
		"""
		Saves the content from Project instance to XML file.
		"""

		self.fileName = fileName
		file = QtCore.QFile(self.fileName)
		file.open(QtCore.QIODevice.WriteOnly)
		xmlWriter = QtCore.QXmlStreamWriter(file)
		xmlWriter.setAutoFormatting(True)
		xmlWriter.writeStartDocument()
		xmlWriter.writeStartElement('Project')

		xmlWriter.writeStartElement('MetaData')
		xmlWriter.writeAttribute('name', self.name)
		xmlWriter.writeAttribute('author', self.author)
		xmlWriter.writeAttribute('description', self.description)
		xmlWriter.writeEndElement()

		xmlWriter.writeStartElement('Net')
		self.__writeNode(self.topRegion, xmlWriter)
		xmlWriter.writeEndElement()

		xmlWriter.writeEndElement()
		xmlWriter.writeEndDocument()
		file.close()

	def __writeNode(self, node, xmlWriter):

		# Write common parameters
		xmlWriter.writeStartElement('Node')
		xmlWriter.writeAttribute('name', node.name)

		# Write specific parameters according to node type
		if node.type == NodeType.region:
			xmlWriter.writeAttribute('type', 'Region')
			xmlWriter.writeAttribute('width', str(node.width))
			xmlWriter.writeAttribute('height', str(node.height))
			xmlWriter.writeAttribute('enableSpatialPooling', str(node.enableSpatialPooling))
			xmlWriter.writeAttribute('potentialRadius', str(node.potentialRadius))
			xmlWriter.writeAttribute('potentialPct', str(node.potentialPct))
			xmlWriter.writeAttribute('globalInhibition', str(node.globalInhibition))
			xmlWriter.writeAttribute('localAreaDensity', str(node.localAreaDensity))
			xmlWriter.writeAttribute('numActiveColumnsPerInhArea', str(node.numActiveColumnsPerInhArea))
			xmlWriter.writeAttribute('stimulusThreshold', str(node.stimulusThreshold))
			xmlWriter.writeAttribute('proximalSynConnectedPerm', str(node.proximalSynConnectedPerm))
			xmlWriter.writeAttribute('proximalSynPermIncrement', str(node.proximalSynPermIncrement))
			xmlWriter.writeAttribute('proximalSynPermDecrement', str(node.proximalSynPermDecrement))
			xmlWriter.writeAttribute('minPctOverlapDutyCycle', str(node.minPctOverlapDutyCycle))
			xmlWriter.writeAttribute('minPctActiveDutyCycle', str(node.minPctActiveDutyCycle))
			xmlWriter.writeAttribute('dutyCyclePeriod', str(node.dutyCyclePeriod))
			xmlWriter.writeAttribute('maxBoost', str(node.maxBoost))
			xmlWriter.writeAttribute('enableTemporalPooling', str(node.enableTemporalPooling))
			xmlWriter.writeAttribute('numCellsPerColumn', str(node.numCellsPerColumn))
			xmlWriter.writeAttribute('learningRadius', str(node.learningRadius))
			xmlWriter.writeAttribute('distalSynInitialPerm', str(node.distalSynInitialPerm))
			xmlWriter.writeAttribute('distalSynConnectedPerm', str(node.distalSynConnectedPerm))
			xmlWriter.writeAttribute('distalSynPermIncrement', str(node.distalSynPermIncrement))
			xmlWriter.writeAttribute('distalSynPermDecrement', str(node.distalSynPermDecrement))
			xmlWriter.writeAttribute('minThreshold', str(node.minThreshold))
			xmlWriter.writeAttribute('activationThreshold', str(node.activationThreshold))
			xmlWriter.writeAttribute('maxNumNewSynapses', str(node.maxNumNewSynapses))
		elif node.type == NodeType.sensor:
			xmlWriter.writeAttribute('type', 'Sensor')
			xmlWriter.writeAttribute('width', str(node.width))
			xmlWriter.writeAttribute('height', str(node.height))
			if node.inputFormat == InputFormat.htm:
				xmlWriter.writeAttribute('inputFormat', "Htm")
			elif node.inputFormat == InputFormat.raw:
				xmlWriter.writeAttribute('inputFormat', "Raw")
				xmlWriter.writeAttribute('encoder', node.encoder)
			if node.dataSourceType == DataSourceType.file:
				xmlWriter.writeAttribute('dataSourceType', "File")
				xmlWriter.writeAttribute('fileName', node.fileName)
			elif node.dataSourceType == DataSourceType.database:
				xmlWriter.writeAttribute('dataSourceType', "Database")
				xmlWriter.writeAttribute('databaseConnectionString', node.databaseConnectionString)
				xmlWriter.writeAttribute('databaseTable', node.databaseTable)
				xmlWriter.writeAttribute('databaseField', node.databaseField)

		# Tranverse all child nodes
		for childNode in node.children:
			self.__writeNode(childNode, xmlWriter)

		xmlWriter.writeEndElement()
예제 #11
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
예제 #12
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