File: Information.html

package info (click to toggle)
octave 10.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 145,388 kB
  • sloc: cpp: 335,976; ansic: 82,241; fortran: 20,963; objc: 9,402; sh: 8,756; yacc: 4,392; lex: 4,333; perl: 1,544; java: 1,366; awk: 1,259; makefile: 660; xml: 192
file content (329 lines) | stat: -rw-r--r-- 21,609 bytes parent folder | download
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Information (GNU Octave (version 10.3.0))</title>

<meta name="description" content="Information (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Information (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Basics.html" rel="up" title="Basics">
<link href="Operators-and-Functions.html" rel="next" title="Operators and Functions">
<link href="Creating-Sparse-Matrices.html" rel="prev" title="Creating Sparse Matrices">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.center {text-align:center}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<div class="subsection-level-extent" id="Information">
<div class="nav-panel">
<p>
Next: <a href="Operators-and-Functions.html" accesskey="n" rel="next">Basic Operators and Functions on Sparse Matrices</a>, Previous: <a href="Creating-Sparse-Matrices.html" accesskey="p" rel="prev">Creating Sparse Matrices</a>, Up: <a href="Basics.html" accesskey="u" rel="up">Creation and Manipulation of Sparse Matrices</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Finding-Information-about-Sparse-Matrices"><span>22.1.3 Finding Information about Sparse Matrices<a class="copiable-link" href="#Finding-Information-about-Sparse-Matrices"> &para;</a></span></h4>

<p>There are a number of functions that allow information concerning
sparse matrices to be obtained.  The most basic of these is
<em class="dfn">issparse</em> that identifies whether a particular Octave object is
in fact a sparse matrix.
</p>
<p>Another very basic function is <em class="dfn">nnz</em> that returns the number of
nonzero entries there are in a sparse matrix, while the function
<em class="dfn">nzmax</em> 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 <em class="dfn">nzmax</em> will not be
the same as <em class="dfn">nnz</em>, but in general they will give the same
result.  The function <em class="dfn">spstats</em> returns some basic statistics on
the columns of a sparse matrix including the number of elements, the
mean and the variance of each column.
</p>
<a class="anchor" id="XREFissparse"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-issparse"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">issparse</strong> <code class="def-code-arguments">(<var class="var">x</var>)</code><a class="copiable-link" href="#index-issparse"> &para;</a></span></dt>
<dd><p>Return true if <var class="var">x</var> is a sparse matrix.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Predicates-for-Numeric-Objects.html#XREFismatrix">ismatrix</a>.
</p></dd></dl>


<a class="anchor" id="XREFnnz"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-nnz"><span><code class="def-type"><var class="var">n</var> =</code> <strong class="def-name">nnz</strong> <code class="def-code-arguments">(<var class="var">A</var>)</code><a class="copiable-link" href="#index-nnz"> &para;</a></span></dt>
<dd><p>Return the number of nonzero elements in <var class="var">A</var>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFnzmax">nzmax</a>, <a class="ref" href="#XREFnonzeros">nonzeros</a>, <a class="ref" href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<a class="anchor" id="XREFnonzeros"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-nonzeros"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">nonzeros</strong> <code class="def-code-arguments">(<var class="var">A</var>)</code><a class="copiable-link" href="#index-nonzeros"> &para;</a></span></dt>
<dd><p>Return a column vector of the nonzero values of the matrix <var class="var">A</var>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>, <a class="ref" href="#XREFnnz">nnz</a>.
</p></dd></dl>


<a class="anchor" id="XREFnzmax"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-nzmax"><span><code class="def-type"><var class="var">n</var> =</code> <strong class="def-name">nzmax</strong> <code class="def-code-arguments">(<var class="var">SM</var>)</code><a class="copiable-link" href="#index-nzmax"> &para;</a></span></dt>
<dd><p>Return the amount of storage allocated to the sparse matrix <var class="var">SM</var>.
</p>
<p>Programming Note: Octave tends to crop unused memory at the first opportunity
for sparse objects.  Thus, in general the value of <code class="code">nzmax</code> will be the
same as <code class="code">nnz</code>, except for some cases of user-created sparse objects.
</p>
<p>Also, note that Octave always reserves storage for at least one value.  Thus,
for empty matrices <code class="code">nnz</code> will report 0, but <code class="code">nzmax</code> will report 1.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFnnz">nnz</a>, <a class="ref" href="Creating-Sparse-Matrices.html#XREFspalloc">spalloc</a>, <a class="ref" href="Creating-Sparse-Matrices.html#XREFsparse">sparse</a>.
</p></dd></dl>


<a class="anchor" id="XREFspstats"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-spstats"><span><code class="def-type">[<var class="var">count</var>, <var class="var">mean</var>, <var class="var">var</var>] =</code> <strong class="def-name">spstats</strong> <code class="def-code-arguments">(<var class="var">S</var>)</code><a class="copiable-link" href="#index-spstats"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-spstats-1"><span><code class="def-type">[<var class="var">count</var>, <var class="var">mean</var>, <var class="var">var</var>] =</code> <strong class="def-name">spstats</strong> <code class="def-code-arguments">(<var class="var">S</var>, <var class="var">j</var>)</code><a class="copiable-link" href="#index-spstats-1"> &para;</a></span></dt>
<dd><p>Return the stats for the nonzero elements of the sparse matrix <var class="var">S</var>.
</p>
<p><var class="var">count</var> is the number of nonzeros in each column, <var class="var">mean</var> is the mean
of the nonzeros in each column, and <var class="var">var</var> is the variance of the
nonzeros in each column.
</p>
<p>Called with two input arguments, if <var class="var">S</var> is the data and <var class="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 class="code">spstats (<var class="var">S</var>)</code> the zeros may disappear.
</p></dd></dl>


<p>When solving linear equations involving sparse matrices Octave
determines the means to solve the equation based on the type of the
matrix (see <a class="pxref" href="Sparse-Linear-Algebra.html">Linear Algebra on Sparse Matrices</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 <em class="dfn">matrix_type</em>
function can be used to determine the type of the sparse matrix prior
to use of the div or ldiv operators.  For example,
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">a = tril (sprandn (1024, 1024, 0.02), -1) ...
    + speye (1024);
matrix_type (a);
ans = Lower
</pre></div></div>

<p>shows that Octave correctly determines the matrix type for lower
triangular matrices.  <em class="dfn">matrix_type</em> can also be used to force
the type of a matrix to be a particular type.  For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">a = matrix_type (tril (sprandn (1024, ...
   1024, 0.02), -1) + speye (1024), &quot;Lower&quot;);
</pre></div></div>

<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>
<p>There are several graphical means of finding out information about
sparse matrices.  The first is the <em class="dfn">spy</em> command, which displays
the structure of the nonzero elements of the
matrix.  See <a class="xref" href="#fig_003aspmatrix">Figure 22.1</a>, for an example of the use of
<em class="dfn">spy</em>.  More advanced graphical information can be obtained with the
<em class="dfn">treeplot</em>, <em class="dfn">etreeplot</em> and <em class="dfn">gplot</em> commands.
</p>
<div class="float" id="fig_003aspmatrix">
<div class="center"><img class="image" src="spmatrix.png" alt="spmatrix">
</div><div class="caption"><p><strong class="strong">Figure 22.1: </strong>Structure of simple sparse matrix.</p></div></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 nonzero.  If each node
is then associated with a set of coordinates, then the <em class="dfn">gplot</em>
command can be used to graphically display the interconnections
between nodes.
</p>
<p>As a trivial example of the use of <em class="dfn">gplot</em> consider the example,
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">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></div></div>

<p>which creates an adjacency matrix <code class="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 class="code">xy</code>.
See <a class="xref" href="#fig_003agplot">Figure 22.2</a>.
</p>
<div class="float" id="fig_003agplot">
<div class="center"><img class="image" src="gplot.png" alt="gplot">
</div><div class="caption"><p><strong class="strong">Figure 22.2: </strong>Simple use of the <em class="dfn">gplot</em> command.</p></div></div>
<p>The dependencies between the nodes of a Cholesky&nbsp;factorization can be
calculated in linear time without explicitly needing to calculate the
Cholesky&nbsp;factorization by the <code class="code">etree</code> command.  This command
returns the elimination tree of the matrix and can be displayed
graphically by the command <code class="code">treeplot (etree (A))</code> if <code class="code">A</code> is
symmetric or <code class="code">treeplot (etree (A+A'))</code> otherwise.
</p>
<a class="anchor" id="XREFspy"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-spy"><span><strong class="def-name">spy</strong> <code class="def-code-arguments">(<var class="var">x</var>)</code><a class="copiable-link" href="#index-spy"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-spy-1"><span><strong class="def-name">spy</strong> <code class="def-code-arguments">(&hellip;, <var class="var">markersize</var>)</code><a class="copiable-link" href="#index-spy-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-spy-2"><span><strong class="def-name">spy</strong> <code class="def-code-arguments">(&hellip;, <var class="var">line_spec</var>)</code><a class="copiable-link" href="#index-spy-2"> &para;</a></span></dt>
<dd><p>Plot the sparsity pattern of the sparse matrix <var class="var">x</var>.
</p>
<p>If the optional numeric argument <var class="var">markersize</var> is given, it determines
the size of the markers used in the plot.
</p>
<p>If the optional string <var class="var">line_spec</var> is given it is passed to <code class="code">plot</code>
and determines the appearance of the plot.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Two_002dDimensional-Plots.html#XREFplot">plot</a>, <a class="ref" href="#XREFgplot">gplot</a>.
</p></dd></dl>


<a class="anchor" id="XREFetree"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-etree"><span><code class="def-type"><var class="var">p</var> =</code> <strong class="def-name">etree</strong> <code class="def-code-arguments">(<var class="var">S</var>)</code><a class="copiable-link" href="#index-etree"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-etree-1"><span><code class="def-type"><var class="var">p</var> =</code> <strong class="def-name">etree</strong> <code class="def-code-arguments">(<var class="var">S</var>, <var class="var">typ</var>)</code><a class="copiable-link" href="#index-etree-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-etree-2"><span><code class="def-type">[<var class="var">p</var>, <var class="var">q</var>] =</code> <strong class="def-name">etree</strong> <code class="def-code-arguments">(<var class="var">S</var>, <var class="var">typ</var>)</code><a class="copiable-link" href="#index-etree-2"> &para;</a></span></dt>
<dd>
<p>Return the elimination tree for the matrix <var class="var">S</var>.
</p>
<p>By default <var class="var">S</var> is assumed to be symmetric and the symmetric elimination
tree is returned.  The argument <var class="var">typ</var> controls whether a symmetric or
column elimination tree is returned.  Valid values of <var class="var">typ</var> are
<code class="code">&quot;sym&quot;</code> or <code class="code">&quot;col&quot;</code>, for symmetric or column elimination tree
respectively.
</p>
<p>Called with a second argument, <code class="code">etree</code> also returns the postorder
permutations on the tree.
</p></dd></dl>


<a class="anchor" id="XREFetreeplot"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-etreeplot"><span><strong class="def-name">etreeplot</strong> <code class="def-code-arguments">(<var class="var">A</var>)</code><a class="copiable-link" href="#index-etreeplot"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-etreeplot-1"><span><strong class="def-name">etreeplot</strong> <code class="def-code-arguments">(<var class="var">A</var>, <var class="var">node_style</var>, <var class="var">edge_style</var>)</code><a class="copiable-link" href="#index-etreeplot-1"> &para;</a></span></dt>
<dd><p>Plot the elimination tree of the matrix <var class="var">A</var> or
<code class="code"><var class="var">A</var>+<var class="var">A</var>'</code> if <var class="var">A</var> in not symmetric.
</p>
<p>The optional parameters <var class="var">node_style</var> and <var class="var">edge_style</var> define the
output style.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtreeplot">treeplot</a>, <a class="ref" href="#XREFgplot">gplot</a>.
</p></dd></dl>


<a class="anchor" id="XREFgplot"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-gplot"><span><strong class="def-name">gplot</strong> <code class="def-code-arguments">(<var class="var">A</var>, <var class="var">xy</var>)</code><a class="copiable-link" href="#index-gplot"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-gplot-1"><span><strong class="def-name">gplot</strong> <code class="def-code-arguments">(<var class="var">A</var>, <var class="var">xy</var>, <var class="var">line_style</var>)</code><a class="copiable-link" href="#index-gplot-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-gplot-2"><span><code class="def-type">[<var class="var">x</var>, <var class="var">y</var>] =</code> <strong class="def-name">gplot</strong> <code class="def-code-arguments">(<var class="var">A</var>, <var class="var">xy</var>)</code><a class="copiable-link" href="#index-gplot-2"> &para;</a></span></dt>
<dd><p>Plot a graph defined by <var class="var">A</var> and <var class="var">xy</var> in the graph theory sense.
</p>
<p><var class="var">A</var> is the adjacency matrix of the array to be plotted and <var class="var">xy</var> is
an <var class="var">n</var>-by-2 matrix containing the coordinates of the nodes of the graph.
</p>
<p>The optional parameter <var class="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 class="var">x</var> and <var class="var">y</var>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtreeplot">treeplot</a>, <a class="ref" href="#XREFetreeplot">etreeplot</a>, <a class="ref" href="#XREFspy">spy</a>.
</p></dd></dl>


<a class="anchor" id="XREFtreeplot"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-treeplot"><span><strong class="def-name">treeplot</strong> <code class="def-code-arguments">(<var class="var">tree</var>)</code><a class="copiable-link" href="#index-treeplot"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-treeplot-1"><span><strong class="def-name">treeplot</strong> <code class="def-code-arguments">(<var class="var">tree</var>, <var class="var">node_style</var>, <var class="var">edge_style</var>)</code><a class="copiable-link" href="#index-treeplot-1"> &para;</a></span></dt>
<dd><p>Produce a graph of tree or forest.
</p>
<p>The first argument is a row vector of parent indices.
</p>
<p>The optional parameters <var class="var">node_style</var> and <var class="var">edge_style</var> define the
output plot style.
</p>
<p>The complexity of the algorithm is O(n) in terms of time and memory
requirements.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFetreeplot">etreeplot</a>, <a class="ref" href="#XREFgplot">gplot</a>.
</p></dd></dl>


<a class="anchor" id="XREFtreelayout"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-treelayout"><span><code class="def-type">[<var class="var">x</var>, <var class="var">y</var>] =</code> <strong class="def-name">treelayout</strong> <code class="def-code-arguments">(<var class="var">tree</var>)</code><a class="copiable-link" href="#index-treelayout"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-treelayout-1"><span><code class="def-type">[<var class="var">x</var>, <var class="var">y</var>] =</code> <strong class="def-name">treelayout</strong> <code class="def-code-arguments">(<var class="var">tree</var>, <var class="var">permutation</var>)</code><a class="copiable-link" href="#index-treelayout-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-treelayout-2"><span><code class="def-type">[<var class="var">x</var>, <var class="var">y</var>, <var class="var">h</var>, <var class="var">s</var>] =</code> <strong class="def-name">treelayout</strong> <code class="def-code-arguments">(&hellip;)</code><a class="copiable-link" href="#index-treelayout-2"> &para;</a></span></dt>
<dd><p>treelayout lays out a tree or a forest.
</p>
<p>The first argument <var class="var">tree</var> is a vector of predecessors.
</p>
<p>The optional parameter <var class="var">permutation</var> is a postorder permutation.
</p>
<p>The complexity of the algorithm is O(n) in terms of time and memory
requirements.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFetreeplot">etreeplot</a>, <a class="ref" href="#XREFgplot">gplot</a>, <a class="ref" href="#XREFtreeplot">treeplot</a>.
</p></dd></dl>


</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Operators-and-Functions.html">Basic Operators and Functions on Sparse Matrices</a>, Previous: <a href="Creating-Sparse-Matrices.html">Creating Sparse Matrices</a>, Up: <a href="Basics.html">Creation and Manipulation of Sparse Matrices</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>