예제 #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 __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()
예제 #5
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()
예제 #6
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."""
예제 #7
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
예제 #8
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