source: orange/orange/doc/modules/orngNetwork.htm @ 6926:1203c5503207

Revision 6926:1203c5503207, 7.3 KB checked in by anzevap <anzevap@…>, 4 years ago (diff)

Added some documentation for the Pathfinder procedure.

Line 
1<html>
2<HEAD>
3<LINK REL=StyleSheet HREF="../style.css" TYPE="text/css">
4<LINK REL=StyleSheet HREF="../style-print.css" TYPE="text/css" MEDIA=print></LINK>
5</HEAD>
6
7<BODY>
8<h1>orngNetwork</h1>
9
10<index name="modules+network">
11
12<p>The orngNetwork module provides the functionality to perform network
13analysis and layout optimization.</p>
14
15<h2>Network</h2>
16
17<p><INDEX name="classes/Network (in orngNetwork)">Network class holds network
18structure information and supports basic network analysis. Network class is
19inherited from <a href='../reference/graph.htm'>orange.GraphAsList</a>. Refer to
20<a href='../reference/graph.htm'>orange.GraphAsList</a> for more graph analysis tools. See the <a href='../reference/pathfinder.htm'>orangeom.Pathfinder</a> class
21for a way to simplify your network.</p>
22
23<p class=section>Attributes</p>
24<DL class =attributes>
25<DT>coors</DT>
26<DD>Coordinates for all vertices. They are initialized to random positions. You can modify them manually or use one of the optimization algorithms. Usage: <code>coors[0][i]</code>, <code>coors[1][i]</code>; 0 for x-axis, 1 for y-axis</DD>
27<DT>items</DT>
28<DD>ExampleTable with information about vertices. Number of rows should match the number of vertices.</DD>
29<DT>links</DT>
30<DD>ExampleTable with information about edges. Number of rows should match the number of edges. Two float attributes named <i>"u"</i> and <i>"v"</i> must be in <i>links</i> table domain to relate the data of an example to an edge. Here, egde is defined by two vertices <i>"u"</i> and <i>"v"</i>.</DD>
31<DT>optimization</DT>
32<DD>An instance of the NetworkOptimization class. Various network layout optimization methods can be applied to the network through this attribute.</DD>
33</DL>
34
35<P class=section>Methods</P>
36<DL class=attributes>
37<DT>Network()</DT>
38<DD>Default constrctor. Creates a network with one vertex.</DD>
39<DT>Network(nVertices, nEdges, directedGraph=False)</DT>
40<DD>Creates a network with n vertices. The nEdges attribute is used to set the number of edge types. It should always be 0, except in some special cases.</DD>
41<!-- <DT>fromSymMatrix(matrix, lower, upper, kNN, andor)</DT>
42<DD></DD> -->
43<DT>fromDistanceMatrix(matrix, lower, upper, kNN=0)</DT>
44<DD>Creates edges between vertices with the distance within given threshold.
45Matrix should be of orange.SymMatrix type. The number ob objects in a matrix
46must match the number of vertices in a network. The kNN parameter can be used to
47specify the minimum number of closest vertices to be connected.</DD>
48<DT>save(file)</DT>
49<DD>Saves the network to a Pajek (.net) or GML file format. ExampleTables <i>items</i> and <i>links</i> are saved automatically if the value is not None. They are saved to "file_items.tab" and "file_links.tab" files.</DD>
50</DL>
51
52<P class=section>Static Methods</P>
53<DL class=attributes>
54<DT>read(file)</DT>
55<DD>Reads the network from a Pajek (.net) or GML file. Usage: <code>orngNetwork.Network.read(filename)</code></DD>
56</DL>
57<h2>NetworkOptimization</h2>
58
59<p><INDEX name="classes/NetworkOptimization (in orngNetwork)">NetworkOptimization 
60is the main class for performing network layout optimization. Network structure is defined in orngNetwork.Network class.</p>
61
62<p class=section>Attributes</p>
63<DL class =attributes>
64<DT>graph</DT>
65<DD>Holds the Network object.</DD>
66</DL>
67<P class=section>Methods</P>
68<DL class=attributes>
69<DT>NetworkOptimization()</DT>
70<DD>Default constrctor.</DD>
71<DT>NetworkOptimization(network)</DT>
72<DD>Constructor that takes the Network object.</DD>
73<DT>random()</DT>
74<DD>Random layout optimization.</DD>
75<DT>fruchtermanReingold(steps=100, temperature=1000, coolFactor=default, hiddenNodes=[], weighted=False)</DT>
76<DD>Fruchterman-Reingold spring layout optimization. Set number of iterations with argument <code>steps</code>, start temperature with <code>temperature</code> (for example: 1000) and set list of hidden nodes with argument <code>hidden_nodes</code>.</DD>
77<DT>radialFruchtermanReingold(center, steps=100, temperature=1000)</DT>
78<DD>Radial Fruchterman-Reingold spring layout optimization. Set center node with attribute <code>center</code>, number of iterations with argument <code>steps</code> and start temperature with <code>temperature</code> (for example: 1000).</DD>
79<DT>circularOriginal()</DT>
80<DD>Circular layout optimization based on original order.</DD>
81<DT>circularRandom()</DT>
82<DD>Circular layout optimization based on random order.</DD>
83<DT>circularCrossingReduction()</DT>
84<DD>Circular layout optimization (Michael Baur, Ulrik Brandes) with crossing reduction.</DD>
85</DL>
86
87<h2>Examples</h2>
88
89<h3>Network constructor and random layout</h3>
90
91<p>In our first example we create a Network object with a simple full graph (K5). Vertices are initially placed randomly. Graph is visualized using pylabs matplotlib. NetworkOptimization class is not needed since we do not apply any layout optimization method in this example.</p>
92
93<p class="header"><a href="network_constructor.py">network_constructor.py</a></p>
94<xmp class=code>import orngNetwork
95from pylab import *
96
97# create graph object of type GraphAsList
98# vertices are placed randomly in Network constructor
99net = orngNetwork.Network(5, 0)
100
101# set edges
102for i in range(4):
103    for j in range(i + 1, 5):
104        net[i,j] = 1
105
106# read all edges and plot a line
107for u, v in net.getEdges():
108    x1, y1 = net.coors[0][u], net.coors[1][u]
109    x2, y2 = net.coors[0][v], net.coors[1][v]
110    plot([x1, x2], [y1, y2], 'b-')
111
112# read x and y coordinates to Python list
113x = net.coors[0]
114y = net.coors[1]
115
116# plot vertices
117plot(x, y, 'ro')
118show()
119</xmp>
120<p>Executing the above script pops-up a pylab window with the
121following graph drawing:</p>
122<img src="network_K5_random.png">
123<h3>Network layout optimization</h3>
124
125<p>This example demonstrates how to optimize network layout using one of included algorithms.</p>
126
127<p class="header">part of <a href="network_optimization.py">network_optimization.py</a></p>
128<xmp class=code># vertices are placed randomly in NetworkOptimization constructor
129networkOptimization = orngNetwork.NetworkOptimization(net)
130
131# optimize verices layout with one of included algorithms
132networkOptimization.fruchtermanReingold(100, 1000)
133</xmp>
134<p>You can use one of the following optimization algorithms:</p>
135<p>
136<ul>
137<li>.random()</li>
138<li>.fruchtermanReingold(steps, temperature, coolingFactor=Default, hiddenNodes=[], weighted=False)</li>
139<li>.radialFruchtermanReingold(center, steps, temperature)</li>
140<li>.circularOriginal()</li>
141<li>.circularRandom()</li>
142<li>.circularCrossingReduction()</li>
143</ul>
144</p>
145<p>Spring forces layout optimization is the result of the above script:</p>
146<img src="network_K5_fr.png">
147<h3>Reading and saving a network</h3>
148
149<p>This example demonstrates reading a network. Network class can read or write Pajek (.net) or GML file format.</p>
150
151<p class="header"><a href="network_read.py">network_read.py</a> (uses <a href="K5.net">K5.net</a>)</p>
152
153<xmp class=code># read the network from file
154net = orngNetwork.Network.read("K5.net")
155
156# save the network to file
157net.save("K5.net")
158</xmp>
159
160<h3>Visualize a network in NetExplorer widget</h3>
161
162<p>This example demonstrates how to display a network in NetExplorer. </p>
163
164<p class="header">part of <a href="network_widget.py">network_widget.py</a></p>
165<xmp class=code>net = orngNetwork.Network.read('musicians.net')
166net.items = orange.ExampleTable('musicians_items.tab')
167
168ow = OWNetExplorer.OWNetExplorer()
169ow.setNetwork(net)
170
171ow.show()
172</xmp>
173
174<img width="800px" src="netexplorer.png">
Note: See TracBrowser for help on using the repository browser.