1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
<html lang="en">
<head>
<title>Information - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Basics.html#Basics" title="Basics">
<link rel="prev" href="Creating-Sparse-Matrices.html#Creating-Sparse-Matrices" title="Creating Sparse Matrices">
<link rel="next" href="Operators-and-Functions.html#Operators-and-Functions" title="Operators and Functions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Information"></a>
Next: <a rel="next" accesskey="n" href="Operators-and-Functions.html#Operators-and-Functions">Operators and Functions</a>,
Previous: <a rel="previous" accesskey="p" href="Creating-Sparse-Matrices.html#Creating-Sparse-Matrices">Creating Sparse Matrices</a>,
Up: <a rel="up" accesskey="u" href="Basics.html#Basics">Basics</a>
<hr>
</div>
<h4 class="subsection">21.1.3 Finding out Information about Sparse Matrices</h4>
<p>There are a number of functions that allow information concerning
sparse matrices to be obtained. The most basic of these is
<dfn>issparse</dfn> that identifies whether a particular Octave object is
in fact a sparse matrix.
<p>Another very basic function is <dfn>nnz</dfn> that returns the number of
non-zero entries there are in a sparse matrix, while the function
<dfn>nzmax</dfn> returns the amount of storage allocated to the sparse
matrix. Note that Octave tends to crop unused memory at the first
opportunity for sparse objects. There are some cases of user created
sparse objects where the value returned by <dfn>nzmax</dfn> will not be
the same as <dfn>nnz</dfn>, but in general they will give the same
result. The function <dfn>spstats</dfn> returns some basic statistics on
the columns of a sparse matrix including the number of elements, the
mean and the variance of each column.
<!-- ./DLD-FUNCTIONS/sparse.cc -->
<p><a name="doc_002dissparse"></a>
<div class="defun">
— Loadable Function: <b>issparse</b> (<var>expr</var>)<var><a name="index-issparse-1663"></a></var><br>
<blockquote><p>Return 1 if the value of the expression <var>expr</var> is a sparse matrix.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dnnz"></a>
<div class="defun">
— Built-in Function: <var>scalar</var> = <b>nnz</b> (<var>a</var>)<var><a name="index-nnz-1664"></a></var><br>
<blockquote><p>Returns the number of non zero elements in <var>a</var>.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dsparse.html#doc_002dsparse">sparse</a>.
</p></blockquote></div>
<!-- ./sparse/nonzeros.m -->
<p><a name="doc_002dnonzeros"></a>
<div class="defun">
— Function File: <b>nonzeros</b> (<var>s</var>)<var><a name="index-nonzeros-1665"></a></var><br>
<blockquote><p>Returns a vector of the non-zero values of the sparse matrix <var>s</var>.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dnzmax"></a>
<div class="defun">
— Built-in Function: <var>scalar</var> = <b>nzmax</b> (<var>SM</var>)<var><a name="index-nzmax-1666"></a></var><br>
<blockquote><p>Return the amount of storage allocated to the sparse matrix <var>SM</var>.
Note that Octave tends to crop unused memory at the first opportunity
for sparse objects. There are some cases of user created sparse objects
where the value returned by <dfn>nzmax</dfn> will not be the same as <dfn>nnz</dfn>,
but in general they will give the same result.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dsparse.html#doc_002dsparse">sparse</a>, <a href="doc_002dspalloc.html#doc_002dspalloc">spalloc</a>.
</p></blockquote></div>
<!-- ./sparse/spstats.m -->
<p><a name="doc_002dspstats"></a>
<div class="defun">
— Function File: [<var>count</var>, <var>mean</var>, <var>var</var>] = <b>spstats</b> (<var>s</var>)<var><a name="index-spstats-1667"></a></var><br>
— Function File: [<var>count</var>, <var>mean</var>, <var>var</var>] = <b>spstats</b> (<var>s, j</var>)<var><a name="index-spstats-1668"></a></var><br>
<blockquote><p>Return the stats for the non-zero elements of the sparse matrix <var>s</var>.
<var>count</var> is the number of non-zeros in each column, <var>mean</var>
is the mean of the non-zeros in each column, and <var>var</var> is the
variance of the non-zeros in each column.
<p>Called with two input arguments, if <var>s</var> is the data and <var>j</var>
is the bin number for the data, compute the stats for each bin. In
this case, bins can contain data values of zero, whereas with
<code>spstats (</code><var>s</var><code>)</code> the zeros may disappear.
</p></blockquote></div>
<p>When solving linear equations involving sparse matrices Octave
determines the means to solve the equation based on the type of the
matrix as discussed in <a href="Sparse-Linear-Algebra.html#Sparse-Linear-Algebra">Sparse Linear Algebra</a>. Octave probes the
matrix type when the div (/) or ldiv (\) operator is first used with
the matrix and then caches the type. However the <dfn>matrix_type</dfn>
function can be used to determine the type of the sparse matrix prior
to use of the div or ldiv operators. For example
<pre class="example"> a = tril (sprandn(1024, 1024, 0.02), -1) ...
+ speye(1024);
matrix_type (a);
ans = Lower
</pre>
<p>show that Octave correctly determines the matrix type for lower
triangular matrices. <dfn>matrix_type</dfn> can also be used to force
the type of a matrix to be a particular type. For example
<pre class="example"> a = matrix_type (tril (sprandn (1024, ...
1024, 0.02), -1) + speye(1024), 'Lower');
</pre>
<p>This allows the cost of determining the matrix type to be
avoided. However, incorrectly defining the matrix type will result in
incorrect results from solutions of linear equations, and so it is
entirely the responsibility of the user to correctly identify the
matrix type
<p>There are several graphical means of finding out information about
sparse matrices. The first is the <dfn>spy</dfn> command, which displays
the structure of the non-zero elements of the
matrix. See <a href="fig_003aspmatrix.html#fig_003aspmatrix">fig:spmatrix</a>, for an example of the use of
<dfn>spy</dfn>. More advanced graphical information can be obtained with the
<dfn>treeplot</dfn>, <dfn>etreeplot</dfn> and <dfn>gplot</dfn> commands.
<div class="float">
<a name="fig_003aspmatrix"></a><div align="center"><img src="spmatrix.png" alt="spmatrix.png"></div>
<p><strong class="float-caption">Figure 21.1: Structure of simple sparse matrix.</strong></p></div>
<p>One use of sparse matrices is in graph theory, where the
interconnections between nodes are represented as an adjacency
matrix. That is, if the i-th node in a graph is connected to the j-th
node. Then the ij-th node (and in the case of undirected graphs the
ji-th node) of the sparse adjacency matrix is non-zero. If each node
is then associated with a set of coordinates, then the <dfn>gplot</dfn>
command can be used to graphically display the interconnections
between nodes.
<p>As a trivial example of the use of <dfn>gplot</dfn>, consider the example
<pre class="example"> A = sparse([2,6,1,3,2,4,3,5,4,6,1,5],
[1,1,2,2,3,3,4,4,5,5,6,6],1,6,6);
xy = [0,4,8,6,4,2;5,0,5,7,5,7]';
gplot(A,xy)
</pre>
<p>which creates an adjacency matrix <code>A</code> where node 1 is connected
to nodes 2 and 6, node 2 with nodes 1 and 3, etc. The coordinates of
the nodes are given in the n-by-2 matrix <code>xy</code>.
See <a href="fig_003agplot.html#fig_003agplot">fig:gplot</a>.
<div class="float">
<a name="fig_003agplot"></a><div align="center"><img src="gplot.png" alt="gplot.png"></div>
<p><strong class="float-caption">Figure 21.2: Simple use of the <dfn>gplot</dfn> command.</strong></p></div>
<p>The dependencies between the nodes of a Cholesky factorization can be
calculated in linear time without explicitly needing to calculate the
Cholesky factorization by the <code>etree</code> command. This command
returns the elimination tree of the matrix and can be displayed
graphically by the command <code>treeplot(etree(A))</code> if <code>A</code> is
symmetric or <code>treeplot(etree(A+A'))</code> otherwise.
<!-- ./sparse/spy.m -->
<p><a name="doc_002dspy"></a>
<div class="defun">
— Function File: <b>spy</b> (<var>x</var>)<var><a name="index-spy-1669"></a></var><br>
— Function File: <b>spy</b> (<var><small class="dots">...</small>, markersize</var>)<var><a name="index-spy-1670"></a></var><br>
— Function File: <b>spy</b> (<var><small class="dots">...</small>, line_spec</var>)<var><a name="index-spy-1671"></a></var><br>
<blockquote><p>Plot the sparsity pattern of the sparse matrix <var>x</var>. If the argument
<var>markersize</var> is given as an scalar value, it is used to determine the
point size in the plot. If the string <var>line_spec</var> is given it is
passed to <code>plot</code> and determines the appearance of the plot.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dplot.html#doc_002dplot">plot</a>.
</p></blockquote></div>
<!-- ./DLD-FUNCTIONS/colamd.cc -->
<p><a name="doc_002detree"></a>
<div class="defun">
— Loadable Function: <var>p</var> = <b>etree</b> (<var>s</var>)<var><a name="index-etree-1672"></a></var><br>
— Loadable Function: <var>p</var> = <b>etree</b> (<var>s, typ</var>)<var><a name="index-etree-1673"></a></var><br>
— Loadable Function: [<var>p</var>, <var>q</var>] = <b>etree</b> (<var>s, typ</var>)<var><a name="index-etree-1674"></a></var><br>
<blockquote>
<p>Returns the elimination tree for the matrix <var>s</var>. By default <var>s</var>
is assumed to be symmetric and the symmetric elimination tree is
returned. The argument <var>typ</var> controls whether a symmetric or
column elimination tree is returned. Valid values of <var>typ</var> are
'sym' or 'col', for symmetric or column elimination tree respectively
<p>Called with a second argument, <dfn>etree</dfn> also returns the postorder
permutations on the tree.
</p></blockquote></div>
<!-- ./sparse/etreeplot.m -->
<p><a name="doc_002detreeplot"></a>
<div class="defun">
— Function File: <b>etreeplot</b> (<var>tree</var>)<var><a name="index-etreeplot-1675"></a></var><br>
— Function File: <b>etreeplot</b> (<var>tree, node_style, edge_style</var>)<var><a name="index-etreeplot-1676"></a></var><br>
<blockquote><p>Plot the elimination tree of the matrix <var>s</var> or
<var>s</var><code>+</code><var>s</var><code>'</code> if <var>s</var> in non-symmetric. The optional
parameters <var>line_style</var> and <var>edge_style</var> define the output
style.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dtreeplot.html#doc_002dtreeplot">treeplot</a>, <a href="doc_002dgplot.html#doc_002dgplot">gplot</a>.
</p></blockquote></div>
<!-- ./sparse/gplot.m -->
<p><a name="doc_002dgplot"></a>
<div class="defun">
— Function File: <b>gplot</b> (<var>a, xy</var>)<var><a name="index-gplot-1677"></a></var><br>
— Function File: <b>gplot</b> (<var>a, xy, line_style</var>)<var><a name="index-gplot-1678"></a></var><br>
— Function File: [<var>x</var>, <var>y</var>] = <b>gplot</b> (<var>a, xy</var>)<var><a name="index-gplot-1679"></a></var><br>
<blockquote><p>Plot a graph defined by <var>A</var> and <var>xy</var> in the graph theory
sense. <var>A</var> is the adjacency matrix of the array to be plotted
and <var>xy</var> is an <var>n</var>-by-2 matrix containing the coordinates of
the nodes of the graph.
<p>The optional parameter <var>line_style</var> defines the output style for
the plot. Called with no output arguments the graph is plotted
directly. Otherwise, return the coordinates of the plot in <var>x</var>
and <var>y</var>.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dtreeplot.html#doc_002dtreeplot">treeplot</a>, <a href="doc_002detreeplot.html#doc_002detreeplot">etreeplot</a>, <a href="doc_002dspy.html#doc_002dspy">spy</a>.
</p></blockquote></div>
<!-- ./sparse/treeplot.m -->
<p><a name="doc_002dtreeplot"></a>
<div class="defun">
— Function File: <b>treeplot</b> (<var>tree</var>)<var><a name="index-treeplot-1680"></a></var><br>
— Function File: <b>treeplot</b> (<var>tree, line_style, edge_style</var>)<var><a name="index-treeplot-1681"></a></var><br>
<blockquote><p>Produces a graph of tree or forest. The first argument is vector of
predecessors, optional parameters <var>line_style</var> and <var>edge_style</var>
define the output style. The complexity of the algorithm is O(n) in
terms of is time and memory requirements.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002detreeplot.html#doc_002detreeplot">etreeplot</a>, <a href="doc_002dgplot.html#doc_002dgplot">gplot</a>.
</p></blockquote></div>
<!-- ./sparse/treelayout.m -->
<p><a name="doc_002dtreelayout"></a>
<div class="defun">
— Function File: <b>treelayout</b> (<var>Tree</var>)<var><a name="index-treelayout-1682"></a></var><br>
— Function File: <b>treelayout</b> (<var>Tree, permutation</var>)<var><a name="index-treelayout-1683"></a></var><br>
<blockquote><p>treelayout lays out a tree or a forest. The first argument <var>Tree</var> is a vector of
predecessors, optional parameter <var>permutation</var> is an optional postorder permutation.
The complexity of the algorithm is O(n) in
terms of time and memory requirements.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002detreeplot.html#doc_002detreeplot">etreeplot</a>, <a href="doc_002dgplot.html#doc_002dgplot">gplot</a>, <a href="doc_002dtreeplot.html#doc_002dtreeplot">treeplot</a>.
</p></blockquote></div>
</body></html>
|