orange-network / _network / widgets /

<name>Net Clustering</name>
<description>Orange widget for community detection in networks</description>
<contact>Miha Stajdohar (miha.stajdohar(@at@)</contact>

import as cd
import OWGUI

from OWWidget import *

class OWNxClustering(OWWidget):

    settingsList = ['method', 'iterationHistory', 'autoApply', 'iterations',

    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'Nx Clustering')

        self.inputs = [("Network",,
                        self.setNetwork, Default)]
        self.outputs = [("Network",,
                        ("Community Detection", cd.CommunityDetection)] = None
        self.method = 0
        self.iterationHistory = 0
        self.autoApply = 0
        self.iterations = 1000
        self.hop_attenuation = 0.1

        OWGUI.spin(self.controlArea, self, "iterations", 1,
                   100000, 1, label="Iterations: ")
        ribg = OWGUI.radioButtonsInBox(self.controlArea, self, "method",
                                       [], "Method", callback=self.cluster)
        OWGUI.appendRadioButton(ribg, self, "method",
                        "Label propagation clustering (Raghavan et al., 2007)",

        OWGUI.appendRadioButton(ribg, self, "method",
                        "Label propagation clustering (Leung et al., 2009)",
        OWGUI.doubleSpin(OWGUI.indentedBox(ribg), self, "hop_attenuation",
                         0, 1, 0.01, label="Hop attenuation (delta): ") = OWGUI.widgetLabel(self.controlArea, ' ')
        OWGUI.checkBox(self.controlArea, self, "iterationHistory",
                       "Append clustering data on each iteration",
        OWGUI.checkBox(self.controlArea, self, "autoApply",
                       "Commit automatically")
        OWGUI.button(self.controlArea, self, "Commit",
                     callback=lambda b=True: self.cluster(b))


    def setNetwork(self, net): = net
        if self.autoApply:

    def cluster(self, btn=False):
        if not btn and not self.autoApply:
            return' ')

        if self.method == 0:
            alg = cd.label_propagation
            kwargs = {'results2items': 1,
                      'resultHistory2items': self.iterationHistory,
                      'iterations': self.iterations}

        elif self.method == 1:
            alg = cd.label_propagation_hop_attenuation
            kwargs = {'results2items': 1,
                      'resultHistory2items': self.iterationHistory,
                      'iterations': self.iterations,
                      'delta': self.hop_attenuation}

        self.send("Community Detection", cd.CommunityDetection(alg, **kwargs))

        if is None:
            self.send("Network", None)

        labels = alg(, **kwargs)'%d clusters found' % len(set(labels.values())))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.