📄 owmosaicdisplay.py
字号:
self.colorPalette = dlg.getDiscretePalette()
#self.changedInteriorColoring()
#self.box6.setEnabled(self.interiorColoring)
self.permutationListToggle()
self.VizRankLearner = MosaicVizRankLearner(self.optimizationDlg)
self.send("Learner", self.VizRankLearner)
def permutationListToggle(self):
if self.permButton.isOn():
self.permutationList.show()
self.updateGraphAndPermList()
else:
self.permutationList.hide()
def setSelectedPermutation(self):
self.removeAllSelections()
if self.permutationList.count() > 0 and self.bestPlacements and self.permutationList.currentItem() < len(self.bestPlacements):
index = self.permutationList.currentItem()
val, attrList, valueOrder = self.bestPlacements[index]
if len(attrList) > 0: self.attr1 = attrList[0]
if len(attrList) > 1: self.attr2 = attrList[1]
if len(attrList) > 2: self.attr3 = attrList[2]
if len(attrList) > 3: self.attr4 = attrList[3]
self.updateGraph(customValueOrderDict = dict([(attrList[i], tuple(valueOrder[i])) for i in range(len(attrList))]))
def orderAttributeValues(self):
attr = None
if self.sort1.isOn(): attr = self.attr1
elif self.sort2.isOn(): attr = self.attr2
elif self.sort3.isOn(): attr = self.attr3
elif self.sort4.isOn(): attr = self.attr4
if self.data and attr != "" and attr != "(None)":
dlg = SortAttributeValuesDlg(self, self.manualAttributeValuesDict.get(attr, None) or getVariableValuesSorted(self.data, attr))
if dlg.exec_loop() == QDialog.Accepted:
self.manualAttributeValuesDict[attr] = [str(dlg.attributeList.text(i)) for i in range(dlg.attributeList.count())]
for control in [self.sort1, self.sort2, self.sort3, self.sort4]:
control.setOn(0)
self.updateGraph()
# initialize combo boxes with discrete attributes
def initCombos(self, data):
self.attr1Combo.clear(); self.attr2Combo.clear(); self.attr3Combo.clear(); self.attr4Combo.clear()
if data == None: return
self.attr2Combo.insertItem("(None)")
self.attr3Combo.insertItem("(None)")
self.attr4Combo.insertItem("(None)")
for attr in data.domain:
if attr.varType == orange.VarTypes.Discrete:
for combo in [self.attr1Combo, self.attr2Combo, self.attr3Combo, self.attr4Combo]:
combo.insertItem(self.icons[orange.VarTypes.Discrete], attr.name)
if self.attr1Combo.count() > 0:
self.attr1 = str(self.attr1Combo.text(0))
self.attr2 = str(self.attr2Combo.text(0 + 2*(self.attr2Combo.count() > 2)))
self.attr3 = str(self.attr3Combo.text(0))
self.attr4 = str(self.attr4Combo.text(0))
# when we resize the widget, we have to redraw the data
def resizeEvent(self, e):
OWWidget.resizeEvent(self,e)
self.canvas.resize(self.canvasView.size().width()-5, self.canvasView.size().height()-5)
self.updateGraph()
# # DATA signal - receive new data and update all fields
def cdata(self, data):
self.closeContext()
self.data = None
self.bestPlacements = None
self.manualAttributeValuesDict = {}
self.optimizationDlg.setData(data)
if data:
self.data = self.optimizationDlg.data
if data.domain.classVar and data.domain.classVar.varType == orange.VarTypes.Discrete:
self.interiorColoring = CLASS_DISTRIBUTION
else:
self.interiorColoring = PEARSON
self.initCombos(self.data)
self.openContext("", data)
self.updateGraphAndPermList()
def subsetdataHander(self, data):
try:
self.subsetData = data.select(self.data.domain)
except:
self.subsetData = None
self.updateGraphAndPermList()
def setShownAttributes(self, attrList, **args):
if not attrList: return
self.attr1 = attrList[0]
if len(attrList) > 1: self.attr2 = attrList[1]
else: self.attr2 = "(None)"
if len(attrList) > 2: self.attr3 = attrList[2]
else: self.attr3 = "(None)"
if len(attrList) > 3: self.attr4 = attrList[3]
else: self.attr4 = "(None)"
self.attributeValuesDict = args.get("customValueOrderDict", None)
self.updateGraphAndPermList()
def getShownAttributes(self):
attrList = [self.attr1, self.attr2, self.attr3, self.attr4]
while "(None)" in attrList: attrList.remove("(None)")
while "" in attrList: attrList.remove("")
return attrList
def changedInteriorColoring(self):
#self.box6.setEnabled(self.interiorColoring)
self.updateGraph()
def updateGraphAndPermList(self, **args):
self.removeAllSelections()
self.permutationList.clear()
if self.permButton.isOn():
attrList = self.getShownAttributes()
if not getattr(self, "bestPlacements", []) or 0 in [attr in self.bestPlacements[0][1] for attr in attrList]: # we might have bestPlacements for a different set of attributes
self.setStatusBarText("Evaluating different attribute permutations. You can stop evaluation by opening VizRank dialog and pressing 'Stop optimization' button.")
self.bestPlacements = self.optimizationDlg.optimizeCurrentAttributeOrder(attrList, updateGraph = 0)
self.setStatusBarText("")
if self.bestPlacements:
for (val, attrs, order) in self.bestPlacements:
self.permutationList.insertItem("%.2f - %s" % (val, attrs))
attrList, valueOrder = self.bestPlacements[0][1], self.bestPlacements[0][2]
self.attributeValuesDict = dict([(attrList[i], tuple(valueOrder[i])) for i in range(len(attrList))])
self.updateGraph(**args)
# ############################################################################
# ############################################################################
# updateGraph - gets called every time the graph has to be updated
def updateGraph(self, **args):
# hide all rectangles
self.warning()
for item in self.canvas.allItems():
if item.rtti() != 123: item.setCanvas(None) # remove all canvas items, except SelectionCurves
for tip in self.tooltips: QToolTip.remove(self.canvasView, tip)
self.names = []; self.tooltips = []
if self.data == None : return
attrList = [self.attr1, self.attr2, self.attr3, self.attr4]
while "(None)" in attrList: attrList.remove("(None)")
while "" in attrList: attrList.remove("")
if attrList == []: return
selectList = attrList
if self.data.domain.classVar:
data = self.data.select(attrList + [self.data.domain.classVar.name])
else:
data = self.data.select(attrList)
data = orange.Preprocessor_dropMissing(data)
self.aprioriDistributions = []
if self.interiorColoring == PEARSON:
for attr in attrList:
self.aprioriDistributions = [orange.Distribution(attr, data) for attr in attrList]
# get the maximum width of rectangle
xOff = 50
width = 50
if len(attrList) > 1:
text = QCanvasText(attrList[1], self.canvas);
font = text.font(); font.setBold(1); text.setFont(font)
width = text.boundingRect().right() - text.boundingRect().left() + 30 + 20
xOff = width
if len(attrList) == 4:
text = QCanvasText(attrList[3], self.canvas);
font = text.font(); font.setBold(1); text.setFont(font)
width += text.boundingRect().right() - text.boundingRect().left() + 30 + 20
# get the maximum height of rectangle
height = 90
yOff = 40
squareSize = min(self.canvasView.size().width() - width - 20, self.canvasView.size().height() - height - 20)
if squareSize < 0: return # canvas is too small to draw rectangles
self.legend = {} # dictionary that tells us, for what attributes did we already show the legend
for attr in attrList: self.legend[attr] = 0
self.drawnSides = dict([(0,0),(1,0),(2,0),(3,0)])
self.drawPositions = {}
if not getattr(self, "attributeValuesDict", None):
self.attributeValuesDict = self.manualAttributeValuesDict
# compute distributions
self.conditionalDict = self.optimizationDlg.getConditionalDistributions(data, attrList)
self.conditionalDict[""] = len(data)
self.conditionalSubsetDict = None
if self.subsetData and self.data.domain == self.subsetData.domain:
#subData = orange.Preprocessor_select(self.subsetData, attributes = [self.subsetData.domain[attr] for attr in attrList] + [self.subsetData.domain.classVar])
#subData = orange.Preprocessor_dropMissing(subData)
#if subData and len(subData) > 0:
# self.conditionalSubsetDict = self.optimizationDlg.getConditionalDistributions(subData, attrList)
# self.conditionalSubsetDict[""] = len(subData)
self.conditionalSubsetDict = self.optimizationDlg.getConditionalDistributions(self.subsetData, attrList)
self.conditionalSubsetDict[""] = len(self.subsetData)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -