Changeset 8004:d19b5798c061 in orange


Ignore:
Timestamp:
06/13/11 17:53:16 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
d139913b090e6d4051b418dc1a07257e6fd6d5eb
Message:

New network documentation.

Location:
orange/Orange/network
Files:
4 edited

Legend:

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

    r7999 r8004  
    77 
    88BaseGraph is primarily used to work with additional data attached to the  
    9 NetworkX graph. Two types of data can be added to the graph:  
    10     * 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. 
    11     * 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. 
     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. 
    1213     
    1314Some other methods, common to all graph types are also added to BaseGraph class. 
  • orange/Orange/network/community.py

    r7999 r8004  
    4343    """Label propagation for community detection, Leung et al., 2009 
    4444     
    45     :param results2items: append a new feature result to items  
    46         (Orange.data.Table) 
     45    :param G: A Orange graph. 
     46    :type G: Orange.network.Graph 
     47     
     48    :param results2items: Append a new feature result to items  
     49        (Orange.data.Table). 
    4750    :type results2items: bool 
    48     :param resultHistory2items: append new features result to items  
    49         (Orange.data.Table) after each iteration of the algorithm 
     51     
     52    :param resultHistory2items: Append new features result to items  
     53        (Orange.data.Table) after each iteration of the algorithm. 
    5054    :type resultHistory2items: bool 
     55     
     56    :param iterations: The maximum number of iterations if there is no convergence.  
     57    :type iterations: int 
     58     
     59    :param delta: The hop attenuation factor.  
     60    :type delta: float 
     61     
     62    :param node_degree_preference: The power on node degree factor.  
     63    :type node_degree_preference: float 
     64     
    5165    """ 
    5266     
     
    99113    """Label propagation for community detection, Raghavan et al., 2007 
    100114     
    101     :param results2items: append a new feature result to items  
    102         (Orange.data.Table) 
     115    :param G: A Orange graph. 
     116    :type G: Orange.network.Graph 
     117     
     118    :param results2items: Append a new feature result to items  
     119        (Orange.data.Table). 
    103120    :type results2items: bool 
    104     :param resultHistory2items: append new features result to items  
    105         (Orange.data.Table) after each iteration of the algorithm 
     121     
     122    :param resultHistory2items: Append new features result to items  
     123        (Orange.data.Table) after each iteration of the algorithm. 
    106124    :type resultHistory2items: bool 
     125     
     126    :param iterations: The maximum number of iterations if there is no convergence.  
     127    :type iterations: int 
     128     
    107129    """ 
    108130     
  • orange/Orange/network/network.py

    r7999 r8004  
    2121MdsType = MdsTypeClass() 
    2222 
     23 
     24def _get_doc(doc): 
     25    tmp = doc.replace('----------', '').replace('--------', '') 
     26    tmp = tmp.replace('nx.', 'Orange.network.') 
     27    return tmp 
     28     
    2329class BaseGraph(): 
    2430    """A collection of methods inherited by all graph types (:obj:`Graph`,  
     
    145151        BaseGraph.__init__(self) 
    146152     
    147     __doc__ += nx.Graph.__doc__ 
    148     __init__.__doc__ = nx.Graph.__init__.__doc__ 
     153    __doc__ += _get_doc(nx.Graph.__doc__) 
     154    __init__.__doc__ = _get_doc(nx.Graph.__init__.__doc__) 
    149155      
    150156class DiGraph(BaseGraph, nx.DiGraph): 
     
    159165        BaseGraph.__init__(self) 
    160166     
    161     __doc__ += nx.Graph.__doc__ 
    162     __init__.__doc__ = nx.DiGraph.__init__.__doc__ 
     167    __doc__ += _get_doc(nx.DiGraph.__doc__) 
     168    __init__.__doc__ = _get_doc(nx.DiGraph.__init__.__doc__) 
    163169      
    164170class MultiGraph(BaseGraph, nx.MultiGraph): 
     
    172178        nx.MultiGraph.__init__(self, data, name, **attr) 
    173179        BaseGraph.__init__(self) 
    174          
    175     __doc__ += nx.Graph.__doc__ 
    176     __init__.__doc__ = nx.MultiGraph.__init__.__doc__ 
     180     
     181    __doc__ += _get_doc(nx.MultiGraph.__doc__) 
     182    __init__.__doc__ = _get_doc(nx.MultiGraph.__init__.__doc__) 
    177183      
    178184class MultiDiGraph(BaseGraph, nx.MultiDiGraph): 
     
    187193        BaseGraph.__init__(self) 
    188194     
    189     __doc__ += nx.Graph.__doc__     
    190     __init__.__doc__ = nx.MultiDiGraph.__init__.__doc__ 
    191  
     195    __doc__ += _get_doc(nx.MultiDiGraph.__doc__) 
     196    __init__.__doc__ = _get_doc(nx.MultiDiGraph.__init__.__doc__) 
     197     
    192198class GraphLayout(orangeom.GraphLayout): 
    193     """A graph layout optimization class. 
     199    """A class for graph layout optimization. Before using any of the layout 
     200    optimization technique, the class have to be initialized with the :obj:`set_graph` 
     201    method. Also, do not forget to call :obj:`set_graph` again if the graph 
     202    structure changes. 
     203     
     204    .. attribute:: coors 
     205    
     206    Coordinates of all vertices. They are initialized to random positions. 
     207    You can modify them manually or use one of the optimization algorithms. 
     208    Usage: coors[0][i], coors[1][i]; 0 for x-axis, 1 for y-axis 
     209     
     210     
     211    .. automethod:: Orange.network.GraphLayout.set_graph 
     212     
     213    **Network optimization** 
     214     
     215    .. automethod:: Orange.network.GraphLayout.random 
     216     
     217    .. automethod:: Orange.network.GraphLayout.fr 
     218     
     219    .. automethod:: Orange.network.GraphLayout.fr_radial 
     220     
     221    .. automethod:: Orange.network.GraphLayout.circular_original 
     222     
     223    .. automethod:: Orange.network.GraphLayout.circular_random 
     224     
     225    .. automethod:: Orange.network.GraphLayout.circular_crossing_reduction 
     226     
     227    **FragViz** 
     228     
     229    .. automethod:: Orange.network.GraphLayout.mds_components 
     230     
     231    .. automethod:: Orange.network.GraphLayout.rotate_components 
     232     
     233    **Helper methods**  
     234     
     235    .. automethod:: Orange.network.GraphLayout.get_vertices_in_rect 
     236     
     237    .. automethod:: Orange.network.GraphLayout.closest_vertex 
     238     
     239    .. automethod:: Orange.network.GraphLayout.vertex_distances 
     240     
     241    .. automethod:: Orange.network.GraphLayout.rotate_vertices 
    194242     
    195243    """ 
     
    200248         
    201249    def set_graph(self, graph=None, positions=None): 
    202         """Initialize graph structure 
    203          
    204         :param graph: NetworkX graph 
     250        """Init graph structure. 
     251         
     252        :param graph: Orange network 
     253        :type graph: Orange.netowork.Graph 
     254         
     255        :param positions: Initial node positions 
     256        :type positions: A list of positions (x, y) 
    205257         
    206258        """ 
     
    213265             
    214266    def random(self): 
     267        """Random graph layout.""" 
     268         
    215269        orangeom.GraphLayout.random(self) 
    216270         
    217271    def fr(self, steps, temperature, coolFactor=0, weighted=False): 
     272        """Fruchterman Reingold graph layout. 
     273         
     274        """ 
     275         
    218276        return orangeom.GraphLayout.fr(self, steps, temperature, coolFactor, weighted) 
    219277         
    220278    def fr_radial(self, center, steps, temperature): 
     279        """Radial Fruchterman Reingold graph layout. 
     280         
     281        """ 
     282         
    221283        return orangeom.GraphLayout.fr_radial(self, center, steps, temperature) 
    222284     
    223285    def circular_original(self): 
     286        """Circular graph layout with original node order.""" 
     287         
    224288        orangeom.GraphLayout.circular_original(self) 
    225289     
    226290    def circular_random(self): 
     291        """Circular graph layout with random node order.""" 
     292         
    227293        orangeom.GraphLayout.circular_random(self) 
    228294     
    229295    def circular_crossing_reduction(self): 
     296        """Circular graph layout with edge crossing reduction.""" 
     297         
    230298        orangeom.GraphLayout.circular_crossing_reduction(self) 
    231299     
    232300    def get_vertices_in_rect(self, x1, y1, x2, y2): 
     301        """Return a list of nodes in given rect.""" 
     302         
    233303        return orangeom.GraphLayout.get_vertices_in_rect(self, x1, y1, x2, y2) 
    234304     
    235305    def closest_vertex(self, x, y): 
     306        """Return the closest node to given point.""" 
     307         
    236308        return orangeom.GraphLayout.closest_vertex(self, x, y) 
    237309     
    238310    def vertex_distances(self, x, y): 
     311        """Return a list of distances from all points to the given position.""" 
     312         
    239313        return orangeom.GraphLayout.vertex_distances(self, x, y) 
    240314     
     
    244318        :param components: list of network components 
    245319        :type components: list of lists of vertex indices 
     320         
    246321        :param phi: list of component rotation angles (unit: radians) 
     322        :type phi: float 
     323         
    247324        """   
    248325        #print phi  
     
    277354                          callbackProgress=None, callbackUpdateCanvas=None): 
    278355        """Rotate the network components using a spring model.""" 
     356         
    279357        if self.items_matrix == None: 
    280358            return 1 
     
    362440    def mds_update_data(self, components, mds, callbackUpdateCanvas): 
    363441        """Translate and rotate the network components to computed positions.""" 
     442         
    364443        component_props = [] 
    365444        x_mds = [] 
     
    575654    def mds_callback(self, a, b=None): 
    576655        """Refresh the UI when running  MDS on network components.""" 
     656         
    577657        if not self.mdsStep % self.mdsRefresh: 
    578658            self.mds_update_data(self.mdsComponentList,  
  • orange/Orange/network/readwrite.py

    r7999 r8004  
    99**************************** 
    1010 
    11  
     11When using networks in Orange data mining suite, I advise you not to use  
     12NetworkX reading and writing methods.  Instead, use new methods provided in 
     13the :obj:`Orange.network.readwrite` module. If, for some reason, you have to  
     14use the original read / write methods, do not forget to cast the network (see  
     15Orange.network.readwrite._wrap method).   
    1216 
    1317""" 
     
    1923import networkx as nx 
    2024import networkx.readwrite as rw 
    21 from networkx.utils import _get_fh 
    22  
    23 import orangeom 
     25 
     26from networkx.utils import _get_fh, make_str, is_string_like 
     27 
    2428import Orange 
    2529import Orange.network 
     30import orangeom 
    2631 
    2732__all__ = ['read', 'write', 'read_gpickle', 'write_gpickle', 'read_pajek',  
     
    3742    return g 
    3843 
     44def _add_doc(myclass, nxclass): 
     45    tmp = nxclass.__doc__.replace('----------', '').replace('--------', '') 
     46    tmp = tmp.replace('-------', '').replace('-----', '') 
     47    tmp = tmp.replace('nx.write', 'Orange.network.readwrite.write') 
     48    tmp = tmp.replace('nx.read', 'Orange.network.readwrite.read') 
     49    tmp = tmp.replace('nx', 'Orange.network.nx') 
     50    myclass.__doc__ += tmp  
     51 
    3952def read(path, encoding='UTF-8'): 
     53    """Read graph in any of the supported file formats (.gpickle, .net, .gml). 
     54    The parser is chosen based on the file extension. 
     55     
     56    :param path: File or filename to write. 
     57    :type path: string 
     58 
     59    Return the network of type :obj:`Orange.network.Graph`,  
     60    :obj:`Orange.network.DiGraph`, :obj:`Orange.network.Graph` or  
     61    :obj:`Orange.network.DiGraph`. 
     62     
     63    """ 
     64     
    4065    #supported = ['.net', '.gml', '.gpickle', '.gz', '.bz2', '.graphml'] 
    4166    supported = ['.net', '.gml', '.gpickle'] 
     
    5883 
    5984def write(G, path, encoding='UTF-8'): 
     85    """Write graph in any of the supported file formats (.gpickle, .net, .gml). 
     86    The file format is chosen based on the file extension. 
     87     
     88    :param G: A Orange graph. 
     89    :type G: Orange.network.Graph 
     90          
     91    :param path: File or filename to write. 
     92    :type path: string 
     93      
     94    """ 
     95     
    6096    #supported = ['.net', '.gml', '.gpickle', '.gz', '.bz2', '.graphml'] 
    6197    supported = ['.net', '.gml', '.gpickle'] 
     
    81117 
    82118def read_gpickle(path): 
     119    """NetworkX read_gpickle method and wrap graph to Orange network. 
     120     
     121    """ 
     122     
    83123    return _wrap(rw.read_gpickle(path)) 
    84124 
     125_add_doc(read_gpickle, rw.read_gpickle) 
     126 
    85127def write_gpickle(G, path): 
     128    """NetworkX write_gpickle method. 
     129     
     130    """ 
     131     
    86132    rw.write_gpickle(G, path) 
    87133 
     134_add_doc(write_gpickle, rw.write_gpickle) 
     135 
    88136def read_pajek(path, encoding='UTF-8'): 
    89     """  
    90     Read Pajek file. 
    91     """ 
     137    """A completely reimplemented method for reading Pajek files. Written in  
     138    C++ for maximum performance.   
     139     
     140    :param path: File or filename to write. 
     141    :type path: string 
     142         
     143    Return the network of type :obj:`Orange.network.Graph` or  
     144    :obj:`Orange.network.DiGraph`. 
     145 
     146 
     147    Examples 
     148 
     149    >>> G=Orange.network.nx.path_graph(4) 
     150    >>> Orange.network.readwrite.write_pajek(G, "test.net") 
     151    >>> G=Orange.network.readwrite.read_pajek("test.net") 
     152 
     153    To create a Graph instead of a MultiGraph use 
     154 
     155    >>> G1=Orange.network.Graph(G) 
     156 
     157    References 
     158 
     159    See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm 
     160    for format information. 
     161     
     162    """ 
     163     
    92164    edges, arcs, items = orangeom.GraphLayout().readPajek(path) 
    93165    if len(arcs) > 0: 
     
    111183 
    112184def write_pajek(G, path, encoding='UTF-8'): 
    113     """ 
    114     A copy&paste of networkx's function with some bugs fixed: 
    115      - call the new generate_pajek. 
    116     """ 
     185    """A copy & paste of NetworkX's function with some bugs fixed (call the new  
     186    generate_pajek). 
     187     
     188    """ 
     189     
    117190    fh=_get_fh(path, 'wb') 
    118191    for line in generate_pajek(G): 
     
    120193        fh.write(line.encode(encoding)) 
    121194 
     195_add_doc(write_pajek, rw.write_pajek) 
     196 
    122197def parse_pajek(lines): 
    123     """ 
    124     Parse string in Pajek file format. 
    125     """ 
     198    """Parse string in Pajek file format. See read_pajek for usage examples. 
     199     
     200    :param lines: a string of network data in Pajek file format. 
     201    :type lines: string 
     202     
     203    """ 
     204     
    126205    return read_pajek(lines) 
    127206 
     207 
    128208def generate_pajek(G): 
    129     """ 
    130     A copy&paste of networkx's function with some bugs fixed: 
    131      - generate one line per object (vertex, edge, arc); do not add one per 
    132        entry in data dictionary. 
    133     """ 
    134     from networkx.utils import make_str, is_string_like 
    135  
     209    """A copy & paste of NetworkX's function with some bugs fixed (generate  
     210    one line per object: vertex, edge, arc. Do not add one per entry in data  
     211    dictionary). 
     212     
     213    :param G: A Orange graph. 
     214    :type G: Orange.network.Graph 
     215     
     216    """ 
     217     
    136218    if G.name=='':  
    137219        name='NetworkX' 
     
    176258        yield s 
    177259         
     260 
     261_add_doc(generate_pajek, rw.generate_pajek) 
     262         
    178263def read_gml(path, encoding='latin-1', relabel=False): 
     264    """NetworkX read_gml method and wrap graph to Orange network. 
     265     
     266    """ 
     267     
    179268    return _wrap(rw.read_gml(path, encoding, relabel)) 
    180269 
     270_add_doc(read_gml, rw.read_gml) 
     271 
    181272def write_gml(G, path): 
     273    """NetworkX write_gml method. 
     274     
     275    """ 
     276     
    182277    rw.write_gml(G, path) 
    183278 
    184 #read_pajek.__doc__ = rw.read_pajek.__doc__ 
    185 #parse_pajek.__doc__ = rw.parse_pajek.__doc__ 
     279_add_doc(write_gml, rw.write_gml) 
Note: See TracChangeset for help on using the changeset viewer.