Changeset 8776:3d530a789fae in orange


Ignore:
Timestamp:
08/25/11 13:05:36 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
daec0952c9408ff504d0673ac12d9e25d5711d5b
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Visualize Qt/OWPubmedView.py

    r8760 r8776  
    1717    """ 
    1818     
    19     def __init__(self, parent, nhops, edge_threshold, algorithm, n_max_neighbors): 
     19    def __init__(self, parent):#, nhops, edge_threshold, algorithm, n_max_neighbors, k): 
    2020        Orange.network.NxView.__init__(self) 
    2121         
    22         self._nhops = nhops 
    23         self._edge_threshold = edge_threshold 
    24         self.algorithm = algorithm # 0 without clustering, 1 with clustering 
    25         self._n_max_neighbors = n_max_neighbors 
    26         #self._center_node = None 
     22        self._nhops = 2 
     23        self._edge_threshold = 0.5 
     24        self.algorithm = 1 # 0 without clustering, 1 with clustering 
     25        self._n_max_neighbors = 10 
    2726        self._center_nodes = [] 
    2827        self.parent = parent 
    29          
     28        self._hidden_nodes = [] 
     29        self._k_algorithm = 0.3 
     30         
    3031    def init_network(self, graph): 
    3132        self._network = graph 
     
    6465            neig = [x for x in self._network.neighbors(i) if x in nodes] #if net.edge[i][x]['weight'] > 0.5] 
    6566            subnet.add_weighted_edges_from([(i,x,w) for x,w in zip(neig, [self._network.edge[i][y]['weight'] for y in neig])]) 
    66      
     67         
     68        subnet.remove_nodes_from(self._hidden_nodes) 
     69        subnet = self._propagate(subnet) 
     70         
    6771        if self._nx_explorer is not None: 
    6872            self._nx_explorer.change_graph(subnet) 
     
    8387    def set_center_nodes(self, c_nodes): 
    8488        self._center_nodes = c_nodes 
     89         
     90    def set_k(self, k): 
     91        self._k_algorithm = k 
    8592     
    8693    def node_selection_changed(self): 
    87      
     94        # selection --> delete_node/delete_node_and_neig/expand/set_score ? 
     95         
    8896        selection = self._nx_explorer.networkCanvas.selected_nodes() 
    89         if len(selection) == 1: 
    90             self._center_node = selection[0] 
    91             self.update_network() 
     97        # case "set_score"  - input = input_score, to be provided 
     98                #self._center_nodes.extend(selection)  # Non servira' 
     99        for i in selection: 
     100            self._network.node[i]['user_score'] = 1 
     101            self._network.node[i]['score'] = 1 # input_score 
     102        # case "expand_node" - with the settings already set 
     103        self._center_nodes.expand(selection) 
     104        # case "delete_node" 
     105        self._hidden_nodes.append(selection) 
     106        # delete_node_and_neig --> ????  
     107         
     108        self.update_network()  #chiama propagate 
    92109         
    93110    def _get_neighbors(self): 
     111    #TO DELETE? 
    94112        nodes = set([self._center_node]) 
    95113        for n in range(self._nhops): 
     
    99117            nodes.update(neighbors) 
    100118        return nodes 
     119         
     120    def _propagate(self, net): 
     121        return 
    101122         
    102123class OWPubmedView(OWWidget): 
     
    119140        self._selected_nodes = [] 
    120141        self._algorithm = 0 
     142        self._k_algorithm = 0.3 
    121143         
    122144        self.loadSettings() 
     
    126148        self.list_titles = OWGUI.listBox(box, self, "selected_titles", "titles", selectionMode=QListWidget.MultiSelection, callback=self.update_view) 
    127149        OWGUI.separator(self.controlArea) 
    128         ib = OWGUI.widgetBox(self.controlArea, "Preferences", orientation="vertical") 
    129         OWGUI.spin(ib, self, "_nhops", 1, 6, 1, label="Number of hops: ", callback=self.update_view) 
    130         OWGUI.spin(ib, self, "_n_max_neighbors", 1, 100, 1, label="Max number of neighbors: ", callback=self.update_view) 
    131         OWGUI.doubleSpin(ib, self, "_edge_threshold", 0, 1, step=0.01, label="Edge threshold: ", callback=self.update_view) 
     150        box_pref = OWGUI.widgetBox(self.controlArea, "Preferences", orientation="vertical") 
     151        OWGUI.spin(box_pref, self, "_nhops", 1, 6, 1, label="Number of hops: ", callback=self.update_view) 
     152        OWGUI.spin(box_pref, self, "_n_max_neighbors", 1, 100, 1, label="Max number of neighbors: ", callback=self.update_view) 
     153        OWGUI.doubleSpin(box_pref, self, "_edge_threshold", 0, 1, step=0.01, label="Edge threshold: ", callback=self.update_view) 
    132154        OWGUI.separator(self.controlArea) 
    133         OWGUI.radioButtonsInBox(self.controlArea, self, "_algorithm", box = "Interest Propagation Algorithm", btnLabels = ["Without clustering", "With clustering"], callback=self.update_view) 
     155        box_alg = OWGUI.widgetBox(self.controlArea, "Interest Propagation Algorithm", orientation="vertical") 
     156        radio_box = OWGUI.radioButtonsInBox(box_alg, self, "_algorithm", [], callback=self.update_view) 
     157        OWGUI.appendRadioButton(radio_box, self, "_algorithm", "Without Clustering", callback=self.update_view) 
     158        OWGUI.doubleSpin(OWGUI.indentedBox(radio_box), self, "_k_algorithm", 0, 1, step=0.01, label="Parameter k: ", callback=self.update_view) 
     159        OWGUI.appendRadioButton(radio_box, self, "_algorithm", "With Clustering", callback=self.update_view) 
    134160         
    135         self.inside_view = PubmedNetworkView(self, self._nhops, self._edge_threshold, self._algorithm, self._n_max_neighbors) 
     161        self.inside_view = PubmedNetworkView(self) 
    136162        self.send("Nx View", self.inside_view) 
    137163         
     
    151177        self.inside_view.set_n_max_neighbors(self._n_max_neighbors) 
    152178        self.inside_view.set_algorithm(self._algorithm) 
     179        self.inside_view.set_k(self._k_algorithm) 
    153180        self._selected_nodes = [self.ids[row] for row in self.selected_titles] 
    154181        self.inside_view.set_center_nodes(self._selected_nodes) 
Note: See TracChangeset for help on using the changeset viewer.