Skip to content

Commit c8eccc1

Browse files
committed
Ressolve hankel dehankel shaping
1 parent 7b2e997 commit c8eccc1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

pydmd/havok.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,18 @@ def r(self):
278278

279279
def hankel(self, X):
280280
"""
281-
Given a data matrix X as a 2D numpy.ndarray, uses the `_delays`
282-
and `_lag` attributes to return the data as a Hankel matrix.
281+
Given a data matrix X as a 1D or 2D numpy.ndarray, uses the `delays`
282+
and `lag` attributes to return the data as a 2D Hankel matrix.
283283
284-
:param X: (n, m) array of data.
284+
:param X: (m,) or (n, m) array of data.
285285
:type X: numpy.ndarray
286286
:return: Hankel matrix of data.
287287
:rtype: numpy.ndarray
288288
"""
289-
if not isinstance(X, np.ndarray) or X.ndim != 2:
290-
raise ValueError("Please ensure that input data is a 2D array.")
289+
if not isinstance(X, np.ndarray) or X.ndim > 2:
290+
raise ValueError("Data must be a 1D or 2D numpy array.")
291+
if X.ndim == 1:
292+
X = X[None]
291293
n, m = X.shape
292294

293295
# Check that the input data contains enough observations.
@@ -308,23 +310,25 @@ def hankel(self, X):
308310

309311
def dehankel(self, H):
310312
"""
311-
Given a Hankel matrix H as a 2D numpy.ndarray, uses the `_delays`
312-
and `_lag` attributes to unravel the data in the Hankel matrix.
313+
Given a Hankel matrix H as a 2D numpy.ndarray, uses the `delays`
314+
and `lag` attributes to unravel the data in the Hankel matrix.
313315
314316
:param H: Hankel matrix of data.
315317
:type H: numpy.ndarray
316-
:return: de-Hankeled (n, m) array of data.
318+
:return: de-Hankeled (m,) or (n, m) array of data.
317319
:rtype: numpy.ndarray
318320
"""
319321
if not isinstance(H, np.ndarray) or H.ndim != 2:
320-
raise ValueError("Please ensure that input data is a 2D array.")
322+
raise ValueError("Data must be a 2D numpy array.")
323+
321324
Hn, Hm = H.shape
322325
n = int(Hn / self._delays)
323326
m = int(Hm + ((self._delays - 1) * self._lag))
324327
X = np.empty((n, m))
325328
for i in range(self._delays):
326329
X[:, i * self._lag : i * self._lag + Hm] = H[i * n : (i + 1) * n]
327-
return X
330+
331+
return np.squeeze(X)
328332

329333
def fit(self, X, t):
330334
"""

0 commit comments

Comments
 (0)