Changeset 9623:191a2624aecd in orange
 Timestamp:
 02/02/12 10:08:33 (2 years ago)
 Branch:
 default
 rebase_source:
 588b9bc44afc52a1fdb8df192b6d569989145639
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/network/network.py
r9588 r9623 61 61 import orangeom 62 62 import readwrite 63 from networkx import algorithms 63 from networkx import algorithms 64 64 from networkx.classes import function 65 65 … … 75 75 tmp = doc.replace('nx.', 'Orange.network.') 76 76 return tmp 77 77 78 78 class BaseGraph(): 79 79 """A collection of methods inherited by all graph types (:obj:`Graph`, … … 81 81 82 82 """ 83 83 84 84 def __init__(self): 85 85 self._items = None 86 86 self._links = None 87 87 88 88 def items(self): 89 89 """Return the :obj:`Orange.data.Table` items with data about network … … 91 91 92 92 """ 93 93 94 94 if self._items is not None and \ 95 95 len(self._items) != self.number_of_nodes(): 96 96 print "Warning: items length does not match the number of nodes." 97 97 98 98 return self._items 99 99 100 100 def set_items(self, items=None): 101 101 """Set the :obj:`Orange.data.Table` items to the given data. Notice … … 103 103 104 104 """ 105 105 106 106 if items is not None: 107 107 if not isinstance(items, Orange.data.Table): … … 109 109 if len(items) != self.number_of_nodes(): 110 110 print "Warning: items length must match the number of nodes." 111 111 112 112 self._items = items 113 113 114 114 def links(self): 115 115 """Return the :obj:`Orange.data.Table` links with data about network … … 117 117 118 118 """ 119 119 120 120 if self._links is not None \ 121 121 and len(self._links) != self.number_of_edges(): 122 122 print "Warning: links length does not match the number of edges." 123 123 124 124 return self._links 125 125 126 126 def set_links(self, links=None): 127 127 """Set the :obj:`Orange.data.Table` links to the given data. Notice … … 129 129 130 130 """ 131 131 132 132 if links is not None: 133 133 if not isinstance(links, Orange.data.Table): … … 135 135 if len(links) != self.number_of_edges(): 136 136 print "Warning: links length must match the number of edges." 137 137 138 138 self._links = links 139 139 140 140 def to_orange_network(self): 141 141 """Convert the current network to >>Orange<< NetworkX standard. To use … … 143 143 [0, no_of_nodes  1]. 144 144 145 """ 146 145 """ 146 147 147 G = self.__class__() 148 148 node_list = sorted(self.nodes()) 149 149 node_to_index = dict(zip(node_list, range(self.number_of_nodes()))) 150 150 index_to_node = dict(zip(range(self.number_of_nodes()), node_list)) 151 151 152 152 G.add_nodes_from(zip(range(self.number_of_nodes()), [copy.deepcopy(self.node[nid]) for nid in node_list])) 153 G.add_edges_from(((node_to_index[u], node_to_index[v], copy.deepcopy(self.edge[u][v])) for u, v in self.edges()))154 153 G.add_edges_from(((node_to_index[u], node_to_index[v], copy.deepcopy(self.edge[u][v])) for u, v in self.edges())) 154 155 155 for id in G.node.keys(): 156 G.node[id]['old_id'] = index_to_node[id] 157 156 G.node[id]['old_id'] = index_to_node[id] 157 158 158 if self.items(): 159 159 G.set_items(self.items()) … … 161 161 if self.links(): 162 162 G.set_links(self.links()) 163 163 164 164 return G 165 165 166 166 ### TODO: OVERRIDE METHODS THAT CHANGE GRAPH STRUCTURE, add warning prints 167 167 168 168 def items_vars(self): 169 169 """Return a list of features in the :obj:`Orange.data.Table` items.""" 170 170 171 171 vars = [] 172 172 if (self._items is not None): 173 173 if isinstance(self._items, Orange.data.Table): 174 174 vars = list(self._items.domain.variables) 175 175 176 176 metas = self._items.domain.getmetas(0) 177 177 vars.extend(var for i, var in metas.iteritems()) 178 178 return vars 179 179 180 180 def links_vars(self): 181 181 """Return a list of features in the :obj:`Orange.data.Table` links.""" 182 182 183 183 vars = [] 184 184 if (self._links is not None): 185 185 if isinstance(self._links, Orange.data.Table): 186 186 vars = list(self._links.domain.variables) 187 187 188 188 metas = self._links.domain.getmetas(0) 189 189 vars.extend(var for i, var in metas.iteritems()) 190 return [x for x in vars if str(x.name) != 'u' and str(x.name) != 'v'] 191 190 return [x for x in vars if str(x.name) != 'u' and str(x.name) != 'v'] 191 192 192 class Graph(BaseGraph, nx.Graph): 193 193 """Bases: `NetworkX.Graph <http://networkx.lanl.gov/reference/classes.graph.html>`_, … … 195 195 196 196 """ 197 198 def __init__(self, data=None, name='', **attr): 197 198 def __init__(self, data=None, name='', **attr): 199 199 nx.Graph.__init__(self, data, name=name, **attr) 200 200 BaseGraph.__init__(self) 201 201 202 202 def subgraph(self, nbunch): 203 203 G = nx.Graph.subgraph(self, nbunch) … … 207 207 return G 208 208 # TODO: _links 209 209 210 210 __doc__ += _get_doc(nx.Graph.__doc__) 211 211 __init__.__doc__ = _get_doc(nx.Graph.__init__.__doc__) 212 212 213 213 class DiGraph(BaseGraph, nx.DiGraph): 214 214 """Bases: `NetworkX.DiGraph <http://networkx.lanl.gov/reference/classes.digraph.html>`_, … … 216 216 217 217 """ 218 219 218 219 220 220 def __init__(self, data=None, name='', **attr): 221 221 nx.DiGraph.__init__(self, data, name=name, **attr) 222 222 BaseGraph.__init__(self) 223 223 224 224 __doc__ += _get_doc(nx.DiGraph.__doc__) 225 225 __init__.__doc__ = _get_doc(nx.DiGraph.__init__.__doc__) 226 226 227 227 class MultiGraph(BaseGraph, nx.MultiGraph): 228 228 """Bases: `NetworkX.MultiGraph <http://networkx.lanl.gov/reference/classes.multigraph.html>`_, … … 230 230 231 231 """ 232 233 232 233 234 234 def __init__(self, data=None, name='', **attr): 235 235 nx.MultiGraph.__init__(self, data, name=name, **attr) 236 236 BaseGraph.__init__(self) 237 237 238 238 __doc__ += _get_doc(nx.MultiGraph.__doc__) 239 239 __init__.__doc__ = _get_doc(nx.MultiGraph.__init__.__doc__) 240 240 241 241 class MultiDiGraph(BaseGraph, nx.MultiDiGraph): 242 242 """Bases: `NetworkX.MultiDiGraph <http://networkx.lanl.gov/reference/classes.multidigraph.html>`_, … … 244 244 245 245 """ 246 247 246 247 248 248 def __init__(self, data=None, name='', **attr): 249 249 nx.MultiDiGraph.__init__(self, data, name=name, **attr) 250 250 BaseGraph.__init__(self) 251 251 252 252 __doc__ += _get_doc(nx.MultiDiGraph.__doc__) 253 253 __init__.__doc__ = _get_doc(nx.MultiDiGraph.__init__.__doc__) 254 254 255 255 class GraphLayout(orangeom.GraphLayout): 256 256 """A class for graph layout optimization. Before using any of the layout … … 329 329 330 330 """ 331 331 332 332 def __init__(self): 333 333 self.graph = None 334 334 self.items_matrix = None 335 335 336 336 def set_graph(self, graph=None, positions=None): 337 337 """Init graph structure. … … 345 345 """ 346 346 self.graph = graph 347 347 348 348 if positions is not None and len(positions) == graph.number_of_nodes(): 349 349 orangeom.GraphLayout.set_graph(self, graph, positions) 350 350 else: 351 351 orangeom.GraphLayout.set_graph(self, graph) 352 352 353 353 def random(self): 354 354 """Random graph layout.""" 355 355 356 356 orangeom.GraphLayout.random(self) 357 357 358 358 def fr(self, steps, temperature, coolFactor=0, weighted=False): 359 359 """FruchtermanReingold spring layout optimization. Set number of … … 362 362 363 363 """ 364 364 365 365 return orangeom.GraphLayout.fr(self, steps, temperature, coolFactor, weighted) 366 366 367 367 def fr_radial(self, center, steps, temperature): 368 368 """Radial FruchtermanReingold spring layout optimization. Set center … … 371 371 372 372 """ 373 373 374 374 return orangeom.GraphLayout.fr_radial(self, center, steps, temperature) 375 375 376 376 def circular_original(self): 377 377 """Circular graph layout with original node order.""" 378 378 379 379 orangeom.GraphLayout.circular_original(self) 380 380 381 381 def circular_random(self): 382 382 """Circular graph layout with random node order.""" 383 383 384 384 orangeom.GraphLayout.circular_random(self) 385 385 386 386 def circular_crossing_reduction(self): 387 387 """Circular graph layout with edge crossing reduction (Michael Baur, … … 389 389 390 390 """ 391 391 392 392 orangeom.GraphLayout.circular_crossing_reduction(self) 393 393 394 394 def get_vertices_in_rect(self, x1, y1, x2, y2): 395 395 """Return a list of nodes in the given rectangle.""" 396 396 397 397 return orangeom.GraphLayout.get_vertices_in_rect(self, x1, y1, x2, y2) 398 398 399 399 def closest_vertex(self, x, y): 400 400 """Return the closest node to given point.""" 401 401 402 402 return orangeom.GraphLayout.closest_vertex(self, x, y) 403 403 404 404 def vertex_distances(self, x, y): 405 405 """Return distances (a list of (distance, vertex) tuples) of all nodes … … 407 407 408 408 """ 409 409 410 410 return orangeom.GraphLayout.vertex_distances(self, x, y) 411 412 def rotate_vertices(self, components, phi): 411 412 def rotate_vertices(self, components, phi): 413 413 """Rotate network components for a given angle. 414 414 … … 419 419 :type phi: float 420 420 421 """ 421 """ 422 422 #print phi 423 423 for i in range(len(components)): 424 424 if phi[i] == 0: 425 425 continue 426 426 427 427 component = components[i] 428 428 429 429 x = self.coors[0][component] 430 430 y = self.coors[1][component] 431 431 432 432 x_center = x.mean() 433 433 y_center = y.mean() 434 434 435 435 x = x  x_center 436 436 y = y  y_center 437 437 438 438 r = numpy.sqrt(x ** 2 + y ** 2) 439 439 fi = numpy.arctan2(y, x) 440 440 441 441 fi += phi[i] 442 442 #fi += factor * M[i] * numpy.pi / 180 443 443 444 444 x = r * numpy.cos(fi) 445 445 y = r * numpy.sin(fi) 446 446 447 447 self.coors[0][component] = x + x_center 448 448 self.coors[1][component] = y + y_center 449 450 def rotate_components(self, maxSteps=100, minMoment=0.000000001, 449 450 def rotate_components(self, maxSteps=100, minMoment=0.000000001, 451 451 callbackProgress=None, callbackUpdateCanvas=None): 452 452 """Rotate the network components using a spring model.""" 453 453 454 454 if self.items_matrix == None: 455 455 return 1 456 456 457 457 if self.graph == None: 458 458 return 1 459 459 460 460 if self.items_matrix.dim != self.graph.number_of_nodes(): 461 461 return 1 462 462 463 463 self.stopRotate = 0 464 464 465 465 # rotate only components with more than one vertex 466 466 components = [component for component \ … … 474 474 while step < maxSteps and (max(M) > minMoment or \ 475 475 min(M) < minMoment) and not self.stopRotate: 476 M = [0] * len(components) 477 476 M = [0] * len(components) 477 478 478 for i in range(len(components)): 479 479 component = components[i] 480 480 481 481 outer_vertices = vertices  set(component) 482 482 483 483 x = self.coors[0][component] 484 484 y = self.coors[1][component] 485 485 486 486 x_center = x.mean() 487 487 y_center = y.mean() 488 488 489 489 for j in range(len(component)): 490 490 u = component[j] … … 500 500 e = math.sqrt((v_x  x_center) ** 2 + \ 501 501 (v_y  y_center) ** 2) 502 502 503 503 M[i] += (1  d) / (e ** 2) * numpy.cross(R, L) 504 504 505 505 tmpM = numpy.array(M) 506 506 #print numpy.min(tmpM), numpy.max(tmpM),numpy.average(tmpM),numpy.min(numpy.abs(tmpM)) 507 507 508 508 phi = [0] * len(components) 509 509 #print "rotating", temperature, M … … 514 514 temperature[i][1] = 1 515 515 dirChange[i] += 1 516 516 517 517 phi[i] = temperature[i][0] * numpy.pi / 180 518 elif M[i] < 0: 518 elif M[i] < 0: 519 519 if temperature[i][1] > 0: 520 520 temperature[i][0] = temperature[i][0] * 5 / 10 521 521 temperature[i][1] = 1 522 522 dirChange[i] += 1 523 523 524 524 phi[i] = temperature[i][0] * numpy.pi / 180 525 525 526 526 # stop rotating when phi is to small to notice the rotation 527 527 if max(phi) < numpy.pi / 1800: 528 528 #print "breaking" 529 529 break 530 530 531 531 self.rotate_vertices(components, phi) 532 532 if callbackUpdateCanvas: callbackUpdateCanvas() … … 534 534 in range(len(dirChange)) if M[i] != 0]), 9) 535 535 step += 1 536 536 537 537 def mds_update_data(self, components, mds, callbackUpdateCanvas): 538 538 """Translate and rotate the network components to computed positions.""" 539 539 540 540 component_props = [] 541 541 x_mds = [] 542 542 y_mds = [] 543 543 phi = [None] * len(components) 544 self.diag_coors = math.sqrt(( 545 min(self.coors[0])  max(self.coors[0])) **2 + \546 (min(self.coors[1])  max(self.coors[1])) **2)547 544 self.diag_coors = math.sqrt((\ 545 min(self.coors[0])  max(self.coors[0])) ** 2 + \ 546 (min(self.coors[1])  max(self.coors[1])) ** 2) 547 548 548 if self.mdsType == MdsType.MDS: 549 549 x = [mds.points[u][0] for u in range(self.graph.number_of_nodes())] 550 550 y = [mds.points[u][1] for u in range(self.graph.number_of_nodes())] 551 self.coors[0][range(self.graph.number_of_nodes())] = 552 self.coors[1][range(self.graph.number_of_nodes())] = 551 self.coors[0][range(self.graph.number_of_nodes())] = x 552 self.coors[1][range(self.graph.number_of_nodes())] = y 553 553 if callbackUpdateCanvas: 554 554 callbackUpdateCanvas() 555 555 return 556 557 for i in range(len(components)): 556 557 for i in range(len(components)): 558 558 component = components[i] 559 559 560 560 if len(mds.points) == len(components): # if average linkage before 561 561 x_avg_mds = mds.points[i][0] … … 564 564 x = [mds.points[u][0] for u in component] 565 565 y = [mds.points[u][1] for u in component] 566 567 x_avg_mds = sum(x) / len(x) 566 567 x_avg_mds = sum(x) / len(x) 568 568 y_avg_mds = sum(y) / len(y) 569 569 # compute rotation angle 570 570 c = [numpy.linalg.norm(numpy.cross(mds.points[u], \ 571 [self.coors[0][u], self.coors[1][u]])) \571 [self.coors[0][u], self.coors[1][u]])) \ 572 572 for u in component] 573 573 n = [numpy.vdot([self.coors[0][u], \ … … 577 577 phi[i] = sum(c) / sum(n) 578 578 #print phi 579 579 580 580 x = self.coors[0][component] 581 581 y = self.coors[1][component] 582 582 583 583 x_avg_graph = sum(x) / len(x) 584 584 y_avg_graph = sum(y) / len(y) 585 586 x_mds.append(x_avg_mds) 585 586 x_mds.append(x_avg_mds) 587 587 y_mds.append(y_avg_mds) 588 588 589 589 component_props.append((x_avg_graph, y_avg_graph, \ 590 590 x_avg_mds, y_avg_mds, phi)) 591 591 592 592 w = max(self.coors[0])  min(self.coors[0]) 593 593 h = max(self.coors[1])  min(self.coors[1]) 594 d = math.sqrt(w **2 + h**2)594 d = math.sqrt(w ** 2 + h ** 2) 595 595 #d = math.sqrt(w*h) 596 e = [math.sqrt((self.coors[0][u]  self.coors[0][v]) **2 +597 (self.coors[1][u]  self.coors[1][v]) **2) for596 e = [math.sqrt((self.coors[0][u]  self.coors[0][v]) ** 2 + 597 (self.coors[1][u]  self.coors[1][v]) ** 2) for 598 598 (u, v) in self.graph.edges()] 599 599 600 600 if self.scalingRatio == 0: 601 601 pass … … 621 621 x2 = self.coors[0][j] 622 622 y2 = self.coors[1][j] 623 e_fr += math.sqrt((x1 x2)**2 + (y1y2)**2)623 e_fr += math.sqrt((x1  x2) ** 2 + (y1  y2) ** 2) 624 624 e_count += 1 625 625 self.mdsScaleRatio = e_fr / e_count … … 633 633 x_avg_graph_j, y_avg_graph_j, x_avg_mds_j, \ 634 634 y_avg_mds_j, phi_j = component_props[j] 635 e_fr += math.sqrt((x_avg_graph_i x_avg_graph_j)**2 + \636 (y_avg_graph_i y_avg_graph_j)**2)635 e_fr += math.sqrt((x_avg_graph_i  x_avg_graph_j) ** 2 + \ 636 (y_avg_graph_i  y_avg_graph_j) ** 2) 637 637 e_count += 1 638 self.mdsScaleRatio = e_fr / e_count 638 self.mdsScaleRatio = e_fr / e_count 639 639 elif self.scalingRatio == 9: 640 640 e_fr = 0 641 641 e_count = 0 642 for i in range(len(components)): 642 for i in range(len(components)): 643 643 component = components[i] 644 644 x = self.coors[0][component] … … 650 650 x2 = x[j] 651 651 y2 = y[j] 652 e_fr += math.sqrt((x1 x2)**2 + (y1y2)**2)652 e_fr += math.sqrt((x1  x2) ** 2 + (y1  y2) ** 2) 653 653 e_count += 1 654 654 self.mdsScaleRatio = e_fr / e_count 655 656 diag_mds = math.sqrt((max(x_mds)  min(x_mds))**2 + (max(y_mds)  \657 min(y_mds)) **2)658 e = [math.sqrt((self.coors[0][u]  self.coors[0][v]) **2 +659 (self.coors[1][u]  self.coors[1][v]) **2) for655 656 diag_mds = math.sqrt((max(x_mds)  min(x_mds)) ** 2 + (max(y_mds)  \ 657 min(y_mds)) ** 2) 658 e = [math.sqrt((self.coors[0][u]  self.coors[0][v]) ** 2 + 659 (self.coors[1][u]  self.coors[1][v]) ** 2) for 660 660 (u, v) in self.graph.edges()] 661 661 e = sum(e) / float(len(e)) 662 662 663 663 x = [mds.points[u][0] for u in range(len(mds.points))] 664 664 y = [mds.points[u][1] for u in range(len(mds.points))] 665 665 w = max(x)  min(x) 666 666 h = max(y)  min(y) 667 d = math.sqrt(w **2 + h**2)668 667 d = math.sqrt(w ** 2 + h ** 2) 668 669 669 if len(x) == 1: 670 670 r = 1 … … 693 693 x2 = mds.points[j][0] 694 694 y2 = mds.points[j][1] 695 e_mds += math.sqrt((x1 x2)**2 + (y1y2)**2)695 e_mds += math.sqrt((x1  x2) ** 2 + (y1  y2) ** 2) 696 696 e_count += 1 697 697 r = self.mdsScaleRatio / e_mds * e_count … … 705 705 x_avg_graph_j, y_avg_graph_j, x_avg_mds_j, \ 706 706 y_avg_mds_j, phi_j = component_props[j] 707 e_mds += math.sqrt((x_avg_mds_i x_avg_mds_j)**2 + \708 (y_avg_mds_i y_avg_mds_j)**2)707 e_mds += math.sqrt((x_avg_mds_i  x_avg_mds_j) ** 2 + \ 708 (y_avg_mds_i  y_avg_mds_j) ** 2) 709 709 e_count += 1 710 710 r = self.mdsScaleRatio / e_mds * e_count … … 718 718 x2 = mds.points[j][0] 719 719 y2 = mds.points[j][1] 720 e_mds += math.sqrt((x1 x2)**2 + (y1y2)**2)720 e_mds += math.sqrt((x1  x2) ** 2 + (y1  y2) ** 2) 721 721 e_count += 1 722 722 r = self.mdsScaleRatio / e_mds * e_count 723 723 724 724 #r = self.mdsScaleRatio / d 725 725 #print "d", d, "r", r 726 726 #r = self.mdsScaleRatio / math.sqrt(self.graph.number_of_nodes()) 727 727 728 728 for i in range(len(components)): 729 729 component = components[i] 730 730 x_avg_graph, y_avg_graph, x_avg_mds, \ 731 731 y_avg_mds, phi = component_props[i] 732 732 733 733 # if phi[i]: # rotate vertices 734 734 # #print "rotate", i, phi[i] … … 738 738 # self.coors[0][component] = [u[0] for u in v] 739 739 # self.coors[1][component] = [u[1] for u in v] 740 740 741 741 # translate vertices 742 742 if not self.rotationOnly: … … 745 745 self.coors[1][component] = \ 746 746 (self.coors[1][component]  y_avg_graph) / r + y_avg_mds 747 747 748 748 if callbackUpdateCanvas: 749 749 callbackUpdateCanvas() 750 750 751 751 def mds_callback(self, a, b=None): 752 752 """Refresh the UI when running MDS on network components.""" 753 753 754 754 if not self.mdsStep % self.mdsRefresh: 755 self.mds_update_data(self.mdsComponentList, 756 self.mds, 755 self.mds_update_data(self.mdsComponentList, 756 self.mds, 757 757 self.callbackUpdateCanvas) 758 758 759 759 if self.mdsType == MdsType.exactSimulation: 760 760 self.mds.points = [[self.coors[0][i], \ … … 762 762 for i in range(len(self.coors))] 763 763 self.mds.freshD = 0 764 764 765 765 if self.callbackProgress != None: 766 766 self.callbackProgress(self.mds.avg_stress, self.mdsStep) 767 767 768 768 self.mdsStep += 1 769 769 … … 772 772 else: 773 773 return 1 774 774 775 775 def mds_components(self, mdsSteps, mdsRefresh, callbackProgress=None, \ 776 776 callbackUpdateCanvas=None, torgerson=0, \ 777 minStressDelta=0, avgLinkage=False, rotationOnly=False, \777 minStressDelta=0, avgLinkage=False, rotationOnly=False, \ 778 778 mdsType=MdsType.componentMDS, scalingRatio=0, \ 779 779 mdsFromCurrentPos=0): … … 786 786 self.information('Set distance matrix to input signal') 787 787 return 1 788 788 789 789 if self.graph == None: 790 790 return 1 791 791 792 792 if self.items_matrix.dim != self.graph.number_of_nodes(): 793 793 return 1 794 794 795 795 self.mdsComponentList = Orange.network.nx.algorithms.components.connected_components(self.graph) 796 796 self.mdsRefresh = mdsRefresh … … 798 798 self.stopMDS = 0 799 799 self.items_matrix.matrixType = Orange.core.SymMatrix.Symmetric 800 self.diag_coors = math.sqrt((min(self.coors[0])  801 max(self.coors[0])) **2 + \800 self.diag_coors = math.sqrt((min(self.coors[0])  \ 801 max(self.coors[0])) ** 2 + \ 802 802 (min(self.coors[1])  \ 803 max(self.coors[1])) **2)803 max(self.coors[1])) ** 2) 804 804 self.rotationOnly = rotationOnly 805 805 self.mdsType = mdsType … … 808 808 w = max(self.coors[0])  min(self.coors[0]) 809 809 h = max(self.coors[1])  min(self.coors[1]) 810 d = math.sqrt(w **2 + h**2)810 d = math.sqrt(w ** 2 + h ** 2) 811 811 #d = math.sqrt(w*h) 812 e = [math.sqrt((self.coors[0][u]  self.coors[0][v]) **2 +813 (self.coors[1][u]  self.coors[1][v]) **2) for812 e = [math.sqrt((self.coors[0][u]  self.coors[0][v]) ** 2 + 813 (self.coors[1][u]  self.coors[1][v]) ** 2) for 814 814 (u, v) in self.graph.edges()] 815 815 self.mdsScaleRatio = d / sum(e) * float(len(e)) 816 816 #print d / sum(e) * float(len(e)) 817 817 818 818 if avgLinkage: 819 819 matrix = self.items_matrix.avgLinkage(self.mdsComponentList) 820 820 else: 821 821 matrix = self.items_matrix 822 822 823 823 #if self.mds == None: 824 824 self.mds = Orange.projection.mds.MDS(matrix) 825 825 826 826 if mdsFromCurrentPos: 827 827 if avgLinkage: … … 833 833 else: 834 834 for u in range(self.graph.number_of_nodes()): 835 self.mds.points[u][0] = self.coors[0][u] 835 self.mds.points[u][0] = self.coors[0][u] 836 836 self.mds.points[u][1] = self.coors[1][u] 837 837 838 838 # set min stress difference between 0.01 and 0.00001 839 839 self.minStressDelta = minStressDelta 840 840 self.callbackUpdateCanvas = callbackUpdateCanvas 841 841 self.callbackProgress = callbackProgress 842 842 843 843 if torgerson: 844 self.mds.Torgerson() 845 846 self.mds.optimize(mdsSteps, Orange.projection.mds.SgnRelStress, self.minStressDelta, \844 self.mds.Torgerson() 845 846 self.mds.optimize(mdsSteps, Orange.projection.mds.SgnRelStress, self.minStressDelta, \ 847 847 progress_callback=self.mds_callback) 848 848 self.mds_update_data(self.mdsComponentList, self.mds, callbackUpdateCanvas) 849 849 850 850 if callbackProgress != None: 851 851 callbackProgress(self.mds.avg_stress, self.mdsStep) 852 852 853 853 del self.rotationOnly 854 854 del self.diag_coors … … 868 868 callbackProgress=None, \ 869 869 callbackUpdateCanvas=None, torgerson=0, \ 870 minStressDelta = 0, scalingRatio=0,\870 minStressDelta=0, scalingRatio=0, \ 871 871 mdsFromCurrentPos=0): 872 872 return self.mds_components(mdsSteps, mdsRefresh, callbackProgress, \ … … 875 875 scalingRatio=scalingRatio, \ 876 876 mdsFromCurrentPos=mdsFromCurrentPos) 877 877 878 878 ########################################################################## 879 879 ### BEGIN: DEPRECATED METHODS (TO DELETE IN ORANGE 3.0) ### 880 880 ########################################################################## 881 881 882 882 def map_to_graph(self, graph): 883 883 nodes = sorted(graph.nodes()) 884 return dict((v, (self.coors[0][i], self.coors[1][i])) for i, v in \884 return dict((v, (self.coors[0][i], self.coors[1][i])) for i, v in \ 885 885 enumerate(nodes)) 886 886 887 887 888 class NxView(object): 888 """Network View 889 890 """ 891 889 """Network View""" 890 892 891 def __init__(self, **attr): 893 892 self._network = None 894 893 self._nx_explorer = None 895 894 896 895 def set_nx_explorer(self, _nx_explorer): 897 896 self._nx_explorer = _nx_explorer 898 897 899 898 def init_network(self, graph): 900 899 return graph 901 902 def node s_selected(self):900 901 def node_selection_changed(self): 903 902 pass 904 903 905 #def node_selection_changed(self): 906 # pass 904 def update_network(self): 905 if self._nx_explorer is not None and self._network is not None: 906 subnet = self._network 907 self._nx_explorer.change_graph(subnet)
Note: See TracChangeset
for help on using the changeset viewer.