示例#1
0
    def startOptimization(self):
        self.clearResults()
        if self.parallelWidget.data == None: return

        if self.optimizationMeasure == VIZRANK and self.fileName == "":
            QMessageBox.information(
                self, "No projection file",
                "If you wish to optimize using VizRank you first have to load a projection file \ncreated by VizRank using Scatterplot widget.",
                QMessageBox.Ok)
            return
        if self.parallelWidget.data == None:
            QMessageBox.information(
                self, "Missing data set",
                "A data set has to be loaded in order to perform optimization.",
                QMessageBox.Ok)
            return

        attrInfo = []
        self.progressBarInit()
        if self.optimizationMeasure == CORRELATION:
            attrList = [
                attr.name
                for attr in self.parallelWidget.data.domain.attributes
            ]
            self.startOptimizationButton.hide()
            self.stopOptimizationButton.show()
            self.canOptimize = 1

            class StopOptimizationException(Exception):
                pass

            def progressSetWithStop(value):
                if not self.canContinueOptimization():
                    raise StopOptimizationException()
                else:
                    self.progressBarSet(value * 0.9)

            try:
                attrInfo = orngVisFuncts.computeCorrelationBetweenAttributes(
                    self.parallelWidget.data,
                    attrList,
                    progressCallback=progressSetWithStop)
            except StopOptimizationException:
                attrInfo = []
                self.startOptimizationButton.show()
                self.stopOptimizationButton.hide()

#            self.progressBarFinished()
#attrInfo = orngVisFuncts.computeCorrelationInsideClassesBetweenAttributes(self.parallelWidget.data, attrList)
        elif self.optimizationMeasure == VIZRANK:
            for (val, [a1, a2]) in self.projections:
                attrInfo.append((val, a1, a2))

            # check if all attributes in loaded projection file are actually present in this data set
            attrs = [
                attr.name
                for attr in self.parallelWidget.data.domain.attributes
            ]
            for (v, a1, a2) in attrInfo:
                if a1 not in attrs:
                    print "attribute " + a1 + " was not found in the data set. You probably loaded wrong file with VizRank projections."
                    return
                if a2 not in attrs:
                    print "attribute " + a2 + " was not found in the data set. You probably loaded wrong file with VizRank projections."
                    return

        if len(attrInfo) == 0:
            print "len(attrInfo) == 0. No attribute pairs. Unable to optimize."
            return

        self.worstVal = -1
        self.canOptimize = 1
        self.startOptimizationButton.hide()
        self.stopOptimizationButton.show()
        #qApp.processEvents()        # allow processing of other events

        if self.orderAllAttributes:
            orngVisFuncts.optimizeAttributeOrder(
                attrInfo, len(self.parallelWidget.data.domain.attributes),
                self, qApp)
        else:
            orngVisFuncts.optimizeAttributeOrder(attrInfo,
                                                 self.numberOfAttributes, self,
                                                 qApp)

        self.stopOptimizationButton.hide()
        self.startOptimizationButton.show()

        self.progressBarFinished()
    def startOptimization(self):
        self.clearResults()
        if self.parallelWidget.data == None: return

        if self.optimizationMeasure == VIZRANK and self.fileName == "":
            QMessageBox.information(self, "No projection file", "If you wish to optimize using VizRank you first have to load a projection file \ncreated by VizRank using Scatterplot widget.", QMessageBox.Ok)
            return
        if self.parallelWidget.data == None:
            QMessageBox.information(self, "Missing data set", "A data set has to be loaded in order to perform optimization.", QMessageBox.Ok)
            return

        attrInfo = []
        self.progressBarInit()
        if self.optimizationMeasure == CORRELATION:
            attrList = [attr.name for attr in self.parallelWidget.data.domain.attributes]
            self.startOptimizationButton.hide()
            self.stopOptimizationButton.show()
            self.canOptimize = 1
            class StopOptimizationException(Exception):
                pass
            def progressSetWithStop(value):
                if not self.canContinueOptimization():
                    raise StopOptimizationException()
                else:
                    self.progressBarSet(value * 0.9)
            try: 
                attrInfo = orngVisFuncts.computeCorrelationBetweenAttributes(self.parallelWidget.data, attrList, progressCallback=progressSetWithStop)
            except StopOptimizationException:
                attrInfo = []
                self.startOptimizationButton.show()
                self.stopOptimizationButton.hide()
                
#            self.progressBarFinished()
            #attrInfo = orngVisFuncts.computeCorrelationInsideClassesBetweenAttributes(self.parallelWidget.data, attrList)
        elif self.optimizationMeasure == VIZRANK:
            for (val, [a1, a2]) in self.projections:
                attrInfo.append((val, a1, a2))

            # check if all attributes in loaded projection file are actually present in this data set
            attrs = [attr.name for attr in self.parallelWidget.data.domain.attributes]
            for (v, a1, a2) in attrInfo:
                if a1 not in attrs:
                    print "attribute " + a1 + " was not found in the data set. You probably loaded wrong file with VizRank projections."
                    return
                if a2 not in attrs:
                    print "attribute " + a2 + " was not found in the data set. You probably loaded wrong file with VizRank projections."
                    return

        if len(attrInfo) == 0:
            print "len(attrInfo) == 0. No attribute pairs. Unable to optimize."; return

        self.worstVal = -1
        self.canOptimize = 1
        self.startOptimizationButton.hide()
        self.stopOptimizationButton.show()
        #qApp.processEvents()        # allow processing of other events

        if self.orderAllAttributes:
            orngVisFuncts.optimizeAttributeOrder(attrInfo, len(self.parallelWidget.data.domain.attributes), self, qApp)
        else:
            orngVisFuncts.optimizeAttributeOrder(attrInfo, self.numberOfAttributes, self, qApp)

        self.stopOptimizationButton.hide()
        self.startOptimizationButton.show()
        
        self.progressBarFinished()