Exemplo n.º 1
0
class RowPanel(QWidget):
    def __init__(self, name):
        QWidget.__init__(self)
        self.__name = name
        self.__layout_queue = []
        self.setMinimumWidth(500)
        self.__layout = QGridLayout()
        """ @type: QGridLayout """
        self.setLayout(self.__layout)
        self.__row = 0
        self.__widgets = {}

        self.__layout.setColumnMinimumWidth(0, 20)
        self.__layout.setColumnMinimumWidth(6, 20)

        self.__popups = []

    def getName(self):
        return self.__name

    def __startNewRow(self):
        self.__layout.setRowStretch(self.__row, 0)

    def __rowFinished(self):
        self.__row += 2
        self.__layout.setRowStretch(self.__row, 1)

    def addRow(self, row_widget, configurator=None):
        """
        Add a new row on a configuration page. Returns the row widget.
        If the row does not have a getLabel() function the row spans both columns.

        @rtype: QWidget
        """
        assert hasattr(row_widget, "getLabel"), "Widget must have a getLabel() method"

        self.__startNewRow()

        if row_widget.getLabel() is None or row_widget.getLabel() == "":
            self.__layout.addWidget(row_widget, self.__row, 1, 1, 3)
        else:
            self.__layout.addWidget(QLabel(row_widget.getLabel()), self.__row, 1, Qt.AlignLeft | Qt.AlignTop)
            self.__layout.addWidget(row_widget, self.__row, 3)

        if not configurator is None:
            button = self.__addConfigurationButton(configurator)
            self.__layout.addWidget(button, self.__row, 5)

        self.__widgets[row_widget] = self.__row

        self.__rowFinished()


    def startTabs(self, name_of_first_tab):
        self.__tab_widget = QTabWidget()
        self.__layout_queue.append(self.__layout)
        self.__layout = None
        self.addTab(name_of_first_tab)

    def addTab(self, name):
        self.__layout = QGridLayout()
        widget = QWidget()
        widget.setLayout(self.__layout)
        self.__tab_widget.addTab(widget, name)


    def endTabs(self):
        self.__layout = self.__layout_queue.pop()
        """ @type: QGridLayout """
        self.__startNewRow()
        self.__layout.addWidget(self.__tab_widget, self.__row, 1, 1, 5)
        self.__rowFinished()
        self.__tab_widget = None


    def startGroup(self, group_title):
        """Start a titled sub group on the page."""
        self.__group_box = QGroupBox(group_title)
        self.__layout_queue.append(self.__layout)
        self.__layout = QGridLayout()

    def endGroup(self):
        """Finish the titled sub group"""
        self.__group_box.setLayout(self.__layout)
        self.__layout = self.__layout_queue.pop()
        """ @type: QGridLayout """
        self.__layout.addRow(self.__group_box)
        self.__group_box = None

    def addLabeledSeparator(self, label):
        """Adds a labeled separator line to the panel."""
        widget = QWidget()
        layout = QVBoxLayout()
        widget.setLayout(layout)

        h_layout = QHBoxLayout()

        frame = QFrame()
        frame.setFrameShape(QFrame.HLine)
        frame.setFrameShadow(QFrame.Sunken)

        h_layout.addWidget(QLabel(label))
        h_layout.addWidget(frame, 1, Qt.AlignBottom)

        layout.addSpacing(2)
        layout.addLayout(h_layout)
        layout.addSpacing(0)

        # widget.setStyleSheet("background-color: #ffff00")

        self.__startNewRow()
        self.__layout.addWidget(widget, self.__row, 0, 1, 7)
        self.__rowFinished()

    def addSeparator(self):
        widget = QWidget()
        layout = QVBoxLayout()
        widget.setLayout(layout)

        frame = QFrame()
        frame.setFrameShape(QFrame.HLine)
        frame.setFrameShadow(QFrame.Sunken)

        layout.addSpacing(5)
        layout.addWidget(frame)
        layout.addSpacing(5)

        self.__startNewRow()
        self.__layout.addWidget(widget, self.__row, 1, 1, 5)
        self.__rowFinished()


    def __addConfigurationButton(self, configurator):
        popup = PopupDialog(configurator.getName(), configurator, self)
        button = popup.getButton()
        button.setText("Configure")
        self.__popups.append(popup)
        return button


    def addSpace(self, size=5):
        """Creates a widget that can be used as spacing on  a panel."""
        space = QWidget()
        space.setMinimumSize(QSize(size, size))
        self.__startNewRow()
        self.__layout.addWidget(space, self.__row, 1, 1, 5)
        self.__rowFinished()
Exemplo n.º 2
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.data = None
        self.preprocessors = None

        box = gui.widgetBox(self.controlArea, self.tr("Name"))
        gui.lineEdit(box, self, "learner_name")

        form = QGridLayout()
        typebox = gui.radioButtonsInBox(
            self.controlArea,
            self,
            "lossfunc",
            [],
            orientation=form,
        )

        # Loss function control
        box = gui.widgetBox(self.controlArea,
                            self.tr("Loss function to be used"))
        buttonbox = gui.radioButtonsInBox(box,
                                          self,
                                          "loss_function",
                                          btnLabels=[
                                              "Squared loss", "Huber",
                                              "Epsilon insensitive",
                                              "Squared Epsilon insensitive"
                                          ],
                                          callback=self._on_func_changed)

        parambox = gui.widgetBox(box, orientation="horizontal")

        box = gui.widgetBox(self.controlArea, self.tr("Penalty"))
        buttonbox = gui.radioButtonsInBox(box,
                                          self,
                                          "penalty_type",
                                          btnLabels=[
                                              "Absolute norm (L1)",
                                              "Euclidean norm (L2)",
                                              "Elastic Net (both)"
                                          ],
                                          callback=self._on_penalty_changed)

        parambox = gui.widgetBox(box, orientation="horizontal")

        box = gui.widgetBox(self.controlArea, self.tr("Learning rate"))
        buttonbox = gui.radioButtonsInBox(
            box,
            self,
            "learning_rate",
            btnLabels=["Inverse scaling", "Constant"],
            callback=self._on_lrate_changed)

        box = gui.widgetBox(self.controlArea, self.tr("Constants"))

        form = QtGui.QFormLayout()
        form.setContentsMargins(0, 0, 0, 0)

        box.layout().addLayout(form)

        alpha = gui.doubleSpin(box, self, "alpha", 0.0, 10.0, step=0.0001)
        form.addRow("Alpha:", alpha)

        spin = gui.doubleSpin(box, self, "eta0", 0.0, 10, step=0.01)
        form.addRow("Eta0:", spin)

        epsilon = gui.doubleSpin(box, self, "epsilon", 0.0, 10.0, step=0.01)
        form.addRow("Epsilon:", epsilon)

        l1_ratio = gui.doubleSpin(box, self, "l1_ratio", 0.0, 10.0, step=0.01)
        form.addRow("L1 ratio:", l1_ratio)

        power_t = gui.doubleSpin(box, self, "power_t", 0.0, 10.0, step=0.01)
        form.addRow("Power t:", power_t)

        # Number of iterations control
        box = gui.widgetBox(self.controlArea, "Number of iterations")
        gui.doubleSpin(box, self, "n_iter", 0, 1e+6, step=1)

        self._func_params = [epsilon]
        self._penalty_params = [l1_ratio]
        self._lrate_params = [power_t]

        gui.button(self.controlArea,
                   self,
                   "&Apply",
                   callback=self.apply,
                   default=True)

        self.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed))

        self.setMinimumWidth(300)

        self._on_func_changed()

        self.apply()
Exemplo n.º 3
0
    def __init__(self):
        super().__init__()

        self.data = None
        self.preprocessors = None

        box = gui.widgetBox(self.controlArea, self.tr("Name"))
        gui.lineEdit(box, self, "learner_name")

        form = QGridLayout()
        typebox = gui.radioButtonsInBox(self.controlArea, self, "lossfunc", [], orientation=form)

        # Loss function control
        box = gui.widgetBox(self.controlArea, self.tr("Loss function to be used"))
        buttonbox = gui.radioButtonsInBox(
            box,
            self,
            "loss_function",
            btnLabels=["Squared loss", "Huber", "Epsilon insensitive", "Squared Epsilon insensitive"],
            callback=self._on_func_changed,
        )

        parambox = gui.widgetBox(box, orientation="horizontal")

        box = gui.widgetBox(self.controlArea, self.tr("Penalty"))
        buttonbox = gui.radioButtonsInBox(
            box,
            self,
            "penalty_type",
            btnLabels=["Absolute norm (L1)", "Euclidean norm (L2)", "Elastic Net (both)"],
            callback=self._on_penalty_changed,
        )

        parambox = gui.widgetBox(box, orientation="horizontal")

        box = gui.widgetBox(self.controlArea, self.tr("Learning rate"))
        buttonbox = gui.radioButtonsInBox(
            box, self, "learning_rate", btnLabels=["Inverse scaling", "Constant"], callback=self._on_lrate_changed
        )

        box = gui.widgetBox(self.controlArea, self.tr("Constants"))

        form = QtGui.QFormLayout()
        form.setContentsMargins(0, 0, 0, 0)

        box.layout().addLayout(form)

        alpha = gui.doubleSpin(box, self, "alpha", 0.0, 10.0, step=0.0001)
        form.addRow("Alpha:", alpha)

        spin = gui.doubleSpin(box, self, "eta0", 0.0, 10, step=0.01)
        form.addRow("Eta0:", spin)

        epsilon = gui.doubleSpin(box, self, "epsilon", 0.0, 10.0, step=0.01)
        form.addRow("Epsilon:", epsilon)

        l1_ratio = gui.doubleSpin(box, self, "l1_ratio", 0.0, 10.0, step=0.01)
        form.addRow("L1 ratio:", l1_ratio)

        power_t = gui.doubleSpin(box, self, "power_t", 0.0, 10.0, step=0.01)
        form.addRow("Power t:", power_t)

        # Number of iterations control
        box = gui.widgetBox(self.controlArea, "Number of iterations")
        gui.doubleSpin(box, self, "n_iter", 0, 1e6, step=1)

        self._func_params = [epsilon]
        self._penalty_params = [l1_ratio]
        self._lrate_params = [power_t]

        gui.button(self.controlArea, self, "&Apply", callback=self.apply, default=True)

        self._on_func_changed()

        self.apply()
Exemplo n.º 4
0
class RowPanel(QWidget):
    def __init__(self, name):
        QWidget.__init__(self)
        self.__name = name
        self.__layout_queue = []
        self.setMinimumWidth(500)
        self.__layout = QGridLayout()
        """ @type: QGridLayout """
        self.setLayout(self.__layout)
        self.__row = 0
        self.__widgets = {}

        self.__layout.setColumnMinimumWidth(0, 20)
        self.__layout.setColumnMinimumWidth(6, 20)

        self.__popups = []

    def getName(self):
        return self.__name

    def __startNewRow(self):
        self.__layout.setRowStretch(self.__row, 0)

    def __rowFinished(self):
        self.__row += 2
        self.__layout.setRowStretch(self.__row, 1)

    def addRow(self,
               row_widget,
               configurator=None,
               configuration_title="Configure"):
        """
        Add a new row on a configuration page. Returns the row widget.
        If the row does not have a getLabel() function the row spans both columns.

        @rtype: QWidget
        """
        assert hasattr(row_widget,
                       "getLabel"), "Widget must have a getLabel() method"

        self.__startNewRow()

        if row_widget.getLabel() is None or row_widget.getLabel() == "":
            self.__layout.addWidget(row_widget, self.__row, 1, 1, 3)
        else:
            self.__layout.addWidget(QLabel(row_widget.getLabel()), self.__row,
                                    1, Qt.AlignLeft | Qt.AlignTop)
            self.__layout.addWidget(row_widget, self.__row, 3)

        if not configurator is None:
            self.__layout.setColumnMinimumWidth(4, 20)
            button = self.__addConfigurationButton(configurator,
                                                   configuration_title)
            self.__layout.addWidget(button, self.__row, 5)

        self.__widgets[row_widget] = self.__row

        self.__rowFinished()

    def startTabs(self, name_of_first_tab):
        self.__tab_widget = QTabWidget()
        self.__layout_queue.append(self.__layout)
        self.__layout = None
        self.addTab(name_of_first_tab)

    def addTab(self, name):
        self.__layout = QGridLayout()
        widget = QWidget()
        widget.setLayout(self.__layout)
        self.__tab_widget.addTab(widget, name)

    def endTabs(self):
        self.__layout = self.__layout_queue.pop()
        """ @type: QGridLayout """
        self.__startNewRow()
        self.__layout.addWidget(self.__tab_widget, self.__row, 1, 1, 5)
        self.__rowFinished()
        self.__tab_widget = None

    def startGroup(self, group_title):
        """Start a titled sub group on the page."""
        self.__group_box = QGroupBox(group_title)
        self.__layout_queue.append(self.__layout)
        self.__layout = QGridLayout()

    def endGroup(self):
        """Finish the titled sub group"""
        self.__group_box.setLayout(self.__layout)
        self.__layout = self.__layout_queue.pop()
        """ @type: QGridLayout """
        self.__layout.addRow(self.__group_box)
        self.__group_box = None

    def addLabeledSeparator(self, label):
        """Adds a labeled separator line to the panel."""
        widget = QWidget()
        layout = QVBoxLayout()
        widget.setLayout(layout)

        h_layout = QHBoxLayout()

        frame = QFrame()
        frame.setFrameShape(QFrame.HLine)
        frame.setFrameShadow(QFrame.Sunken)

        h_layout.addWidget(QLabel(label))
        h_layout.addWidget(frame, 1, Qt.AlignBottom)

        layout.addSpacing(2)
        layout.addLayout(h_layout)
        layout.addSpacing(0)

        # widget.setStyleSheet("background-color: #ffff00")

        self.__startNewRow()
        self.__layout.addWidget(widget, self.__row, 0, 1, 7)
        self.__rowFinished()

    def addSeparator(self):
        widget = QWidget()
        layout = QVBoxLayout()
        widget.setLayout(layout)

        frame = QFrame()
        frame.setFrameShape(QFrame.HLine)
        frame.setFrameShadow(QFrame.Sunken)

        layout.addSpacing(5)
        layout.addWidget(frame)
        layout.addSpacing(5)

        self.__startNewRow()
        self.__layout.addWidget(widget, self.__row, 1, 1, 5)
        self.__rowFinished()

    def __addConfigurationButton(self, configurator, configuration_title):
        popup = PopupDialog(configurator.getName(), configurator, self)
        button = popup.getButton()
        button.setText(configuration_title)
        self.__popups.append(popup)
        return button

    def addSpace(self, size=5):
        """Creates a widget that can be used as spacing on  a panel."""
        space = QWidget()
        space.setMinimumSize(QSize(size, size))
        self.__startNewRow()
        self.__layout.addWidget(space, self.__row, 1, 1, 5)
        self.__rowFinished()