Changeset 9630:112c812933ee in orange


Ignore:
Timestamp:
02/04/12 19:01:15 (2 years ago)
Author:
Miha Stajdohar <miha.stajdohar@…>
Branch:
default
rebase_source:
ca2cc804f1f0c447d29e6f41925e26ec4319a398
Message:

Fixed a bug when appending clustering results multiple times.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Unsupervised/OWNxClustering.py

    r9622 r9630  
    33<description>Orange widget for community detection in networks</description> 
    44<icon>icons/Network.png</icon> 
    5 <contact>Miha Stajdohar (miha.stajdohar(@at@)gmail.com)</contact>  
     5<contact>Miha Stajdohar (miha.stajdohar(@at@)gmail.com)</contact> 
    66<priority>6430</priority> 
    77""" 
    88 
    9 import Orange 
     9import Orange.network 
    1010import Orange.network.community as cd 
    1111import OWGUI 
     
    1616class OWNxClustering(OWWidget): 
    1717 
    18     settingsList = ['method', 'iterationHistory', 'autoApply', 'iterations', 'hop_attenuation'] 
     18    settingsList = ['method', 'iterationHistory', 'autoApply', 'iterations', 
     19                    'hop_attenuation'] 
    1920 
    2021    def __init__(self, parent=None, signalManager=None): 
    2122        OWWidget.__init__(self, parent, signalManager, 'Nx Clustering') 
    2223 
    23         self.inputs = [("Network", Orange.network.Graph, self.setNetwork, Default)] 
     24        self.inputs = [("Network", Orange.network.Graph, 
     25                        self.setNetwork, Default)] 
    2426        self.outputs = [("Network", Orange.network.Graph)] 
    2527 
     
    3234        self.loadSettings() 
    3335 
    34         OWGUI.spin(self.controlArea, self, "iterations", 1, 100000, 1, label="Iterations: ") 
    35         ribg = OWGUI.radioButtonsInBox(self.controlArea, self, "method", [], "Method", callback=self.cluster) 
    36         OWGUI.appendRadioButton(ribg, self, "method", "Label propagation clustering (Raghavan et al., 2007)", callback=self.cluster) 
     36        OWGUI.spin(self.controlArea, self, "iterations", 1, 
     37                   100000, 1, label="Iterations: ") 
     38        ribg = OWGUI.radioButtonsInBox(self.controlArea, self, "method", 
     39                                       [], "Method", callback=self.cluster) 
     40        OWGUI.appendRadioButton(ribg, self, "method", 
     41                        "Label propagation clustering (Raghavan et al., 2007)", 
     42                        callback=self.cluster) 
    3743 
    38         OWGUI.appendRadioButton(ribg, self, "method", "Label propagation clustering (Leung et al., 2009)", callback=self.cluster) 
    39         OWGUI.doubleSpin(OWGUI.indentedBox(ribg), self, "hop_attenuation", 0, 1, 0.01, label="Hop attenuation (delta): ") 
    40  
     44        OWGUI.appendRadioButton(ribg, self, "method", 
     45                        "Label propagation clustering (Leung et al., 2009)", 
     46                        callback=self.cluster) 
     47        OWGUI.doubleSpin(OWGUI.indentedBox(ribg), self, "hop_attenuation", 
     48                         0, 1, 0.01, label="Hop attenuation (delta): ") 
    4149 
    4250        self.info = OWGUI.widgetLabel(self.controlArea, ' ') 
    43         OWGUI.checkBox(self.controlArea, self, "iterationHistory", "Append clustering data on each iteration") 
    44         autoApplyCB = OWGUI.checkBox(self.controlArea, self, "autoApply", "Commit automatically") 
    45         OWGUI.button(self.controlArea, self, "Commit", callback=self.cluster) 
     51        OWGUI.checkBox(self.controlArea, self, "iterationHistory", 
     52                       "Append clustering data on each iteration", 
     53                       callback=self.cluster) 
     54        OWGUI.checkBox(self.controlArea, self, "autoApply", 
     55                       "Commit automatically") 
     56        OWGUI.button(self.controlArea, self, "Commit", 
     57                     callback=lambda b=True: self.cluster(b)) 
    4658 
    4759    def setNetwork(self, net): 
     
    5062            self.cluster() 
    5163 
    52     def cluster(self): 
     64    def cluster(self, btn=False): 
     65        if not btn and not self.autoApply: 
     66            return 
     67 
    5368        self.info.setText(' ') 
    5469 
     
    6984                                    delta=self.hop_attenuation) 
    7085 
    71         self.info.setText('%d clusters found' % len(set(labels.items()))) 
     86        self.info.setText('%d clusters found' % len(set(labels.values()))) 
    7287        self.send("Network", self.net) 
Note: See TracChangeset for help on using the changeset viewer.