Commits

Miha Stajdohar committed 6fa0241

Fixed some more bug connected to new architecture.

Comments (0)

Files changed (3)

_modelmaps/widgets/OWModelEmbedder.py

 
 import sip
 
+import OWGUI
+import orngMisc
+
 from OWWidget import *
-
-import OWGUI
-import orange
+from Orange import data, misc, distance, modelmaps
 
 import OWScatterPlot
 import OWRadviz
 class OWModelEmbedder(OWWidget):
     settingsList = []
 
-    def __init__(self, parent=None, signalManager = None):
-        OWWidget.__init__(self, parent, signalManager, "Model Embedder")
-        
-        self.inputs = [("Data", orange.ExampleTable, self.setData),
-                       ("Model", orange.Example, self.setModel)]
-        
-        self.outputs = [("Selected Data", ExampleTable), ("Other Data", ExampleTable)]
-        
+    def __init__(self, parent=None, signalManager=None, name='Model Embedder'):
+
+        OWWidget.__init__(self, parent, signalManager, name, noReport=True)
+
+        self.inputs = [("Data", data.Table, self.setData),
+                       ("Model", modelmaps.Model, self.setModel)]
+
+        self.outputs = [("Selected Data", data.Table), ("Other Data", data.Table)]
+
         self.ow = None
         self.data = None
         self.model = None
-        
+
         self.loadSettings()
-        
+
         self.widgets = {}
-        
+
     def setData(self, data):
         self.data = data
         self.showWidget()
-        
+
     def setModel(self, model):
         self.model = model
         self.showWidget()
-        
+
     def setWidget(self, widgetType):
         if str(widgetType) in self.widgets:
             self.ow = self.widgets[str(widgetType)]
         else:
-            self.ow = widgetType(self) 
+            self.ow = widgetType(self)
             self.widgets[str(widgetType)] = self.ow
         return self.ow
-                
+
     def showWidget(self):
         self.information()
-        
+
         if self.ow is not None:
             self.ow.topWidgetPart.hide()
             self.ow.setLayout(self.layout())
-        elif self.layout() is not None: 
+        elif self.layout() is not None:
             sip.delete(self.layout())
-            
+
         self.ow = None
-        if self.data is None: 
+        if self.data is None:
             self.information("No learning data given.")
             return
         if self.model is None: return
         if "model" not in self.model.domain: return
         if "attributes" in self.model.domain:
             attr = self.model["attributes"].value.split(', ')
-        
+
         modelType = self.model["model"].value.upper()
-        
+
         projWidget = None
-        if modelType == "SCATTERPLOT" or modelType == "SCATTTERPLOT": 
+        if modelType == "SCATTERPLOT" or modelType == "SCATTTERPLOT":
             projWidget = self.setWidget(OWScatterPlot.OWScatterPlot)
 
         if modelType == "RADVIZ":
-            projWidget = self.setWidget(OWRadviz.OWRadviz) 
-            
-        if modelType == "POLYVIZ": 
-            projWidget = self.setWidget(OWPolyviz.OWPolyviz) 
-            
+            projWidget = self.setWidget(OWRadviz.OWRadviz)
+
+        if modelType == "POLYVIZ":
+            projWidget = self.setWidget(OWPolyviz.OWPolyviz)
+
         if projWidget is not None:
             self.ow.setData(self.data)
             self.ow.setShownAttributes(attr)
-            self.ow.handleNewSignals() 
-        
+            self.ow.handleNewSignals()
+
         ################################
         ### add new model types here ###
         ################################
-        
-        if modelType == "SPCA" or modelType == "LINPROJ": 
-            self.setWidget(OWLinProj.OWLinProj) 
+
+        if modelType == "SPCA" or modelType == "LINPROJ":
+            self.setWidget(OWLinProj.OWLinProj)
             self.ow.setData(self.data)
             self.ow.setShownAttributes(attr)
-            self.ow.handleNewSignals() 
+            self.ow.handleNewSignals()
             xAnchors, yAnchors = self.model["anchors"].value
             self.ow.updateGraph(None, setAnchors=1, XAnchors=xAnchors, YAnchors=yAnchors)
-            
+
         if modelType == "TREE":
             self.setWidget(OWClassificationTreeGraph.OWClassificationTreeGraph)
             classifier = self.model["classifier"].value
             self.ow.ctree(classifier)
-            
+
         if modelType == "BAYES":
-            self.setWidget(OWNomogram.OWNomogram) 
+            self.setWidget(OWNomogram.OWNomogram)
             classifier = self.model["classifier"].value
             self.ow.classifier(classifier)
-            
+
         if modelType == "KNN":
-            exclude = [att for att in self.data.domain if att.name not in attr + [self.data.domain.classVar.name]]
-            data2 = orange.Preprocessor_ignore(self.data, attributes = exclude)
-            dist = orange.ExamplesDistanceConstructor_Euclidean(data2)
-            smx = orange.SymMatrix(len(data2))
+            #exclude = [att for att in self.data.domain if att.name not in attr + [self.data.domain.classVar.name]]
+            #data2 = orange.Preprocessor_ignore(self.data, attributes=exclude)
+            domain = data.Domain(attr + [self.data.domain.classVar.name], self.data.domain)
+            data2 = data.Table(domain, data)
+            dist = distance.Euclidean(data2)
+            smx = misc.SymMatrix(len(data2))
             smx.setattr('items', data2)
             pb = OWGUI.ProgressBar(self, 100)
-            milestones = orngMisc.progressBarMilestones(len(data2)*(len(data2)-1)/2, 100)
+            milestones = orngMisc.progressBarMilestones(len(data2) * (len(data2) - 1) / 2, 100)
             count = 0
             for i in range(len(data2)):
-                for j in range(i+1):
+                for j in range(i + 1):
                     smx[i, j] = dist(data2[i], data2[j])
                     if count in milestones:
                         pb.advance()
             pb.finish()
             self.setWidget(OWMDS.OWMDS)
             self.ow.cmatrix(smx)
-            
+
         if self.ow is not None:
             self.ow.send = self.send
             if self.layout() is not None: sip.delete(self.layout())
             self.setLayout(self.ow.layout())
             self.ow.topWidgetPart.show()
-        
+
         self.update()
-        
-        
+
+
 if __name__ == "__main__":
-    import sys
-    from PyQt4 import QtGui
-    
-    app = QtGui.QApplication(sys.argv)
+    appl = QApplication(sys.argv)
     view = OWModelEmbedder()
     view.show()
     view.setWindowTitle("Model Embedder")
-    sys.exit(app.exec_())
+    appl.exec_()

_modelmaps/widgets/OWModelFile.py

 <icon>icons/DistanceFile.png</icon>
 <priority>6510</priority>
 """
-
-from OWWidget import *
-
-import OWGUI
-import Orange
-import orngMisc
-import exceptions
 import os.path
 import cPickle as pickle
 import bz2
 
+import OWGUI
+import orngMisc
+
+from OWWidget import *
+from Orange import data, misc
+
 class OWModelFile(OWWidget):
     settingsList = ["files", "file_index"]
 
     def __init__(self, parent=None, signalManager=None):
         OWWidget.__init__(self, parent, signalManager, name='Model File', wantMainArea=0, resizingEnabled=1)
 
-        self.outputs = [("Distances", Orange.misc.SymMatrix),
-                        ("Model Meta-data", Orange.data.Table),
-                        ("Original Data", Orange.data.Table)]
+        self.outputs = [("Distances", misc.SymMatrix),
+                        ("Model Meta-data", data.Table),
+                        ("Original Data", data.Table)]
 
         #self.dataFileBox.setTitle("Model File")
         self.files = []
         try:
             matrix, self.model_data, self.original_data = pickle.load(bz2.BZ2File('%s' % fn, "r"))
 
-            self.matrix = Orange.misc.SymMatrix(len(matrix))
+            self.matrix = misc.SymMatrix(len(matrix))
             milestones = orngMisc.progressBarMilestones(self.matrix.dim, 100)
             for i in range(self.matrix.dim):
                 for j in range(i + 1):

_modelmaps/widgets/OWModelMap.py

 """
 <name>Model Map</name>
-<description>Visualization and analysis of prediction models.</description>
+<description>Visualization and analysis of prediction models</description>
 <icon>icons/Network.png</icon>
 <contact>Miha Stajdohar (miha.stajdohar(@at@)gmail.com)</contact> 
 <priority>6520</priority>
 """
-
-import scipy.stats
-
-import orngVizRank
-import orngStat
+import os.path
 
 import OWToolbars
 import OWColorPalette
 import OWNxCanvasQt
 
-from Orange import classification, data, feature, misc
+from Orange import classification, data, feature, misc, modelmaps
 
 from orngScaleLinProjData import *
 from OWNxExplorer import *
 from OWNxHist import *
 from OWDistributions import OWDistributionGraph
 
-dir = os.path.dirname(__file__) + "/../"
+dir = Orange.utils.environ.widget_install_dir
 
 ICON_PATHS = [("TREE", "Classify/icons/ClassificationTree"),
               ("SCATTERPLOT", "Visualize/icons/ScatterPlot"),
 
 ICON_SIZES = ["16", "32", "40", "48", "60"]
 
-MODEL_IMAGES = {"MISSING": "%sicons/Unknown.png" % dir}
+MODEL_IMAGES = {"MISSING": os.path.join(dir, "icons/Unknown.png")}
 
 PIXMAP_CACHE = {}
 
 for size in ICON_SIZES:
     for model, path in ICON_PATHS:
-        MODEL_IMAGES[model + size] = "%s%s_%s.png" % (dir, path, size)
+        MODEL_IMAGES[model + size] = os.path.join(dir, "%s_%s.png" % (path, size))
 
 class ModelItem(orangeqt.ModelItem):
     def __init__(self, index, x=None, y=None, parent=None):
 
         self.inputs = [("Distances", misc.SymMatrix, self.setMatrix, Default),
                        ("Model Subset", data.Table, self.setSubsetModels)]
-        self.outputs = [("Model", data.Instance),
+
+        self.outputs = [("Model", modelmaps.Model),
                         ("Classifier", classification.Classifier),
                         ("Selected Models", data.Table)]
 
         self.attrDifference = []
         self.attrDifferenceList = []
 
+        self.colorSettings = self.edgeColorSettings
+
         self.loadSettings()
 
         self.matrixTab = OWGUI.widgetBox(self.tabs, addToLayout=0, margin=4)
         selection = self.networkCanvas.selected_nodes()
 
         if len(selection) == 1:
-            modelInstance = self.graph.items()[selection[0]]
-            # modelInfo - Python Dict; keys: method, classifier, probabilities,
-            # results, XAnchors, YAnchors, attributes
-            modelInfo = self.graph_matrix.results[modelInstance['uuid'].value]
-
-            #uuid = modelInstance["uuid"].value
-            #method, vizr_result, projection_points, classifier, attrs = self.matrix.results[uuid]
-
-            if 'YAnchors' in modelInfo and 'XAnchors' in modelInfo:
-                if not modelInstance.domain.hasmeta('anchors'):
-                    modelInstance.domain.addmeta(feature.Descriptor.new_meta_id(), feature.Python('anchors'))
-                modelInstance['anchors'] = (modelInfo['XAnchors'], modelInfo['YAnchors'])
-
-            if 'classifier' in modelInfo and modelInfo['classifier'] is not None:
-                if not modelInstance.domain.hasmeta('classifier'):
-                    modelInstance.domain.addmeta(feature.Descriptor.new_meta_id(), feature.Python('classifier'))
-                modelInstance['classifier'] = modelInfo['classifier']
-                self.send('Classifier', modelInfo['classifier'])
-
-            self.send('Model', modelInstance)
+            model = self.graph.items()[selection[0]]['model'].value
+            self.send('Model', model)
             self.send('Selected Models', self.graph.items().getitems(selection))
         elif len(selection) > 1:
             self.send('Model', None)