def menuNodeAddRegion_click(self, event):
        """
        Add a feeder region to the selected region.
        """

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

            self.main_window.markProjectChanges(True)

            # Add new region below highlighted region
            new_region = Region(entered_text)
            Global.project.network.addFeederNode(new_region,
                                                 self.under_mouse_node)

            # Redraw the tree to show the updates.
            self.repaint()
            self.updateCode()
예제 #2
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()
예제 #3
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()
    def __init__(self, main_window):
        """
        Initializes a new instance of this class.
        """
        QtWidgets.QWidget.__init__(self)
        self.main_window = main_window

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

        # Node that is selected for visualization of its details.
        self.selected_node = None

        # Node that is highlighted due to mouse is on it.
        self.under_mouse_node = None

        # Space to skip horizontally between siblings
        # and vertically between generations
        self.offset_horizontal = 15
        self.offset_vertical = 30

        self.initUI()
예제 #5
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
예제 #6
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.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
예제 #7
0
    def readNode(self, node_dict):

        # Read type of node
        name = node_dict['name']
        type = node_dict['type']

        # Create a node from parameters
        node = None
        if type == 'Region':
            node = Region(name)
        elif type == 'Sensor':
            node = Sensor(name)
        node.width = node_dict['width']
        node.height = node_dict['height']

        # Read specific parameters according to node type
        if type == 'Region':
            node.enable_spatial_learning = node_dict['enable_spatial_learning']
            node.potential_radius = node_dict['potential_radius']
            node.potential_pct = node_dict['potential_pct']
            node.global_inhibition = node_dict['global_inhibition']
            node.local_area_density = node_dict['local_area_density']
            node.num_active_columns_per_inh_area = node_dict['num_active_columns_per_inh_area']
            node.stimulus_threshold = node_dict['stimulus_threshold']
            node.proximal_syn_connected_perm = node_dict['proximal_syn_connected_perm']
            node.proximal_syn_perm_increment = node_dict['proximal_syn_perm_increment']
            node.proximal_syn_perm_decrement = node_dict['proximal_syn_perm_decrement']
            node.min_pct_overlap_duty_cycle = node_dict['min_pct_overlap_duty_cycle']
            node.min_pct_active_duty_cycle = node_dict['min_pct_active_duty_cycle']
            node.duty_cycle_period = node_dict['duty_cycle_period']
            node.max_boost = node_dict['max_boost']
            node.sp_seed = node_dict['sp_seed']
            node.enable_temporal_learning = node_dict['enable_temporal_learning']
            node.cells_per_column = node_dict['cells_per_column']
            node.distal_syn_initial_perm = node_dict['distal_syn_initial_perm']
            node.distal_syn_connected_perm = node_dict['distal_syn_connected_perm']
            node.distal_syn_perm_increment = node_dict['distal_syn_perm_increment']
            node.distal_syn_perm_decrement = node_dict['distal_syn_perm_decrement']
            node.min_threshold = node_dict['min_threshold']
            node.activation_threshold = node_dict['activation_threshold']
            node.max_new_synapses = node_dict['max_new_synapses']
            node.tp_seed = node_dict['tp_seed']
        elif type == 'Sensor':
            data_source_type = node_dict['data_source_type']
            if data_source_type == "File":
                node.data_source_type = DataSourceType.FILE
                node.file_name = node_dict['file_name']
            elif data_source_type == "Database":
                node.data_source_type = DataSourceType.DATABASE
                node.database_connection_string = node_dict['database_connection_string']
                node.database_table = node_dict['database_table']
            node.predictions_method = node_dict['predictions_method']
            if node.predictions_method == PredictionsMethod.CLASSIFICATION:
                node.enable_classification_learning = node_dict['enable_classification_learning']
                node.enable_classification_inference = node_dict['enable_classification_inference']

            # If still is not end of element it's because this node has encodings
            for encoding_dict in node_dict['encodings']:
                encoding = self.readEncoding(encoding_dict)
                node.encodings.append(encoding)

        return node