- 积分
- 1626
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-1-5
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 qxsw2016 于 2018-6-9 11:15 编辑
利用1951-1999年浙江的降水指数,进行SSA分析,窗口长度取为M = 10,并重建成分RC1,RC3+RC4.
def ReComponents(n,rc): #重建成分
m = rc.shape[0]
p = rc.shape[1]
y = zeros(n)
for k in arange(n):
if(k<m-1):
y_m = 0
for i in arange(m):
for j in arange(p):
if((i+j)==k):
y_m = y_m + rc[i,j]
y[k] = y_m/(k+1)
elif(k>=m-1 and k<=n-m):
y_m = 0
for i in arange(m):
for j in arange(p):
if((i+j)==k):
y_m = y_m + rc[i,j]
y[k] = y_m/m
else:
y_m = 0
for i in arange(m):
for j in arange(p):
if((i+j)==k):
y_m = y_m +rc[i,j]
y[k] = y_m/(n-k)
return y
fn= 'F:\dataset\ZJJJA.txt'
ncol = numasciicol(fn)
nrow = numasciirow(fn)
#print ncol,nrow
fndata = asciiread(fn,shape=(nrow,ncol))
RJJA = fndata[:,0] #标准化数据
m= 10 #窗口长度或嵌入空间维数
n = 49 #1951-1999
p = n-m+1
S = zeros((m,m))#Toeplitz矩阵
x = zeros((m,p))
c = zeros(m)
#print RJJA
for i in arange(m):
x[i,:] = RJJA[i:i+p] #时迟排列相空间矩阵
for i in arange(m):
c = sum(RJJA[0:n-i]*RJJA[i:n])/(n-i)
for i in arange(m):
for j in arange(i,m):
S[i,j] = c[j-i] #右上
for i in arange(1,m):
for j in arange(0,i):
S[i,j] = S[j,i]
lamda,V = linalg.eig(S)
TC = np.dot(V.T, x)
V = V[:,::-1]
TC = TC[::-1,:]
lamda = lamda[::-1]
#print S
#第一个重建成分rc1
rc1 = np.dot(V[:,0].reshape(m,1),TC[0,:].reshape(1,p))
yk = ReComponents(n,rc1)
xtick = zeros([n])
for i in arange(n):
xtick = i+1951
subplot(2,1,1)
plot(xtick,yk,'b-')
title('RC1')
#第三、四个重建成分rc3、rc4
rc3 = np.dot(V[:,2].reshape(m,1),TC[2,:].reshape(1,p))
rc4 = np.dot(V[:,3].reshape(m,1),TC[3,:].reshape(1,p))
yk = ReComponents(n,rc3)+ReComponents(n,rc4)
subplot(2,1,2)
plot(xtick,yk,'b-')
title('RC3+RC4')
|
|