Ejemplo n.º 1
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'PurgeDomain', wantMainArea=False)
        self.settingsList=["removeValues", "removeAttributes", "removeClassAttribute", "removeClasses", "autoSend", "sortValues", "sortClasses"]

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data", ExampleTable)]

        self.data = None

        self.preRemoveValues = self.removeValues = 1
        self.removeAttributes = 1
        self.removeClassAttribute = 1
        self.preRemoveClasses = self.removeClasses = 1
        self.autoSend = 1
        self.dataChanged = False

        self.sortValues = self.sortClasses = True

        self.loadSettings()

        self.removedAttrs = self.reducedAttrs = self.resortedAttrs = self.classAttr = "-"

        boxAt = OWGUI.widgetBox(self.controlArea, "Attributes", addSpace=True)
        OWGUI.checkBox(boxAt, self, 'sortValues', 'Sort attribute values', callback = self.optionsChanged)
        rua = OWGUI.checkBox(boxAt, self, "removeAttributes", "Remove attributes with less than two values", callback = self.removeAttributesChanged)

        ruv = OWGUI.checkBox(OWGUI.indentedBox(boxAt, sep=OWGUI.checkButtonOffsetHint(rua)), self, "removeValues", "Remove unused attribute values", callback = self.optionsChanged)
        rua.disables = [ruv]
        rua.makeConsistent()


        boxAt = OWGUI.widgetBox(self.controlArea, "Classes", addSpace=True)
        OWGUI.checkBox(boxAt, self, 'sortClasses', 'Sort classes', callback = self.optionsChanged)
        rua = OWGUI.checkBox(boxAt, self, "removeClassAttribute", "Remove class attribute if there are less than two classes", callback = self.removeClassesChanged)
        ruv = OWGUI.checkBox(OWGUI.indentedBox(boxAt, sep=OWGUI.checkButtonOffsetHint(rua)), self, "removeClasses", "Remove unused class values", callback = self.optionsChanged)
        rua.disables = [ruv]
        rua.makeConsistent()


        box3 = OWGUI.widgetBox(self.controlArea, 'Statistics', addSpace=True)
        OWGUI.label(box3, self, "Removed attributes: %(removedAttrs)s")
        OWGUI.label(box3, self, "Reduced attributes: %(reducedAttrs)s")
        OWGUI.label(box3, self, "Resorted attributes: %(resortedAttrs)s")
        OWGUI.label(box3, self, "Class attribute: %(classAttr)s")
        
        box2 = OWGUI.widgetBox(self.controlArea, "Send")
        btSend = OWGUI.button(box2, self, "Send data", callback = self.process, default=True)
        cbAutoSend = OWGUI.checkBox(box2, self, "autoSend", "Send automatically")

        OWGUI.setStopper(self, btSend, cbAutoSend, "dataChanged", self.process)
        
        OWGUI.rubber(self.controlArea)
Ejemplo n.º 2
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'PurgeDomain', wantMainArea=False)
        self.settingsList=["removeValues", "removeAttributes", "removeClassAttribute", "removeClasses", "autoSend", "sortValues", "sortClasses"]

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data", ExampleTable)]

        self.data = None

        self.preRemoveValues = self.removeValues = 1
        self.removeAttributes = 1
        self.removeClassAttribute = 1
        self.preRemoveClasses = self.removeClasses = 1
        self.autoSend = 1
        self.dataChanged = False

        self.sortValues = self.sortClasses = True

        self.loadSettings()

        self.removedAttrs = self.reducedAttrs = self.resortedAttrs = self.classAttr = "-"

        boxAt = OWGUI.widgetBox(self.controlArea, "Attributes", addSpace=True)
        OWGUI.checkBox(boxAt, self, 'sortValues', 'Sort attribute values', callback = self.optionsChanged)
        rua = OWGUI.checkBox(boxAt, self, "removeAttributes", "Remove attributes with less than two values", callback = self.removeAttributesChanged)

        ruv = OWGUI.checkBox(OWGUI.indentedBox(boxAt, sep=OWGUI.checkButtonOffsetHint(rua)), self, "removeValues", "Remove unused attribute values", callback = self.optionsChanged)
        rua.disables = [ruv]
        rua.makeConsistent()


        boxAt = OWGUI.widgetBox(self.controlArea, "Classes", addSpace=True)
        OWGUI.checkBox(boxAt, self, 'sortClasses', 'Sort classes', callback = self.optionsChanged)
        rua = OWGUI.checkBox(boxAt, self, "removeClassAttribute", "Remove class attribute if there are less than two classes", callback = self.removeClassesChanged)
        ruv = OWGUI.checkBox(OWGUI.indentedBox(boxAt, sep=OWGUI.checkButtonOffsetHint(rua)), self, "removeClasses", "Remove unused class values", callback = self.optionsChanged)
        rua.disables = [ruv]
        rua.makeConsistent()


        box3 = OWGUI.widgetBox(self.controlArea, 'Statistics', addSpace=True)
        OWGUI.label(box3, self, "Removed attributes: %(removedAttrs)s")
        OWGUI.label(box3, self, "Reduced attributes: %(reducedAttrs)s")
        OWGUI.label(box3, self, "Resorted attributes: %(resortedAttrs)s")
        OWGUI.label(box3, self, "Class attribute: %(classAttr)s")
        
        box2 = OWGUI.widgetBox(self.controlArea, "Send")
        btSend = OWGUI.button(box2, self, "Send data", callback = self.process, default=True)
        cbAutoSend = OWGUI.checkBox(box2, self, "autoSend", "Send automatically")

        OWGUI.setStopper(self, btSend, cbAutoSend, "dataChanged", self.process)
        
        OWGUI.rubber(self.controlArea)
Ejemplo n.º 3
0
    def __init__(self, parent=None):
        BaseEditor.__init__(self, parent)
        self.discInd = 0
        self.numberOfIntervals = 3
        #        box = OWGUI.widgetBox(self, "Discretize")
        rb = OWGUI.radioButtonsInBox(self,
                                     self,
                                     "discInd", [],
                                     box="Discretize",
                                     callback=self.onChange)
        for label, _, _ in self.DISCRETIZERS[:-1]:
            OWGUI.appendRadioButton(rb, self, "discInd", label)
        self.sliderBox = OWGUI.widgetBox(
            OWGUI.indentedBox(rb,
                              sep=OWGUI.checkButtonOffsetHint(rb.buttons[-1])),
            "Num. of intervals (for equal width/frequency)")
        OWGUI.hSlider(self.sliderBox,
                      self,
                      "numberOfIntervals",
                      callback=self.onChange,
                      minValue=1)
        OWGUI.appendRadioButton(rb, self, "discInd", self.DISCRETIZERS[-1][0])
        OWGUI.rubber(rb)

        self.updateSliderBox()
Ejemplo n.º 4
0
 def __init__(self, parent=None, signalManager=None, name="Ensemble"):
     OWWidget.__init__(self, parent, signalManager, name, wantMainArea=False)
     
     self.inputs = [("Learner", orange.Learner, self.setLearner), ("Data", ExampleTable, self.setData)]
     self.outputs = [("Learner", orange.Learner), ("Classifier", orange.Classifier)]
     
     self.method = 0
     self.t = 10
     
     self.loadSettings()
     
     box = OWGUI.radioButtonsInBox(self.controlArea, self, "method",
                                   [name for name, _ in self.METHODS], 
                                   box="Ensemble",
                                   callback=self.onChange)
     
     i_box = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(box.buttons[0]))
     
     OWGUI.spin(i_box, self, "t", min=1, max=100, step=1, label="Number of created classifiers:")
     OWGUI.rubber(self.controlArea)
     OWGUI.button(self.controlArea, self, "&Apply", callback=self.commit)
     
     self.data = None
     self.learner = None
     
     self.resize(100, 100)
    def __init__ (self, parent=None, signalManager = None, name = "Logistic regression"):
        OWWidget.__init__(self, parent, signalManager, name, wantMainArea = 0, resizingEnabled = 0)

        self.inputs = [("Data", ExampleTable, self.setData), ("Preprocess", PreprocessedLearner, self.setPreprocessor)]
        self.outputs = [("Learner", orange.Learner), ("Classifier", orange.Classifier), ("Features", list)]

        from orngTree import TreeLearner
        imputeByModel = orange.ImputerConstructor_model()
        imputeByModel.learnerDiscrete = TreeLearner(measure = "infoGain", minSubset = 50)
        imputeByModel.learnerContinuous = TreeLearner(measure = "retis", minSubset = 50)
        self.imputationMethods = [imputeByModel, orange.ImputerConstructor_average(), orange.ImputerConstructor_minimal(), orange.ImputerConstructor_maximal(), None]
        self.imputationMethodsStr = ["Classification/Regression trees", "Average values", "Minimal value", "Maximal value", "None (skip examples)"]

        self.name = "Logistic regression"
        self.univariate = 0
        self.stepwiseLR = 0
        self.addCrit = 10
        self.removeCrit = 10
        self.numAttr = 10
        self.limitNumAttr = False
        self.zeroPoint = 0
        self.imputation = 1

        self.data = None
        self.preprocessor = None

        self.loadSettings()

        OWGUI.lineEdit(self.controlArea, self, 'name', box='Learner/Classifier Name', tooltip='Name to be used by other widgets to identify your learner/classifier.')
        OWGUI.separator(self.controlArea)

        box = OWGUI.widgetBox(self.controlArea, "Attribute selection")

        stepwiseCb = OWGUI.checkBox(box, self, "stepwiseLR", "Stepwise attribute selection")
        ibox = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(stepwiseCb))
        addCritSpin = OWGUI.spin(ibox, self, "addCrit", 1, 50, label="Add threshold [%]", labelWidth=155, tooltip="Requested significance for adding an attribute")
        remCritSpin = OWGUI.spin(ibox, self, "removeCrit", 1, 50, label="Remove threshold [%]", labelWidth=155, tooltip="Requested significance for removing an attribute")
        limitAttSpin = OWGUI.checkWithSpin(ibox, self, "Limit number of attributes to ", 1, 100, "limitNumAttr", "numAttr", step=1, labelWidth=155, tooltip="Maximum number of attributes. Algorithm stops when it selects specified number of attributes.")
        stepwiseCb.disables += [addCritSpin, remCritSpin, limitAttSpin]
        stepwiseCb.makeConsistent()
        
        OWGUI.separator(self.controlArea)

        self.imputationCombo = OWGUI.comboBox(self.controlArea, self, "imputation", box="Imputation of unknown values", items=self.imputationMethodsStr)
        OWGUI.separator(self.controlArea)

        applyButton = OWGUI.button(self.controlArea, self, "&Apply", callback=self.applyLearner, default=True)

        OWGUI.rubber(self.controlArea)
        #self.adjustSize()

        self.applyLearner()
Ejemplo n.º 6
0
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Concatenate",
                          wantMainArea=False, resizingEnabled=False)
        self.inputs = [("Primary Data", orange.ExampleTable, self.setData),
                       ("Additional Data", orange.ExampleTable, self.setMoreData, Multiple)]
        self.outputs = [("Data", ExampleTable)]

        self.mergeAttributes = 0
        self.dataSourceSelected = 1
        self.addIdAs = 0
        self.dataSourceName = "clusterId"

        self.primary = None
        self.additional = {}
        
        self.loadSettings()
        
        bg = self.bgMerge = OWGUI.radioButtonsInBox(self.controlArea, self, "mergeAttributes", [], "Domains merging", callback = self.apply)
        OWGUI.widgetLabel(bg, "When there is no primary table, the domain should be")
        OWGUI.appendRadioButton(bg, self, "mergeAttributes", "Union of attributes appearing in all tables")
        OWGUI.appendRadioButton(bg, self, "mergeAttributes", "Intersection of attributes in all tables")
        bg.layout().addSpacing(6)
        label = OWGUI.widgetLabel(bg, "The resulting table will have class only if there is no conflict between input classes.")
        label.setWordWrap(True)

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Data source IDs", addSpace=True)
        cb = OWGUI.checkBox(box, self, "dataSourceSelected", "Append data source IDs")
        self.classificationBox = ib = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(cb))

        form = QFormLayout(
            spacing=8, labelAlignment=Qt.AlignLeft, formAlignment=Qt.AlignLeft,
            fieldGrowthPolicy=QFormLayout.AllNonFixedFieldsGrow
        )
        ib.layout().addLayout(form)

        form.addRow("Name",
                    OWGUI.lineEdit(ib, self, "dataSourceName", valueType=str))

        aa = OWGUI.comboBox(ib, self, "addIdAs", items=["Class attribute", "Attribute", "Meta attribute"])
        cb.disables.append(ib)
        cb.makeConsistent()
        form.addRow("Place", aa)

        OWGUI.button(self.controlArea, self, "Apply Changes", callback = self.apply, default=True)
        
        OWGUI.rubber(self.controlArea)

        self.adjustSize()
        
        self.dataReport = None
    def __init__(self,parent=None, signalManager = None, name = "Continuizer"):
        OWWidget.__init__(self, parent, signalManager, name, wantMainArea = 0)

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data", ExampleTable), ("Preprocessor", PreprocessedLearner)]

        self.multinomialTreatment = 0
        self.targetValue = 0
        self.continuousTreatment = 0
        self.classTreatment = 0
        self.zeroBased = 1
        self.autosend = 0
        self.dataChanged = False
        self.loadSettings()

        bgMultiTreatment = OWGUI.widgetBox(self.controlArea, "Multinomial attributes")
        OWGUI.radioButtonsInBox(bgMultiTreatment, self, "multinomialTreatment", btnLabels=[x[0] for x in self.multinomialTreats], callback=self.sendDataIf)

        self.controlArea.layout().addSpacing(4)

        bgMultiTreatment = OWGUI.widgetBox(self.controlArea, "Continuous attributes")
        OWGUI.radioButtonsInBox(bgMultiTreatment, self, "continuousTreatment", btnLabels=[x[0] for x in self.continuousTreats], callback=self.sendDataIf)

        self.controlArea.layout().addSpacing(4)

        bgClassTreatment = OWGUI.widgetBox(self.controlArea, "Discrete class attribute")
        self.ctreat = OWGUI.radioButtonsInBox(bgClassTreatment, self, "classTreatment", btnLabels=[x[0] for x in self.classTreats], callback=self.sendDataIf)
#        hbox = OWGUI.widgetBox(bgClassTreatment, orientation = "horizontal")
#        OWGUI.separator(hbox, 19, 4)
        hbox = OWGUI.indentedBox(bgClassTreatment, sep=OWGUI.checkButtonOffsetHint(self.ctreat.buttons[-1]), orientation="horizontal")
        self.cbTargetValue = OWGUI.comboBox(hbox, self, "targetValue", label="Target Value ", items=[], orientation="horizontal", callback=self.cbTargetSelected)
        def setEnabled(*args):
            self.cbTargetValue.setEnabled(self.classTreatment == 3)
        self.connect(self.ctreat.group, SIGNAL("buttonClicked(int)"), setEnabled)
        setEnabled() 

        self.controlArea.layout().addSpacing(4)

        zbbox = OWGUI.widgetBox(self.controlArea, "Value range")
        OWGUI.radioButtonsInBox(zbbox, self, "zeroBased", btnLabels=self.valueRanges, callback=self.sendDataIf)

        self.controlArea.layout().addSpacing(4)

        snbox = OWGUI.widgetBox(self.controlArea, "Send data")
        OWGUI.button(snbox, self, "Send data", callback=self.sendData, default=True)
        OWGUI.checkBox(snbox, self, "autosend", "Send automatically", callback=self.enableAuto)
        self.data = None
        self.sendPreprocessor()
        self.resize(150,300)
Ejemplo n.º 8
0
    def __init__(self,parent=None, signalManager = None, name = "Continuizer"):
        OWWidget.__init__(self, parent, signalManager, name, wantMainArea = 0)

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data", ExampleTable), ("Preprocessor", PreprocessedLearner)]

        self.multinomialTreatment = 0
        self.targetValue = 0
        self.continuousTreatment = 0
        self.classTreatment = 0
        self.zeroBased = 1
        self.autosend = 0
        self.dataChanged = False
        self.loadSettings()

        bgMultiTreatment = OWGUI.widgetBox(self.controlArea, "Multinomial attributes")
        OWGUI.radioButtonsInBox(bgMultiTreatment, self, "multinomialTreatment", btnLabels=[x[0] for x in self.multinomialTreats], callback=self.sendDataIf)

        self.controlArea.layout().addSpacing(4)

        bgMultiTreatment = OWGUI.widgetBox(self.controlArea, "Continuous attributes")
        OWGUI.radioButtonsInBox(bgMultiTreatment, self, "continuousTreatment", btnLabels=[x[0] for x in self.continuousTreats], callback=self.sendDataIf)

        self.controlArea.layout().addSpacing(4)

        bgClassTreatment = OWGUI.widgetBox(self.controlArea, "Discrete class attribute")
        self.ctreat = OWGUI.radioButtonsInBox(bgClassTreatment, self, "classTreatment", btnLabels=[x[0] for x in self.classTreats], callback=self.sendDataIf)
#        hbox = OWGUI.widgetBox(bgClassTreatment, orientation = "horizontal")
#        OWGUI.separator(hbox, 19, 4)
        hbox = OWGUI.indentedBox(bgClassTreatment, sep=OWGUI.checkButtonOffsetHint(self.ctreat.buttons[-1]), orientation="horizontal")
        self.cbTargetValue = OWGUI.comboBox(hbox, self, "targetValue", label="Target Value ", items=[], orientation="horizontal", callback=self.cbTargetSelected)
        def setEnabled(*args):
            self.cbTargetValue.setEnabled(self.classTreatment == 3)
        self.connect(self.ctreat.group, SIGNAL("buttonClicked(int)"), setEnabled)
        setEnabled() 

        self.controlArea.layout().addSpacing(4)

        zbbox = OWGUI.widgetBox(self.controlArea, "Value range")
        OWGUI.radioButtonsInBox(zbbox, self, "zeroBased", btnLabels=self.valueRanges, callback=self.sendDataIf)

        self.controlArea.layout().addSpacing(4)

        snbox = OWGUI.widgetBox(self.controlArea, "Send data")
        OWGUI.button(snbox, self, "Send data", callback=self.sendData, default=True)
        OWGUI.checkBox(snbox, self, "autosend", "Send automatically", callback=self.enableAuto)
        self.data = None
        self.sendPreprocessor()
        self.resize(150,300)
Ejemplo n.º 9
0
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Concatenate", wantMainArea=0)
        self.inputs = [("Primary Data", orange.ExampleTable, self.setData), ("Additional Data", orange.ExampleTable, self.setMoreData, Multiple)]
        self.outputs = [("Data", ExampleTable)]

        self.mergeAttributes = 0
        self.dataSourceSelected = 1
        self.addIdAs = 0
        self.dataSourceName = "clusterId"

        self.primary = None
        self.additional = {}
        
        self.loadSettings()
        
        bg = self.bgMerge = OWGUI.radioButtonsInBox(self.controlArea, self, "mergeAttributes", [], "Domains merging", callback = self.apply)
        OWGUI.widgetLabel(bg, "When there is no primary table, the domain should be")
        OWGUI.appendRadioButton(bg, self, "mergeAttributes", "Union of attributes appearing in all tables")
        OWGUI.appendRadioButton(bg, self, "mergeAttributes", "Intersection of attributes in all tables")
        OWGUI.widgetLabel(bg, "The resulting table will have class only if there is no conflict between input classes.")

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Data source IDs", addSpace=True)
        cb = OWGUI.checkBox(box, self, "dataSourceSelected", "Append data source IDs")
        self.classificationBox = ib = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(cb))
        le = OWGUI.lineEdit(ib, self, "dataSourceName", "Name" + "  ", orientation='horizontal', valueType = str)
        OWGUI.separator(ib, height = 4)
        aa = OWGUI.comboBox(ib, self, "addIdAs", label = "Place" + "  ", orientation = 'horizontal', items = ["Class attribute", "Attribute", "Meta attribute"])
        cb.disables.append(ib)
        cb.makeConsistent()
        
        OWGUI.button(self.controlArea, self, "Apply Changes", callback = self.apply, default=True)
        
        OWGUI.rubber(self.controlArea)

        self.adjustSize()
        
        self.dataReport = None
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Concatenate", wantMainArea=0)
        self.inputs = [("Primary Data", orange.ExampleTable, self.setData), ("Additional Data", orange.ExampleTable, self.setMoreData, Multiple)]
        self.outputs = [("Data", ExampleTable)]

        self.mergeAttributes = 0
        self.dataSourceSelected = 1
        self.addIdAs = 0
        self.dataSourceName = "clusterId"

        self.primary = None
        self.additional = {}
        
        self.loadSettings()
        
        bg = self.bgMerge = OWGUI.radioButtonsInBox(self.controlArea, self, "mergeAttributes", [], "Domains merging", callback = self.apply)
        OWGUI.widgetLabel(bg, "When there is no primary table, the domain should be")
        OWGUI.appendRadioButton(bg, self, "mergeAttributes", "Union of attributes appearing in all tables")
        OWGUI.appendRadioButton(bg, self, "mergeAttributes", "Intersection of attributes in all tables")
        OWGUI.widgetLabel(bg, "The resulting table will have class only if there is no conflict between input classes.")

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Data source IDs", addSpace=True)
        cb = OWGUI.checkBox(box, self, "dataSourceSelected", "Append data source IDs")
        self.classificationBox = ib = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(cb))
        le = OWGUI.lineEdit(ib, self, "dataSourceName", "Name" + "  ", orientation='horizontal', valueType = str)
        OWGUI.separator(ib, height = 4)
        aa = OWGUI.comboBox(ib, self, "addIdAs", label = "Place" + "  ", orientation = 'horizontal', items = ["Class attribute", "Attribute", "Meta attribute"])
        cb.disables.append(ib)
        cb.makeConsistent()
        
        OWGUI.button(self.controlArea, self, "Apply Changes", callback = self.apply, default=True)
        
        OWGUI.rubber(self.controlArea)

        self.adjustSize()
        
        self.dataReport = None
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager,
                          'Hierarchical Clustering', wantGraph=True)

        self.inputs = [("Distances", Orange.misc.SymMatrix, self.set_matrix)]

        self.outputs = [("Selected Data", Orange.data.Table),
                        ("Other Data", Orange.data.Table),
                        ("Centroids", Orange.data.Table)]

        self.linkage = [
            ("Single linkage", hierarchical.HierarchicalClustering.Single),
            ("Average linkage", hierarchical.HierarchicalClustering.Average),
            ("Ward's linkage", hierarchical.HierarchicalClustering.Ward),
            ("Complete linkage", hierarchical.HierarchicalClustering.Complete),
        ]

        self.Linkage = 3
        self.Annotation = 0
        self.PrintDepthCheck = 0
        self.PrintDepth = 10
        # initial horizontal and vertical dendrogram size
        self.HDSize = 500
        self.VDSize = 800
        self.ManualHorSize = 0
        self.AutoResize = 0
        self.TextSize = 8
        self.LineSpacing = 4
        self.SelectionMode = 0
        self.AppendClusters = 0
        self.CommitOnChange = 0
        self.ClassifyName = "HC_class"
        self.addIdAs = 0

        self.loadSettings()

        self.inputMatrix = None
        self.root_cluster = None
        self.selectedExamples = None

        self.selectionChanged = False

        self.linkageMethods = [a[0] for a in self.linkage]

        #################################
        ##GUI
        #################################

        #HC Settings
        OWGUI.comboBox(self.controlArea, self, "Linkage", box="Linkage",
                       items=self.linkageMethods,
                       tooltip="Choose linkage method",
                       callback=self.run_clustering,
                       addSpace=True)
        #Label
        box = OWGUI.widgetBox(self.controlArea, "Annotation", addSpace=True)
        self.labelCombo = OWGUI.comboBox(
            box, self, "Annotation",
            items=["None"],
            tooltip="Choose label attribute",
            callback=self.update_labels
        )

        OWGUI.spin(box, self, "TextSize", label="Text size",
                   min=5, max=15, step=1,
                   callback=self.update_font,
                   controlWidth=40,
                   keyboardTracking=False)

        # Dendrogram graphics settings
        dendrogramBox = OWGUI.widgetBox(self.controlArea, "Limits",
                                        addSpace=True)

        form = QFormLayout()
        form.setLabelAlignment(Qt.AlignLeft)

        # Depth settings
        sw = OWGUI.widgetBox(dendrogramBox, orientation="horizontal",
                             addToLayout=False)
        cw = OWGUI.widgetBox(dendrogramBox, orientation="horizontal",
                             addToLayout=False)

        OWGUI.hSlider(sw, self, "PrintDepth", minValue=1, maxValue=50,
                      callback=self.on_depth_change)

        cblp = OWGUI.checkBox(cw, self, "PrintDepthCheck", "Show to depth",
                              callback=self.on_depth_change,
                              disables=[sw])
        form.addRow(cw, sw)

        checkWidth = OWGUI.checkButtonOffsetHint(cblp)

        # Width settings
        sw = OWGUI.widgetBox(dendrogramBox, orientation="horizontal",
                             addToLayout=False)
        cw = OWGUI.widgetBox(dendrogramBox, orientation="horizontal",
                             addToLayout=False)

        hsb = OWGUI.spin(sw, self, "HDSize", min=200, max=10000, step=10,
                         callback=self.on_width_changed,
                         callbackOnReturn=False,
                         keyboardTracking=False)

        OWGUI.checkBox(cw, self, "ManualHorSize", "Horizontal size",
                       callback=self.on_width_changed,
                       disables=[sw])

        sw.setEnabled(self.ManualHorSize)

        self.hSizeBox = hsb
        form.addRow(cw, sw)
        dendrogramBox.layout().addLayout(form)

        # Selection settings
        box = OWGUI.widgetBox(self.controlArea, "Selection")
        OWGUI.checkBox(box, self, "SelectionMode", "Show cutoff line",
                       callback=self.update_cutoff_line)

        cb = OWGUI.checkBox(box, self, "AppendClusters", "Append cluster IDs",
                            callback=self.commit_data_if)

        self.classificationBox = ib = OWGUI.widgetBox(box, margin=0)

        form = QWidget()
        le = OWGUI.lineEdit(form, self, "ClassifyName", None, callback=None,
                            orientation="horizontal")
        self.connect(le, SIGNAL("editingFinished()"), self.commit_data_if)

        aa = OWGUI.comboBox(form, self, "addIdAs", label=None,
                            orientation="horizontal",
                            items=["Class attribute",
                                   "Attribute",
                                   "Meta attribute"],
                            callback=self.commit_data_if)

        layout = QFormLayout()
        layout.setSpacing(8)
        layout.setContentsMargins(0, 5, 0, 5)
        layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
        layout.setLabelAlignment(Qt.AlignLeft)
        layout.addRow("Name  ", le)
        layout.addRow("Place  ", aa)

        form.setLayout(layout)

        ib.layout().addWidget(form)
        ib.layout().setContentsMargins(checkWidth, 5, 5, 5)

        cb.disables.append(ib)
        cb.makeConsistent()

        OWGUI.separator(box)
        cbAuto = OWGUI.checkBox(box, self, "CommitOnChange",
                                "Commit on change")
        btCommit = OWGUI.button(box, self, "&Commit", self.commit_data,
                                default=True)
        OWGUI.setStopper(self, btCommit, cbAuto, "selectionChanged",
                         self.commit_data)

        OWGUI.rubber(self.controlArea)
        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveGraph)

        self.scale_scene = scale = ScaleScene(self, self)
        self.headerView = ScaleView(scale, self)
        self.footerView = ScaleView(scale, self)

        self.dendrogram = DendrogramScene(self)
        self.dendrogramView = DendrogramView(self.dendrogram, self.mainArea)

        self.connect(self.dendrogram,
                     SIGNAL("clusterSelectionChanged()"),
                     self.on_selection_change)

        self.connect(self.dendrogram,
                     SIGNAL("sceneRectChanged(QRectF)"),
                     scale.scene_rect_update)

        self.connect(self.dendrogram,
                     SIGNAL("dendrogramGeometryChanged(QRectF)"),
                     self.on_dendrogram_geometry_change)

        self.connect(self.dendrogram,
                     SIGNAL("cutoffValueChanged(float)"),
                     self.on_cuttof_value_changed)

        self.connect(self.dendrogramView,
                     SIGNAL("viewportResized(QSize)"),
                     self.on_width_changed)

        self.connect(self.dendrogramView,
                     SIGNAL("transformChanged(QTransform)"),
                     self.headerView.setTransform)
        self.connect(self.dendrogramView,
                     SIGNAL("transformChanged(QTransform)"),
                     self.footerView.setTransform)

        self.mainArea.layout().addWidget(self.headerView)
        self.mainArea.layout().addWidget(self.dendrogramView)
        self.mainArea.layout().addWidget(self.footerView)

        self.dendrogram.header = self.headerView
        self.dendrogram.footer = self.footerView

        self.connect(self.dendrogramView.horizontalScrollBar(),
                     SIGNAL("valueChanged(int)"),
                     self.footerView.horizontalScrollBar().setValue)

        self.connect(self.dendrogramView.horizontalScrollBar(),
                     SIGNAL("valueChanged(int)"),
                     self.headerView.horizontalScrollBar().setValue)

        self.dendrogram.setSceneRect(0, 0, self.HDSize, self.VDSize)
        self.dendrogram.update()
        self.resize(800, 500)

        self.natural_dendrogram_width = 800
        self.dendrogramView.set_fit_to_width(not self.ManualHorSize)

        self.matrix = None
        self.selectionList = []
        self.selected_clusters = []
    def __init__(self, parent=None, signalManager=None, name="Select data"):
        OWWidget.__init__(self, parent, signalManager, name,
                          wantMainArea=0)  #initialize base class

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Matching Data", ExampleTable, Default),
                        ("Unmatched Data", ExampleTable)]

        self.name2var = {}  # key: variable name, item: orange.Variable
        self.Conditions = []

        self.currentVar = None
        self.NegateCondition = False
        self.currentOperatorDict = {
            orange.VarTypes.Continuous:
            Operator(Operator.operatorsC[0], orange.VarTypes.Continuous),
            orange.VarTypes.Discrete:
            Operator(Operator.operatorsD[0], orange.VarTypes.Discrete),
            orange.VarTypes.String:
            Operator(Operator.operatorsS[0], orange.VarTypes.String)
        }
        self.Num1 = 0.0
        self.Num2 = 0.0
        self.Str1 = ""
        self.Str2 = ""
        self.attrSearchText = ""
        self.currentVals = []
        self.CaseSensitive = False
        self.updateOnChange = True
        self.purgeAttributes = True
        self.purgeClasses = True
        self.oldPurgeClasses = True

        self.loadedVarNames = []
        self.loadedConditions = []
        self.loadSettings()

        w = QWidget(self)
        self.controlArea.layout().addWidget(w)
        grid = QGridLayout()
        grid.setMargin(0)
        w.setLayout(grid)

        boxAttrCond = OWGUI.widgetBox(self,
                                      '',
                                      orientation=QGridLayout(),
                                      addToLayout=0)
        grid.addWidget(boxAttrCond, 0, 0, 1, 3)
        glac = boxAttrCond.layout()
        glac.setColumnStretch(0, 2)
        glac.setColumnStretch(1, 1)
        glac.setColumnStretch(2, 2)

        boxAttr = OWGUI.widgetBox(self, 'Attribute', addToLayout=0)
        glac.addWidget(boxAttr, 0, 0)
        self.lbAttr = OWGUI.listBox(boxAttr, self, callback=self.lbAttrChange)

        self.leSelect = OWGUI.lineEdit(boxAttr,
                                       self,
                                       "attrSearchText",
                                       label="Search: ",
                                       orientation="horizontal",
                                       callback=self.setLbAttr,
                                       callbackOnType=1)

        boxOper = OWGUI.widgetBox(self, 'Operator')
        # operators 0: empty
        self.lbOperatosNone = OWGUI.listBox(boxOper, self)
        # operators 1: discrete
        self.lbOperatorsD = OWGUI.listBox(boxOper,
                                          self,
                                          callback=self.lbOperatorsChange)
        self.lbOperatorsD.hide()
        self.lbOperatorsD.addItems(Operator.operatorsD +
                                   [Operator.operatorDef])
        # operators 2: continuous
        self.lbOperatorsC = OWGUI.listBox(boxOper,
                                          self,
                                          callback=self.lbOperatorsChange)
        self.lbOperatorsC.hide()
        self.lbOperatorsC.addItems(Operator.operatorsC +
                                   [Operator.operatorDef])
        # operators 6: string
        self.lbOperatorsS = OWGUI.listBox(boxOper,
                                          self,
                                          callback=self.lbOperatorsChange)
        self.lbOperatorsS.hide()
        self.lbOperatorsS.addItems(Operator.operatorsS +
                                   [Operator.operatorDef])
        self.lbOperatorsDict = {
            0: self.lbOperatosNone,
            orange.VarTypes.Continuous: self.lbOperatorsC,
            orange.VarTypes.Discrete: self.lbOperatorsD,
            orange.VarTypes.String: self.lbOperatorsS
        }

        glac.addWidget(boxOper, 0, 1)
        self.cbNot = OWGUI.checkBox(boxOper, self, "NegateCondition", "Negate")

        self.boxIndices = {}
        self.valuesStack = QStackedWidget(self)
        glac.addWidget(self.valuesStack, 0, 2)

        # values 0: empty
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout=0)
        self.boxIndices[0] = boxVal
        self.valuesStack.addWidget(boxVal)

        # values 1: discrete
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout=0)
        self.boxIndices[orange.VarTypes.Discrete] = boxVal
        self.valuesStack.addWidget(boxVal)
        self.lbVals = OWGUI.listBox(boxVal, self, callback=self.lbValsChange)

        # values 2: continuous between num and num
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout=0)
        self.boxIndices[orange.VarTypes.Continuous] = boxVal
        self.valuesStack.addWidget(boxVal)
        self.leNum1 = OWGUI.lineEdit(boxVal,
                                     self,
                                     "Num1",
                                     validator=QDoubleValidator(self))
        self.lblAndCon = OWGUI.widgetLabel(boxVal, "and")
        self.leNum2 = OWGUI.lineEdit(boxVal,
                                     self,
                                     "Num2",
                                     validator=QDoubleValidator(self))
        boxAttrStat = OWGUI.widgetBox(boxVal, "Statistics")
        self.lblMin = OWGUI.widgetLabel(boxAttrStat, "Min: ")
        self.lblAvg = OWGUI.widgetLabel(boxAttrStat, "Avg: ")
        self.lblMax = OWGUI.widgetLabel(boxAttrStat, "Max: ")
        self.lblDefined = OWGUI.widgetLabel(boxAttrStat,
                                            "Defined for ---- examples")
        OWGUI.rubber(boxAttrStat)

        # values 6: string between str and str
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout=0)
        self.boxIndices[orange.VarTypes.String] = boxVal
        self.valuesStack.addWidget(boxVal)
        self.leStr1 = OWGUI.lineEdit(boxVal, self, "Str1")
        self.lblAndStr = OWGUI.widgetLabel(boxVal, "and")
        self.leStr2 = OWGUI.lineEdit(boxVal, self, "Str2")
        self.cbCaseSensitive = OWGUI.checkBox(boxVal, self, "CaseSensitive",
                                              "Case sensitive")

        self.boxButtons = OWGUI.widgetBox(self, orientation="horizontal")
        grid.addWidget(self.boxButtons, 1, 0, 1, 3)
        self.btnNew = OWGUI.button(self.boxButtons, self, "Add",
                                   self.OnNewCondition)
        self.btnUpdate = OWGUI.button(self.boxButtons, self, "Modify",
                                      self.OnUpdateCondition)
        self.btnRemove = OWGUI.button(self.boxButtons, self, "Remove",
                                      self.OnRemoveCondition)
        self.btnOR = OWGUI.button(self.boxButtons, self, "OR",
                                  self.OnDisjunction)
        self.btnMoveUp = OWGUI.button(self.boxButtons, self, "Move Up",
                                      self.btnMoveUpClicked)
        self.btnMoveDown = OWGUI.button(self.boxButtons, self, "Move Down",
                                        self.btnMoveDownClicked)
        self.btnRemove.setEnabled(False)
        self.btnUpdate.setEnabled(False)
        self.btnMoveUp.setEnabled(False)
        self.btnMoveDown.setEnabled(False)

        boxCriteria = OWGUI.widgetBox(self,
                                      'Data Selection Criteria',
                                      addToLayout=0)
        grid.addWidget(boxCriteria, 2, 0, 1, 3)
        self.criteriaTable = QTableWidget(boxCriteria)
        boxCriteria.layout().addWidget(self.criteriaTable)
        self.criteriaTable.setShowGrid(False)
        self.criteriaTable.setSelectionMode(QTableWidget.SingleSelection)
        self.criteriaTable.setColumnCount(2)
        self.criteriaTable.verticalHeader().setClickable(False)
        #self.criteriaTable.verticalHeader().setResizeEnabled(False,-1)
        self.criteriaTable.horizontalHeader().setClickable(False)
        self.criteriaTable.setHorizontalHeaderLabels(["Active", "Condition"])
        self.criteriaTable.resizeColumnToContents(0)
        self.criteriaTable.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.criteriaTable.horizontalHeader().setResizeMode(
            1, QHeaderView.Stretch)
        self.connect(self.criteriaTable, SIGNAL('cellClicked(int, int)'),
                     self.currentCriteriaChange)

        boxDataIn = OWGUI.widgetBox(self, 'Data In', addToLayout=0)
        grid.addWidget(boxDataIn, 3, 0)
        self.dataInExamplesLabel = OWGUI.widgetLabel(boxDataIn, "num examples")
        self.dataInAttributesLabel = OWGUI.widgetLabel(boxDataIn,
                                                       "num attributes")
        OWGUI.rubber(boxDataIn)

        boxDataOut = OWGUI.widgetBox(self, 'Data Out', addToLayout=0)
        grid.addWidget(boxDataOut, 3, 1)
        self.dataOutExamplesLabel = OWGUI.widgetLabel(boxDataOut,
                                                      "num examples")
        self.dataOutAttributesLabel = OWGUI.widgetLabel(
            boxDataOut, "num attributes")
        OWGUI.rubber(boxDataOut)

        boxSettings = OWGUI.widgetBox(self, 'Commit', addToLayout=0)
        grid.addWidget(boxSettings, 3, 2)
        cb = OWGUI.checkBox(boxSettings,
                            self,
                            "purgeAttributes",
                            "Remove unused values/attributes",
                            box=None,
                            callback=self.OnPurgeChange)
        self.purgeClassesCB = OWGUI.checkBox(OWGUI.indentedBox(
            boxSettings, sep=OWGUI.checkButtonOffsetHint(cb)),
                                             self,
                                             "purgeClasses",
                                             "Remove unused classes",
                                             callback=self.OnPurgeChange)
        OWGUI.checkBox(boxSettings,
                       self,
                       "updateOnChange",
                       "Commit on change",
                       box=None)
        btnUpdate = OWGUI.button(boxSettings,
                                 self,
                                 "Commit",
                                 self.setOutput,
                                 default=True)

        self.icons = self.createAttributeIconDict()
        self.setData(None)
        self.lbOperatorsD.setCurrentRow(0)
        self.lbOperatorsC.setCurrentRow(0)
        self.lbOperatorsS.setCurrentRow(0)
        self.resize(500, 661)
        grid.setRowStretch(0, 10)
        grid.setRowStretch(2, 10)
Ejemplo n.º 13
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "Data Table")

        self.inputs = [("Examples", ExampleTable, self.dataset,
                        Multiple + Default)]
        self.outputs = [("Selected Examples", ExampleTable)]

        self.data = {}  # key: id, value: ExampleTable
        self.showMetas = {}  # key: id, value: (True/False, columnList)
        self.showMeta = 1
        self.showAttributeLabels = 1
        self.showDistributions = 1
        self.distColorRgb = (220, 220, 220, 255)
        self.distColor = QColor(*self.distColorRgb)
        self.locale = QLocale()
        self.autoCommit = False

        self.loadSettings()

        # info box
        infoBox = OWGUI.widgetBox(self.controlArea, "Info")
        self.infoEx = OWGUI.widgetLabel(infoBox, 'No data on input.')
        self.infoMiss = OWGUI.widgetLabel(infoBox, ' ')
        OWGUI.widgetLabel(infoBox, ' ')
        self.infoAttr = OWGUI.widgetLabel(infoBox, ' ')
        self.infoMeta = OWGUI.widgetLabel(infoBox, ' ')
        OWGUI.widgetLabel(infoBox, ' ')
        self.infoClass = OWGUI.widgetLabel(infoBox, ' ')
        infoBox.setMinimumWidth(200)
        OWGUI.separator(self.controlArea)

        # settings box
        boxSettings = OWGUI.widgetBox(self.controlArea, "Settings")
        self.cbShowMeta = OWGUI.checkBox(boxSettings,
                                         self,
                                         "showMeta",
                                         'Show meta attributes',
                                         callback=self.cbShowMetaClicked)
        self.cbShowMeta.setEnabled(False)
        self.cbShowAttLbls = OWGUI.checkBox(
            boxSettings,
            self,
            "showAttributeLabels",
            'Show attribute labels (if any)',
            callback=self.cbShowAttLabelsClicked)
        self.cbShowAttLbls.setEnabled(True)
        self.cbShowDistributions = OWGUI.checkBox(
            boxSettings,
            self,
            "showDistributions",
            'Visualize continuous values',
            callback=self.cbShowDistributions)
        colBox = OWGUI.indentedBox(boxSettings,
                                   sep=OWGUI.checkButtonOffsetHint(
                                       self.cbShowDistributions),
                                   orientation="horizontal")
        OWGUI.widgetLabel(colBox, "Color: ")
        self.colButton = OWGUI.toolButton(colBox,
                                          self,
                                          self.changeColor,
                                          width=20,
                                          height=20,
                                          debuggingEnabled=0)
        OWGUI.rubber(colBox)

        resizeColsBox = OWGUI.widgetBox(boxSettings, 0, "horizontal", 0)
        OWGUI.label(resizeColsBox, self, "Resize columns: ")
        OWGUI.toolButton(resizeColsBox,
                         self,
                         self.increaseColWidth,
                         tooltip="Increase the width of the columns",
                         width=20,
                         height=20).setText("+")
        OWGUI.toolButton(resizeColsBox,
                         self,
                         self.decreaseColWidth,
                         tooltip="Decrease the width of the columns",
                         width=20,
                         height=20).setText("-")
        OWGUI.rubber(resizeColsBox)

        self.btnResetSort = OWGUI.button(
            boxSettings,
            self,
            "Restore Order of Examples",
            callback=self.btnResetSortClicked,
            tooltip="Show examples in the same order as they appear in the file"
        )

        OWGUI.separator(self.controlArea)
        selectionBox = OWGUI.widgetBox(self.controlArea, "Selection")
        self.sendButton = OWGUI.button(selectionBox, self, "Send selections",
                                       self.commit)
        cb = OWGUI.checkBox(selectionBox,
                            self,
                            "autoCommit",
                            "Commit on any change",
                            callback=self.commitIf)
        OWGUI.setStopper(self, self.sendButton, cb, "selectionChangedFlag",
                         self.commit)

        OWGUI.rubber(self.controlArea)

        # GUI with tabs
        self.tabs = OWGUI.tabWidget(self.mainArea)
        self.id2table = {}  # key: widget id, value: table
        self.table2id = {}  # key: table, value: widget id
        self.connect(self.tabs, SIGNAL("currentChanged(QWidget*)"),
                     self.tabClicked)

        self.selectionChangedFlag = False

        self.updateColor()
Ejemplo n.º 14
0
    def __init__(self, parent=None, signalManager=None):
        "Constructor"
        OWWidget.__init__(self, parent, signalManager, "&Distributions", TRUE)
        # settings
        self.numberOfBars = 5
        self.barSize = 50
        self.showContinuousClassGraph = 1
        self.showProbabilities = 1
        self.showConfidenceIntervals = 0
        self.smoothLines = 0
        self.lineWidth = 1
        self.showMainTitle = 0
        self.showXaxisTitle = 1
        self.showYaxisTitle = 1
        self.showYPaxisTitle = 1

        self.attribute = ""
        self.targetValue = 0
        self.visibleOutcomes = []
        self.outcomes = []

        # tmp values
        self.mainTitle = ""
        self.xaxisTitle = ""
        self.yaxisTitle = "frequency"
        self.yPaxisTitle = ""

        # GUI
        #        self.tabs = OWGUI.tabWidget(self.controlArea)
        #        self.GeneralTab = OWGUI.createTabPage(self.tabs, "Main")
        #        self.SettingsTab = OWGUI.createTabPage(self.tabs, "Settings")
        self.GeneralTab = self.SettingsTab = self.controlArea

        self.graph = OWDistributionGraph(self, self.mainArea)
        # Set a fixed minimum width. This disables the dynamic minimumSizeHint
        # from the layout, which can return a uselessly large width for the
        # x axis when showing a discrete variable with many values.
        self.graph.setMinimumWidth(250)

        self.mainArea.layout().addWidget(self.graph)
        self.graph.setYRlabels(None)
        self.graph.setAxisScale(QwtPlot.yRight, 0.0, 1.0, 0.1)
        self.connect(self.graphButton, SIGNAL("clicked()"),
                     self.graph.saveToFile)

        self.loadSettings()

        self.barSize = 50

        # inputs
        # data and graph temp variables
        self.inputs = [("Data", ExampleTable, self.setData, Default)]

        self.data = None
        self.outcomenames = []
        self.probGraphValues = []

        b = OWGUI.widgetBox(self.controlArea, "Variable", addSpace=True)
        self.variablesQCB = OWGUI.comboBox(b,
                                           self,
                                           "attribute",
                                           valueType=str,
                                           sendSelectedValue=True,
                                           callback=self.setVariable)
        OWGUI.widgetLabel(b, "Displayed outcomes")
        self.outcomesQLB = OWGUI.listBox(
            b,
            self,
            "visibleOutcomes",
            "outcomes",
            selectionMode=QListWidget.MultiSelection,
            callback=self.outcomeSelectionChange)

        # GUI connections
        # options dialog connections
        #        b = OWGUI.widgetBox(self.SettingsTab, "Bars")
        #        OWGUI.spin(b, self, "numberOfBars", label="Number of bars", min=5, max=60, step=5, callback=self.setNumberOfBars, callbackOnReturn=True)
        #        self.numberOfBarsSlider = OWGUI.hSlider(self.SettingsTab, self, 'numberOfBars', box='Number of bars', minValue=5, maxValue=60, step=5, callback=self.setNumberOfBars, ticks=5)
        #        self.numberOfBarsSlider.setTracking(0) # no change until the user stop dragging the slider

        #        self.barSizeSlider = OWGUI.hSlider(self.SettingsTab, self, 'barSize', box="Bar size", minValue=30, maxValue=100, step=5, callback=self.setBarSize, ticks=10)
        #        OWGUI.spin(b, self, "barSize", label="Bar size", min=30, max=100, step=5, callback=self.setBarSize, callbackOnReturn=True)

        box = OWGUI.widgetBox(self.SettingsTab,
                              "General graph settings",
                              addSpace=True)
        box.setMinimumWidth(180)
        box2 = OWGUI.widgetBox(box, orientation="horizontal")
        OWGUI.checkBox(box2,
                       self,
                       'showMainTitle',
                       'Main title',
                       callback=self.setShowMainTitle)
        OWGUI.lineEdit(box2,
                       self,
                       'mainTitle',
                       callback=self.setMainTitle,
                       enterPlaceholder=True)

        box3 = OWGUI.widgetBox(box, orientation="horizontal")
        OWGUI.checkBox(box3,
                       self,
                       'showXaxisTitle',
                       'X axis title',
                       callback=self.setShowXaxisTitle)
        OWGUI.lineEdit(box3,
                       self,
                       'xaxisTitle',
                       callback=self.setXaxisTitle,
                       enterPlaceholder=True)

        box4 = OWGUI.widgetBox(box, orientation="horizontal")
        OWGUI.checkBox(box4,
                       self,
                       'showYaxisTitle',
                       'Y axis title',
                       callback=self.setShowYaxisTitle)
        OWGUI.lineEdit(box4,
                       self,
                       'yaxisTitle',
                       callback=self.setYaxisTitle,
                       enterPlaceholder=True)

        OWGUI.checkBox(box,
                       self,
                       'graph.showContinuousClassGraph',
                       'Show continuous class graph',
                       callback=self.setShowContinuousClassGraph)
        OWGUI.spin(box,
                   self,
                   "numberOfBars",
                   label="Number of bars",
                   min=5,
                   max=60,
                   step=5,
                   callback=self.setNumberOfBars,
                   callbackOnReturn=True)

        self.probabilityPlotBox = box5 = OWGUI.widgetBox(
            self.SettingsTab, "Probability plot")
        self.showProb = OWGUI.checkBox(box5,
                                       self,
                                       'showProbabilities',
                                       'Show probabilities',
                                       callback=self.setShowProbabilities)
        self.targetQCB = OWGUI.comboBox(OWGUI.indentedBox(
            box5, sep=OWGUI.checkButtonOffsetHint(self.showProb)),
                                        self,
                                        "targetValue",
                                        label="Target value",
                                        valueType=int,
                                        callback=self.setTarget)

        box6 = OWGUI.widgetBox(box5, orientation="horizontal")

        self.showYPaxisCheck = OWGUI.checkBox(box6,
                                              self,
                                              'showYPaxisTitle',
                                              'Axis title',
                                              callback=self.setShowYPaxisTitle)
        self.yPaxisEdit = OWGUI.lineEdit(box6,
                                         self,
                                         'yPaxisTitle',
                                         callback=self.setYPaxisTitle,
                                         enterPlaceholder=True)
        self.confIntCheck = OWGUI.checkBox(
            box5,
            self,
            'showConfidenceIntervals',
            'Show confidence intervals',
            callback=self.setShowConfidenceIntervals)
        self.cbSmooth = OWGUI.checkBox(box5,
                                       self,
                                       'smoothLines',
                                       'Smooth probability lines',
                                       callback=self.setSmoothLines)
        self.showProb.disables = [
            self.showYPaxisCheck, self.yPaxisEdit, self.confIntCheck,
            self.targetQCB, self.cbSmooth
        ]
        self.showProb.makeConsistent()

        #        self.barSizeSlider = OWGUI.hSlider(box5, self, 'lineWidth', box='Line width', minValue=1, maxValue=9, step=1, callback=self.setLineWidth, ticks=1)

        OWGUI.rubber(self.SettingsTab)

        #add controls to self.controlArea widget

        self.icons = self.createAttributeIconDict()

        self.graph.numberOfBars = self.numberOfBars
        self.graph.barSize = self.barSize
        self.graph.setShowMainTitle(self.showMainTitle)
        self.graph.setShowXaxisTitle(self.showXaxisTitle)
        self.graph.setShowYLaxisTitle(self.showYaxisTitle)
        self.graph.setShowYRaxisTitle(self.showYPaxisTitle)
        self.graph.setMainTitle(self.mainTitle)
        self.graph.setXaxisTitle(self.xaxisTitle)
        self.graph.setYLaxisTitle(self.yaxisTitle)
        self.graph.setYRaxisTitle(self.yPaxisTitle)
        self.graph.showProbabilities = self.showProbabilities
        self.graph.showConfidenceIntervals = self.showConfidenceIntervals
        self.graph.smoothLines = self.smoothLines
        self.graph.lineWidth = self.lineWidth
        #self.graph.variableContinuous = self.VariableContinuous
        self.graph.targetValue = self.targetValue
Ejemplo n.º 15
0
    def __init__(self, parent=None, signalManager = None, name='TreeViewer2D'):
        OWWidget.__init__(self, parent, signalManager, name, wantGraph=True)
        self.root = None
        self.selectedNode = None

        self.inputs = [("Classification Tree", orange.TreeClassifier, self.ctree)]
        self.outputs = [("Examples", ExampleTable)]

        #set default settings
        self.ZoomAutoRefresh = 0
        self.AutoArrange = 0
        self.ToolTipsEnabled = 1
        self.MaxTreeDepth = 5; self.MaxTreeDepthB = 0
        self.LineWidth = 5; self.LineWidthMethod = 2
        self.NodeSize = 5
        self.MaxNodeWidth = 150
        self.LimitNodeWidth = True
        self.NodeInfo = [0, 1]

        self.Zoom = 5
        self.VSpacing = 5; self.HSpacing = 5
        self.TruncateText = 1
        
        self.loadSettings()
        self.NodeInfo.sort()

# Changed when the GUI was simplified - added here to override any saved settings
        self.VSpacing = 1; self.HSpacing = 1
        self.ToolTipsEnabled = 1
        self.LineWidth = 15  # Also reset when the LineWidthMethod is changed!
        
        # GUI definition
#        self.tabs = OWGUI.tabWidget(self.controlArea)

        # GENERAL TAB
        # GeneralTab = OWGUI.createTabPage(self.tabs, "General")
#        GeneralTab = TreeTab = OWGUI.createTabPage(self.tabs, "Tree")
#        NodeTab = OWGUI.createTabPage(self.tabs, "Node")

        GeneralTab = NodeTab = TreeTab = self.controlArea
        
        self.infBox = OWGUI.widgetBox(GeneralTab, 'Info', sizePolicy = QSizePolicy(QSizePolicy.Minimum , QSizePolicy.Fixed ), addSpace=True)
        self.infoa = OWGUI.widgetLabel(self.infBox, 'No tree.')
        self.infob = OWGUI.widgetLabel(self.infBox, " ")

        self.sizebox = OWGUI.widgetBox(GeneralTab, "Size", addSpace=True)
        OWGUI.hSlider(self.sizebox, self, 'Zoom', label='Zoom', minValue=1, maxValue=10, step=1,
                      callback=self.toggleZoomSlider, ticks=1)
        OWGUI.separator(self.sizebox)
        
        cb, sb = OWGUI.checkWithSpin(self.sizebox, self, "Max node width:", 50, 200, "LimitNodeWidth", "MaxNodeWidth",
                                     tooltip="Limit the width of tree nodes",
                                     checkCallback=self.toggleNodeSize,
                                     spinCallback=self.toggleNodeSize,
                                     step=10)
        b = OWGUI.checkBox(OWGUI.indentedBox(self.sizebox, sep=OWGUI.checkButtonOffsetHint(cb)), self, "TruncateText", "Truncate text", callback=self.toggleTruncateText)
        cb.disables.append(b)
        cb.makeConsistent() 

        OWGUI.checkWithSpin(self.sizebox, self, 'Max tree depth:', 1, 20, 'MaxTreeDepthB', "MaxTreeDepth",
                            tooltip='Defines the depth of the tree displayed',
                            checkCallback=self.toggleTreeDepth,
                            spinCallback=self.toggleTreeDepth)
        
        
        self.edgebox = OWGUI.widgetBox(GeneralTab, "Edge Widths", addSpace=True)
        OWGUI.comboBox(self.edgebox, self,  'LineWidthMethod',
                                items=['Equal width', 'Root node', 'Parent node'],
                                callback=self.toggleLineWidth)
        # Node information
        grid = QGridLayout()
        grid.setContentsMargins(*self.controlArea.layout().getContentsMargins())
        
        navButton = OWGUI.button(self.controlArea, self, "Navigator", self.toggleNavigator, debuggingEnabled = 0, addToLayout=False)
#        findbox = OWGUI.widgetBox(self.controlArea, orientation = "horizontal")
        self.centerRootButton=OWGUI.button(self.controlArea, self, "Find Root", addToLayout=False,
                                           callback=lambda :self.rootNode and \
                                           self.sceneView.centerOn(self.rootNode.x(), self.rootNode.y()))
        self.centerNodeButton=OWGUI.button(self.controlArea, self, "Find Selected", addToLayout=False,
                                           callback=lambda :self.selectedNode and \
                                           self.sceneView.centerOn(self.selectedNode.scenePos()))
        grid.addWidget(navButton, 0, 0, 1, 2)
        grid.addWidget(self.centerRootButton, 1, 0)
        grid.addWidget(self.centerNodeButton, 1, 1)
        self.leftWidgetPart.layout().insertLayout(1, grid)
        
        self.NodeTab=NodeTab
        self.TreeTab=TreeTab
        self.GeneralTab=GeneralTab
#        OWGUI.rubber(NodeTab)
        self.rootNode=None
        self.tree=None
        self.resize(800, 500)
        
        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveGraph)
    def __init__(self, parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Predictions")

        self.callbackDeposit = []
        self.inputs = [("Data", ExampleTable, self.setData), ("Predictors", orange.Classifier, self.setPredictor, Multiple)]
        self.outputs = [("Predictions", ExampleTable)]
        self.predictors = {}

        # saveble settings
        self.showProb = 1;
        self.showClass = 1
        self.ShowAttributeMethod = 0
        self.sendOnChange = 1
        self.classes = []
        self.selectedClasses = []
        self.loadSettings()
        self.datalabel = "N/A"
        self.predictorlabel = "N/A"
        self.tasklabel = "N/A"
        self.precision = 2
        self.doPrediction = False
        self.outvar = None # current output variable (set by the first predictor/data set send in)

        self.data = None
        self.changedFlag = False
        
        self.loadSettings()

        # GUI - Options

        # Options - classification
        ibox = OWGUI.widgetBox(self.controlArea, "Info")
        OWGUI.label(ibox, self, "Data: %(datalabel)s")
        OWGUI.label(ibox, self, "Predictors: %(predictorlabel)s")
        OWGUI.label(ibox, self, "Task: %(tasklabel)s")
        OWGUI.separator(self.controlArea)
        
        self.copt = OWGUI.widgetBox(self.controlArea, "Options (classification)")
        self.copt.setDisabled(1)
        cb = OWGUI.checkBox(self.copt, self, 'showProb', "Show predicted probabilities", callback=self.setPredictionDelegate)#self.updateTableOutcomes)

#        self.lbClasses = OWGUI.listBox(self.copt, self, selectionMode = QListWidget.MultiSelection, callback = self.updateTableOutcomes)
        ibox = OWGUI.indentedBox(self.copt, sep=OWGUI.checkButtonOffsetHint(cb))
        self.lbcls = OWGUI.listBox(ibox, self, "selectedClasses", "classes",
                                   callback=[self.setPredictionDelegate, self.checksendpredictions],
#                                   callback=[self.updateTableOutcomes, self.checksendpredictions],
                                   selectionMode=QListWidget.MultiSelection)
        self.lbcls.setFixedHeight(50)

        OWGUI.spin(ibox, self, "precision", 1, 6, label="No. of decimals: ",
                   orientation=0, callback=self.setPredictionDelegate) #self.updateTableOutcomes)
        
        cb.disables.append(ibox)
        ibox.setEnabled(bool(self.showProb))

        OWGUI.checkBox(self.copt, self, 'showClass', "Show predicted class",
                       callback=[self.setPredictionDelegate, self.checksendpredictions])
#                       callback=[self.updateTableOutcomes, self.checksendpredictions])

        OWGUI.separator(self.controlArea)

        self.att = OWGUI.widgetBox(self.controlArea, "Data attributes")
        OWGUI.radioButtonsInBox(self.att, self, 'ShowAttributeMethod', ['Show all', 'Hide all'], callback=lambda :self.setDataModel(self.data)) #self.updateAttributes)
        self.att.setDisabled(1)
        OWGUI.rubber(self.controlArea)

        OWGUI.separator(self.controlArea)
        self.outbox = OWGUI.widgetBox(self.controlArea, "Output")
        
        b = self.commitBtn = OWGUI.button(self.outbox, self, "Send Predictions", callback=self.sendpredictions, default=True)
        cb = OWGUI.checkBox(self.outbox, self, 'sendOnChange', 'Send automatically')
        OWGUI.setStopper(self, b, cb, "changedFlag", callback=self.sendpredictions)
        OWGUI.checkBox(self.outbox, self, "doPrediction", "Replace/add predicted class",
                       tooltip="Apply the first predictor to input examples and replace/add the predicted value as the new class variable.",
                       callback=self.checksendpredictions)

        self.outbox.setDisabled(1)

        ## GUI table

        self.splitter = splitter = QSplitter(Qt.Horizontal, self.mainArea)
        self.dataView = QTableView()
        self.predictionsView = QTableView()
        
        self.dataView.verticalHeader().setDefaultSectionSize(22)
        self.dataView.setHorizontalScrollMode(QTableWidget.ScrollPerPixel)
        self.dataView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.dataView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        
        self.predictionsView.verticalHeader().setDefaultSectionSize(22)
        self.predictionsView.setHorizontalScrollMode(QTableWidget.ScrollPerPixel)
        self.predictionsView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.predictionsView.verticalHeader().hide()
        
        
#        def syncVertical(value):
#            """ sync vertical scroll positions of the two views
#            """
#            v1 = self.predictionsView.verticalScrollBar().value()
#            if v1 != value:
#                self.predictionsView.verticalScrollBar().setValue(value)
#            v2 = self.dataView.verticalScrollBar().value()
#            if v2 != value:
#                self.dataView.verticalScrollBar().setValue(v1)
                
        self.connect(self.dataView.verticalScrollBar(), SIGNAL("valueChanged(int)"), self.syncVertical)
        self.connect(self.predictionsView.verticalScrollBar(), SIGNAL("valueChanged(int)"), self.syncVertical)
        
        splitter.addWidget(self.dataView)
        splitter.addWidget(self.predictionsView)
        splitter.setHandleWidth(3)
        splitter.setChildrenCollapsible(False)
        self.mainArea.layout().addWidget(splitter)
        
        self.spliter_restore_state = -1, 0
        self.dataModel = None
        self.predictionsModel = None
        
        self.resize(800, 600)
        
        self.handledAllSignalsFlag = False
Ejemplo n.º 17
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "TestLearners")

        self.inputs = [("Data", ExampleTable, self.setData, Default),
                       ("Separate Test Data", ExampleTable, self.setTestData),
                       ("Learner", orange.Learner, self.setLearner, Multiple),
                       ("Preprocess", PreprocessedLearner,
                        self.setPreprocessor)]
        self.outputs = [("Evaluation Results", orngTest.ExperimentResults)]

        # Settings
        self.resampling = 0  # cross-validation
        self.nFolds = 5  # cross validation folds
        self.pLearning = 70  # size of learning set when sampling [%]
        self.pRepeat = 10
        self.precision = 4
        self.applyOnAnyChange = True
        self.selectedCScores = [
            i for (i, s) in enumerate(self.cStatistics) if s.show
        ]
        self.selectedRScores = [
            i for (i, s) in enumerate(self.rStatistics) if s.show
        ]
        self.targetClass = 0
        self.loadSettings()
        self.resampling = 0  # cross-validation

        self.stat = self.cStatistics

        self.data = None  # input data set
        self.testdata = None  # separate test data set
        self.learners = {}  # set of learners (input)
        self.results = None  # from orngTest
        self.preprocessor = None

        self.controlArea.layout().setSpacing(8)
        # GUI
        self.sBtns = OWGUI.radioButtonsInBox(
            self.controlArea,
            self,
            "resampling",
            box="Sampling",
            btnLabels=self.resamplingMethods[:1],
            callback=self.newsampling)
        indent = OWGUI.checkButtonOffsetHint(self.sBtns.buttons[-1])

        ibox = OWGUI.widgetBox(OWGUI.indentedBox(self.sBtns, sep=indent))
        OWGUI.spin(ibox,
                   self,
                   'nFolds',
                   2,
                   100,
                   step=1,
                   label='Number of folds:',
                   callback=lambda p=0: self.conditionalRecompute(p))
        OWGUI.separator(self.sBtns, height=3)

        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[1])  # leave one out
        OWGUI.separator(self.sBtns, height=3)
        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[2])  # random sampling

        ibox = OWGUI.widgetBox(OWGUI.indentedBox(self.sBtns, sep=indent))
        OWGUI.spin(ibox,
                   self,
                   'pRepeat',
                   1,
                   100,
                   step=1,
                   label='Repeat train/test:',
                   callback=lambda p=2: self.conditionalRecompute(p))

        OWGUI.widgetLabel(ibox, "Relative training set size:")

        OWGUI.hSlider(ibox,
                      self,
                      'pLearning',
                      minValue=10,
                      maxValue=100,
                      step=1,
                      ticks=10,
                      labelFormat="   %d%%",
                      callback=lambda p=2: self.conditionalRecompute(p))

        OWGUI.separator(self.sBtns, height=3)
        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[3])  # test on train
        OWGUI.separator(self.sBtns, height=3)
        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[4])  # test on test

        self.trainDataBtn = self.sBtns.buttons[-2]
        self.testDataBtn = self.sBtns.buttons[-1]
        self.testDataBtn.setDisabled(True)

        #        box = OWGUI.widgetBox(self.sBtns, orientation='vertical', addSpace=False)
        #        OWGUI.separator(box)
        OWGUI.separator(self.sBtns)
        OWGUI.checkBox(self.sBtns,
                       self,
                       'applyOnAnyChange',
                       label="Apply on any change",
                       callback=self.applyChange)
        self.applyBtn = OWGUI.button(self.sBtns,
                                     self,
                                     "&Apply",
                                     callback=lambda f=True: self.recompute(f))
        self.applyBtn.setDisabled(True)

        if self.resampling == 4:
            self.resampling = 3

#        OWGUI.separator(self.controlArea)

# statistics
        self.statLayout = QStackedLayout()
        #        self.cbox = OWGUI.widgetBox(self.controlArea, spacing=8, margin=0)
        #        self.cbox.layout().setSpacing(8)
        self.cbox = OWGUI.widgetBox(self.controlArea, addToLayout=False)
        self.cStatLabels = [s.name for s in self.cStatistics]
        self.cstatLB = OWGUI.listBox(self.cbox,
                                     self,
                                     'selectedCScores',
                                     'cStatLabels',
                                     box="Performance scores",
                                     selectionMode=QListWidget.MultiSelection,
                                     callback=self.newscoreselection)
        #        OWGUI.separator(self.cbox)
        self.cbox.layout().addSpacing(8)
        self.targetCombo = OWGUI.comboBox(self.cbox,
                                          self,
                                          "targetClass",
                                          orientation=0,
                                          callback=[self.changedTarget],
                                          box="Target class")

        self.rStatLabels = [s.name for s in self.rStatistics]
        self.rbox = OWGUI.widgetBox(self.controlArea,
                                    "Performance scores",
                                    addToLayout=False)
        self.rstatLB = OWGUI.listBox(self.rbox,
                                     self,
                                     'selectedRScores',
                                     'rStatLabels',
                                     selectionMode=QListWidget.MultiSelection,
                                     callback=self.newscoreselection)

        self.statLayout.addWidget(self.cbox)
        self.statLayout.addWidget(self.rbox)
        self.controlArea.layout().addLayout(self.statLayout)

        self.statLayout.setCurrentWidget(self.cbox)

        #        self.rstatLB.box.hide()

        # score table
        # table with results
        self.g = OWGUI.widgetBox(self.mainArea, 'Evaluation Results')
        self.tab = OWGUI.table(self.g, selectionMode=QTableWidget.NoSelection)

        #self.lab = QLabel(self.g)

        self.resize(680, 470)
Ejemplo n.º 18
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'k-Means Clustering')

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data", ExampleTable), ("Centroids", ExampleTable)]

        #set default settings
        self.K = 2
        self.optimized = True
        self.optimizationFrom = 2
        self.optimizationTo = 5
        self.scoring = 0
        self.distanceMeasure = 0
        self.initializationType = 0
        self.restarts = 1
        self.classifySelected = 1
        self.addIdAs = 0
        self.runAnyChange = 1
        self.classifyName = "Cluster"

        self.settingsChanged = False

        self.loadSettings()

        self.data = None  # holds input data
        self.km = None  # holds clustering object

        # GUI definition
        # settings

        box = OWGUI.widgetBox(self.controlArea,
                              "Clusters (k)",
                              addSpace=True,
                              spacing=0)
        #        left, top, right, bottom = box.getContentsMargins()
        #        box.setContentsMargins(left, 0, right, 0)
        bg = OWGUI.radioButtonsInBox(box,
                                     self,
                                     "optimized", [],
                                     callback=self.setOptimization)

        fixedBox = OWGUI.widgetBox(box,
                                   orientation="horizontal",
                                   margin=0,
                                   spacing=bg.layout().spacing())

        button = OWGUI.appendRadioButton(bg,
                                         self,
                                         "optimized",
                                         "Fixed",
                                         insertInto=fixedBox,
                                         tooltip="Fixed number of clusters")

        button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        fixedBox.layout().setAlignment(button, Qt.AlignLeft)
        self.fixedSpinBox = OWGUI.spin(OWGUI.widgetBox(fixedBox),
                                       self,
                                       "K",
                                       min=2,
                                       max=30,
                                       tooltip="Fixed number of clusters",
                                       callback=self.update,
                                       callbackOnReturn=True)

        optimizedBox = OWGUI.widgetBox(box,
                                       margin=0,
                                       spacing=bg.layout().spacing())
        button = OWGUI.appendRadioButton(bg,
                                         self,
                                         "optimized",
                                         "Optimized",
                                         insertInto=optimizedBox)

        box = OWGUI.indentedBox(optimizedBox,
                                sep=OWGUI.checkButtonOffsetHint(button))

        box.layout().setSpacing(0)
        self.optimizationBox = box

        OWGUI.spin(box,
                   self,
                   "optimizationFrom",
                   label="From",
                   min=2,
                   max=99,
                   tooltip="Minimum number of clusters to try",
                   callback=self.updateOptimizationFrom,
                   callbackOnReturn=True)

        OWGUI.spin(box,
                   self,
                   "optimizationTo",
                   label="To",
                   min=3,
                   max=100,
                   tooltip="Maximum number of clusters to try",
                   callback=self.updateOptimizationTo,
                   callbackOnReturn=True)

        OWGUI.comboBox(box,
                       self,
                       "scoring",
                       label="Scoring",
                       orientation="horizontal",
                       items=[m[0] for m in self.scoringMethods],
                       callback=self.update)

        box = OWGUI.widgetBox(self.controlArea, "Settings", addSpace=True)

        OWGUI.comboBox(box,
                       self,
                       "distanceMeasure",
                       label="Distance measures",
                       items=[name for name, _ in self.distanceMeasures],
                       tooltip=None,
                       indent=20,
                       callback=self.update)

        cb = OWGUI.comboBox(box,
                            self,
                            "initializationType",
                            label="Initialization",
                            items=[name for name, _ in self.initializations],
                            tooltip=None,
                            indent=20,
                            callback=self.update)

        OWGUI.spin(cb.box,
                   self,
                   "restarts",
                   label="Restarts",
                   orientation="horizontal",
                   min=1,
                   max=100 if not orngDebugging.orngDebuggingEnabled else 5,
                   callback=self.update,
                   callbackOnReturn=True)

        box = OWGUI.widgetBox(self.controlArea, "Cluster IDs", addSpace=True)
        cb = OWGUI.checkBox(box, self, "classifySelected",
                            "Append cluster indices")

        box = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(cb))

        form = QWidget()
        le = OWGUI.lineEdit(form,
                            self,
                            "classifyName",
                            None,
                            orientation="horizontal",
                            valueType=str)

        cc = OWGUI.comboBox(
            form,
            self,
            "addIdAs",
            label=" ",
            orientation="horizontal",
            items=["Class attribute", "Attribute", "Meta attribute"])

        layout = QFormLayout()
        layout.setSpacing(8)
        layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
        layout.setLabelAlignment(Qt.AlignLeft | Qt.AlignJustify)
        layout.addRow("Name  ", le)
        layout.addRow("Place  ", cc)

        form.setLayout(layout)
        box.layout().addWidget(form)
        left, top, right, bottom = layout.getContentsMargins()
        layout.setContentsMargins(0, top, right, bottom)

        cb.disables.append(box)
        cb.makeConsistent()

        box = OWGUI.widgetBox(self.controlArea, "Run")
        cb = OWGUI.checkBox(box, self, "runAnyChange", "Run after any change")
        self.runButton = b = OWGUI.button(box,
                                          self,
                                          "Run Clustering",
                                          callback=self.run)

        OWGUI.setStopper(self, b, cb, "settingsChanged", callback=self.run)

        OWGUI.rubber(self.controlArea)

        # display of clustering results
        self.optimizationReportBox = OWGUI.widgetBox(self.mainArea)
        self.tableBox = OWGUI.widgetBox(self.optimizationReportBox,
                                        "Optimization Report")
        self.table = OWGUI.table(self.tableBox,
                                 selectionMode=QTableWidget.SingleSelection)

        self.table.setHorizontalScrollMode(QTableWidget.ScrollPerPixel)
        self.table.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setColumnCount(3)
        self.table.setHorizontalHeaderLabels(["k", "Best", "Score"])
        self.table.verticalHeader().hide()
        self.table.horizontalHeader().setStretchLastSection(True)

        self.table.setItemDelegateForColumn(
            2, OWGUI.TableBarItem(self, self.table))

        self.table.setItemDelegateForColumn(1,
                                            OWGUI.IndicatorItemDelegate(self))

        self.table.setSizePolicy(QSizePolicy.MinimumExpanding,
                                 QSizePolicy.MinimumExpanding)

        self.connect(self.table, SIGNAL("itemSelectionChanged()"),
                     self.tableItemSelected)

        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        self.mainArea.setSizePolicy(QSizePolicy.MinimumExpanding,
                                    QSizePolicy.MinimumExpanding)

        OWGUI.rubber(self.topWidgetPart)

        self.updateOptimizationGui()
Ejemplo n.º 19
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "SampleData", wantMainArea=0)

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data Sample", ExampleTable), ("Remaining Data", ExampleTable)]

        # initialization of variables
        self.data = None  # dataset (incoming stream)
        self.indices = None  # indices that control sampling

        self.Stratified = 1  # use stratified sampling if possible?
        self.Repeat = 0  # can elements repeat in a sample?
        self.UseSpecificSeed = 0  # use a specific random seed?
        self.RandomSeed = 1  # specific seed used
        self.GroupSeed = 1  # current seed for multiple group selection
        self.outFold = 1  # folder/group to output
        self.Folds = 1  # total number of folds/groups

        self.SelectType = 0  # sampling type (LOO, CV, ...)
        self.useCases = 0  # use a specific number of cases?
        self.nCases = 25  # number of cases to use
        self.selPercentage = 30  # sample size in %
        self.CVFolds = 10  # number of CV folds
        self.nGroups = 3  # number of groups
        self.pGroups = [0.1, 0.25, 0.5]  # sizes of groups
        self.GroupText = "0.1,0.25,0.5"  # assigned to Groups Control (for internal use)
        self.autocommit = False

        # Invalidated settings flag.
        self.outputInvalidateFlag = False

        self.loadSettings()

        # GUI

        # Info Box
        box1 = OWGUI.widgetBox(self.controlArea, "Information", addSpace=True)
        # Input data set info
        self.infoa = OWGUI.widgetLabel(box1, "No data on input.")
        # Sampling type/parameters info
        self.infob = OWGUI.widgetLabel(box1, " ")
        # Output data set info
        self.infoc = OWGUI.widgetLabel(box1, " ")

        # Options Box
        box2 = OWGUI.widgetBox(self.controlArea, "Options", addSpace=True)
        OWGUI.checkBox(box2, self, "Stratified", "Stratified (if possible)", callback=self.settingsChanged)

        OWGUI.checkWithSpin(
            box2,
            self,
            "Set random seed:",
            0,
            32767,
            "UseSpecificSeed",
            "RandomSeed",
            checkCallback=self.settingsChanged,
            spinCallback=self.settingsChanged,
        )

        # Sampling Type Box
        self.s = [None, None, None, None]
        self.sBox = OWGUI.widgetBox(self.controlArea, "Sampling type", addSpace=True)
        self.sBox.buttons = []

        # Random Sampling
        self.s[0] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", "Random sampling")

        # indent
        indent = OWGUI.checkButtonOffsetHint(self.s[0])
        # repeat checkbox
        self.h1Box = OWGUI.indentedBox(self.sBox, sep=indent, orientation="horizontal")
        OWGUI.checkBox(self.h1Box, self, "Repeat", "With replacement", callback=self.settingsChanged)

        # specified number of elements checkbox
        self.h2Box = OWGUI.indentedBox(self.sBox, sep=indent, orientation="horizontal")
        check, _ = OWGUI.checkWithSpin(
            self.h2Box,
            self,
            "Sample size (instances):",
            1,
            1000000000,
            "useCases",
            "nCases",
            checkCallback=self.settingsChanged,
            spinCallback=self.settingsChanged,
        )

        # percentage slider
        self.h3Box = OWGUI.indentedBox(self.sBox, sep=indent)
        OWGUI.widgetLabel(self.h3Box, "Sample size:")

        self.slidebox = OWGUI.widgetBox(self.h3Box, orientation="horizontal")
        OWGUI.hSlider(
            self.slidebox,
            self,
            "selPercentage",
            minValue=1,
            maxValue=100,
            step=1,
            ticks=10,
            labelFormat="   %d%%",
            callback=self.settingsChanged,
        )

        # Sample size (instances) check disables the Percentage slider.
        # TODO: Should be an exclusive option (radio buttons)
        check.disables.extend([(-1, self.h3Box)])
        check.makeConsistent()

        # Cross Validation sampling options
        self.s[1] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", "Cross validation")

        box = OWGUI.indentedBox(self.sBox, sep=indent, orientation="horizontal")
        OWGUI.spin(box, self, "CVFolds", 2, 100, step=1, label="Number of folds:  ", callback=self.settingsChanged)

        # Leave-One-Out
        self.s[2] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", "Leave-one-out")

        # Multiple Groups
        self.s[3] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", "Multiple subsets")
        gbox = OWGUI.indentedBox(self.sBox, sep=indent, orientation="horizontal")
        OWGUI.lineEdit(
            gbox, self, "GroupText", label='Subset sizes (e.g. "0.1, 0.2, 0.5"):', callback=self.multipleChanged
        )

        # Output Group Box
        box = OWGUI.widgetBox(self.controlArea, "Output Data for Fold / Group", addSpace=True)
        self.foldcombo = OWGUI.comboBox(
            box,
            self,
            "outFold",
            items=range(1, 101),
            label="Fold / group:",
            orientation="horizontal",
            sendSelectedValue=1,
            valueType=int,
            callback=self.invalidate,
        )
        self.foldcombo.setEnabled(self.SelectType != 0)

        # Sample Data box
        OWGUI.rubber(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Sample Data")
        cb = OWGUI.checkBox(box, self, "autocommit", "Sample on any change")
        self.sampleButton = OWGUI.button(box, self, "Sample &Data", callback=self.sdata, default=True)
        OWGUI.setStopper(self, self.sampleButton, cb, "outputInvalidateFlag", callback=self.sdata)

        # set initial radio button on (default sample type)
        self.s[self.SelectType].setChecked(True)

        # Connect radio buttons (SelectType)
        for i, button in enumerate(self.s):
            button.toggled[bool].connect(lambda state, i=i: self.samplingTypeChanged(state, i))

        self.process()

        self.resize(200, 275)
Ejemplo n.º 20
0
    def __init__(self,
                 parent=None,
                 signalManager=None,
                 name="Logistic regression"):
        OWWidget.__init__(self,
                          parent,
                          signalManager,
                          name,
                          wantMainArea=0,
                          resizingEnabled=0)

        self.inputs = [("Examples", ExampleTable, self.setData),
                       ("Preprocess", PreprocessedLearner,
                        self.setPreprocessor)]
        self.outputs = [("Learner", orange.Learner),
                        ("Classifier", orange.Classifier),
                        ("Attributes", list)]

        from orngTree import TreeLearner
        imputeByModel = orange.ImputerConstructor_model()
        imputeByModel.learnerDiscrete = TreeLearner(measure="infoGain",
                                                    minSubset=50)
        imputeByModel.learnerContinuous = TreeLearner(measure="retis",
                                                      minSubset=50)
        self.imputationMethods = [
            imputeByModel,
            orange.ImputerConstructor_average(),
            orange.ImputerConstructor_minimal(),
            orange.ImputerConstructor_maximal(), None
        ]
        self.imputationMethodsStr = [
            "Classification/Regression trees", "Average values",
            "Minimal value", "Maximal value", "None (skip examples)"
        ]

        self.name = "Logistic regression"
        self.univariate = 0
        self.stepwiseLR = 0
        self.addCrit = 10
        self.removeCrit = 10
        self.numAttr = 10
        self.limitNumAttr = False
        self.zeroPoint = 0
        self.imputation = 1

        self.data = None
        self.preprocessor = None

        self.loadSettings()

        OWGUI.lineEdit(
            self.controlArea,
            self,
            'name',
            box='Learner/Classifier Name',
            tooltip=
            'Name to be used by other widgets to identify your learner/classifier.'
        )
        OWGUI.separator(self.controlArea)

        box = OWGUI.widgetBox(self.controlArea, "Attribute selection")

        stepwiseCb = OWGUI.checkBox(box, self, "stepwiseLR",
                                    "Stepwise attribute selection")
        ibox = OWGUI.indentedBox(box,
                                 sep=OWGUI.checkButtonOffsetHint(stepwiseCb))
        addCritSpin = OWGUI.spin(
            ibox,
            self,
            "addCrit",
            1,
            50,
            label="Add threshold [%]",
            labelWidth=155,
            tooltip="Requested significance for adding an attribute")
        remCritSpin = OWGUI.spin(
            ibox,
            self,
            "removeCrit",
            1,
            50,
            label="Remove threshold [%]",
            labelWidth=155,
            tooltip="Requested significance for removing an attribute")
        limitAttSpin = OWGUI.checkWithSpin(
            ibox,
            self,
            "Limit number of attributes to ",
            1,
            100,
            "limitNumAttr",
            "numAttr",
            step=1,
            labelWidth=155,
            tooltip=
            "Maximum number of attributes. Algorithm stops when it selects specified number of attributes."
        )
        stepwiseCb.disables += [addCritSpin, remCritSpin, limitAttSpin]
        stepwiseCb.makeConsistent()

        OWGUI.separator(self.controlArea)

        self.imputationCombo = OWGUI.comboBox(
            self.controlArea,
            self,
            "imputation",
            box="Imputation of unknown values",
            items=self.imputationMethodsStr)
        OWGUI.separator(self.controlArea)

        applyButton = OWGUI.button(self.controlArea,
                                   self,
                                   "&Apply",
                                   callback=self.applyLearner)

        OWGUI.rubber(self.controlArea)
        #self.adjustSize()

        self.applyLearner()
Ejemplo n.º 21
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self,
                          parent,
                          signalManager,
                          'SampleData',
                          wantMainArea=0)

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data Sample", ExampleTable),
                        ("Remaining Data", ExampleTable)]

        # initialization of variables
        self.data = None  # dataset (incoming stream)
        self.indices = None  # indices that control sampling

        self.Stratified = 1  # use stratified sampling if possible?
        self.Repeat = 0  # can elements repeat in a sample?
        self.UseSpecificSeed = 0  # use a specific random seed?
        self.RandomSeed = 1  # specific seed used
        self.GroupSeed = 1  # current seed for multiple group selection
        self.outFold = 1  # folder/group to output
        self.Folds = 1  # total number of folds/groups

        self.SelectType = 0  # sampling type (LOO, CV, ...)
        self.useCases = 0  # use a specific number of cases?
        self.nCases = 25  # number of cases to use
        self.selPercentage = 30  # sample size in %
        self.CVFolds = 10  # number of CV folds
        self.nGroups = 3  # number of groups
        self.pGroups = [0.1, 0.25, 0.5]  # sizes of groups
        self.GroupText = '0.1,0.25,0.5'  # assigned to Groups Control (for internal use)
        self.autocommit = False

        # Invalidated settings flag.
        self.outputInvalidateFlag = False

        self.loadSettings()

        # GUI

        # Info Box
        box1 = OWGUI.widgetBox(self.controlArea, "Information", addSpace=True)
        # Input data set info
        self.infoa = OWGUI.widgetLabel(box1, 'No data on input.')
        # Sampling type/parameters info
        self.infob = OWGUI.widgetLabel(box1, ' ')
        # Output data set info
        self.infoc = OWGUI.widgetLabel(box1, ' ')

        # Options Box
        box2 = OWGUI.widgetBox(self.controlArea, 'Options', addSpace=True)
        OWGUI.checkBox(box2,
                       self,
                       'Stratified',
                       'Stratified (if possible)',
                       callback=self.settingsChanged)

        OWGUI.checkWithSpin(box2,
                            self,
                            'Set random seed:',
                            0,
                            32767,
                            'UseSpecificSeed',
                            'RandomSeed',
                            checkCallback=self.settingsChanged,
                            spinCallback=self.settingsChanged)

        # Sampling Type Box
        self.s = [None, None, None, None]
        self.sBox = OWGUI.widgetBox(self.controlArea,
                                    "Sampling type",
                                    addSpace=True)
        self.sBox.buttons = []

        # Random Sampling
        self.s[0] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            'Random sampling')

        # indent
        indent = OWGUI.checkButtonOffsetHint(self.s[0])
        # repeat checkbox
        self.h1Box = OWGUI.indentedBox(self.sBox,
                                       sep=indent,
                                       orientation="horizontal")
        OWGUI.checkBox(self.h1Box,
                       self,
                       'Repeat',
                       'With replacement',
                       callback=self.settingsChanged)

        # specified number of elements checkbox
        self.h2Box = OWGUI.indentedBox(self.sBox,
                                       sep=indent,
                                       orientation="horizontal")
        check, _ = OWGUI.checkWithSpin(self.h2Box,
                                       self,
                                       'Sample size (instances):',
                                       1,
                                       1000000000,
                                       'useCases',
                                       'nCases',
                                       checkCallback=self.settingsChanged,
                                       spinCallback=self.settingsChanged)

        # percentage slider
        self.h3Box = OWGUI.indentedBox(self.sBox, sep=indent)
        OWGUI.widgetLabel(self.h3Box, "Sample size:")

        self.slidebox = OWGUI.widgetBox(self.h3Box, orientation="horizontal")
        OWGUI.hSlider(self.slidebox,
                      self,
                      'selPercentage',
                      minValue=1,
                      maxValue=100,
                      step=1,
                      ticks=10,
                      labelFormat="   %d%%",
                      callback=self.settingsChanged)

        # Sample size (instances) check disables the Percentage slider.
        # TODO: Should be an exclusive option (radio buttons)
        check.disables.extend([(-1, self.h3Box)])
        check.makeConsistent()

        # Cross Validation sampling options
        self.s[1] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            "Cross validation")

        box = OWGUI.indentedBox(self.sBox,
                                sep=indent,
                                orientation="horizontal")
        OWGUI.spin(box,
                   self,
                   'CVFolds',
                   2,
                   100,
                   step=1,
                   label='Number of folds:  ',
                   callback=self.settingsChanged)

        # Leave-One-Out
        self.s[2] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            "Leave-one-out")

        # Multiple Groups
        self.s[3] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            'Multiple subsets')
        gbox = OWGUI.indentedBox(self.sBox,
                                 sep=indent,
                                 orientation="horizontal")
        OWGUI.lineEdit(gbox,
                       self,
                       'GroupText',
                       label='Subset sizes (e.g. "0.1, 0.2, 0.5"):',
                       callback=self.multipleChanged)

        # Output Group Box
        box = OWGUI.widgetBox(self.controlArea,
                              'Output Data for Fold / Group',
                              addSpace=True)
        self.foldcombo = OWGUI.comboBox(box,
                                        self,
                                        "outFold",
                                        items=range(1, 101),
                                        label='Fold / group:',
                                        orientation="horizontal",
                                        sendSelectedValue=1,
                                        valueType=int,
                                        callback=self.invalidate)
        self.foldcombo.setEnabled(self.SelectType != 0)

        # Sample Data box
        OWGUI.rubber(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Sample Data")
        cb = OWGUI.checkBox(box, self, "autocommit", "Sample on any change")
        self.sampleButton = OWGUI.button(box,
                                         self,
                                         'Sample &Data',
                                         callback=self.sdata,
                                         default=True)
        OWGUI.setStopper(self,
                         self.sampleButton,
                         cb,
                         "outputInvalidateFlag",
                         callback=self.sdata)

        # set initial radio button on (default sample type)
        self.s[self.SelectType].setChecked(True)

        # Connect radio buttons (SelectType)
        for i, button in enumerate(self.s):
            button.toggled[bool].connect(
                lambda state, i=i: self.samplingTypeChanged(state, i))

        self.process()

        self.resize(200, 275)
Ejemplo n.º 22
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'k-Means Clustering')

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data", ExampleTable), ("Centroids", ExampleTable)]

        #set default settings
        self.K = 2
        self.optimized = True
        self.optimizationFrom = 2
        self.optimizationTo = 5
        self.scoring = 0
        self.distanceMeasure = 0
        self.initializationType = 0
        self.restarts = 1
        self.classifySelected = 1
        self.addIdAs = 0
        self.runAnyChange = 1
        self.classifyName = "Cluster"

        self.settingsChanged = False

        self.loadSettings()

        self.data = None  # holds input data
        self.km = None    # holds clustering object

        # GUI definition
        # settings

        box = OWGUI.widgetBox(self.controlArea, "Clusters (k)",
                              addSpace=True, spacing=0)
#        left, top, right, bottom = box.getContentsMargins()
#        box.setContentsMargins(left, 0, right, 0)
        bg = OWGUI.radioButtonsInBox(box, self, "optimized", [],
                                     callback=self.setOptimization)

        fixedBox = OWGUI.widgetBox(box, orientation="horizontal",
                                   margin=0, spacing=bg.layout().spacing())

        button = OWGUI.appendRadioButton(bg, self, "optimized", "Fixed",
                                         insertInto=fixedBox,
                                         tooltip="Fixed number of clusters")

        button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        fixedBox.layout().setAlignment(button, Qt.AlignLeft)
        self.fixedSpinBox = OWGUI.spin(OWGUI.widgetBox(fixedBox), self, "K",
                                       min=2, max=30,
                                       tooltip="Fixed number of clusters",
                                       callback=self.update,
                                       callbackOnReturn=True)

        optimizedBox = OWGUI.widgetBox(box, margin=0,
                                       spacing=bg.layout().spacing())
        button = OWGUI.appendRadioButton(bg, self, "optimized", "Optimized",
                                         insertInto=optimizedBox)

        box = OWGUI.indentedBox(optimizedBox,
                                sep=OWGUI.checkButtonOffsetHint(button))

        box.layout().setSpacing(0)
        self.optimizationBox = box

        OWGUI.spin(box, self, "optimizationFrom", label="From",
                   min=2, max=99,
                   tooltip="Minimum number of clusters to try",
                   callback=self.updateOptimizationFrom,
                   callbackOnReturn=True)

        OWGUI.spin(box, self, "optimizationTo", label="To",
                   min=3, max=100,
                   tooltip="Maximum number of clusters to try",
                   callback=self.updateOptimizationTo,
                   callbackOnReturn=True)

        OWGUI.comboBox(box, self, "scoring", label="Scoring",
                       orientation="horizontal",
                       items=[m[0] for m in self.scoringMethods],
                       callback=self.update)

        box = OWGUI.widgetBox(self.controlArea, "Settings", addSpace=True)

        OWGUI.comboBox(box, self, "distanceMeasure", label="Distance measures",
                       items=[name for name, _ in self.distanceMeasures],
                       tooltip=None,
                       indent=20,
                       callback=self.update)

        cb = OWGUI.comboBox(box, self, "initializationType",
                            label="Initialization",
                            items=[name for name, _ in self.initializations],
                            tooltip=None,
                            indent=20,
                            callback=self.update)

        OWGUI.spin(cb.box, self, "restarts", label="Restarts",
                   orientation="horizontal",
                   min=1,
                   max=100 if not orngDebugging.orngDebuggingEnabled else 5,
                   callback=self.update,
                   callbackOnReturn=True)

        box = OWGUI.widgetBox(self.controlArea, "Cluster IDs", addSpace=True)
        cb = OWGUI.checkBox(box, self, "classifySelected",
                            "Append cluster indices")

        box = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(cb))

        form = QWidget()
        le = OWGUI.lineEdit(form, self, "classifyName", None,
                            orientation="horizontal",
                            valueType=str)

        cc = OWGUI.comboBox(form, self, "addIdAs", label=" ",
                            orientation="horizontal",
                            items=["Class attribute",
                                   "Attribute",
                                   "Meta attribute"])

        layout = QFormLayout()
        layout.setSpacing(8)
        layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
        layout.setLabelAlignment(Qt.AlignLeft | Qt.AlignJustify)
        layout.addRow("Name  ", le)
        layout.addRow("Place  ", cc)

        form.setLayout(layout)
        box.layout().addWidget(form)
        left, top, right, bottom = layout.getContentsMargins()
        layout.setContentsMargins(0, top, right, bottom)

        cb.disables.append(box)
        cb.makeConsistent()

        box = OWGUI.widgetBox(self.controlArea, "Run")
        cb = OWGUI.checkBox(box, self, "runAnyChange", "Run after any change")
        self.runButton = b = OWGUI.button(box, self, "Run Clustering",
                                          callback=self.run)

        OWGUI.setStopper(self, b, cb, "settingsChanged", callback=self.run)

        OWGUI.rubber(self.controlArea)

        # display of clustering results
        self.optimizationReportBox = OWGUI.widgetBox(self.mainArea)
        self.tableBox = OWGUI.widgetBox(self.optimizationReportBox,
                                        "Optimization Report")
        self.table = OWGUI.table(self.tableBox,
                                 selectionMode=QTableWidget.SingleSelection)

        self.table.setHorizontalScrollMode(QTableWidget.ScrollPerPixel)
        self.table.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setColumnCount(3)
        self.table.setHorizontalHeaderLabels(["k", "Best", "Score"])
        self.table.verticalHeader().hide()
        self.table.horizontalHeader().setStretchLastSection(True)

        self.table.setItemDelegateForColumn(
            2, OWGUI.TableBarItem(self, self.table))

        self.table.setItemDelegateForColumn(
            1, OWGUI.IndicatorItemDelegate(self))

        self.table.setSizePolicy(QSizePolicy.MinimumExpanding,
                                 QSizePolicy.MinimumExpanding)

        self.connect(self.table,
                     SIGNAL("itemSelectionChanged()"),
                     self.tableItemSelected)

        self.setSizePolicy(QSizePolicy.Preferred,
                           QSizePolicy.Preferred)

        self.mainArea.setSizePolicy(QSizePolicy.MinimumExpanding,
                                    QSizePolicy.MinimumExpanding)

        OWGUI.rubber(self.topWidgetPart)

        self.updateOptimizationGui()
    def __init__(self, parent=None, signalManager = None):
        "Constructor"
        OWWidget.__init__(self, parent, signalManager, "&Distributions", TRUE)
        # settings
        self.numberOfBars = 5
        self.barSize = 50
        self.showContinuousClassGraph=1
        self.showProbabilities = 1
        self.showConfidenceIntervals = 0
        self.smoothLines = 0
        self.lineWidth = 1
        self.showMainTitle = 0
        self.showXaxisTitle = 1
        self.showYaxisTitle = 1
        self.showYPaxisTitle = 1

        self.attribute = ""
        self.targetValue = 0
        self.visibleOutcomes = []
        self.outcomes = []

        # tmp values
        self.mainTitle = ""
        self.xaxisTitle = ""
        self.yaxisTitle = "frequency"
        self.yPaxisTitle = ""

        # GUI
#        self.tabs = OWGUI.tabWidget(self.controlArea)
#        self.GeneralTab = OWGUI.createTabPage(self.tabs, "Main")
#        self.SettingsTab = OWGUI.createTabPage(self.tabs, "Settings")
        self.GeneralTab = self.SettingsTab = self.controlArea

        self.graph = OWDistributionGraph(self, self.mainArea)
        self.mainArea.layout().addWidget(self.graph)
        self.graph.setYRlabels(None)
        self.graph.setAxisScale(QwtPlot.yRight, 0.0, 1.0, 0.1)
        self.connect(self.graphButton, SIGNAL("clicked()"), self.graph.saveToFile)
        
        self.loadSettings()

        self.barSize = 50

        # inputs
        # data and graph temp variables
        self.inputs = [("Data", ExampleTable, self.setData, Default)]

        self.data = None
        self.outcomenames = []
        self.probGraphValues = []

        b = OWGUI.widgetBox(self.controlArea, "Variable", addSpace=True)
        self.variablesQCB = OWGUI.comboBox(b, self, "attribute", valueType = str, sendSelectedValue = True, callback=self.setVariable)
        OWGUI.widgetLabel(b, "Displayed outcomes")
        self.outcomesQLB = OWGUI.listBox(b, self, "visibleOutcomes", "outcomes", selectionMode = QListWidget.MultiSelection, callback = self.outcomeSelectionChange)

        # GUI connections
        # options dialog connections
#        b = OWGUI.widgetBox(self.SettingsTab, "Bars")
#        OWGUI.spin(b, self, "numberOfBars", label="Number of bars", min=5, max=60, step=5, callback=self.setNumberOfBars, callbackOnReturn=True)
#        self.numberOfBarsSlider = OWGUI.hSlider(self.SettingsTab, self, 'numberOfBars', box='Number of bars', minValue=5, maxValue=60, step=5, callback=self.setNumberOfBars, ticks=5)
#        self.numberOfBarsSlider.setTracking(0) # no change until the user stop dragging the slider

#        self.barSizeSlider = OWGUI.hSlider(self.SettingsTab, self, 'barSize', box="Bar size", minValue=30, maxValue=100, step=5, callback=self.setBarSize, ticks=10)
#        OWGUI.spin(b, self, "barSize", label="Bar size", min=30, max=100, step=5, callback=self.setBarSize, callbackOnReturn=True)

        box = OWGUI.widgetBox(self.SettingsTab, "General graph settings", addSpace=True)
        box.setMinimumWidth(180)
        box2 = OWGUI.widgetBox(box, orientation = "horizontal")
        OWGUI.checkBox(box2, self, 'showMainTitle', 'Main title', callback = self.setShowMainTitle)
        OWGUI.lineEdit(box2, self, 'mainTitle', callback = self.setMainTitle, enterPlaceholder=True)

        box3 = OWGUI.widgetBox(box, orientation = "horizontal")
        OWGUI.checkBox(box3, self, 'showXaxisTitle', 'X axis title', callback = self.setShowXaxisTitle)
        OWGUI.lineEdit(box3, self, 'xaxisTitle', callback = self.setXaxisTitle, enterPlaceholder=True)

        box4 = OWGUI.widgetBox(box, orientation = "horizontal")
        OWGUI.checkBox(box4, self, 'showYaxisTitle', 'Y axis title', callback = self.setShowYaxisTitle)
        OWGUI.lineEdit(box4, self, 'yaxisTitle', callback = self.setYaxisTitle, enterPlaceholder=True)

        OWGUI.checkBox(box, self, 'graph.showContinuousClassGraph', 'Show continuous class graph', callback=self.setShowContinuousClassGraph)
        OWGUI.spin(box, self, "numberOfBars", label="Number of bars", min=5, max=60, step=5, callback=self.setNumberOfBars, callbackOnReturn=True)

        self.probabilityPlotBox = box5 = OWGUI.widgetBox(self.SettingsTab, "Probability plot")
        self.showProb = OWGUI.checkBox(box5, self, 'showProbabilities', 'Show probabilities', callback = self.setShowProbabilities)
        self.targetQCB = OWGUI.comboBox(OWGUI.indentedBox(box5, sep=OWGUI.checkButtonOffsetHint(self.showProb)), self, "targetValue", label="Target value", valueType=int, callback=self.setTarget)

        box6 = OWGUI.widgetBox(box5, orientation = "horizontal")

        self.showYPaxisCheck = OWGUI.checkBox(box6, self, 'showYPaxisTitle', 'Axis title', callback = self.setShowYPaxisTitle)
        self.yPaxisEdit = OWGUI.lineEdit(box6, self, 'yPaxisTitle', callback = self.setYPaxisTitle, enterPlaceholder=True)
        self.confIntCheck = OWGUI.checkBox(box5, self, 'showConfidenceIntervals', 'Show confidence intervals', callback = self.setShowConfidenceIntervals)
        self.cbSmooth = OWGUI.checkBox(box5, self, 'smoothLines', 'Smooth probability lines', callback = self.setSmoothLines)
        self.showProb.disables = [self.showYPaxisCheck, self.yPaxisEdit, self.confIntCheck, self.targetQCB, self.cbSmooth]
        self.showProb.makeConsistent()


#        self.barSizeSlider = OWGUI.hSlider(box5, self, 'lineWidth', box='Line width', minValue=1, maxValue=9, step=1, callback=self.setLineWidth, ticks=1)
        
        OWGUI.rubber(self.SettingsTab)

        #add controls to self.controlArea widget

        self.icons = self.createAttributeIconDict()

        self.graph.numberOfBars = self.numberOfBars
        self.graph.barSize = self.barSize
        self.graph.setShowMainTitle(self.showMainTitle)
        self.graph.setShowXaxisTitle(self.showXaxisTitle)
        self.graph.setShowYLaxisTitle(self.showYaxisTitle)
        self.graph.setShowYRaxisTitle(self.showYPaxisTitle)
        self.graph.setMainTitle(self.mainTitle)
        self.graph.setXaxisTitle(self.xaxisTitle)
        self.graph.setYLaxisTitle(self.yaxisTitle)
        self.graph.setYRaxisTitle(self.yPaxisTitle)
        self.graph.showProbabilities = self.showProbabilities
        self.graph.showConfidenceIntervals = self.showConfidenceIntervals
        self.graph.smoothLines = self.smoothLines
        self.graph.lineWidth = self.lineWidth
        #self.graph.variableContinuous = self.VariableContinuous
        self.graph.targetValue = self.targetValue
Ejemplo n.º 24
0
    def __init__(self, parent=None, signalManager=None, name="Interactive Discretization"):
        OWWidget.__init__(self, parent, signalManager, name)
        self.showBaseLine=1
        self.showLookaheadLine=1
        self.showTargetClassProb=1
        self.showRug=0
        self.snap=1
        self.measure=0
        self.targetClass=0
        self.discretization = self.classDiscretization = self.indiDiscretization = 1
        self.intervals = self.classIntervals = self.indiIntervals = 3
        self.outputOriginalClass = True
        self.indiData = []
        self.indiLabels = []
        self.resetIndividuals = 0
        self.customClassSplits = ""

        self.selectedAttr = 0
        self.customSplits = ["", "", ""]
        self.autoApply = True
        self.dataChanged = False
        self.autoSynchronize = True
        self.pointsChanged = False

        self.customLineEdits = []
        self.needsDiscrete = []

        self.data = self.originalData = None

        self.loadSettings()

        self.inputs=[("Data", ExampleTable, self.setData)]
        self.outputs=[("Data", ExampleTable)]
        self.measures=[("Information gain", orange.MeasureAttribute_info()),
                       #("Gain ratio", orange.MeasureAttribute_gainRatio),
                       ("Gini", orange.MeasureAttribute_gini()),
                       ("chi-square", orange.MeasureAttribute_chiSquare()),
                       ("chi-square prob.", orange.MeasureAttribute_chiSquare(computeProbabilities=1)),
                       ("Relevance", orange.MeasureAttribute_relevance()),
                       ("ReliefF", orange.MeasureAttribute_relief())]
        self.discretizationMethods=["Leave continuous", "Entropy-MDL discretization", "Equal-frequency discretization", "Equal-width discretization", "Remove continuous attributes"]
        self.classDiscretizationMethods=["Equal-frequency discretization", "Equal-width discretization"]
        self.indiDiscretizationMethods=["Default", "Leave continuous", "Entropy-MDL discretization", "Equal-frequency discretization", "Equal-width discretization", "Remove attribute"]

        self.mainHBox =  OWGUI.widgetBox(self.mainArea, orientation=0)

        vbox = self.controlArea
        box = OWGUI.radioButtonsInBox(vbox, self, "discretization", self.discretizationMethods[:-1], "Default discretization", callback=[self.clearLineEditFocus, self.defaultMethodChanged])
        self.needsDiscrete.append(box.buttons[1])
        box.setSizePolicy(QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed))
        indent = OWGUI.checkButtonOffsetHint(self.needsDiscrete[-1])
        self.interBox = OWGUI.widgetBox(OWGUI.indentedBox(box, sep=indent))
        OWGUI.widgetLabel(self.interBox, "Number of intervals (for equal width/frequency)")
        OWGUI.separator(self.interBox, height=4)
        self.intervalSlider=OWGUI.hSlider(OWGUI.indentedBox(self.interBox), self, "intervals", None, 2, 10, callback=[self.clearLineEditFocus, self.defaultMethodChanged])
        OWGUI.appendRadioButton(box, self, "discretization", self.discretizationMethods[-1])
        OWGUI.separator(vbox)

        ribg = OWGUI.radioButtonsInBox(vbox, self, "resetIndividuals", ["Use default discretization for all attributes", "Explore and set individual discretizations"], "Individual attribute treatment", callback = self.setAllIndividuals)
        ll = QWidget(ribg)
        ll.setFixedHeight(1)
        OWGUI.widgetLabel(ribg, "Set discretization of all attributes to")
        hcustbox = OWGUI.widgetBox(OWGUI.indentedBox(ribg), 0, 0)
        for c in range(1, 4):
            OWGUI.appendRadioButton(ribg, self, "resetIndividuals", "Custom %i" % c, insertInto = hcustbox)

        OWGUI.separator(vbox)

        box = self.classDiscBox = OWGUI.radioButtonsInBox(vbox, self, "classDiscretization", self.classDiscretizationMethods, "Class discretization", callback=[self.clearLineEditFocus, self.classMethodChanged])
        cinterBox = OWGUI.widgetBox(box)
        self.intervalSlider=OWGUI.hSlider(OWGUI.indentedBox(cinterBox, sep=indent), self, "classIntervals", None, 2, 10, callback=[self.clearLineEditFocus, self.classMethodChanged], label="Number of intervals")
        hbox = OWGUI.widgetBox(box, orientation = 0)
        OWGUI.appendRadioButton(box, self, "discretization", "Custom" + "  ", insertInto = hbox)
        self.classCustomLineEdit = OWGUI.lineEdit(hbox, self, "customClassSplits", callback = self.classCustomChanged, focusInCallback = self.classCustomSelected)
#        Can't validate - need to allow spaces
        box.setSizePolicy(QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed))
        OWGUI.separator(box)
        self.classIntervalsLabel = OWGUI.widgetLabel(box, "Current splits: ")
        OWGUI.separator(box)
        OWGUI.checkBox(box, self, "outputOriginalClass", "Output original class", callback = self.commitIf)
        OWGUI.widgetLabel(box, "("+"Widget always uses discretized class internally."+")")

        OWGUI.separator(vbox)
        #OWGUI.rubber(vbox)

        box = OWGUI.widgetBox(vbox, "Commit")
        applyButton = OWGUI.button(box, self, "Commit", callback = self.commit, default=True)
        autoApplyCB = OWGUI.checkBox(box, self, "autoApply", "Commit automatically", callback=[self.clearLineEditFocus])
        OWGUI.setStopper(self, applyButton, autoApplyCB, "dataChanged", self.commit)
        OWGUI.rubber(vbox)

        #self.mainSeparator = OWGUI.separator(self.mainHBox, width=25)        # space between control and main area
        self.mainIABox =  OWGUI.widgetBox(self.mainHBox, "Individual attribute settings")
        self.mainBox = OWGUI.widgetBox(self.mainIABox, orientation=0)
        OWGUI.separator(self.mainIABox)#, height=30)
        graphBox = OWGUI.widgetBox(self.mainIABox, "", orientation=0)
        
        
#        self.needsDiscrete.append(graphBox)
        graphOptBox = OWGUI.widgetBox(graphBox)
        OWGUI.separator(graphBox, width=10)
        
        graphGraphBox = OWGUI.widgetBox(graphBox)
        self.graph = DiscGraph(self, graphGraphBox)
        graphGraphBox.layout().addWidget(self.graph)
        reportButton2 = OWGUI.button(graphGraphBox, self, "Report Graph", callback = self.reportGraph, debuggingEnabled=0)

        #graphOptBox.layout().setSpacing(4)
        box = OWGUI.widgetBox(graphOptBox, "Split gain measure", addSpace=True)
        self.measureCombo=OWGUI.comboBox(box, self, "measure", orientation=0, items=[e[0] for e in self.measures], callback=[self.clearLineEditFocus, self.graph.invalidateBaseScore, self.graph.plotBaseCurve])
        OWGUI.checkBox(box, self, "showBaseLine", "Show discretization gain", callback=[self.clearLineEditFocus, self.graph.plotBaseCurve])
        OWGUI.checkBox(box, self, "showLookaheadLine", "Show lookahead gain", callback=self.clearLineEditFocus)
        self.needsDiscrete.append(box)

        box = OWGUI.widgetBox(graphOptBox, "Target class", addSpace=True)
        self.targetCombo=OWGUI.comboBox(box, self, "targetClass", orientation=0, callback=[self.clearLineEditFocus, self.graph.targetClassChanged])
        stc = OWGUI.checkBox(box, self, "showTargetClassProb", "Show target class probability", callback=[self.clearLineEditFocus, self.graph.plotProbCurve])
        OWGUI.checkBox(box, self, "showRug", "Show rug (may be slow)", callback=[self.clearLineEditFocus, self.graph.plotRug])
        self.needsDiscrete.extend([self.targetCombo, stc])

        box = OWGUI.widgetBox(graphOptBox, "Editing", addSpace=True)
        OWGUI.checkBox(box, self, "snap", "Snap to grid", callback=[self.clearLineEditFocus])
        syncCB = OWGUI.checkBox(box, self, "autoSynchronize", "Apply on the fly", callback=self.clearLineEditFocus)
        syncButton = OWGUI.button(box, self, "Apply", callback = self.synchronizePressed)
        OWGUI.setStopper(self, syncButton, syncCB, "pointsChanged", self.synchronize)
        OWGUI.rubber(graphOptBox)

        self.attrList = OWGUI.listBox(self.mainBox, self, callback = self.individualSelected)
        self.attrList.setItemDelegate(CustomListItemDelegate(self.attrList))
        self.attrList.setFixedWidth(300)

        self.defaultMethodChanged()

        OWGUI.separator(self.mainBox, width=10)
        box = OWGUI.radioButtonsInBox(OWGUI.widgetBox(self.mainBox), self, "indiDiscretization", [], callback=[self.clearLineEditFocus, self.indiMethodChanged])
        #hbbox = OWGUI.widgetBox(box)
        #hbbox.layout().setSpacing(4)
        for meth in self.indiDiscretizationMethods[:-1]:
            OWGUI.appendRadioButton(box, self, "indiDiscretization", meth)
        self.needsDiscrete.append(box.buttons[2])
        self.indiInterBox = OWGUI.indentedBox(box, sep=indent, orientation = "horizontal")
        OWGUI.widgetLabel(self.indiInterBox, "Num. of intervals: ")
        self.indiIntervalSlider = OWGUI.hSlider(self.indiInterBox, self, "indiIntervals", None, 2, 10, callback=[self.clearLineEditFocus, self.indiMethodChanged], width = 100)
        OWGUI.rubber(self.indiInterBox) 
        OWGUI.appendRadioButton(box, self, "indiDiscretization", self.indiDiscretizationMethods[-1])
        #OWGUI.rubber(hbbox)
        #OWGUI.separator(box)
        #hbbox = OWGUI.widgetBox(box)
        for i in range(3):
            hbox = OWGUI.widgetBox(box, orientation = "horizontal")
            OWGUI.appendRadioButton(box, self, "indiDiscretization", "Custom %i" % (i+1) + " ", insertInto = hbox)
            le = OWGUI.lineEdit(hbox, self, "", callback = lambda w=i: self.customChanged(w), focusInCallback = lambda w=i: self.customSelected(w))
            le.setFixedWidth(110)
            self.customLineEdits.append(le)
            OWGUI.toolButton(hbox, self, "CC", width=30, callback = lambda w=i: self.copyToCustom(w))
            OWGUI.rubber(hbox)
        OWGUI.rubber(box)

        #self.controlArea.setFixedWidth(0)

        self.contAttrIcon =  self.createAttributeIconDict()[orange.VarTypes.Continuous]
        
        self.setAllIndividuals()
Ejemplo n.º 25
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self,
                          parent,
                          signalManager,
                          'SampleData',
                          wantMainArea=0)

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Sample", ExampleTable),
                        ("Remaining Examples", ExampleTable)]

        # initialization of variables
        self.data = None  # dataset (incoming stream)
        self.indices = None  # indices that control sampling
        self.ind = None  # indices that control sampling

        self.Stratified = 1  # use stratified sampling if possible?
        self.Repeat = 0  # can elements repeat in a sample?
        self.UseSpecificSeed = 0  # use a specific random seed?
        self.RandomSeed = 1  # specific seed used
        self.GroupSeed = 1  # current seed for multiple group selection
        self.outFold = 1  # folder/group to output
        self.Folds = 1  # total number of folds/groups

        self.SelectType = 0  # sampling type (LOO, CV, ...)
        self.useCases = 0  # use a specific number of cases?
        self.nCases = 25  # number of cases to use
        self.selPercentage = 30  # sample size in %
        self.LOO = 1  # use LOO?
        self.CVFolds = 10  # number of CV folds
        self.CVFoldsInternal = 10  # number of CV folds (for internal use)
        self.nGroups = 3  # number of groups
        self.pGroups = [0.1, 0.25, 0.5]  # sizes of groups
        self.GroupText = '0.1,0.25,0.5'  # assigned to Groups Control (for internal use)

        self.loadSettings()
        # GUI

        # Info Box
        box1 = OWGUI.widgetBox(self.controlArea, "Information", addSpace=True)
        self.infoa = OWGUI.widgetLabel(box1, 'No data on input.')
        self.infob = OWGUI.widgetLabel(box1, ' ')
        self.infoc = OWGUI.widgetLabel(box1, ' ')

        # Options Box
        box2 = OWGUI.widgetBox(self.controlArea, 'Options', addSpace=True)
        OWGUI.checkBox(box2,
                       self,
                       'Stratified',
                       'Stratified (if possible)',
                       callback=self.settingsChanged)
        OWGUI.checkWithSpin(box2,
                            self,
                            'Set random seed:',
                            0,
                            32767,
                            'UseSpecificSeed',
                            'RandomSeed',
                            checkCallback=self.settingsChanged,
                            spinCallback=self.settingsChanged)

        # Sampling Type Box
        self.s = [None, None, None, None]
        self.sBox = OWGUI.widgetBox(self.controlArea,
                                    "Sampling type",
                                    addSpace=True)
        self.sBox.buttons = []

        # Random Sampling
        self.s[0] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            'Random sampling')

        # indent
        indent = sep = OWGUI.checkButtonOffsetHint(self.s[0])
        # repeat checkbox
        self.h1Box = OWGUI.indentedBox(self.sBox,
                                       sep=indent,
                                       orientation="horizontal")
        OWGUI.checkBox(self.h1Box,
                       self,
                       'Repeat',
                       'With replacement',
                       callback=self.settingsChanged)

        # specified number of elements checkbox
        self.h2Box = OWGUI.indentedBox(self.sBox,
                                       sep=indent,
                                       orientation="horizontal")
        OWGUI.checkWithSpin(self.h2Box,
                            self,
                            'Sample size (instances):',
                            1,
                            1000000000,
                            'useCases',
                            'nCases',
                            checkCallback=[self.uCases, self.settingsChanged],
                            spinCallback=self.settingsChanged)
        OWGUI.rubber(self.h2Box)

        # percentage slider
        self.h3Box = OWGUI.indentedBox(self.sBox,
                                       sep=indent,
                                       orientation="horizontal")
        OWGUI.widgetLabel(self.h3Box, "Sample size:")
        self.slidebox = OWGUI.indentedBox(self.sBox,
                                          sep=indent,
                                          orientation="horizontal")
        OWGUI.hSlider(self.slidebox,
                      self,
                      'selPercentage',
                      minValue=1,
                      maxValue=100,
                      step=1,
                      ticks=10,
                      labelFormat="   %d%%",
                      callback=self.settingsChanged)

        # Cross Validation
        self.s[1] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            'Cross validation')

        box = OWGUI.indentedBox(self.sBox,
                                sep=indent,
                                orientation="horizontal")
        OWGUI.spin(box,
                   self,
                   'CVFolds',
                   2,
                   100,
                   step=1,
                   label='Number of folds:  ',
                   callback=[self.changeCombo, self.settingsChanged])
        OWGUI.rubber(box)

        # Leave-One-Out
        self.s[2] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            'Leave-one-out')

        # Multiple Groups
        self.s[3] = OWGUI.appendRadioButton(self.sBox, self, "SelectType",
                                            'Multiple subsets')
        gbox = OWGUI.indentedBox(self.sBox,
                                 sep=indent,
                                 orientation="horizontal")
        OWGUI.lineEdit(gbox,
                       self,
                       'GroupText',
                       label='Subset sizes (e.g. "0.1, 0.2, 0.5"):',
                       callback=self.multipleChanged)

        # Output Group Box
        self.foldcombo = OWGUI.comboBox(self.controlArea,
                                        self,
                                        "outFold",
                                        'Output Data for Fold / Group',
                                        'Fold / group:',
                                        orientation="horizontal",
                                        items=list(range(1, 101)),
                                        callback=self.foldChanged,
                                        sendSelectedValue=1,
                                        valueType=int)
        self.foldcombo.setEnabled(False)

        # Select Data Button
        OWGUI.rubber(self.controlArea)
        self.sampleButton = OWGUI.button(self.controlArea,
                                         self,
                                         'Sample &Data',
                                         callback=self.process,
                                         addToLayout=False)
        self.buttonBackground.layout().setDirection(QBoxLayout.TopToBottom)
        self.buttonBackground.layout().insertWidget(0, self.sampleButton)
        self.buttonBackground.show()
        self.s[self.SelectType].setChecked(
            True)  # set initial radio button on (default sample type)

        # CONNECTIONS
        # set connections for RadioButton (SelectType)
        self.dummy1 = [None] * len(self.s)
        for i in range(len(self.s)):
            self.dummy1[i] = lambda x, v=i: self.sChanged(x, v)
            self.connect(self.s[i], SIGNAL("toggled(bool)"), self.dummy1[i])

        # final touch
        self.resize(200, 275)
Ejemplo n.º 26
0
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Mosaic display", True, True)

        #set default settings
        self.data = None
        self.unprocessedSubsetData = None
        self.subsetData = None
        self.names = []     # class values

        self.inputs = [("Data", ExampleTable, self.setData, Default), ("Data Subset", ExampleTable, self.setSubsetData)]
        self.outputs = [("Selected Data", ExampleTable), ("Learner", orange.Learner)]

        #load settings
        self.colorSettings = None
        self.selectedSchemaIndex = 0
        self.interiorColoring = 0
        self.cellspace = 4
        self.showAprioriDistributionBoxes = 1
        self.useBoxes = 1
        self.showSubsetDataBoxes = 1
        self.horizontalDistribution = 0
        self.showAprioriDistributionLines = 0
        self.boxSize = 5
        self.exploreAttrPermutations = 0
        self.attr1 = ""
        self.attr2 = ""
        self.attr3 = ""
        self.attr4 = ""

        self.attributeNameOffset = 30
        self.attributeValueOffset = 15
        self.residuals = [] # residual values if the residuals are visualized
        self.aprioriDistributions = []
        self.colorPalette = None
        self.permutationDict = {}
        self.manualAttributeValuesDict = {}
        self.conditionalDict = None
        self.conditionalSubsetDict = None
        self.activeRule = None
        self.removeUnusedValues = 0

        self.selectionRectangle = None
        self.selectionConditionsHistorically = []
        self.selectionConditions = []

        # color paletes for visualizing pearsons residuals
        #self.blueColors = [QColor(255, 255, 255), QColor(117, 149, 255), QColor(38, 43, 232), QColor(1,5,173)]
        self.blueColors = [QColor(255, 255, 255), QColor(210, 210, 255), QColor(110, 110, 255), QColor(0,0,255)]
        self.redColors = [QColor(255, 255, 255), QColor(255, 200, 200), QColor(255, 100, 100), QColor(255, 0, 0)]

        self.loadSettings()

        self.tabs = OWGUI.tabWidget(self.controlArea)
        self.GeneralTab = OWGUI.createTabPage(self.tabs, "Main")
        self.SettingsTab = OWGUI.createTabPage(self.tabs, "Settings")

        self.canvas = QGraphicsScene()
        self.canvasView = MosaicSceneView(self, self.canvas, self.mainArea)
        self.mainArea.layout().addWidget(self.canvasView)
        self.canvasView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.canvasView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.canvasView.setRenderHint(QPainter.Antialiasing)
        #self.canvasView.setAlignment(Qt.AlignLeft | Qt.AlignTop)

        #GUI
        #add controls to self.controlArea widget
        #self.controlArea.setMinimumWidth(235)

        texts = ["1st Attribute", "2nd Attribute", "3rd Attribute", "4th Attribute"]
        for i in range(1,5):
            box = OWGUI.widgetBox(self.GeneralTab, texts[i-1], orientation = "horizontal")
            combo = OWGUI.comboBox(box, self, "attr" + str(i), None, callback = self.updateGraphAndPermList, sendSelectedValue = 1, valueType = str)

            butt = OWGUI.button(box, self, "", callback = self.orderAttributeValues, tooltip = "Change the order of attribute values", debuggingEnabled = 0)
            butt.setFixedSize(26, 24)
            butt.setCheckable(1)
            butt.setIcon(QIcon(os.path.join(self.widgetDir, "icons/Dlg_sort.png")))

            setattr(self, "sort"+str(i), butt)
            setattr(self, "attr" + str(i)+ "Combo", combo)

        self.optimizationDlg = OWMosaicOptimization(self, self.signalManager)

        optimizationButtons = OWGUI.widgetBox(self.GeneralTab, "Dialogs", orientation = "horizontal")
        OWGUI.button(optimizationButtons, self, "VizRank", callback = self.optimizationDlg.reshow, debuggingEnabled = 0, tooltip = "Find attribute combinations that will separate different classes as clearly as possible.")

        self.collapsableWBox = OWGUI.collapsableWidgetBox(self.GeneralTab, "Explore Attribute Permutations", self, "exploreAttrPermutations", callback = self.permutationListToggle)
        self.permutationList = OWGUI.listBox(self.collapsableWBox, self, callback = self.setSelectedPermutation)
        #self.permutationList.hide()
        self.GeneralTab.layout().addStretch(100)

        # ######################
        # SETTINGS TAB
        # ######################
        box5 = OWGUI.widgetBox(self.SettingsTab, "Colors in Cells Represent...", addSpace = 1)
        OWGUI.comboBox(box5, self, "interiorColoring", None, items = self.interiorColoringOpts, callback = self.updateGraph)
        #box5.setSizePolicy(QSizePolicy(QSizePolicy.Minimum , QSizePolicy.Fixed ))

        box = OWGUI.widgetBox(self.SettingsTab, "Visual Settings", addSpace = 1)
        
        OWGUI.hSlider(box, self, 'cellspace', label = "Cell distance: ", minValue=1, maxValue=15, step=1, callback = self.updateGraph, tooltip = "What is the minimum distance between two rectangles in the plot?")
        OWGUI.checkBox(box, self, "removeUnusedValues", "Remove unused attribute values", tooltip = "Do you want to remove unused attribute values?\nThis setting will not be considered until new data is received.")

        self.box6 = OWGUI.widgetBox(self.SettingsTab, "Cell Distribution Settings", addSpace = 1)
        OWGUI.comboBox(self.box6, self, 'horizontalDistribution', items = ["Show Distribution Vertically", "Show Distribution Horizontally"], tooltip = "Do you wish to see class distribution drawn horizontally or vertically?", callback = self.updateGraph)
        OWGUI.checkBox(self.box6, self, 'showAprioriDistributionLines', 'Show apriori distribution with lines', callback = self.updateGraph, tooltip = "Show the lines that represent the apriori class distribution")

        self.box8 = OWGUI.widgetBox(self.SettingsTab, "Boxes in Cells", addSpace = 1)
        OWGUI.hSlider(self.box8, self, 'boxSize', label = "Size: ", minValue=1, maxValue=15, step=1, callback = self.updateGraph, tooltip = "What is the size of the boxes on the left and right edge of each cell?")
        OWGUI.checkBox(self.box8, self, 'showSubsetDataBoxes', 'Show class distribution of subset data', callback = self.updateGraph, tooltip = "Show small boxes at right (or bottom) edge of cells to represent class distribution of examples from example subset input.")
        cb = OWGUI.checkBox(self.box8, self, 'useBoxes', 'Use boxes on left to show...', callback = self.updateGraph, tooltip = "Show small boxes at left (or top) edge of cells to represent additional information.")
        indBox = OWGUI.indentedBox(self.box8, sep=OWGUI.checkButtonOffsetHint(cb))
        OWGUI.comboBox(indBox, self, 'showAprioriDistributionBoxes', items = self.subboxesOpts, tooltip = "Show additional boxes for each mosaic cell representing:\n - expected class distribution (assuming independence between attributes)\n - apriori class distribution (based on all examples).", callback = self.updateGraph)

        hbox = OWGUI.widgetBox(self.SettingsTab, "Colors", addSpace = 1)
        OWGUI.button(hbox, self, "Set Colors", self.setColors, tooltip = "Set the color palette for class values", debuggingEnabled = 0)

        #self.box6.setSizePolicy(QSizePolicy(QSizePolicy.Minimum , QSizePolicy.Fixed ))
        self.SettingsTab.layout().addStretch(1)

        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveToFileCanvas)
        self.icons = self.createAttributeIconDict()
        self.resize(830, 550)

        self.VizRankLearner = MosaicTreeLearner(self.optimizationDlg)
        self.send("Learner", self.VizRankLearner)

        self.wdChildDialogs = [self.optimizationDlg]        # used when running widget debugging

        self.collapsableWBox.updateControls()
        dlg = self.createColorDialog()
        self.colorPalette = dlg.getDiscretePalette("discPalette")
        self.selectionColorPalette = [QColor(*col) for col in OWColorPalette.defaultRGBColors]
Ejemplo n.º 27
0
    def __init__(self, parent=None, signalManager=None, name='TreeViewer2D'):
        OWWidget.__init__(self, parent, signalManager, name, wantGraph=True)
        self.root = None
        self.selectedNode = None

        self.inputs = [("Classification Tree",
                        Orange.classification.tree.TreeClassifier, self.ctree)]
        self.outputs = [("Examples", ExampleTable)]

        #set default settings
        self.ZoomAutoRefresh = 0
        self.AutoArrange = 0
        self.ToolTipsEnabled = 1
        self.MaxTreeDepth = 5
        self.MaxTreeDepthB = 0
        self.LineWidth = 5
        self.LineWidthMethod = 2
        self.NodeSize = 5
        self.MaxNodeWidth = 150
        self.LimitNodeWidth = True
        self.NodeInfo = [0, 1]

        self.Zoom = 5
        self.VSpacing = 5
        self.HSpacing = 5
        self.TruncateText = 1

        self.loadSettings()
        self.NodeInfo.sort()

        # Changed when the GUI was simplified - added here to override any saved settings
        self.VSpacing = 1
        self.HSpacing = 1
        self.ToolTipsEnabled = 1
        self.LineWidth = 15  # Also reset when the LineWidthMethod is changed!

        # GUI definition
        #        self.tabs = OWGUI.tabWidget(self.controlArea)

        # GENERAL TAB
        # GeneralTab = OWGUI.createTabPage(self.tabs, "General")
        #        GeneralTab = TreeTab = OWGUI.createTabPage(self.tabs, "Tree")
        #        NodeTab = OWGUI.createTabPage(self.tabs, "Node")

        GeneralTab = NodeTab = TreeTab = self.controlArea

        self.infBox = OWGUI.widgetBox(GeneralTab,
                                      'Info',
                                      sizePolicy=QSizePolicy(
                                          QSizePolicy.Minimum,
                                          QSizePolicy.Fixed),
                                      addSpace=True)
        self.infoa = OWGUI.widgetLabel(self.infBox, 'No tree.')
        self.infob = OWGUI.widgetLabel(self.infBox, " ")

        self.sizebox = OWGUI.widgetBox(GeneralTab, "Size", addSpace=True)
        OWGUI.hSlider(self.sizebox,
                      self,
                      'Zoom',
                      label='Zoom',
                      minValue=1,
                      maxValue=10,
                      step=1,
                      callback=self.toggleZoomSlider,
                      ticks=1)
        OWGUI.separator(self.sizebox)

        cb, sb = OWGUI.checkWithSpin(self.sizebox,
                                     self,
                                     "Max node width:",
                                     50,
                                     200,
                                     "LimitNodeWidth",
                                     "MaxNodeWidth",
                                     tooltip="Limit the width of tree nodes",
                                     checkCallback=self.toggleNodeSize,
                                     spinCallback=self.toggleNodeSize,
                                     step=10)
        b = OWGUI.checkBox(OWGUI.indentedBox(
            self.sizebox, sep=OWGUI.checkButtonOffsetHint(cb)),
                           self,
                           "TruncateText",
                           "Truncate text",
                           callback=self.toggleTruncateText)
        cb.disables.append(b)
        cb.makeConsistent()

        OWGUI.checkWithSpin(self.sizebox,
                            self,
                            'Max tree depth:',
                            1,
                            20,
                            'MaxTreeDepthB',
                            "MaxTreeDepth",
                            tooltip='Defines the depth of the tree displayed',
                            checkCallback=self.toggleTreeDepth,
                            spinCallback=self.toggleTreeDepth)

        self.edgebox = OWGUI.widgetBox(GeneralTab,
                                       "Edge Widths",
                                       addSpace=True)
        OWGUI.comboBox(self.edgebox,
                       self,
                       'LineWidthMethod',
                       items=['Equal width', 'Root node', 'Parent node'],
                       callback=self.toggleLineWidth)
        # Node information
        grid = QGridLayout()
        grid.setContentsMargins(
            *self.controlArea.layout().getContentsMargins())

        navButton = OWGUI.button(self.controlArea,
                                 self,
                                 "Navigator",
                                 self.toggleNavigator,
                                 debuggingEnabled=0,
                                 addToLayout=False)
        #        findbox = OWGUI.widgetBox(self.controlArea, orientation = "horizontal")
        self.centerRootButton=OWGUI.button(self.controlArea, self, "Find Root", addToLayout=False,
                                           callback=lambda :self.rootNode and \
                                           self.sceneView.centerOn(self.rootNode.x(), self.rootNode.y()))
        self.centerNodeButton=OWGUI.button(self.controlArea, self, "Find Selected", addToLayout=False,
                                           callback=lambda :self.selectedNode and \
                                           self.sceneView.centerOn(self.selectedNode.scenePos()))
        grid.addWidget(navButton, 0, 0, 1, 2)
        grid.addWidget(self.centerRootButton, 1, 0)
        grid.addWidget(self.centerNodeButton, 1, 1)
        self.leftWidgetPart.layout().insertLayout(1, grid)

        self.NodeTab = NodeTab
        self.TreeTab = TreeTab
        self.GeneralTab = GeneralTab
        #        OWGUI.rubber(NodeTab)
        self.rootNode = None
        self.tree = None
        self.resize(800, 500)

        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveGraph)
Ejemplo n.º 28
0
    def __init__(self, parent = None, signalManager = None, name = "Pade"):
        OWWidget.__init__(self, parent, signalManager, name, wantMainArea = 0)  #initialize base class
        self.inputs = [("Data", ExampleTable, self.onDataInput)]
        self.outputs = [("Data", ExampleTable)]

        self.attributes = []
        self.dimensions = []
        self.output = 0
        self.outputAttr = 0
        self.derivativeAsMeta = 0
        self.savedDerivativeAsMeta = 0
        self.correlationsAsMeta = 1
        self.differencesAsMeta = 1
        self.originalAsMeta = 1
        self.enableThreshold = 0
        self.threshold = 0.0
        self.method = 2
        self.useMQCNotation = False
        #self.persistence = 40

        self.nNeighbours = 30

        self.loadSettings()

        box = OWGUI.widgetBox(self.controlArea, "Attributes") #, addSpace = True)
        lb = self.lb = OWGUI.listBox(box, self, "dimensions", "attributes", selectionMode=QListWidget.MultiSelection, callback=self.dimensionsChanged)
        hbox = OWGUI.widgetBox(box, orientation=0)
        OWGUI.button(hbox, self, "All", callback=self.onAllAttributes)
        OWGUI.button(hbox, self, "None", callback=self.onNoAttributes)
        lb.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding))
        lb.setMinimumSize(200, 200)
        
        OWGUI.separator(self.controlArea)

        box = OWGUI.widgetBox(self.controlArea, "Method") #, addSpace = True)
        OWGUI.comboBox(box, self, "method", callback = self.methodChanged, items = self.methodNames)
#        self.nNeighboursSpin = OWGUI.spin(box, self, "nNeighbours", 10, 200, 10, label = "Number of neighbours" + "  ", callback = self.methodChanged)
        #self.persistenceSpin = OWGUI.spin(box, self, "persistence", 0, 100, 5, label = "Persistence (0-100)" + "  ", callback = self.methodChanged, controlWidth=50)

        OWGUI.separator(box)
        hbox = OWGUI.widgetBox(box, orientation=0)
        threshCB = OWGUI.checkBox(hbox, self, "enableThreshold", "Ignore differences below ")
#        OWGUI.rubber(hbox, orientation = 0)
        ledit = OWGUI.lineEdit(hbox, self, "threshold", valueType=float, validator=QDoubleValidator(0, 1e30, 0, self), controlWidth=50)
        threshCB.disables.append(ledit)
        threshCB.makeConsistent()
        OWGUI.checkBox(box, self, "useMQCNotation", label = "Use MQC notation")

        OWGUI.separator(self.controlArea)
        
        box = OWGUI.radioButtonsInBox(self.controlArea, self, "output", self.outputTypes, box="Output class", callback=self.dimensionsChanged)
        self.outputLB = OWGUI.comboBox(OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(box.buttons[-1])), self, "outputAttr", callback=self.outputDiffChanged)
        
        OWGUI.separator(self.controlArea)
        
        box = OWGUI.widgetBox(self.controlArea, "Output meta attributes") #, addSpace = True)
        self.metaCB = OWGUI.checkBox(box, self, "derivativeAsMeta", label="Qualitative constraint")
        OWGUI.checkBox(box, self, "differencesAsMeta", label="Derivatives of selected attributes")
        OWGUI.checkBox(box, self, "correlationsAsMeta", label="Absolute values of derivatives")
        OWGUI.checkBox(box, self, "originalAsMeta", label="Original class attribute")

        self.applyButton = OWGUI.button(self.controlArea, self, "&Apply", callback=self.apply, disabled=True, default=True)
        
        self.contAttributes = []
        self.dimensions = []
        self.data = None
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "Nomogram", 1)

        #self.setWFlags(Qt.WResizeNoErase | Qt.WRepaintNoErase) #this works like magic.. no flicker during repaint!
        self.parent = parent
        #        self.setWFlags(self.getWFlags()+Qt.WStyle_Maximize)

        self.callbackDeposit = []  # deposit for OWGUI callback functions
        self.alignType = 0
        self.contType = 0
        self.yAxis = 0
        self.probability = 0
        self.verticalSpacing = 60
        self.verticalSpacingContinuous = 100
        self.diff_between_ordinal = 30
        self.fontSize = 9
        self.lineWidth = 1
        self.histogram = 0
        self.histogram_size = 10
        self.data = None
        self.cl = None
        self.confidence_check = 0
        self.confidence_percent = 95
        self.sort_type = 0

        self.loadSettings()

        self.pointsName = ["Total", "Total"]
        self.totalPointsName = ["Probability", "Probability"]
        self.bnomogram = None

        self.inputs = [("Classifier", orange.Classifier, self.classifier)]

        self.TargetClassIndex = 0
        self.targetCombo = OWGUI.comboBox(
            self.controlArea,
            self,
            "TargetClassIndex",
            " Target Class ",
            addSpace=True,
            tooltip='Select target (prediction) class in the model.',
            callback=self.setTarget)

        self.alignRadio = OWGUI.radioButtonsInBox(
            self.controlArea,
            self,
            'alignType', ['Align left', 'Align by zero influence'],
            box='Attribute placement',
            tooltips=[
                'Attributes in nomogram are left aligned',
                'Attributes are not aligned, top scale represents true (normalized) regression coefficient value'
            ],
            addSpace=True,
            callback=self.showNomogram)
        self.verticalSpacingLabel = OWGUI.spin(
            self.alignRadio,
            self,
            'verticalSpacing',
            15,
            200,
            label='Vertical spacing:',
            orientation=0,
            tooltip='Define space (pixels) between adjacent attributes.',
            callback=self.showNomogram)

        self.ContRadio = OWGUI.radioButtonsInBox(
            self.controlArea,
            self,
            'contType', ['1D projection', '2D curve'],
            'Continuous attributes',
            tooltips=[
                'Continuous attribute are presented on a single scale',
                'Two dimensional space is used to present continuous attributes in nomogram.'
            ],
            addSpace=True,
            callback=[
                lambda: self.verticalSpacingContLabel.setDisabled(
                    not self.contType), self.showNomogram
            ])

        self.verticalSpacingContLabel = OWGUI.spin(
            OWGUI.indentedBox(self.ContRadio,
                              sep=OWGUI.checkButtonOffsetHint(
                                  self.ContRadio.buttons[-1])),
            self,
            'verticalSpacingContinuous',
            15,
            200,
            label="Height",
            orientation=0,
            tooltip=
            'Define space (pixels) between adjacent 2d presentation of attributes.',
            callback=self.showNomogram)
        self.verticalSpacingContLabel.setDisabled(not self.contType)

        self.yAxisRadio = OWGUI.radioButtonsInBox(
            self.controlArea,
            self,
            'yAxis', ['Point scale', 'Log odds ratios'],
            'Scale',
            tooltips=[
                'values are normalized on a 0-100 point scale',
                'values on top axis show log-linear contribution of attribute to full model'
            ],
            addSpace=True,
            callback=self.showNomogram)

        layoutBox = OWGUI.widgetBox(self.controlArea,
                                    "Display",
                                    orientation=1,
                                    addSpace=True)

        self.probabilityCheck = OWGUI.checkBox(layoutBox,
                                               self,
                                               'probability',
                                               'Show prediction',
                                               tooltip='',
                                               callback=self.setProbability)

        self.CICheck, self.CILabel = OWGUI.checkWithSpin(
            layoutBox,
            self,
            'Confidence intervals (%):',
            min=1,
            max=99,
            step=1,
            checked='confidence_check',
            value='confidence_percent',
            checkCallback=self.showNomogram,
            spinCallback=self.showNomogram)

        self.histogramCheck, self.histogramLabel = OWGUI.checkWithSpin(
            layoutBox,
            self,
            'Show histogram, size',
            min=1,
            max=30,
            checked='histogram',
            value='histogram_size',
            step=1,
            tooltip='-(TODO)-',
            checkCallback=self.showNomogram,
            spinCallback=self.showNomogram)

        OWGUI.separator(layoutBox)
        self.sortOptions = [
            "No sorting", "Absolute importance", "Positive influence",
            "Negative influence"
        ]
        self.sortBox = OWGUI.comboBox(layoutBox,
                                      self,
                                      "sort_type",
                                      label="Sort by ",
                                      items=self.sortOptions,
                                      callback=self.sortNomogram,
                                      orientation="horizontal")

        OWGUI.rubber(self.controlArea)

        self.connect(self.graphButton, SIGNAL("clicked()"),
                     self.menuItemPrinter)

        #add a graph widget
        self.header = OWNomogramHeader(None, self.mainArea)
        self.header.setFixedHeight(60)
        self.header.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.header.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.graph = OWNomogramGraph(self.bnomogram, self.mainArea)
        self.graph.setMinimumWidth(200)
        self.graph.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.footer = OWNomogramHeader(None, self.mainArea)
        self.footer.setFixedHeight(60 * 2 + 10)
        self.footer.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.footer.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.mainArea.layout().addWidget(self.header)
        self.mainArea.layout().addWidget(self.graph)
        self.mainArea.layout().addWidget(self.footer)
        self.resize(700, 500)
        #self.repaint()
        #self.update()

        # mouse pressed flag
        self.mousepr = False
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'SampleData', wantMainArea = 0)

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data Sample", ExampleTable), ("Remaining Data", ExampleTable)]

        # initialization of variables
        self.data = None                        # dataset (incoming stream)
        self.indices = None                     # indices that control sampling
        self.ind = None                         # indices that control sampling

        self.Stratified = 1                     # use stratified sampling if possible?
        self.Repeat = 0                         # can elements repeat in a sample?
        self.UseSpecificSeed = 0                # use a specific random seed?
        self.RandomSeed = 1                     # specific seed used
        self.GroupSeed = 1                      # current seed for multiple group selection
        self.outFold = 1                        # folder/group to output
        self.Folds = 1                          # total number of folds/groups

        self.SelectType = 0                     # sampling type (LOO, CV, ...)
        self.useCases = 0                       # use a specific number of cases?
        self.nCases = 25                        # number of cases to use
        self.selPercentage = 30                 # sample size in %
        self.LOO = 1                            # use LOO?
        self.CVFolds = 10                       # number of CV folds
        self.CVFoldsInternal = 10               # number of CV folds (for internal use)
        self.nGroups = 3                        # number of groups
        self.pGroups = [0.1,0.25,0.5]           # sizes of groups
        self.GroupText = '0.1,0.25,0.5'         # assigned to Groups Control (for internal use)

        self.loadSettings()
        # GUI
        
        # Info Box
        box1 = OWGUI.widgetBox(self.controlArea, "Information", addSpace=True)
        self.infoa = OWGUI.widgetLabel(box1, 'No data on input.')
        self.infob = OWGUI.widgetLabel(box1, ' ')
        self.infoc = OWGUI.widgetLabel(box1, ' ')
        
        # Options Box
        box2 = OWGUI.widgetBox(self.controlArea, 'Options', addSpace=True)
        OWGUI.checkBox(box2, self, 'Stratified', 'Stratified (if possible)', callback=self.settingsChanged)
        OWGUI.checkWithSpin(box2, self, 'Set random seed:', 0, 32767, 'UseSpecificSeed', 'RandomSeed', checkCallback=self.settingsChanged, spinCallback=self.settingsChanged)

        # Sampling Type Box
        self.s = [None, None, None, None]
        self.sBox = OWGUI.widgetBox(self.controlArea, "Sampling type", addSpace=True)
        self.sBox.buttons = []

        # Random Sampling
        self.s[0] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", 'Random sampling')
        
        # indent 
        indent = sep=OWGUI.checkButtonOffsetHint(self.s[0])
        # repeat checkbox
        self.h1Box = OWGUI.indentedBox(self.sBox, sep=indent, orientation = "horizontal")
        OWGUI.checkBox(self.h1Box, self, 'Repeat', 'With replacement', callback=self.settingsChanged)

        # specified number of elements checkbox
        self.h2Box = OWGUI.indentedBox(self.sBox, sep=indent, orientation = "horizontal")
        OWGUI.checkWithSpin(self.h2Box, self, 'Sample size (instances):', 1, 1000000000, 'useCases', 'nCases', checkCallback=[self.uCases, self.settingsChanged], spinCallback=self.settingsChanged)
        OWGUI.rubber(self.h2Box)
        
        # percentage slider
        self.h3Box = OWGUI.indentedBox(self.sBox, sep=indent, orientation = "horizontal")
        OWGUI.widgetLabel(self.h3Box, "Sample size:")
        self.slidebox = OWGUI.indentedBox(self.sBox, sep=indent, orientation = "horizontal")
        OWGUI.hSlider(self.slidebox, self, 'selPercentage', minValue=1, maxValue=100, step=1, ticks=10, labelFormat="   %d%%", callback=self.settingsChanged)

        # Cross Validation
        self.s[1] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", 'Cross validation')
        
        box = OWGUI.indentedBox(self.sBox, sep=indent, orientation = "horizontal")
        OWGUI.spin(box, self, 'CVFolds', 2, 100, step=1, label='Number of folds:  ', callback=[self.changeCombo, self.settingsChanged])
        OWGUI.rubber(box)

        # Leave-One-Out
        self.s[2] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", 'Leave-one-out')

        # Multiple Groups
        self.s[3] = OWGUI.appendRadioButton(self.sBox, self, "SelectType", 'Multiple subsets')
        gbox = OWGUI.indentedBox(self.sBox, sep=indent, orientation = "horizontal")
        OWGUI.lineEdit(gbox, self, 'GroupText', label='Subset sizes (e.g. "0.1, 0.2, 0.5"):', callback=self.multipleChanged)

        # Output Group Box
        self.foldcombo = OWGUI.comboBox(self.controlArea, self, "outFold", 'Output Data for Fold / Group', 'Fold / group:', orientation = "horizontal", items = range(1,101), callback = self.foldChanged, sendSelectedValue = 1, valueType = int)
        self.foldcombo.setEnabled(False)

        # Select Data Button
        OWGUI.rubber(self.controlArea)
        self.sampleButton = OWGUI.button(self.controlArea, self, 'Sample &Data', callback = self.process, addToLayout=False, default=True)
        self.buttonBackground.layout().setDirection(QBoxLayout.TopToBottom)
        self.buttonBackground.layout().insertWidget(0, self.sampleButton)
        self.buttonBackground.show()
        self.s[self.SelectType].setChecked(True)    # set initial radio button on (default sample type)

        # CONNECTIONS
        # set connections for RadioButton (SelectType)
        self.dummy1 = [None]*len(self.s)
        for i in range(len(self.s)):
            self.dummy1[i] = lambda x, v=i: self.sChanged(x, v)
            self.connect(self.s[i], SIGNAL("toggled(bool)"), self.dummy1[i])

        # final touch
        self.resize(200, 275)
Ejemplo n.º 31
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self,
                          parent,
                          signalManager,
                          'Hierarchical Clustering',
                          wantGraph=True)

        self.inputs = [("Distances", Orange.misc.SymMatrix, self.set_matrix)]

        self.outputs = [("Selected Data", Orange.data.Table),
                        ("Other Data", Orange.data.Table),
                        ("Centroids", Orange.data.Table)]

        self.linkage = [
            ("Single linkage", hierarchical.HierarchicalClustering.Single),
            ("Average linkage", hierarchical.HierarchicalClustering.Average),
            ("Ward's linkage", hierarchical.HierarchicalClustering.Ward),
            ("Complete linkage", hierarchical.HierarchicalClustering.Complete),
        ]

        self.Linkage = 3
        self.Annotation = 0
        self.PrintDepthCheck = 0
        self.PrintDepth = 10
        # initial horizontal and vertical dendrogram size
        self.HDSize = 500
        self.VDSize = 800
        self.ManualHorSize = 0
        self.AutoResize = 0
        self.TextSize = 8
        self.LineSpacing = 4
        self.SelectionMode = 0
        self.AppendClusters = 0
        self.CommitOnChange = 0
        self.ClassifyName = "HC_class"
        self.addIdAs = 0

        self.loadSettings()

        self.inputMatrix = None
        self.root_cluster = None
        self.selectedExamples = None

        self.selectionChanged = False

        self.linkageMethods = [a[0] for a in self.linkage]

        #################################
        ##GUI
        #################################

        #HC Settings
        OWGUI.comboBox(self.controlArea,
                       self,
                       "Linkage",
                       box="Linkage",
                       items=self.linkageMethods,
                       tooltip="Choose linkage method",
                       callback=self.run_clustering,
                       addSpace=True)
        #Label
        box = OWGUI.widgetBox(self.controlArea, "Annotation", addSpace=True)
        self.labelCombo = OWGUI.comboBox(box,
                                         self,
                                         "Annotation",
                                         items=["None"],
                                         tooltip="Choose label attribute",
                                         callback=self.update_labels)

        OWGUI.spin(box,
                   self,
                   "TextSize",
                   label="Text size",
                   min=5,
                   max=15,
                   step=1,
                   callback=self.update_font,
                   controlWidth=40,
                   keyboardTracking=False)

        # Dendrogram graphics settings
        dendrogramBox = OWGUI.widgetBox(self.controlArea,
                                        "Limits",
                                        addSpace=True)

        form = QFormLayout()
        form.setLabelAlignment(Qt.AlignLeft)

        # Depth settings
        sw = OWGUI.widgetBox(dendrogramBox,
                             orientation="horizontal",
                             addToLayout=False)
        cw = OWGUI.widgetBox(dendrogramBox,
                             orientation="horizontal",
                             addToLayout=False)

        OWGUI.hSlider(sw,
                      self,
                      "PrintDepth",
                      minValue=1,
                      maxValue=50,
                      callback=self.on_depth_change)

        cblp = OWGUI.checkBox(cw,
                              self,
                              "PrintDepthCheck",
                              "Show to depth",
                              callback=self.on_depth_change,
                              disables=[sw])
        form.addRow(cw, sw)

        checkWidth = OWGUI.checkButtonOffsetHint(cblp)

        # Width settings
        sw = OWGUI.widgetBox(dendrogramBox,
                             orientation="horizontal",
                             addToLayout=False)
        cw = OWGUI.widgetBox(dendrogramBox,
                             orientation="horizontal",
                             addToLayout=False)

        hsb = OWGUI.spin(sw,
                         self,
                         "HDSize",
                         min=200,
                         max=10000,
                         step=10,
                         callback=self.on_width_changed,
                         callbackOnReturn=False,
                         keyboardTracking=False)

        OWGUI.checkBox(cw,
                       self,
                       "ManualHorSize",
                       "Horizontal size",
                       callback=self.on_width_changed,
                       disables=[sw])

        sw.setEnabled(self.ManualHorSize)

        self.hSizeBox = hsb
        form.addRow(cw, sw)
        dendrogramBox.layout().addLayout(form)

        # Selection settings
        box = OWGUI.widgetBox(self.controlArea, "Selection")
        OWGUI.checkBox(box,
                       self,
                       "SelectionMode",
                       "Show cutoff line",
                       callback=self.update_cutoff_line)

        cb = OWGUI.checkBox(box,
                            self,
                            "AppendClusters",
                            "Append cluster IDs",
                            callback=self.commit_data_if)

        self.classificationBox = ib = OWGUI.widgetBox(box, margin=0)

        form = QWidget()
        le = OWGUI.lineEdit(form,
                            self,
                            "ClassifyName",
                            None,
                            callback=None,
                            orientation="horizontal")
        self.connect(le, SIGNAL("editingFinished()"), self.commit_data_if)

        aa = OWGUI.comboBox(
            form,
            self,
            "addIdAs",
            label=None,
            orientation="horizontal",
            items=["Class attribute", "Attribute", "Meta attribute"],
            callback=self.commit_data_if)

        layout = QFormLayout()
        layout.setSpacing(8)
        layout.setContentsMargins(0, 5, 0, 5)
        layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
        layout.setLabelAlignment(Qt.AlignLeft)
        layout.addRow("Name  ", le)
        layout.addRow("Place  ", aa)

        form.setLayout(layout)

        ib.layout().addWidget(form)
        ib.layout().setContentsMargins(checkWidth, 5, 5, 5)

        cb.disables.append(ib)
        cb.makeConsistent()

        OWGUI.separator(box)
        cbAuto = OWGUI.checkBox(box, self, "CommitOnChange",
                                "Commit on change")
        btCommit = OWGUI.button(box,
                                self,
                                "&Commit",
                                self.commit_data,
                                default=True)
        OWGUI.setStopper(self, btCommit, cbAuto, "selectionChanged",
                         self.commit_data)

        OWGUI.rubber(self.controlArea)
        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveGraph)

        self.scale_scene = scale = ScaleScene(self, self)
        self.headerView = ScaleView(scale, self)
        self.footerView = ScaleView(scale, self)

        self.dendrogram = DendrogramScene(self)
        self.dendrogramView = DendrogramView(self.dendrogram, self.mainArea)

        self.connect(self.dendrogram, SIGNAL("clusterSelectionChanged()"),
                     self.on_selection_change)

        self.connect(self.dendrogram, SIGNAL("sceneRectChanged(QRectF)"),
                     scale.scene_rect_update)

        self.connect(self.dendrogram,
                     SIGNAL("dendrogramGeometryChanged(QRectF)"),
                     self.on_dendrogram_geometry_change)

        self.connect(self.dendrogram, SIGNAL("cutoffValueChanged(float)"),
                     self.on_cuttof_value_changed)

        self.connect(self.dendrogramView, SIGNAL("viewportResized(QSize)"),
                     self.on_width_changed)

        self.connect(self.dendrogramView,
                     SIGNAL("transformChanged(QTransform)"),
                     self.headerView.setTransform)
        self.connect(self.dendrogramView,
                     SIGNAL("transformChanged(QTransform)"),
                     self.footerView.setTransform)

        self.mainArea.layout().addWidget(self.headerView)
        self.mainArea.layout().addWidget(self.dendrogramView)
        self.mainArea.layout().addWidget(self.footerView)

        self.dendrogram.header = self.headerView
        self.dendrogram.footer = self.footerView

        self.connect(self.dendrogramView.horizontalScrollBar(),
                     SIGNAL("valueChanged(int)"),
                     self.footerView.horizontalScrollBar().setValue)

        self.connect(self.dendrogramView.horizontalScrollBar(),
                     SIGNAL("valueChanged(int)"),
                     self.headerView.horizontalScrollBar().setValue)

        self.dendrogram.setSceneRect(0, 0, self.HDSize, self.VDSize)
        self.dendrogram.update()
        self.resize(800, 500)

        self.natural_dendrogram_width = 800
        self.dendrogramView.set_fit_to_width(not self.ManualHorSize)

        self.matrix = None
        self.selectionList = []
        self.selected_clusters = []
Ejemplo n.º 32
0
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Nomogram", 1)

        #self.setWFlags(Qt.WResizeNoErase | Qt.WRepaintNoErase) #this works like magic.. no flicker during repaint!
        self.parent = parent
#        self.setWFlags(self.getWFlags()+Qt.WStyle_Maximize)

        self.callbackDeposit = [] # deposit for OWGUI callback functions
        self.alignType = 0
        self.contType = 0
        self.yAxis = 0
        self.probability = 0
        self.verticalSpacing = 60
        self.verticalSpacingContinuous = 100
        self.diff_between_ordinal = 30
        self.fontSize = 9
        self.lineWidth = 1
        self.histogram = 0
        self.histogram_size = 10
        self.data = None
        self.cl = None
        self.confidence_check = 0
        self.confidence_percent = 95
        self.sort_type = 0

        self.loadSettings()

        self.pointsName = ["Total", "Total"]
        self.totalPointsName = ["Probability", "Probability"]
        self.bnomogram = None


        self.inputs=[("Classifier", orange.Classifier, self.classifier)]


        self.TargetClassIndex = 0
        self.targetCombo = OWGUI.comboBox(self.controlArea, self, "TargetClassIndex", " Target Class ", addSpace=True, tooltip='Select target (prediction) class in the model.', callback = self.setTarget)

        self.alignRadio = OWGUI.radioButtonsInBox(self.controlArea, self,  'alignType', ['Align left', 'Align by zero influence'], box='Attribute placement',
                                                  tooltips=['Attributes in nomogram are left aligned', 'Attributes are not aligned, top scale represents true (normalized) regression coefficient value'],
                                                  addSpace=True,
                                                  callback=self.showNomogram)
        self.verticalSpacingLabel = OWGUI.spin(self.alignRadio, self, 'verticalSpacing', 15, 200, label = 'Vertical spacing:',  orientation = 0, tooltip='Define space (pixels) between adjacent attributes.', callback = self.showNomogram)

        self.ContRadio = OWGUI.radioButtonsInBox(self.controlArea, self, 'contType',   ['1D projection', '2D curve'], 'Continuous attributes',
                                tooltips=['Continuous attribute are presented on a single scale', 'Two dimensional space is used to present continuous attributes in nomogram.'],
                                addSpace=True,
                                callback=[lambda:self.verticalSpacingContLabel.setDisabled(not self.contType), self.showNomogram])

        self.verticalSpacingContLabel = OWGUI.spin(OWGUI.indentedBox(self.ContRadio, sep=OWGUI.checkButtonOffsetHint(self.ContRadio.buttons[-1])), self, 'verticalSpacingContinuous', 15, 200, label = "Height", orientation=0, tooltip='Define space (pixels) between adjacent 2d presentation of attributes.', callback = self.showNomogram)
        self.verticalSpacingContLabel.setDisabled(not self.contType)

        self.yAxisRadio = OWGUI.radioButtonsInBox(self.controlArea, self, 'yAxis', ['Point scale', 'Log odds ratios'], 'Scale',
                                tooltips=['values are normalized on a 0-100 point scale','values on top axis show log-linear contribution of attribute to full model'],
                                addSpace=True,
                                callback=self.showNomogram)

        layoutBox = OWGUI.widgetBox(self.controlArea, "Display", orientation=1, addSpace=True)

        self.probabilityCheck = OWGUI.checkBox(layoutBox, self, 'probability', 'Show prediction',  tooltip='', callback = self.setProbability)

        self.CICheck, self.CILabel = OWGUI.checkWithSpin(layoutBox, self, 'Confidence intervals (%):', min=1, max=99, step = 1, checked='confidence_check', value='confidence_percent', checkCallback=self.showNomogram, spinCallback = self.showNomogram)

        self.histogramCheck, self.histogramLabel = OWGUI.checkWithSpin(layoutBox, self, 'Show histogram, size', min=1, max=30, checked='histogram', value='histogram_size', step = 1, tooltip='-(TODO)-', checkCallback=self.showNomogram, spinCallback = self.showNomogram)

        OWGUI.separator(layoutBox)
        self.sortOptions = ["No sorting", "Absolute importance", "Positive influence", "Negative influence"]
        self.sortBox = OWGUI.comboBox(layoutBox, self, "sort_type", label="Sort by ", items=self.sortOptions, callback = self.sortNomogram, orientation="horizontal")


        OWGUI.rubber(self.controlArea)

        self.connect(self.graphButton, SIGNAL("clicked()"), self.menuItemPrinter)



        #add a graph widget
        self.header = OWNomogramHeader(None, self.mainArea)
        self.header.setFixedHeight(60)
        self.header.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.header.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.graph = OWNomogramGraph(self.bnomogram, self.mainArea)
        self.graph.setMinimumWidth(200)
        self.graph.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.footer = OWNomogramHeader(None, self.mainArea)
        self.footer.setFixedHeight(60*2+10)
        self.footer.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.footer.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.mainArea.layout().addWidget(self.header)
        self.mainArea.layout().addWidget(self.graph)
        self.mainArea.layout().addWidget(self.footer)
        self.resize(700,500)
        #self.repaint()
        #self.update()

        # mouse pressed flag
        self.mousepr = False
Ejemplo n.º 33
0
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Mosaic display", True, True)

        #set default settings
        self.data = None
        self.unprocessedSubsetData = None
        self.subsetData = None
        self.names = []     # class values

        self.inputs = [("Data", ExampleTable, self.setData, Default), ("Data Subset", ExampleTable, self.setSubsetData)]
        self.outputs = [("Selected Data", ExampleTable), ("Learner", orange.Learner)]

        #load settings
        self.colorSettings = None
        self.selectedSchemaIndex = 0
        self.interiorColoring = 0
        self.cellspace = 4
        self.showAprioriDistributionBoxes = 1
        self.useBoxes = 1
        self.showSubsetDataBoxes = 1
        self.horizontalDistribution = 0
        self.showAprioriDistributionLines = 0
        self.boxSize = 5
        self.exploreAttrPermutations = 0
        self.attr1 = ""
        self.attr2 = ""
        self.attr3 = ""
        self.attr4 = ""

        self.attributeNameOffset = 30
        self.attributeValueOffset = 15
        self.residuals = [] # residual values if the residuals are visualized
        self.aprioriDistributions = []
        self.colorPalette = None
        self.permutationDict = {}
        self.manualAttributeValuesDict = {}
        self.conditionalDict = None
        self.conditionalSubsetDict = None
        self.activeRule = None
        self.removeUnusedValues = 0

        self.selectionRectangle = None
        self.selectionConditionsHistorically = []
        self.selectionConditions = []

        # color paletes for visualizing pearsons residuals
        #self.blueColors = [QColor(255, 255, 255), QColor(117, 149, 255), QColor(38, 43, 232), QColor(1,5,173)]
        self.blueColors = [QColor(255, 255, 255), QColor(210, 210, 255), QColor(110, 110, 255), QColor(0,0,255)]
        self.redColors = [QColor(255, 255, 255), QColor(255, 200, 200), QColor(255, 100, 100), QColor(255, 0, 0)]

        self.loadSettings()

        self.tabs = OWGUI.tabWidget(self.controlArea)
        self.GeneralTab = OWGUI.createTabPage(self.tabs, "Main")
        self.SettingsTab = OWGUI.createTabPage(self.tabs, "Settings")

        self.canvas = QGraphicsScene()
        self.canvasView = MosaicSceneView(self, self.canvas, self.mainArea)
        self.mainArea.layout().addWidget(self.canvasView)
        self.canvasView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.canvasView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.canvasView.setRenderHint(QPainter.Antialiasing)
        #self.canvasView.setAlignment(Qt.AlignLeft | Qt.AlignTop)

        #GUI
        #add controls to self.controlArea widget
        #self.controlArea.setMinimumWidth(235)

        texts = ["1st Attribute", "2nd Attribute", "3rd Attribute", "4th Attribute"]
        for i in range(1,5):
            box = OWGUI.widgetBox(self.GeneralTab, texts[i-1], orientation = "horizontal")
            combo = OWGUI.comboBox(box, self, "attr" + str(i), None, callback = self.updateGraphAndPermList, sendSelectedValue = 1, valueType = str)

            butt = OWGUI.button(box, self, "", callback = self.orderAttributeValues, tooltip = "Change the order of attribute values", debuggingEnabled = 0)
            butt.setFixedSize(26, 24)
            butt.setCheckable(1)
            butt.setIcon(QIcon(os.path.join(self.widgetDir, "icons/Dlg_sort.png")))

            setattr(self, "sort"+str(i), butt)
            setattr(self, "attr" + str(i)+ "Combo", combo)

        self.optimizationDlg = OWMosaicOptimization(self, self.signalManager)

        optimizationButtons = OWGUI.widgetBox(self.GeneralTab, "Dialogs", orientation = "horizontal")
        OWGUI.button(optimizationButtons, self, "VizRank", callback = self.optimizationDlg.reshow, debuggingEnabled = 0, tooltip = "Find attribute combinations that will separate different classes as clearly as possible.")

        self.collapsableWBox = OWGUI.collapsableWidgetBox(self.GeneralTab, "Explore Attribute Permutations", self, "exploreAttrPermutations", callback = self.permutationListToggle)
        self.permutationList = OWGUI.listBox(self.collapsableWBox, self, callback = self.setSelectedPermutation)
        #self.permutationList.hide()
        self.GeneralTab.layout().addStretch(100)

        # ######################
        # SETTINGS TAB
        # ######################
        box5 = OWGUI.widgetBox(self.SettingsTab, "Colors in Cells Represent...", addSpace = 1)
        OWGUI.comboBox(box5, self, "interiorColoring", None, items = self.interiorColoringOpts, callback = self.updateGraph)
        #box5.setSizePolicy(QSizePolicy(QSizePolicy.Minimum , QSizePolicy.Fixed ))

        box = OWGUI.widgetBox(self.SettingsTab, "Visual Settings", addSpace = 1)
        
        OWGUI.hSlider(box, self, 'cellspace', label = "Cell distance: ", minValue=1, maxValue=15, step=1, callback = self.updateGraph, tooltip = "What is the minimum distance between two rectangles in the plot?")
        OWGUI.checkBox(box, self, "removeUnusedValues", "Remove unused attribute values", tooltip = "Do you want to remove unused attribute values?\nThis setting will not be considered until new data is received.")

        self.box6 = OWGUI.widgetBox(self.SettingsTab, "Cell Distribution Settings", addSpace = 1)
        OWGUI.comboBox(self.box6, self, 'horizontalDistribution', items = ["Show Distribution Vertically", "Show Distribution Horizontally"], tooltip = "Do you wish to see class distribution drawn horizontally or vertically?", callback = self.updateGraph)
        OWGUI.checkBox(self.box6, self, 'showAprioriDistributionLines', 'Show apriori distribution with lines', callback = self.updateGraph, tooltip = "Show the lines that represent the apriori class distribution")

        self.box8 = OWGUI.widgetBox(self.SettingsTab, "Boxes in Cells", addSpace = 1)
        OWGUI.hSlider(self.box8, self, 'boxSize', label = "Size: ", minValue=1, maxValue=15, step=1, callback = self.updateGraph, tooltip = "What is the size of the boxes on the left and right edge of each cell?")
        OWGUI.checkBox(self.box8, self, 'showSubsetDataBoxes', 'Show class distribution of subset data', callback = self.updateGraph, tooltip = "Show small boxes at right (or bottom) edge of cells to represent class distribution of examples from example subset input.")
        cb = OWGUI.checkBox(self.box8, self, 'useBoxes', 'Use boxes on left to show...', callback = self.updateGraph, tooltip = "Show small boxes at left (or top) edge of cells to represent additional information.")
        indBox = OWGUI.indentedBox(self.box8, sep=OWGUI.checkButtonOffsetHint(cb))
        OWGUI.comboBox(indBox, self, 'showAprioriDistributionBoxes', items = self.subboxesOpts, tooltip = "Show additional boxes for each mosaic cell representing:\n - expected class distribution (assuming independence between attributes)\n - apriori class distribution (based on all examples).", callback = self.updateGraph)

        hbox = OWGUI.widgetBox(self.SettingsTab, "Colors", addSpace = 1)
        OWGUI.button(hbox, self, "Set Colors", self.setColors, tooltip = "Set the color palette for class values", debuggingEnabled = 0)

        #self.box6.setSizePolicy(QSizePolicy(QSizePolicy.Minimum , QSizePolicy.Fixed ))
        self.SettingsTab.layout().addStretch(1)

        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveToFileCanvas)
        self.icons = self.createAttributeIconDict()
        self.resize(830, 550)

        self.VizRankLearner = MosaicTreeLearner(self.optimizationDlg)
        self.send("Learner", self.VizRankLearner)

        self.wdChildDialogs = [self.optimizationDlg]        # used when running widget debugging

        self.collapsableWBox.updateControls()
        dlg = self.createColorDialog()
        self.colorPalette = dlg.getDiscretePalette("discPalette")
        self.selectionColorPalette = [QColor(*col) for col in OWColorPalette.defaultRGBColors]
Ejemplo n.º 34
0
    def __init__(self, parent=None, signalManager=None, name="Interactive Discretization"):
        OWWidget.__init__(self, parent, signalManager, name)
        self.showBaseLine=1
        self.showLookaheadLine=1
        self.showTargetClassProb=1
        self.showRug=0
        self.snap=1
        self.measure=0
        self.targetClass=0
        self.discretization = self.classDiscretization = self.indiDiscretization = 1
        self.intervals = self.classIntervals = self.indiIntervals = 3
        self.outputOriginalClass = True
        self.indiData = []
        self.indiLabels = []
        self.resetIndividuals = 0
        self.customClassSplits = ""

        self.selectedAttr = 0
        self.customSplits = ["", "", ""]
        self.autoApply = True
        self.dataChanged = False
        self.autoSynchronize = True
        self.pointsChanged = False

        self.customLineEdits = []
        self.needsDiscrete = []

        self.data = self.originalData = None

        self.loadSettings()

        self.inputs=[("Data", ExampleTable, self.setData)]
        self.outputs=[("Data", ExampleTable)]
        self.measures=[("Information gain", orange.MeasureAttribute_info()),
                       #("Gain ratio", orange.MeasureAttribute_gainRatio),
                       ("Gini", orange.MeasureAttribute_gini()),
                       ("chi-square", orange.MeasureAttribute_chiSquare()),
                       ("chi-square prob.", orange.MeasureAttribute_chiSquare(computeProbabilities=1)),
                       ("Relevance", orange.MeasureAttribute_relevance()),
                       ("ReliefF", orange.MeasureAttribute_relief())]
        self.discretizationMethods=["Leave continuous", "Entropy-MDL discretization", "Equal-frequency discretization", "Equal-width discretization", "Remove continuous attributes"]
        self.classDiscretizationMethods=["Equal-frequency discretization", "Equal-width discretization"]
        self.indiDiscretizationMethods=["Default", "Leave continuous", "Entropy-MDL discretization", "Equal-frequency discretization", "Equal-width discretization", "Remove attribute"]

        self.mainHBox =  OWGUI.widgetBox(self.mainArea, orientation=0)

        vbox = self.controlArea
        box = OWGUI.radioButtonsInBox(vbox, self, "discretization", self.discretizationMethods[:-1], "Default discretization", callback=[self.clearLineEditFocus, self.defaultMethodChanged])
        self.needsDiscrete.append(box.buttons[1])
        box.setSizePolicy(QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed))
        indent = OWGUI.checkButtonOffsetHint(self.needsDiscrete[-1])
        self.interBox = OWGUI.widgetBox(OWGUI.indentedBox(box, sep=indent))
        OWGUI.widgetLabel(self.interBox, "Number of intervals (for equal width/frequency)")
        OWGUI.separator(self.interBox, height=4)
        self.intervalSlider=OWGUI.hSlider(OWGUI.indentedBox(self.interBox), self, "intervals", None, 2, 10, callback=[self.clearLineEditFocus, self.defaultMethodChanged])
        OWGUI.appendRadioButton(box, self, "discretization", self.discretizationMethods[-1])
        OWGUI.separator(vbox)

        ribg = OWGUI.radioButtonsInBox(vbox, self, "resetIndividuals", ["Use default discretization for all attributes", "Explore and set individual discretizations"], "Individual attribute treatment", callback = self.setAllIndividuals)
        ll = QWidget(ribg)
        ll.setFixedHeight(1)
        OWGUI.widgetLabel(ribg, "Set discretization of all attributes to")
        hcustbox = OWGUI.widgetBox(OWGUI.indentedBox(ribg), 0, 0)
        for c in range(1, 4):
            OWGUI.appendRadioButton(ribg, self, "resetIndividuals", "Custom %i" % c, insertInto = hcustbox)

        OWGUI.separator(vbox)

        box = self.classDiscBox = OWGUI.radioButtonsInBox(vbox, self, "classDiscretization", self.classDiscretizationMethods, "Class discretization", callback=[self.clearLineEditFocus, self.classMethodChanged])
        cinterBox = OWGUI.widgetBox(box)
        self.intervalSlider=OWGUI.hSlider(OWGUI.indentedBox(cinterBox, sep=indent), self, "classIntervals", None, 2, 10, callback=[self.clearLineEditFocus, self.classMethodChanged], label="Number of intervals")
        hbox = OWGUI.widgetBox(box, orientation = 0)
        OWGUI.appendRadioButton(box, self, "discretization", "Custom" + "  ", insertInto = hbox)
        self.classCustomLineEdit = OWGUI.lineEdit(hbox, self, "customClassSplits", callback = self.classCustomChanged, focusInCallback = self.classCustomSelected)
#        Can't validate - need to allow spaces
        box.setSizePolicy(QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed))
        OWGUI.separator(box)
        self.classIntervalsLabel = OWGUI.widgetLabel(box, "Current splits: ")
        OWGUI.separator(box)
        OWGUI.checkBox(box, self, "outputOriginalClass", "Output original class", callback = self.commitIf)
        OWGUI.widgetLabel(box, "("+"Widget always uses discretized class internally."+")")

        OWGUI.separator(vbox)
        #OWGUI.rubber(vbox)

        box = OWGUI.widgetBox(vbox, "Commit")
        applyButton = OWGUI.button(box, self, "Commit", callback = self.commit, default=True)
        autoApplyCB = OWGUI.checkBox(box, self, "autoApply", "Commit automatically", callback=[self.clearLineEditFocus])
        OWGUI.setStopper(self, applyButton, autoApplyCB, "dataChanged", self.commit)
        OWGUI.rubber(vbox)

        #self.mainSeparator = OWGUI.separator(self.mainHBox, width=25)        # space between control and main area
        self.mainIABox =  OWGUI.widgetBox(self.mainHBox, "Individual attribute settings")
        self.mainBox = OWGUI.widgetBox(self.mainIABox, orientation=0)
        OWGUI.separator(self.mainIABox)#, height=30)
        graphBox = OWGUI.widgetBox(self.mainIABox, "", orientation=0)
        
        
#        self.needsDiscrete.append(graphBox)
        graphOptBox = OWGUI.widgetBox(graphBox)
        OWGUI.separator(graphBox, width=10)
        
        graphGraphBox = OWGUI.widgetBox(graphBox)
        self.graph = DiscGraph(self, graphGraphBox)
        graphGraphBox.layout().addWidget(self.graph)
        reportButton2 = OWGUI.button(graphGraphBox, self, "Report Graph", callback = self.reportGraph, debuggingEnabled=0)

        #graphOptBox.layout().setSpacing(4)
        box = OWGUI.widgetBox(graphOptBox, "Split gain measure", addSpace=True)
        self.measureCombo=OWGUI.comboBox(box, self, "measure", orientation=0, items=[e[0] for e in self.measures], callback=[self.clearLineEditFocus, self.graph.invalidateBaseScore, self.graph.plotBaseCurve])
        OWGUI.checkBox(box, self, "showBaseLine", "Show discretization gain", callback=[self.clearLineEditFocus, self.graph.plotBaseCurve])
        OWGUI.checkBox(box, self, "showLookaheadLine", "Show lookahead gain", callback=self.clearLineEditFocus)
        self.needsDiscrete.append(box)

        box = OWGUI.widgetBox(graphOptBox, "Target class", addSpace=True)
        self.targetCombo=OWGUI.comboBox(box, self, "targetClass", orientation=0, callback=[self.clearLineEditFocus, self.graph.targetClassChanged])
        stc = OWGUI.checkBox(box, self, "showTargetClassProb", "Show target class probability", callback=[self.clearLineEditFocus, self.graph.plotProbCurve])
        OWGUI.checkBox(box, self, "showRug", "Show rug (may be slow)", callback=[self.clearLineEditFocus, self.graph.plotRug])
        self.needsDiscrete.extend([self.targetCombo, stc])

        box = OWGUI.widgetBox(graphOptBox, "Editing", addSpace=True)
        OWGUI.checkBox(box, self, "snap", "Snap to grid", callback=[self.clearLineEditFocus])
        syncCB = OWGUI.checkBox(box, self, "autoSynchronize", "Apply on the fly", callback=self.clearLineEditFocus)
        syncButton = OWGUI.button(box, self, "Apply", callback = self.synchronizePressed)
        OWGUI.setStopper(self, syncButton, syncCB, "pointsChanged", self.synchronize)
        OWGUI.rubber(graphOptBox)

        self.attrList = OWGUI.listBox(self.mainBox, self, callback = self.individualSelected)
        self.attrList.setItemDelegate(CustomListItemDelegate(self.attrList))
        self.attrList.setFixedWidth(300)

        self.defaultMethodChanged()

        OWGUI.separator(self.mainBox, width=10)
        box = OWGUI.radioButtonsInBox(OWGUI.widgetBox(self.mainBox), self, "indiDiscretization", [], callback=[self.clearLineEditFocus, self.indiMethodChanged])
        #hbbox = OWGUI.widgetBox(box)
        #hbbox.layout().setSpacing(4)
        for meth in self.indiDiscretizationMethods[:-1]:
            OWGUI.appendRadioButton(box, self, "indiDiscretization", meth)
        self.needsDiscrete.append(box.buttons[2])
        self.indiInterBox = OWGUI.indentedBox(box, sep=indent, orientation = "horizontal")
        OWGUI.widgetLabel(self.indiInterBox, "Num. of intervals: ")
        self.indiIntervalSlider = OWGUI.hSlider(self.indiInterBox, self, "indiIntervals", None, 2, 10, callback=[self.clearLineEditFocus, self.indiMethodChanged], width = 100)
        OWGUI.rubber(self.indiInterBox) 
        OWGUI.appendRadioButton(box, self, "indiDiscretization", self.indiDiscretizationMethods[-1])
        #OWGUI.rubber(hbbox)
        #OWGUI.separator(box)
        #hbbox = OWGUI.widgetBox(box)
        for i in range(3):
            hbox = OWGUI.widgetBox(box, orientation = "horizontal")
            OWGUI.appendRadioButton(box, self, "indiDiscretization", "Custom %i" % (i+1) + " ", insertInto = hbox)
            le = OWGUI.lineEdit(hbox, self, "", callback = lambda w=i: self.customChanged(w), focusInCallback = lambda w=i: self.customSelected(w))
            le.setFixedWidth(110)
            self.customLineEdits.append(le)
            OWGUI.toolButton(hbox, self, "CC", width=30, callback = lambda w=i: self.copyToCustom(w))
            OWGUI.rubber(hbox)
        OWGUI.rubber(box)

        #self.controlArea.setFixedWidth(0)

        self.contAttrIcon =  self.createAttributeIconDict()[orange.VarTypes.Continuous]
        
        self.setAllIndividuals()
    def __init__(self, parent = None, signalManager = None, name = "Select data"):
        OWWidget.__init__(self, parent, signalManager, name, wantMainArea = 0)  #initialize base class

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Matching Data", ExampleTable, Default), ("Unmatched Data", ExampleTable)]

        self.name2var = {}   # key: variable name, item: orange.Variable
        self.Conditions = []

        self.currentVar = None
        self.NegateCondition = False
        self.currentOperatorDict = {orange.VarTypes.Continuous: Operator(Operator.operatorsC[0], orange.VarTypes.Continuous),
                                    orange.VarTypes.Discrete: Operator(Operator.operatorsD[0],orange.VarTypes.Discrete),
                                    orange.VarTypes.String: Operator(Operator.operatorsS[0], orange.VarTypes.String)}
        self.Num1 = 0.0
        self.Num2 = 0.0
        self.Str1 = ""
        self.Str2 = ""
        self.attrSearchText = ""
        self.currentVals = []
        self.CaseSensitive = False
        self.updateOnChange = True
        self.purgeAttributes = True
        self.purgeClasses = True
        self.oldPurgeClasses = True

        self.loadedVarNames = []
        self.loadedConditions = []
        self.loadSettings()

        w = QWidget(self)
        self.controlArea.layout().addWidget(w)
        grid = QGridLayout()
        grid.setMargin(0)
        w.setLayout(grid)

        boxAttrCond = OWGUI.widgetBox(self, '', orientation = QGridLayout(), addToLayout = 0)
        grid.addWidget(boxAttrCond, 0,0,1,3)
        glac = boxAttrCond.layout()
        glac.setColumnStretch(0,2)
        glac.setColumnStretch(1,1)
        glac.setColumnStretch(2,2)

        boxAttr = OWGUI.widgetBox(self, 'Attribute', addToLayout = 0)
        glac.addWidget(boxAttr,0,0)
        self.lbAttr = OWGUI.listBox(boxAttr, self, callback = self.lbAttrChange)

        self.leSelect = OWGUI.lineEdit(boxAttr, self, "attrSearchText", label = "Search: ", orientation = "horizontal", callback = self.setLbAttr, callbackOnType = 1)

        boxOper = OWGUI.widgetBox(self, 'Operator')
        # operators 0: empty
        self.lbOperatosNone = OWGUI.listBox(boxOper, self)
        # operators 1: discrete
        self.lbOperatorsD = OWGUI.listBox(boxOper, self, callback = self.lbOperatorsChange)
        self.lbOperatorsD.hide()
        self.lbOperatorsD.addItems(Operator.operatorsD + [Operator.operatorDef])
        # operators 2: continuous
        self.lbOperatorsC = OWGUI.listBox(boxOper, self, callback = self.lbOperatorsChange)
        self.lbOperatorsC.hide()
        self.lbOperatorsC.addItems(Operator.operatorsC + [Operator.operatorDef])
        # operators 6: string
        self.lbOperatorsS = OWGUI.listBox(boxOper, self, callback = self.lbOperatorsChange)
        self.lbOperatorsS.hide()
        self.lbOperatorsS.addItems(Operator.operatorsS + [Operator.operatorDef])
        self.lbOperatorsDict = {0: self.lbOperatosNone,
                                orange.VarTypes.Continuous: self.lbOperatorsC,
                                orange.VarTypes.Discrete: self.lbOperatorsD,
                                orange.VarTypes.String: self.lbOperatorsS}

        glac.addWidget(boxOper,0,1)
        self.cbNot = OWGUI.checkBox(boxOper, self, "NegateCondition", "Negate")

        self.boxIndices = {}
        self.valuesStack = QStackedWidget(self)
        glac.addWidget(self.valuesStack, 0, 2)

        # values 0: empty
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout = 0)
        self.boxIndices[0] = boxVal
        self.valuesStack.addWidget(boxVal)

        # values 1: discrete
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout = 0)
        self.boxIndices[orange.VarTypes.Discrete] = boxVal
        self.valuesStack.addWidget(boxVal)
        self.lbVals = OWGUI.listBox(boxVal, self, callback = self.lbValsChange)

        # values 2: continuous between num and num
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout = 0)
        self.boxIndices[orange.VarTypes.Continuous] = boxVal
        self.valuesStack.addWidget(boxVal)
        self.leNum1 = OWGUI.lineEdit(boxVal, self, "Num1", validator=QDoubleValidator(self))
        self.lblAndCon = OWGUI.widgetLabel(boxVal, "and")
        self.leNum2 = OWGUI.lineEdit(boxVal, self, "Num2", validator=QDoubleValidator(self))
        boxAttrStat = OWGUI.widgetBox(boxVal, "Statistics")
        self.lblMin = OWGUI.widgetLabel(boxAttrStat, "Min: ")
        self.lblAvg = OWGUI.widgetLabel(boxAttrStat, "Avg: ")
        self.lblMax = OWGUI.widgetLabel(boxAttrStat, "Max: ")
        self.lblDefined = OWGUI.widgetLabel(boxAttrStat, "Defined for ---- examples")
        OWGUI.rubber(boxAttrStat)

        # values 6: string between str and str
        boxVal = OWGUI.widgetBox(self, "Values", addToLayout = 0)
        self.boxIndices[orange.VarTypes.String] = boxVal
        self.valuesStack.addWidget(boxVal)
        self.leStr1 = OWGUI.lineEdit(boxVal, self, "Str1")
        self.lblAndStr = OWGUI.widgetLabel(boxVal, "and")
        self.leStr2 = OWGUI.lineEdit(boxVal, self, "Str2")
        self.cbCaseSensitive = OWGUI.checkBox(boxVal, self, "CaseSensitive", "Case sensitive")

        self.boxButtons = OWGUI.widgetBox(self, orientation = "horizontal")
        grid.addWidget(self.boxButtons, 1,0,1,3)
        self.btnNew = OWGUI.button(self.boxButtons, self, "Add", self.OnNewCondition)
        self.btnUpdate = OWGUI.button(self.boxButtons, self, "Modify", self.OnUpdateCondition)
        self.btnRemove = OWGUI.button(self.boxButtons, self, "Remove", self.OnRemoveCondition)
        self.btnOR = OWGUI.button(self.boxButtons, self, "OR", self.OnDisjunction)
        self.btnMoveUp = OWGUI.button(self.boxButtons, self, "Move Up", self.btnMoveUpClicked)
        self.btnMoveDown = OWGUI.button(self.boxButtons, self, "Move Down", self.btnMoveDownClicked)
        self.btnRemove.setEnabled(False)
        self.btnUpdate.setEnabled(False)
        self.btnMoveUp.setEnabled(False)
        self.btnMoveDown.setEnabled(False)


        boxCriteria = OWGUI.widgetBox(self, 'Data Selection Criteria', addToLayout = 0)
        grid.addWidget(boxCriteria, 2,0,1,3)
        self.criteriaTable = QTableWidget(boxCriteria)
        boxCriteria.layout().addWidget(self.criteriaTable)
        self.criteriaTable.setShowGrid(False)
        self.criteriaTable.setSelectionMode(QTableWidget.SingleSelection)
        self.criteriaTable.setColumnCount(2)
        self.criteriaTable.verticalHeader().setClickable(False)
        #self.criteriaTable.verticalHeader().setResizeEnabled(False,-1)
        self.criteriaTable.horizontalHeader().setClickable(False)
        self.criteriaTable.setHorizontalHeaderLabels(["Active", "Condition"])
        self.criteriaTable.resizeColumnToContents(0)
        self.criteriaTable.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.criteriaTable.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)
        self.connect(self.criteriaTable, SIGNAL('cellClicked(int, int)'), self.currentCriteriaChange)

        boxDataIn = OWGUI.widgetBox(self, 'Data In', addToLayout = 0)
        grid.addWidget(boxDataIn, 3,0)
        self.dataInExamplesLabel = OWGUI.widgetLabel(boxDataIn, "num examples")
        self.dataInAttributesLabel = OWGUI.widgetLabel(boxDataIn, "num attributes")
        OWGUI.rubber(boxDataIn)

        boxDataOut = OWGUI.widgetBox(self, 'Data Out', addToLayout = 0)
        grid.addWidget(boxDataOut, 3,1)
        self.dataOutExamplesLabel = OWGUI.widgetLabel(boxDataOut, "num examples")
        self.dataOutAttributesLabel = OWGUI.widgetLabel(boxDataOut, "num attributes")
        OWGUI.rubber(boxDataOut)

        boxSettings = OWGUI.widgetBox(self, 'Commit', addToLayout = 0)
        grid.addWidget(boxSettings, 3,2)
        cb = OWGUI.checkBox(boxSettings, self, "purgeAttributes", "Remove unused values/attributes", box=None, callback=self.OnPurgeChange)
        self.purgeClassesCB = OWGUI.checkBox(OWGUI.indentedBox(boxSettings, sep=OWGUI.checkButtonOffsetHint(cb)), self, "purgeClasses", "Remove unused classes", callback=self.OnPurgeChange)
        OWGUI.checkBox(boxSettings, self, "updateOnChange", "Commit on change", box=None)
        btnUpdate = OWGUI.button(boxSettings, self, "Commit", self.setOutput, default=True)

        self.icons = self.createAttributeIconDict()
        self.setData(None)
        self.lbOperatorsD.setCurrentRow(0)
        self.lbOperatorsC.setCurrentRow(0)
        self.lbOperatorsS.setCurrentRow(0)
        self.resize(500,661)
        grid.setRowStretch(0, 10)
        grid.setRowStretch(2, 10)
Ejemplo n.º 36
0
    def __init__(self, parent=None, signalManager=None, name='TreeViewer2D'):
        OWWidget.__init__(self, parent, signalManager, name, wantGraph=True)
        self.root = None
        self.selectedNode = None

        self.inputs = [("Classification Tree", orange.TreeClassifier,
                        self.ctree)]
        self.outputs = [("Examples", ExampleTable)]

        #set default settings
        self.ZoomAutoRefresh = 0
        self.AutoArrange = 0
        self.ToolTipsEnabled = 1
        self.MaxTreeDepth = 5
        self.MaxTreeDepthB = 0
        self.LineWidth = 5
        self.LineWidthMethod = 0
        self.NodeSize = 5
        self.MaxNodeWidth = 150
        self.LimitNodeWidth = True
        self.NodeInfo = [0, 1]

        self.NodeColorMethod = 0
        self.Zoom = 5
        self.VSpacing = 5
        self.HSpacing = 5
        self.TruncateText = 1

        self.loadSettings()
        self.NodeInfo.sort()

        # GUI definition
        self.tabs = OWGUI.tabWidget(self.controlArea)

        # GENERAL TAB
        GeneralTab = OWGUI.createTabPage(self.tabs, "General")
        TreeTab = OWGUI.createTabPage(self.tabs, "Tree")
        NodeTab = OWGUI.createTabPage(self.tabs, "Node")

        OWGUI.hSlider(GeneralTab,
                      self,
                      'Zoom',
                      box='Zoom',
                      minValue=1,
                      maxValue=10,
                      step=1,
                      callback=self.toggleZoomSlider,
                      ticks=1)
        OWGUI.hSlider(GeneralTab,
                      self,
                      'VSpacing',
                      box='Vertical spacing',
                      minValue=1,
                      maxValue=10,
                      step=1,
                      callback=self.toggleVSpacing,
                      ticks=1)
        OWGUI.hSlider(GeneralTab,
                      self,
                      'HSpacing',
                      box='Horizontal spacing',
                      minValue=1,
                      maxValue=10,
                      step=1,
                      callback=self.toggleHSpacing,
                      ticks=1)

        OWGUI.checkBox(GeneralTab,
                       self,
                       'ToolTipsEnabled',
                       'Show node tool tips',
                       tooltip='When mouse over the node show tool tip',
                       callback=self.updateNodeToolTips)
        #        OWGUI.checkBox(GeneralTab, self, 'TruncateText', 'Truncate text to fit margins',
        #                       tooltip='Truncate any text to fit the node width',
        #                       callback=self.toggleTruncateText)

        self.infBox = OWGUI.widgetBox(GeneralTab,
                                      'Tree Size',
                                      sizePolicy=QSizePolicy(
                                          QSizePolicy.Minimum,
                                          QSizePolicy.Fixed))
        self.infoa = OWGUI.widgetLabel(self.infBox, 'No tree.')
        self.infob = OWGUI.widgetLabel(self.infBox, " ")

        # TREE TAB
        OWGUI.checkWithSpin(TreeTab,
                            self,
                            'Max tree depth:',
                            1,
                            20,
                            'MaxTreeDepthB',
                            "MaxTreeDepth",
                            tooltip='Defines the depth of the tree displayed',
                            checkCallback=self.toggleTreeDepth,
                            spinCallback=self.toggleTreeDepth)
        OWGUI.spin(
            TreeTab,
            self,
            'LineWidth',
            min=1,
            max=10,
            step=1,
            label='Max line width:',
            tooltip='Defines max width of the edges that connect tree nodes',
            callback=self.toggleLineWidth)
        OWGUI.radioButtonsInBox(
            TreeTab,
            self,
            'LineWidthMethod', ['No dependency', 'Root node', 'Parent node'],
            box='Reference for Line Width',
            tooltips=[
                'All edges are of the same width',
                'Line width is relative to number of cases in root node',
                'Line width is relative to number of cases in parent node'
            ],
            callback=self.toggleLineWidth)

        # NODE TAB
        #        # Node size options

        cb, sb = OWGUI.checkWithSpin(NodeTab,
                                     self,
                                     "Max node width:",
                                     50,
                                     200,
                                     "LimitNodeWidth",
                                     "MaxNodeWidth",
                                     tooltip="Limit the width of tree nodes",
                                     checkCallback=self.toggleNodeSize,
                                     spinCallback=self.toggleNodeSize,
                                     step=10)
        b = OWGUI.checkBox(OWGUI.indentedBox(
            NodeTab, sep=OWGUI.checkButtonOffsetHint(cb)),
                           self,
                           "TruncateText",
                           "Truncate text",
                           callback=self.toggleTruncateText)
        cb.disables.append(b)
        cb.makeConsistent()
        #        w = OWGUI.widgetBox(NodeTab, orientation="horizontal")
        #        cb = OWGUI.checkBox(w, self, "LimitNodeWidth", "Max node width", callback=self.toggleNodeSize)
        #        sl = OWGUI.hSlider(w, self, 'MaxNodeWidth', #box='Max node width',
        #                      minValue=50, maxValue=200, step=10,
        #                      callback=self.toggleNodeSize, ticks=50)
        #        cb.disables.append(sl)
        #        cb.makeConsistent()

        # Node information
        grid = QGridLayout()
        grid.setContentsMargins(
            *self.controlArea.layout().getContentsMargins())

        navButton = OWGUI.button(self.controlArea,
                                 self,
                                 "Navigator",
                                 self.toggleNavigator,
                                 debuggingEnabled=0,
                                 addToLayout=False)
        #        findbox = OWGUI.widgetBox(self.controlArea, orientation = "horizontal")
        self.centerRootButton=OWGUI.button(self.controlArea, self, "Find Root", addToLayout=False,
                                           callback=lambda :self.rootNode and \
                                           self.sceneView.centerOn(self.rootNode.x(), self.rootNode.y()))
        self.centerNodeButton=OWGUI.button(self.controlArea, self, "Find Selected", addToLayout=False,
                                           callback=lambda :self.selectedNode and \
                                           self.sceneView.centerOn(self.selectedNode.scenePos()))
        grid.addWidget(navButton, 0, 0, 1, 2)
        grid.addWidget(self.centerRootButton, 1, 0)
        grid.addWidget(self.centerNodeButton, 1, 1)
        self.leftWidgetPart.layout().insertLayout(1, grid)

        self.NodeTab = NodeTab
        self.TreeTab = TreeTab
        self.GeneralTab = GeneralTab
        OWGUI.rubber(GeneralTab)
        OWGUI.rubber(TreeTab)
        #        OWGUI.rubber(NodeTab)
        self.rootNode = None
        self.tree = None
        self.resize(800, 500)

        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveGraph)