Changeset 7364:f46d45c6796b in orange


Ignore:
Timestamp:
02/04/11 00:21:43 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
d57cbf31defb5ec7192e2365392c83dcbfb7d3c0
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/network/__init__.py

    r7312 r7364  
    1515=========================== 
    1616 
    17 .. autoclass:: Orange.network.NetworkOptimization 
    18    :members: 
     17    .. autoclass:: Orange.network.NetworkOptimization 
     18       :members: 
     19       :exclude-members: collapse  
    1920    
    2021============================= 
     
    2526   :members: 
    2627    
     28    
     29======== 
     30Examples 
     31======== 
     32 
     33Network constructor and random layout 
     34===================================== 
     35 
     36In our first example we create a Network object with a simple full graph (K5).  
     37Vertices are initially placed randomly. Graph is visualized using pylabs  
     38matplotlib. NetworkOptimization class is not needed because we do not apply any  
     39layout optimization method in this example. 
     40 
     41`network-constructor.py`_ 
     42 
     43.. literalinclude:: code/network-constructor.py 
     44 
     45Executing the above script pops-up a pylab window with the following graph  
     46drawing: 
     47 
     48.. image:: files/network-K5-random.png 
     49 
     50Network layout optimization 
     51=========================== 
     52 
     53This example demonstrates how to optimize network layout using one of included  
     54algorithms. 
     55 
     56part of `network-optimization.py`_ 
     57 
     58.. literalinclude:: code/network-optimization.py 
     59    :lines: 12-16 
     60     
     61The following optimization algorithms are supported: 
     62 
     63* .random() 
     64* .fruchtermanReingold(steps, temperature, coolingFactor=Default, hiddenNodes=[], weighted=False) 
     65* .radialFruchtermanReingold(center, steps, temperature) 
     66* .circularOriginal() 
     67* .circularRandom() 
     68* .circularCrossingReduction() 
     69 
     70Spring forces layout optimization is the result of the above script: 
     71 
     72.. image:: files/network-K5-fr.png 
     73 
     74Reading and saving a network 
     75============================ 
     76 
     77This example demonstrates reading a network. Network class can read or write  
     78Pajek (.net) or GML file format. 
     79 
     80`network-read.py`_ (uses: `K5.net`_): 
     81 
     82.. literalinclude:: code/network-read.py 
     83    :lines: 4-5 
     84 
     85Visualize a network in NetExplorer widget 
     86========================================= 
     87 
     88This example demonstrates how to display a network in NetExplorer. 
     89 
     90part of `network-widget.py`_ 
     91 
     92.. literalinclude:: code/network-widget.py 
     93    :lines: 10-16 
     94     
     95.. image:: files/network-explorer.png 
     96    :width: 100% 
     97 
     98.. _network-constructor.py: code/network-constructor.py 
     99.. _network-optimization.py: code/network-optimization.py 
     100.. _network-read.py: code/network-read.py 
     101.. _K5.net: code/K5.net 
     102.. _network-widget.py: code/network-widget.py 
     103 
    27104""" 
    28105import random 
     
    56133        You can modify them manually or use one of the optimization algorithms.  
    57134        Usage: coors[0][i], coors[1][i]; 0 for x-axis, 1 for y-axis 
    58         
     135     
     136     
    59137    .. attribute:: items 
    60138    
     
    78156         
    79157        Creates edges between vertices with the distance within given  
    80         threshold. The . 
     158        threshold. The DistanceMatrix dimension should equal the number of  
     159        vertices. 
    81160         
    82161        :param matrix: number of objects in a matrix must match the number  
     
    90169            connected. 
    91170        :type kNN: int 
     171         
     172    .. method:: hideVertices(vertices) 
     173         
     174        Remove vertices from optimize list 
     175         
     176    .. method:: showVertices(vertices) 
     177     
     178        Add vertices to optimize list 
     179         
     180    .. method:: showAll() 
     181     
     182        Add all vertices to optimize list 
     183         
     184    .. method:: getVisible() 
     185     
     186        Return optimize list 
    92187     
    93188    """ 
     
    288383class NetworkOptimization(orangeom.NetworkOptimization): 
    289384     
    290     """main class for performing network layout optimization. Network structure  
    291     is defined in network.Network class. 
     385    """Perform network layout optimization. Network structure is defined in  
     386    :obj:Orange.network.Network class. 
     387     
     388    :param network: Network to optimize 
     389    :type network: Orange.network.Network 
     390     
     391    .. attribute:: graph 
     392     
     393    Holds the :obj:`Orange.network.Network` object. 
     394     
     395    .. method:: random() 
     396     
     397    Random layout optimization. 
     398     
     399    .. method:: fruchtermanReingold(steps=100, temperature=1000, coolFactor=default, hiddenNodes=[], weighted=False)  
     400         
     401    Fruchterman-Reingold spring layout optimization. Set number of iterations  
     402    with argument steps, start temperature with temperature (for example: 1000)  
     403    and set list of hidden nodes with argument hidden_nodes.     
     404         
     405    .. method:: radialFruchtermanReingold(center, steps=100, temperature=1000) 
     406     
     407    Radial Fruchterman-Reingold spring layout optimization. Set center node  
     408    with attribute center, number of iterations with argument steps and start  
     409    temperature with temperature (for example: 1000). 
     410     
     411    .. method:: circularOriginal() 
     412     
     413    Circular layout optimization based on original order. 
     414     
     415    .. method:: circularRandom() 
     416     
     417    Circular layout optimization based on random order. 
     418     
     419    .. method:: circularCrossingReduction() 
     420     
     421    Circular layout optimization (Michael Baur, Ulrik Brandes) with crossing  
     422    reduction. 
     423     
     424    .. method:: closestVertex(x, y) 
     425     
     426    Return the closest vertex to (x, y) coordinate.   
     427     
     428    .. method:: vertexDistances(x, y) 
     429     
     430    Return distances (list of (distance, vertex) tuples) of all vertices to  
     431    the given coordinate. 
     432     
     433    .. method:: getVerticesInRect(x1, y1, x2, y2) 
     434     
     435    Return a list of all vertices in given rectangle. 
    292436     
    293437    """ 
     
    308452        self.mds = None 
    309453         
    310     def computeForces(self): 
     454    def setNetwork(network): 
     455        """Set the network object for layout optimization. 
     456     
     457        :param network: network object for layout optimization 
     458        :type network: Orange.network.Network 
     459         
     460        """ 
     461        self.setGraph(network) 
     462         
     463    def _computeForces(self): 
     464        """Compute forces for each vertex for force vector visualization.""" 
    311465        n = self.graph.nVertices 
    312466        vertices = set(range(n)) 
     
    350504     
    351505    def collapse(self): 
     506        """Experimental method to group cliques to meta nodes.""" 
    352507        if len(self.graph.getNodes(1)) > 0: 
    353508            nodes = list(set(range(self.graph.nVertices)) - \ 
     
    408563             
    409564    def getVars(self): 
     565        """Return a list of features in network items.""" 
    410566        vars = [] 
    411567        if (self.graph != None): 
     
    420576     
    421577    def getEdgeVars(self): 
     578        """Return a list of features in network links.""" 
    422579        vars = [] 
    423580        if (self.graph != None): 
     
    433590     
    434591    def getData(self, i, j): 
     592        import warnings 
     593        warnings.warn("Deprecated.", DeprecationWarning) 
    435594        if self.graph.items is orange.ExampleTable: 
    436595            return self.data[i][j] 
     
    439598         
    440599    def nVertices(self): 
     600        import warnings 
     601        warnings.warn("Deprecated.", DeprecationWarning) 
    441602        if self.graph: 
    442603            return self.graph.nVertices 
    443604         
    444     def rotateVertices(self, components, phi):    
     605    def rotateVertices(self, components, phi):  
     606        """Rotate network components for a given angle. 
     607         
     608        :param components: list of network components 
     609        :type components: list of lists of vertex indices 
     610        :param phi: list of component rotation angles (unit: radians) 
     611        """   
    445612        #print phi  
    446613        for i in range(len(components)): 
     
    8971064 
    8981065    def saveNetwork(self, fn): 
    899         print "This method is deprecated. Use orngNetwork.Network.saveNetwork" 
     1066        import warnings 
     1067        warnings.warn("Deprecated. Use Orange.network.Network.saveNetwork",  
     1068                      DeprecationWarning) 
    9001069        name = '' 
    9011070        try: 
     
    9711140     
    9721141    def readNetwork(self, fn, directed=0): 
    973         print "This method is deprecated. Use orngNetwork.Network.readNetwork" 
     1142        import warnings 
     1143        warnings.warn("Deprecated. Use Orange.network.Network.readNetwork",  
     1144                      DeprecationWarning) 
    9741145        network = Network(1,directed) 
    9751146        net = network.readPajek(fn, directed) 
     
    9791150     
    9801151class NetworkClustering(): 
    981  
     1152     
     1153    """A collection of algorithms for community detection in graphs. 
     1154     
     1155    :param network: network data for community detection 
     1156    :type network: Orange.network.Network 
     1157    """  
     1158     
    9821159    random.seed(0) 
    9831160     
     
    9871164         
    9881165    def labelPropagation(self, results2items=0, resultHistory2items=0): 
    989         """Label propagation method from Raghavan et al., 2007""" 
     1166        """Label propagation method from Raghavan et al., 2007 
     1167         
     1168        :param results2items: append a new feature result to items  
     1169            (Orange.data.Table) 
     1170        :type results2items: bool 
     1171        :param resultHistory2items: append new features result to items  
     1172            (Orange.data.Table) after each iteration of the algorithm 
     1173        :type resultHistory2items: bool 
     1174        """ 
    9901175         
    9911176        vertices = range(self.net.nVertices) 
Note: See TracChangeset for help on using the changeset viewer.