scipy: eig() returns only two eigenvectores similart to MATLAB and the rest do not make sense when compared with MATLAB eig()
This is what I’m comparing Scipy with:
In the Matlab link, please go to the “Examples” tab and you’ll see the code I’ve embedded here in Matlab and see the plots.
This is how Singular Spectrum Analysis is done and I need to get the eigenvectors of the decomposition. The 1st and 2nd eigenvectors are similar (acceptable) but from 3rd on, they do not make sense. Am I missing something?
Here is the code I’m running:
M = 30 # window length = embedding dimension
N = 200 # length of generated time series
T = 22 # period length of sine function
stdnoise = 1 # noise-to-signal ratio
t = np.arange(0,N)
X = np.sin(2*np.pi*t/T)
noise = np.random.normal(0, 1, size=N)
X = X+noise
X = X-np.mean(X)
X = X/np.std(X)
plt.plot(t, X)
Y = np.zeros((N-M+1,M))
for m in range(1,M):
Y[:,m] = X[m-1:(N-M+1)+m-1]
Cemb = np.dot(Y.T,Y)/(N-M+1)
Lambda,RHO = la.eig(Cemb)
idx = Lambda.argsort()[::-1]
Lambda = [idx]
RHO = RHO[:,idx]
fig, ax = plt.subplots(figsize=(16,1))
ax.plot(RHO[:,0])
ax.plot(RHO[:,1])
fig, ax = plt.subplots(figsize=(16,1))
ax.plot(RHO[:,2])
ax.plot(RHO[:,3])
The problem is the periodics/cycles/frequncy of RHO[:,0],RHO[:,1] matches the MATLAB code but RHO[:,2],RHO[:,3] etc. don’t. May be I missed something but this result is odd.
Thanks.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 35 (19 by maintainers)
You can use MATLAB Online for free to confirm the variability of the MATLAB code as well. I just copied the MATLAB code and got the following, which is qualitatively different from what’s plotted in the tutorial, but in line with the results I’ve seen from the Python.
Here’s another: