Changeset 8015:b76046958ef8 in orange


Ignore:
Timestamp:
06/14/11 13:55:59 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
d4b7c18ee9609496b11d737a90e4b9c2832928df
Message:

Added some documentation examples.

Location:
orange/Orange/network
Files:
2 edited

Legend:

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

    r8004 r8015  
    1 """  
    2 .. index:: network 
     1""" 
    32 
    4 ********* 
    5 BaseGraph 
    6 ********* 
     3************************* 
     4Network classes in Orange 
     5************************* 
    76 
    8 BaseGraph is primarily used to work with additional data attached to the  
    9 NetworkX graph. Two types of data can be added to the graph: 
     7Orange network classes are derived from `NetworkX basic graph types <http://networkx.lanl.gov/reference/classes.html>`_  
     8and :obj:`Orange.network.BaseGraph`. They provide data structures and methods  
     9for storing graphs, network analysis and layout optimization. 
    1010 
    11 * items (:obj:`Orange.data.Table`) - a table containing data about graph nodes. Each row in the table should correspond to a node with ID set to the row index. 
    12 * links (:obj:`Orange.data.Table`) - a table containing data about graph edges. Each row in the table corresponds to an edge. Two columns titled "u" and "v" must be given in the table, each containing indices of nodes on the given edge. 
     11There are four graph types: :obj:`Orange.network.Graph`,  
     12:obj:`Orange.network.DiGraph`, :obj:`Orange.network.MultiGraph` and 
     13:obj:`Orange.network.MultiDiGraph`. The choice of graph class depends on the  
     14structure of the graph you want to represent. 
     15 
     16Examples 
     17======== 
     18 
     19Reading and writing a network 
     20----------------------------- 
     21 
     22This example demonstrates reading a network. Network class can read or write  
     23Pajek (.net) or GML file format. 
     24 
     25`network-read-nx.py`_ (uses: `K5.net`_): 
     26 
     27.. literalinclude:: code/network-read.py 
     28    :lines: 5-6 
    1329     
    14 Some other methods, common to all graph types are also added to BaseGraph class. 
     30.. _network-read-nx.py: code/network-read-nx.py 
     31.. _K5.net: code/K5.net 
     32 
     33Visualize a network in NetExplorer widget 
     34----------------------------------------- 
     35 
     36This example demonstrates how to display a network in NetExplorer. 
     37 
     38part of `network-widget.py`_ 
     39 
     40.. literalinclude:: code/network-widget.py 
     41    :lines: 10-16 
    1542     
    16 .. autoclass:: Orange.network.BaseGraph 
    17    :members: 
     43.. image:: files/network-explorer.png 
     44    :width: 100% 
    1845 
    19 *********** 
    20 Graph types 
    21 *********** 
     46.. _network-widget.py: code/network-widget.py 
    2247 
    23 The reference in this section is complemented with the original NetworkX  
    24 library reference. For a complete documentation please refer to the  
    25 `NetworkX docs <http://networkx.lanl.gov/reference/>`_. All methods from the 
    26 NetworkX package can be used for graph analysis and manipulation with exception 
    27 to read and write graph methods. For reading and writing graphs please refer to  
    28 the Orange.network.readwrite docs.  
    29  
    30 Graph 
    31 ===== 
    32  
    33 .. autoclass:: Orange.network.Graph 
    34    :members: 
    35  
    36 DiGraph 
    37 ======= 
    38     
    39 .. autoclass:: Orange.network.DiGraph 
    40    :members: 
    41  
    42 MultiGraph 
    43 ========== 
    44     
    45 .. autoclass:: Orange.network.MultiGraph 
    46    :members: 
    47     
    48 MultiDiGraph 
    49 ============ 
    50     
    51 .. autoclass:: Orange.network.MultiDiGraph 
    52    :members: 
    53     
    5448""" 
    5549 
  • orange/Orange/network/network.py

    r8004 r8015  
     1"""  
     2.. index:: network 
     3 
     4********* 
     5BaseGraph 
     6********* 
     7 
     8BaseGraph is primarily used to work with additional data attached to the  
     9NetworkX graph. Two types of data can be added to the graph: 
     10 
     11* items (:obj:`Orange.data.Table`) - a table containing data about graph nodes. Each row in the table should correspond to a node with ID set to the row index. 
     12* links (:obj:`Orange.data.Table`) - a table containing data about graph edges. Each row in the table corresponds to an edge. Two columns titled "u" and "v" must be given in the table, each containing indices of nodes on the given edge. 
     13     
     14Some other methods, common to all graph types are also added to BaseGraph class. 
     15     
     16.. autoclass:: Orange.network.BaseGraph 
     17   :members: 
     18 
     19*********** 
     20Graph types 
     21*********** 
     22 
     23The reference in this section is complemented with the original NetworkX  
     24library reference. For a complete documentation please refer to the  
     25`NetworkX docs <http://networkx.lanl.gov/reference/>`_. All methods from the 
     26NetworkX package can be used for graph analysis and manipulation with exception 
     27to read and write graph methods. For reading and writing graphs please refer to  
     28the Orange.network.readwrite docs.  
     29 
     30Graph 
     31===== 
     32 
     33.. autoclass:: Orange.network.Graph 
     34   :members: 
     35 
     36DiGraph 
     37======= 
     38    
     39.. autoclass:: Orange.network.DiGraph 
     40   :members: 
     41 
     42MultiGraph 
     43========== 
     44    
     45.. autoclass:: Orange.network.MultiGraph 
     46   :members: 
     47    
     48MultiDiGraph 
     49============ 
     50    
     51.. autoclass:: Orange.network.MultiDiGraph 
     52   :members: 
     53    
     54""" 
     55 
    156import copy 
    257import math 
     
    241296    .. automethod:: Orange.network.GraphLayout.rotate_vertices 
    242297     
     298    **Examples** 
     299     
     300    *Network constructor and random layout* 
     301     
     302    In our first example we create a Network object with a simple full graph (K5).  
     303    Vertices are initially placed randomly. Graph is visualized using pylabs  
     304    matplotlib.  
     305         
     306    `network-constructor-nx.py`_ 
     307     
     308    .. literalinclude:: code/network-constructor-nx.py 
     309     
     310    Executing the above saves a pylab window with the following graph drawing: 
     311     
     312    .. image:: files/network-K5-random.png 
     313     
     314    .. _network-constructor-nx.py: code/network-constructor-nx.py 
     315     
     316    *Network layout optimization* 
     317     
     318    This example demonstrates how to optimize network layout using one of the 
     319    included algorithms. 
     320     
     321    part of `network-optimization-nx.py`_ 
     322     
     323    .. literalinclude:: code/network-optimization-nx.py 
     324        :lines: 14-19 
     325         
     326    The result of the above script is a spring force layout optimization: 
     327     
     328    .. image:: files/network-K5-fr.png 
     329     
     330    .. _network-optimization-nx.py: code/network-optimization-nx.py 
     331     
    243332    """ 
    244333     
     
    270359         
    271360    def fr(self, steps, temperature, coolFactor=0, weighted=False): 
    272         """Fruchterman Reingold graph layout. 
     361        """Fruchterman-Reingold spring layout optimization. Set number of  
     362        iterations with argument steps, start temperature with temperature  
     363        (for example: 1000). 
    273364         
    274365        """ 
     
    277368         
    278369    def fr_radial(self, center, steps, temperature): 
    279         """Radial Fruchterman Reingold graph layout. 
     370        """Radial Fruchterman-Reingold spring layout optimization. Set center  
     371        node with attribute center, number of iterations with argument steps  
     372        and start temperature with temperature (for example: 1000). 
    280373         
    281374        """ 
     
    294387     
    295388    def circular_crossing_reduction(self): 
    296         """Circular graph layout with edge crossing reduction.""" 
     389        """Circular graph layout with edge crossing reduction (Michael Baur,  
     390        Ulrik Brandes). 
     391         
     392        """ 
    297393         
    298394        orangeom.GraphLayout.circular_crossing_reduction(self) 
    299395     
    300396    def get_vertices_in_rect(self, x1, y1, x2, y2): 
    301         """Return a list of nodes in given rect.""" 
     397        """Return a list of nodes in the given rectangle.""" 
    302398         
    303399        return orangeom.GraphLayout.get_vertices_in_rect(self, x1, y1, x2, y2) 
     
    309405     
    310406    def vertex_distances(self, x, y): 
    311         """Return a list of distances from all points to the given position.""" 
     407        """Return distances (a list of (distance, vertex) tuples) of all nodes  
     408        to the given position. 
     409         
     410        """ 
    312411         
    313412        return orangeom.GraphLayout.vertex_distances(self, x, y) 
Note: See TracChangeset for help on using the changeset viewer.