forked from xiaolongma/jburkardt-f
-
Notifications
You must be signed in to change notification settings - Fork 1
/
svd_basis.html
499 lines (454 loc) · 14.9 KB
/
svd_basis.html
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<html>
<head>
<title>
SVD_BASIS - Extract singular vectors from data
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
SVD_BASIS<br> Extract singular vectors from data
</h1>
<hr>
<p>
<b>SVD_BASIS</b>
is a FORTRAN90 program which
applies the singular value decomposition to
a set of data vectors, to extract the leading "modes" of the data.
</p>
<p>
This procedure, originally devised by Karl Pearson, has arisen
repeatedly in a variety of fields, and hence is known under
various names, including:
<ul>
<li>
the Hotelling transform;
</li>
<li>
the discrete Karhunen-Loeve transform (KLT)
</li>
<li>
Principal Component Analysis (PCA)
</li>
<li>
Principal Orthogonal Direction (POD)
</li>
<li>
Proper Orthogonal Decomposition (POD)
</li>
<li>
Singular Value Decomposition (SVD)
</li>
</ul>
</p>
<p>
This program is intended as an intermediate application, in
the following situation:
<ol>
<li>
a "high fidelity" or "high resolution" PDE solver is used
to determine many (say <b>N</b> = 500) solutions of a discretized
PDE at various times, or parameter values. Each solution
may be regarded as an <b>M</b> vector. Typically, each solution
involves an <b>M</b> by <b>M</b> linear system, greatly reduced in
complexity because of bandedness or sparsity.
</li>
<li>
This program is applied to extract <b>L</b> dominant modes from
the <b>N</b> solutions. This is done using the singular value
decomposition of the <b>M</b> by <b>N</b> matrix, each of whose columns
is one of the original solution vectors.
</li>
<li>
a "reduced order model" program may then attempt to solve
a discretized version of the PDE, using the <b>L</b> dominant
modes as basis vectors. Typically, this means that a dense
<b>L</b> by<b>L</b> linear system will be involved.
</li>
</ol>
</p>
<p>
Thus, the program might read in 500 files, and write out
5 or 10 files of the corresponding size and "shape", representing
the dominant solution modes.
</p>
<p>
The optional normalization step involves computing the average
of all the solution vectors and subtracting that average from
each solution. In this case, the average vector is treated as
a special "mode 0", and also written out to a file.
</p>
<p>
To compute the singular value decomposition, we first construct
the <b>M</b> by <b>N</b> matrix <b>A</b> using individual solution vectors
as columns:
<blockquote><b>
A = [ X1 | X2 | ... | XN ]
</b></blockquote>
</p>
<p>
The singular value decomposition has the form:
<blockquote><b>
A = U * S * V'
</b></blockquote>
and is determined using the DGESVD routine from the linear algebra
package <a href = "../../f_src/lapack/lapack.html">LAPACK</a>.
The leading <b>L</b> columns of the orthogonal <b>M</b> by <b>M</b>
matrix <b>U</b>, associated with the largest singular values <b>S</b>,
are chosen to form the basis.
</p>
<p>
In most PDE's, the solution vector has some structure; perhaps
there are 100 nodes, and at each node the solution has perhaps
4 components (horizontal and vertical velocity, pressure, and
temperature, say). While the solution is therefore a vector
of length 400, it's more natural to think of it as a sort of
table of 100 items, each with 4 components. You can use that
idea to organize your solution data files; in other words, your
data files can each have 100 lines, containing 4 values on each line.
As long as every line has the same number of values, and every
data file has the same form, the program can figure out what's
going on.
</p>
<p>
The program assumes that each solution vector is stored in a separate
data file and that the files are numbered consecutively, such as
<i>data01.txt</i>, <i>data02,txt</i>, ... In a data file, comments
(beginning with '#") and blank lines are allowed. Except for
comment lines, each line of the file is assumed to represent all
the component values of the solution at a particular node.
</p>
<p>
Here, for instance, is a tiny data file for a problem with just
3 nodes, and 4 solution components at each node:
<pre>
# This is solution file number 1
#
1 2 3 4
5 6 7 8
9 10 11 12
</pre>
</p>
<p>
The program is interactive, but requires only a very small
amount of input:
<ul>
<li>
<b>L</b>, the number of basis vectors to be extracted from the data;
</li>
<li>
the name of the first input data file in the first set.
</li>
<li>
the name of the first input data file in the second set, if any.
(you are allowed to define a master data set composed of several
groups of files, each consisting of a sequence of consecutive
file names)
</li>
<li>
a BLANK line, when there are no more sets of data to be added.
</li>
<li>
"Y" if the vectors should be averaged, the average subtracted
from all vectors, and the average written out as an extra
"mode 0" vector;
</li>
<li>
"Y" if the output files may include some initial comment lines,
which will be indicated by initial "#" characters.
</li>
</ul>
</p>
<p>
The program computes <b>L</b> basis vectors,
and writes each one to a separate file, starting with <i>svd_001.txt</i>,
<i>svd_002.txt</i> and so on. The basis vectors are written with the
same component and node structure that was encountered on the
solution files. Each vector will have unit Euclidean norm.
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>SVD_BASIS</b> is available in
<a href = "../../cpp_src/svd_basis/svd_basis.html">a C++ version</a> and
<a href = "../../f_src/svd_basis/svd_basis.html">a FORTRAN90 version</a> and
<a href = "../../m_src/svd_basis/svd_basis.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../m_src/brain_sensor_pod/brain_sensor_pod.html">
BRAIN_SENSOR_POD</a>,
a MATLAB program which
applies the method of Proper Orthogonal Decomposition
to seek underlying patterns in sets of 40 sensor readings of
brain activity.
</p>
<p>
<a href = "../../datasets/burgers/burgers.html">
BURGERS</a>,
a dataset which
contains 40 successive
solutions to the Burgers equation. This data can be analyzed
using <b>SVD_BASIS</b>.
</p>
<p>
<a href = "../../f_src/cvt_basis/cvt_basis.html">
CVT_BASIS</a>,
a FORTRAN90 program which
uses discrete Centroidal Voronoi Tessellation (CVT) techniques to produce a
small set of basis vectors that are good cluster centers for a
large set of data vectors;
</p>
<p>
<a href = "../../f_src/lapack_examples/lapack_examples.html">
LAPACK_EXAMPLES</a>,
a FORTRAN90 program which
demonstrates the use of the LAPACK linear algebra library.
</p>
<p>
<a href = "../../f_src/pod_basis_flow/pod_basis_flow.html">
POD_BASIS_FLOW</a>,
a FORTRAN90 program which
is based on the same algorithm used by
SVD_BASIS, but specialized to handle solution data from a
particular set of fluid flow problems.
</p>
<p>
<a href = "../../f_src/svd_basis_weight/svd_basis_weight.html">
SVD_BASIS_WEIGHT</a>,
a FORTRAN90 program which
is similar to <b>SVD_BASIS</b>, but which allows the user to
assign weights to each data vector.
</p>
<p>
<a href = "../../f_src/svd_demo/svd_demo.html">
SVD_DEMO</a>,
a FORTRAN90 program which
demonstrates the singular value decomposition for a simple example.
</p>
<p>
<a href = "../../f_src/svd_truncated/svd_truncated.html">
SVD_TRUNCATED</a>,
a FORTRAN90 program which
demonstrates the computation of the reduced or truncated
Singular Value Decomposition (SVD) that is useful for cases when
one dimension of the matrix is much smaller than the other.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Edward Anderson, Zhaojun Bai, Christian Bischof, Susan Blackford,
James Demmel, Jack Dongarra, Jeremy Du Croz, Anne Greenbaum,
Sven Hammarling, Alan McKenney, Danny Sorensen,<br>
LAPACK User's Guide,<br>
Third Edition,<br>
SIAM, 1999,<br>
ISBN: 0898714478,<br>
LC: QA76.73.F25L36
</li>
<li>
Gal Berkooz, Philip Holmes, John Lumley,<br>
The proper orthogonal decomposition in the analysis
of turbulent flows,<br>
Annual Review of Fluid Mechanics,<br>
Volume 25, 1993, pages 539-575.
</li>
<li>
John Burkardt, Max Gunzburger, Hyung-Chun Lee,<br>
Centroidal Voronoi Tessellation-Based Reduced-Order
Modelling of Complex Systems,<br>
SIAM Journal on Scientific Computing,<br>
Volume 28, Number 2, 2006, pages 459-484.
</li>
<li>
Lawrence Sirovich,<br>
Turbulence and the dynamics of coherent structures, Parts I-III,<br>
Quarterly of Applied Mathematics,<br>
Volume 45, Number 3, 1987, pages 561-590.
</li>
</ol>
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "svd_basis.f90">svd_basis.f90</a>, the source code.
</li>
<li>
<a href = "svd_basis.sh">svd_basis.sh</a>,
commands to compile and load the source code.
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
The user's input, and the program's output are here:
<ul>
<li>
<a href = "input.txt">input.txt</a>,
five lines of input that define a run.
</li>
<li>
<a href = "output.txt">output.txt</a>,
the printed output.
</li>
</ul>
</p>
<p>
The input data consists of 5 files:
<ul>
<li>
<a href = "data01.txt">data01.txt</a>,
input data file #1.
</li>
<li>
<a href = "data02.txt">data02.txt</a>,
input data file #2.
</li>
<li>
<a href = "data03.txt">data03.txt</a>,
input data file #3.
</li>
<li>
<a href = "data04.txt">data04.txt</a>,
input data file #4.
</li>
<li>
<a href = "data05.txt">data05.txt</a>,
input data file #5.
</li>
</ul>
</p>
<p>
The output data consists of 4 files, the first containing the
average, and the next three containing the SVD basis vectors:
<ul>
<li>
<a href = "svd_000.txt">svd_000.txt</a>,
output SVD file #0 (contains the average, which was
requested by the user in the input file.).
</li>
<li>
<a href = "svd_001.txt">svd_001.txt</a>,
output SVD file #1.
</li>
<li>
<a href = "svd_002.txt">svd_002.txt</a>,
output SVD file #2.
</li>
<li>
<a href = "svd_003.txt">svd_003.txt</a>,
output SVD file #3.
</li>
</ul>
</p>
<h3 align = "center">
List of Routines:
</h3>
<p>
<ul>
<li>
<b>MAIN</b> is the main program for SVD_BASIS.
</li>
<li>
<b>BASIS_WRITE</b> writes a basis vector to a file.
</li>
<li>
<b>CH_CAP</b> capitalizes a single character.
</li>
<li>
<b>CH_EQI</b> is a case insensitive comparison of two characters for equality.
</li>
<li>
<b>CH_IS_DIGIT</b> is TRUE if a character is a decimal digit.
</li>
<li>
<b>CH_TO_DIGIT</b> returns the integer value of a base 10 digit.
</li>
<li>
<b>DIGIT_INC</b> increments a decimal digit.
</li>
<li>
<b>DIGIT_TO_CH</b> returns the character representation of a decimal digit.
</li>
<li>
<b>FILE_COLUMN_COUNT</b> counts the number of columns in the first line of a file.
</li>
<li>
<b>FILE_EXIST</b> reports whether a file exists.
</li>
<li>
<b>FILE_NAME_INC_NOWRAP</b> increments a partially numeric filename.
</li>
<li>
<b>FILE_ROW_COUNT</b> counts the number of row records in a file.
</li>
<li>
<b>GET_UNIT</b> returns a free FORTRAN unit number.
</li>
<li>
<b>I4_INPUT</b> prints a prompt string and reads an I4 from the user.
</li>
<li>
<b>R8MAT_DATA_READ</b> reads data from an R8MAT file.
</li>
<li>
<b>R8MAT_HEADER_READ</b> reads the header from an R8MAT file.
</li>
<li>
<b>R8MAT_PRINT</b> prints an R8MAT.
</li>
<li>
<b>R8MAT_PRINT_SOME</b> prints some of an R8MAT.
</li>
<li>
<b>S_INPUT</b> prints a prompt string and reads a string from the user.
</li>
<li>
<b>S_TO_I4</b> reads an I4 from a string.
</li>
<li>
<b>S_TO_R8</b> reads an R8 from a string.
</li>
<li>
<b>S_TO_R8VEC</b> reads an R8VEC from a string.
</li>
<li>
<b>S_WORD_COUNT</b> counts the number of "words" in a string.
</li>
<li>
<b>SINGULAR_VECTORS</b> computes the desired singular values.
</li>
<li>
<b>TIMESTAMP</b> prints the current YMDHMS date as a time stamp.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../f_src.html">
the FORTRAN90 source codes</a>.
</p>
<hr>
<i>
Last revised on 22 November 2011.
</i>
<!-- John Burkardt -->
</body>
</html>