Skip to content

Commit e1aad5e

Browse files
sichinagamtezzele
authored andcommitted
Added documentation
1 parent 77357e3 commit e1aad5e

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

pydmd/preprocessing/randomized.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,46 @@
1212
from pydmd.utils import compute_rqb
1313

1414
svd_rank_type = Union[int, float]
15-
seed_type = Union[None, int]
1615

1716
def randomized_preprocessing(
1817
dmd: DMDBase,
1918
svd_rank: svd_rank_type,
2019
oversampling: int,
2120
power_iters: int,
2221
test_matrix: np.ndarray = None,
23-
seed: seed_type = None,
22+
seed: int = None,
2423
):
2524
"""
2625
Randomized QB pre-processing.
2726
2827
:param dmd: DMD instance to be wrapped.
28+
:param svd_rank: target rank of the input data.
29+
:param oversampling: amount to oversample beyond the target rank.
30+
:param power_iters: number of power iterations to perform.
31+
:param test_matrix: optional custom random test matrix.
32+
:param seed: optional random generator seed.
2933
"""
3034
return PrePostProcessingDMD(
3135
dmd,
3236
partial(
33-
_rand_preprocessing,
37+
_pre,
3438
svd_rank=svd_rank,
3539
oversampling=oversampling,
3640
power_iters=power_iters,
3741
test_matrix=test_matrix,
3842
seed=seed,
3943
),
40-
_rand_postprocessing,
44+
_post,
4145
)
4246

43-
def _rand_preprocessing(
47+
def _pre(
4448
state: Dict,
4549
X: np.ndarray,
4650
svd_rank: svd_rank_type,
4751
oversampling: int,
4852
power_iters: int,
4953
test_matrix: np.ndarray,
50-
seed: seed_type,
54+
seed: int,
5155
**kwargs
5256
):
5357
Q = compute_rqb(
@@ -58,5 +62,5 @@ def _rand_preprocessing(
5862
return (state["compression_matrix"].dot(X),) + tuple(kwargs.values())
5963

6064

61-
def _rand_postprocessing(state: Dict, X: np.ndarray) -> np.ndarray:
65+
def _post(state: Dict, X: np.ndarray) -> np.ndarray:
6266
return state["compression_matrix"].conj().T.dot(X)

pydmd/rdmd.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111

1212
from .cdmd import CDMD
13-
from .utils import compute_rank, compute_rqb
13+
from .utils import compute_rqb
1414

1515

1616
class RDMD(CDMD):
@@ -24,13 +24,13 @@ class RDMD(CDMD):
2424
:param seed: Seed used to initialize the random generator when computing
2525
random test matrices.
2626
:type seed: int
27-
:param oversampling: Number of additional samples (beyond the desired rank)
28-
to use when computing the random test matrix. Note that values {5,10}
29-
tend to be sufficient.
27+
:param oversampling: Number of additional samples (beyond the target rank)
28+
to use when computing the random test matrix. Note that values in the
29+
range [5, 10] tend to be sufficient.
3030
:type oversampling: int
3131
:param power_iters: Number of power iterations to perform when executing
32-
the Randomized QB Decomposition. Note that values {1,2} often lead to
33-
considerable improvements.
32+
the Randomized QB Decomposition. Note that as many as 1 to 2 power
33+
iterations often lead to considerable improvements.
3434
:type power_iters: int
3535
"""
3636

pydmd/utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,45 @@ def compute_rqb(
201201
) -> NamedTuple(
202202
"RQB", [("Q", np.ndarray), ("B", np.ndarray), ("Omega", np.ndarray)]
203203
):
204+
"""
205+
Randomized QB Decomposition.
206+
207+
:param X: the matrix to decompose.
208+
:type X: np.ndarray
209+
:param svd_rank: the rank for the truncation; If 0, the method computes
210+
the optimal rank and uses it for truncation; if positive interger,
211+
the method uses the argument for the truncation; if float between 0
212+
and 1, the rank is the number of the biggest singular values that
213+
are needed to reach the 'energy' specified by `svd_rank`; if -1,
214+
the method does not compute truncation. Use this parameter to
215+
define the target rank of the input matrix.
216+
:type svd_rank: int or float
217+
:param oversampling: Number of additional samples (beyond the target rank)
218+
to use when computing the random test matrix. Note that values in the
219+
range [5, 10] tend to be sufficient.
220+
:type oversampling: int
221+
:param power_iters: Number of power iterations to perform when executing
222+
the Randomized QB Decomposition. Note that as many as 1 to 2 power
223+
iterations often lead to considerable improvements.
224+
:type power_iters: int
225+
:param Omega: The random test matrix that will be used when executing
226+
the Randomized QB Decomposition. If not provided, the `svd_rank` and
227+
`oversampling` parameters will be used to compute the random matrix.
228+
:type Omega: numpy.ndarray
229+
:param seed: Seed used to initialize the random generator when computing
230+
random test matrices.
231+
:type seed: int
232+
:return: the orthonormal basis matrix, the transformed data matrix, and
233+
the random test matrix.
234+
:rtype: NamedTuple("RQB", [('Q', np.ndarray),
235+
('B', np.ndarray),
236+
('Omega', np.ndarray)])
237+
238+
References:
239+
N. Benjamin Erichson, Lionel Mathelin, J. Nathan Kutz, Steven L. Brunton.
240+
Randomized dynamic mode decomposition. SIAM Journal on Applied Dynamical
241+
Systems, 18, 2019.
242+
"""
204243
if X.ndim != 2:
205244
raise ValueError("Please ensure that input data is a 2D array.")
206245

0 commit comments

Comments
 (0)