⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owlinprojgraph.py

📁 orange源码 数据挖掘技术
💻 PY
📖 第 1 页 / 共 4 页
字号:
            OWGraph.onMousePressed(self, e)


    def onMouseReleased(self, e):
        if self.manualPositioning:
            self.mouseCurrentlyPressed = 0
            self.selectedAnchorIndex = None
        else:
            OWGraph.onMouseReleased(self, e)

    # ############################################################## 
    # draw tooltips
    def onMouseMoved(self, e):
        redraw = (self.tooltipCurveKeys != [] or self.tooltipMarkers != [])

        for key in self.tooltipCurveKeys:  self.removeCurve(key)
        for marker in self.tooltipMarkers: self.removeMarker(marker)
        self.tooltipCurveKeys = []
        self.tooltipMarkers = []

        xFloat = self.invTransform(QwtPlot.xBottom, e.x())
        yFloat = self.invTransform(QwtPlot.yLeft, e.y())

        # in case we are drawing a rectangle, we don't draw enhanced tooltips
        # because it would then fail to draw the rectangle
        if self.mouseCurrentlyPressed:
            if not self.manualPositioning:
                OWGraph.onMouseMoved(self, e)
                if redraw: self.replot()
            else:
                if self.selectedAnchorIndex != None:
                    if self.widget.freeVizDlg.restrain == 1:
                        rad = sqrt(xFloat**2 + yFloat**2)
                        xFloat /= rad
                        yFloat /= rad
                    elif self.widget.freeVizDlg.restrain == 2:
                        rad = sqrt(xFloat**2 + yFloat**2)
                        phi = 2 * self.selectedAnchorIndex * math.pi / len(self.anchorData)
                        xFloat = rad * cos(phi)
                        yFloat = rad * sin(phi)
                    self.anchorData[self.selectedAnchorIndex] = (xFloat, yFloat, self.anchorData[self.selectedAnchorIndex][2]) 
                    self.updateData(self.shownAttributes)
                    self.repaint()
                    #self.replot()
                    #self.widget.recomputeEnergy()
            return 
            
        dictValue = "%.1f-%.1f"%(xFloat, yFloat)
        if self.dataMap.has_key(dictValue):
            points = self.dataMap[dictValue]
            bestDist = 100.0
            for (x_i, y_i, color, index, extraString) in points:
                currDist = sqrt((xFloat-x_i)*(xFloat-x_i) + (yFloat-y_i)*(yFloat-y_i))
                if currDist < bestDist:
                    bestDist = currDist
                    nearestPoint = (x_i, y_i, color, index, extraString)

            (x_i, y_i, color, index, extraString) = nearestPoint
            intX = self.transform(QwtPlot.xBottom, x_i)
            intY = self.transform(QwtPlot.yLeft, y_i)
            if len(self.anchorData) > 50:
                text = "Too many attributes.<hr>Example index = %d" % (index)
                self.showTip(intX, intY, text)

            elif self.tooltipKind == LINE_TOOLTIPS and bestDist < 0.05:
                shownAnchorData = filter(lambda p, r=self.hideRadius**2/100: p[0]**2+p[1]**2>r, self.anchorData)
                for (xAnchor,yAnchor,label) in shownAnchorData:
                    if self.anchorsAsVectors and not self.scalingByVariance:
                        attrVal = self.scaledData[self.attributeNameIndex[label]][index]
                        markerX, markerY = xAnchor*attrVal, yAnchor*attrVal
                        key = self.addCurve("Tooltip curve", color, color, 1, style = QwtCurve.Lines, symbol = QwtSymbol.None, xData = [0, markerX], yData = [0, markerY], lineWidth=3)
                        fontsize = 9
                        markerAlign = (markerY>0 and Qt.AlignTop or Qt.AlignBottom) + (markerX>0 and Qt.AlignRight or Qt.AlignLeft)
                    else:
                        key = self.addCurve("Tooltip curve", color, color, 1, style = QwtCurve.Lines, symbol = QwtSymbol.None, xData = [x_i, xAnchor], yData = [y_i, yAnchor])
                        markerX, markerY = (x_i + xAnchor)/2.0, (y_i + yAnchor)/2.0
                        fontsize = 12
                        markerAlign = Qt.AlignCenter
                    
                    self.tooltipCurveKeys.append(key)

                    # draw text
                    marker = None
                    if self.tooltipValue == TOOLTIPS_SHOW_DATA:
                        marker = self.addMarker(str(self.rawdata[index][label]), markerX, markerY, markerAlign, bold = 1)
                    elif self.tooltipValue == TOOLTIPS_SHOW_SPRINGS:
                        marker = self.addMarker("%.3f" % (self.scaledData[self.attributeNameIndex[label]][index]), markerX, markerY, markerAlign, bold = 1)
                    font = self.markerFont(marker)
                    font.setPointSize(fontsize)
                    font.setBold(FALSE)
                    self.setMarkerFont(marker, font)

                    self.tooltipMarkers.append(marker)

            elif self.tooltipKind == VISIBLE_ATTRIBUTES or self.tooltipKind == ALL_ATTRIBUTES:
                if self.tooltipKind == VISIBLE_ATTRIBUTES:
                    shownAnchorData = filter(lambda p, r=self.hideRadius**2/100: p[0]**2+p[1]**2>r, self.anchorData)
                    labels = [s for (xA, yA, s) in shownAnchorData]
                else:
                    labels = []

                text = self.getExampleTooltipText(self.rawdata, self.rawdata[index], labels)
                text += "<br><hr>Example index = %d" % (index)
                if extraString:
                    text += "<hr>" + extraString

                self.showTip(intX, intY, text)
                
        OWGraph.onMouseMoved(self, e)
        self.replot()
 
    
    # send 2 example tables. in first is the data that is inside selected rects (polygons), in the second is unselected data
    def getSelectionsAsExampleTables(self, attrList, useAnchorData = 1, addProjectedPositions = 0):
        if not self.rawdata: return (None, None)
        if addProjectedPositions == 0 and not self.selectionCurveKeyList: return (None, self.rawdata)       # if no selections exist
        if (useAnchorData and len(self.anchorData) < 3) or len(attrList) < 3: return (None, None)

        xAttr=orange.FloatVariable("X Positions")
        yAttr=orange.FloatVariable("Y Positions")
        if addProjectedPositions == 1:
            domain=orange.Domain([xAttr,yAttr] + [v for v in self.rawdata.domain.variables])
        elif addProjectedPositions == 2:
            domain=orange.Domain(self.rawdata.domain)
            domain.addmeta(orange.newmetaid(), xAttr)
            domain.addmeta(orange.newmetaid(), yAttr)
        else:
            domain = orange.Domain(self.rawdata.domain)

        domain.addmetas(self.rawdata.domain.getmetas())
        
        if useAnchorData: indices = [self.attributeNameIndex[val[2]] for val in self.anchorData]
        else:             indices = [self.attributeNameIndex[label] for label in attrList]
        validData = self.getValidList(indices)
        if len(validData) == 0: return (None, None)
        
        array = self.createProjectionAsNumericArray(attrList, settingsDict = {"scaleFactor": self.scaleFactor, "useAnchorData": useAnchorData, "removeMissingData": 0})
        selIndices, unselIndices = self.getSelectionsAsIndices(attrList, useAnchorData, validData)
        
        if addProjectedPositions:
            selected = orange.ExampleTable(domain, self.rawdata.selectref(selIndices))
            unselected = orange.ExampleTable(domain, self.rawdata.selectref(unselIndices))
            selIndex = 0; unselIndex = 0
            for i in range(len(selIndices)):
                if selIndices[i]:
                    selected[selIndex][xAttr] = array[i][0]
                    selected[selIndex][yAttr] = array[i][1]
                    selIndex += 1
                else:
                    unselected[unselIndex][xAttr] = array[i][0]
                    unselected[unselIndex][yAttr] = array[i][1]
                    unselIndex += 1
        else:
            selected = self.rawdata.selectref(selIndices)
            unselected = self.rawdata.selectref(unselIndices)

        if len(selected) == 0: selected = None
        if len(unselected) == 0: unselected = None
        return (selected, unselected)
    

    def getSelectionsAsIndices(self, attrList, useAnchorData = 1, validData = None):
        if not self.rawdata: return [], []

        attrIndices = [self.attributeNameIndex[attr] for attr in attrList]
        if not validData: validData = self.getValidList(attrIndices)
        
        array = self.createProjectionAsNumericArray(attrList, settingsDict = {"scaleFactor": self.scaleFactor, "useAnchorData": useAnchorData, "removeMissingData": 0})
        array = Numeric.transpose(array)
        return self.getSelectedPoints(array[0], array[1], validData)
            
        
    def getOptimalClusters(self, attributes, minLength, maxLength, addResultFunct):
        self.triedPossibilities = 0

        # replace attribute names with indices in domain - faster searching
        attributes = [self.attributeNameIndex[name] for name in attributes]
        classIndex = self.attributeNameIndex[self.rawdata.domain.classVar.name]

        # variables and domain for the table
        xVar = orange.FloatVariable("xVar")
        yVar = orange.FloatVariable("yVar")
        domain = orange.Domain([xVar, yVar, self.rawdata.domain.classVar])
        anchorList = [(self.createXAnchors(i), self.createYAnchors(i)) for i in range(minLength, maxLength+1)]

        self.widget.progressBarInit()
        startTime = time.time()

        # build list of indices for permutations of different number of attributes
        permutationIndices = {}
        for i in range(3, maxLength+1):
            permutationIndices[i] = orngVisFuncts.generateDifferentPermutations(range(i))

        classListFull = Numeric.transpose(self.rawdata.toNumeric("c")[0])[0]
        for z in range(minLength-1, len(attributes)):
            for u in range(minLength-1, maxLength):
                combinations = orngVisFuncts.combinations(attributes[:z], u)

                XAnchors = anchorList[u+1-minLength][0]
                YAnchors = anchorList[u+1-minLength][1]
                
                for attrList in combinations:
                    attrs = attrList + [attributes[z]] # remove the value of this attribute subset
                    permutations = permutationIndices[len(attrs)]
                    
                    validData = self.getValidList(attrs)
                    classList = Numeric.compress(validData, classListFull)
                    selectedData = Numeric.compress(validData, Numeric.take(self.noJitteringScaledData, attrs))
                    sum_i = self._getSum_i(selectedData)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -