pymcssa.utils

 1import numpy as np
 2import warnings
 3
 4def Tmat(ts, m):
 5        """Construct a trajectory (Hankel) matrix from a 1-D time series.
 6        Each row of the resulting matrix represents a lagged segment of the input
 7        series of length `m`. The matrix has shape (nd, m), where nd = n - m + 1.
 8        
 9        Args:
10        ts (array-like): 1-D time series of length n.
11        m (int): Window length (embedding dimension). Must satisfy 1 < m <= n.
12        
13        Returns:
14        ndarray: Trajectory matrix of shape (nd, m).
15        
16        Raises:
17        ValueError: If m > n.
18        
19        Warns:
20        UserWarning: If m >= n/2, which may lead to reduced separability of 
21                     components in SSA or MCSSA analysis.
22        """
23        ts = np.asarray(ts)
24        n=len(ts)
25        if m>n:
26            raise ValueError("Window length m cannot exceed time series length .")
27        if m >= n/2:
28             warnings.warn("Window length m is large (m ≥ n/2); "
29                           "this may reduce separability of components.",UserWarning)
30
31        nd=n-m+1
32        T=np.zeros((nd,m))
33        for i in range(np.shape(T)[0]):
34            for j in range(np.shape(T)[1]):
35                T[i,j]=ts[i+j]
36        return T
def Tmat(ts, m):
 5def Tmat(ts, m):
 6        """Construct a trajectory (Hankel) matrix from a 1-D time series.
 7        Each row of the resulting matrix represents a lagged segment of the input
 8        series of length `m`. The matrix has shape (nd, m), where nd = n - m + 1.
 9        
10        Args:
11        ts (array-like): 1-D time series of length n.
12        m (int): Window length (embedding dimension). Must satisfy 1 < m <= n.
13        
14        Returns:
15        ndarray: Trajectory matrix of shape (nd, m).
16        
17        Raises:
18        ValueError: If m > n.
19        
20        Warns:
21        UserWarning: If m >= n/2, which may lead to reduced separability of 
22                     components in SSA or MCSSA analysis.
23        """
24        ts = np.asarray(ts)
25        n=len(ts)
26        if m>n:
27            raise ValueError("Window length m cannot exceed time series length .")
28        if m >= n/2:
29             warnings.warn("Window length m is large (m ≥ n/2); "
30                           "this may reduce separability of components.",UserWarning)
31
32        nd=n-m+1
33        T=np.zeros((nd,m))
34        for i in range(np.shape(T)[0]):
35            for j in range(np.shape(T)[1]):
36                T[i,j]=ts[i+j]
37        return T

Construct a trajectory (Hankel) matrix from a 1-D time series. Each row of the resulting matrix represents a lagged segment of the input series of length m. The matrix has shape (nd, m), where nd = n - m + 1.

Args: ts (array-like): 1-D time series of length n. m (int): Window length (embedding dimension). Must satisfy 1 < m <= n.

Returns: ndarray: Trajectory matrix of shape (nd, m).

Raises: ValueError: If m > n.

Warns: UserWarning: If m >= n/2, which may lead to reduced separability of components in SSA or MCSSA analysis.