Skip to content

Commit

Permalink
add new parameters to DMDBase subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
fandreuz committed Mar 1, 2021
1 parent d5e6331 commit 7f7d4c1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
8 changes: 6 additions & 2 deletions pydmd/cdmd.py
Expand Up @@ -48,14 +48,18 @@ class CDMD(DMDBase):
numpy.ndarray
:param bool opt: flag to compute optimal amplitudes. See :class:`DMDBase`.
Default is False.
:param numpy.array rescale_mode: None means no rescaling, empty array means
automatic rescaling using SV, otherwise the user chooses the preferred
scaling.
"""

def __init__(self,
svd_rank=0,
tlsq_rank=0,
compression_matrix='uniform',
opt=False):
super(CDMD, self).__init__(svd_rank, tlsq_rank, True, opt)
opt=False,
rescale_mode=None):
super(CDMD, self).__init__(svd_rank, tlsq_rank, True, opt, rescale_mode)
self.compression_matrix = compression_matrix

def _compress_snapshots(self):
Expand Down
3 changes: 3 additions & 0 deletions pydmd/dmd.py
Expand Up @@ -30,6 +30,9 @@ class DMD(DMDBase):
Default is False.
:param bool opt: flag to compute optimal amplitudes. See :class:`DMDBase`.
Default is False.
:param numpy.array rescale_mode: None means no rescaling, empty array means
automatic rescaling using SV, otherwise the user chooses the preferred
scaling.
"""

def fit(self, X):
Expand Down
9 changes: 7 additions & 2 deletions pydmd/dmdc.py
Expand Up @@ -32,14 +32,19 @@ class DMDc(DMDBase):
for the `_fit_B_unknown` method of this class. It should be greater or
equal than `svd_rank`. For the possible values please refer to the
`svd_rank` parameter description above.
:param numpy.array rescale_mode: None means no rescaling, empty array means
automatic rescaling using SV, otherwise the user chooses the preferred
scaling.
:type svd_rank_omega: int or float
"""
def __init__(self, svd_rank=0, tlsq_rank=0, opt=False, svd_rank_omega=-1):
def __init__(self, svd_rank=0, tlsq_rank=0, opt=False, svd_rank_omega=-1,
rescale_mode=None):
self.svd_rank = svd_rank
self.tlsq_rank = tlsq_rank
self.opt = opt
self.svd_rank_omega = svd_rank_omega
self.original_time = None
self.rescale_mode = rescale_mode

self._eigs = None
self._Atilde = None
Expand Down Expand Up @@ -142,7 +147,7 @@ def _fit_B_unknown(self, X, Y):
omega = np.vstack([X, self._controlin])

Up, sp, Vp = self._compute_svd(omega, self.svd_rank_omega)

Up1 = Up[:self._snapshots.shape[0], :]
Up2 = Up[self._snapshots.shape[0]:, :]

Expand Down
3 changes: 3 additions & 0 deletions pydmd/fbdmd.py
Expand Up @@ -24,6 +24,9 @@ class FbDMD(DMDBase):
Default is False.
:param bool opt: flag to compute optimal amplitudes. See :class:`DMDBase`.
Default is False.
:param numpy.array rescale_mode: None means no rescaling, empty array means
automatic rescaling using SV, otherwise the user chooses the preferred
scaling.
Reference: Dawson et al. https://arxiv.org/abs/1507.02264
"""
Expand Down
9 changes: 7 additions & 2 deletions pydmd/hodmd.py
Expand Up @@ -24,12 +24,17 @@ class HODMD(DMDBase):
Default is False.
:param bool opt: flag to compute optimal amplitudes. See :class:`DMDBase`.
Default is False.
:param numpy.array rescale_mode: None means no rescaling, empty array means
automatic rescaling using SV, otherwise the user chooses the preferred
scaling.
:param int d: the new order for spatial dimension of the input snapshots.
Default is 1.
"""

def __init__(self, svd_rank=0, tlsq_rank=0, exact=False, opt=False, d=1):
super(HODMD, self).__init__(svd_rank, tlsq_rank, exact, opt)
def __init__(self, svd_rank=0, tlsq_rank=0, exact=False, opt=False, d=1,
rescale_mode=None):
super(HODMD, self).__init__(svd_rank, tlsq_rank, exact, opt,
rescale_mode)
self.d = d

def fit(self, X):
Expand Down
9 changes: 7 additions & 2 deletions pydmd/mrdmd.py
Expand Up @@ -32,6 +32,9 @@ class MrDMD(DMDBase):
Default is False.
:param bool opt: flag to compute optimal amplitudes. See :class:`DMDBase`.
Default is False.
:param numpy.array rescale_mode: None means no rescaling, empty array means
automatic rescaling using SV, otherwise the user chooses the preferred
scaling.
:param int max_cycles: the maximum number of mode oscillations in any given
time scale. Default is 1.
:param int max_level: the maximum number of levels. Defualt is 6.
Expand All @@ -43,8 +46,10 @@ def __init__(self,
exact=False,
opt=False,
max_cycles=1,
max_level=6):
super(MrDMD, self).__init__(svd_rank, tlsq_rank, exact, opt)
max_level=6,
rescale_mode=None):
super(MrDMD, self).__init__(svd_rank, tlsq_rank, exact, opt,
rescale_mode)
self.max_cycles = max_cycles
self.max_level = max_level
self._nsamples = None
Expand Down
14 changes: 9 additions & 5 deletions pydmd/optdmd.py
Expand Up @@ -18,7 +18,7 @@ def pinv_diag(x):
Utility function to compute the pseudo-inverse of a diagonal matrix.
:param array_like x: diagonal of the matrix to be pseudo-inversed.
:return: the computed pseudo-inverse
:return: the computed pseudo-inverse
:rtype: numpy.ndarray
"""
t = x.dtype.char.lower()
Expand Down Expand Up @@ -59,17 +59,21 @@ class OptDMD(DMDBase):
Default is False.
:param bool opt: flag to compute optimal amplitudes. See :class:`DMDBase`.
Default is False.
:param numpy.array rescale_mode: None means no rescaling, empty array means
automatic rescaling using SV, otherwise the user chooses the preferred
scaling.
"""

def __init__(self,
factorization="evd",
svd_rank=-1,
tlsq_rank=0,
exact=False,
opt=False
):
opt=False,
rescale_mode=None):

super(OptDMD, self).__init__(svd_rank, tlsq_rank, exact, opt)
super(OptDMD, self).__init__(svd_rank, tlsq_rank, exact, opt,
rescale_mode)
self.factorization = factorization

self._svds = None
Expand Down Expand Up @@ -129,7 +133,7 @@ def fit(self, X, Y=None):
_, self._input_space, self._output_space = self._eig_from_lowrank_op(self._Atilde, Uz, Q)

self._modes = self._output_space

return self

def predict(self, X):
Expand Down

0 comments on commit 7f7d4c1

Please sign in to comment.